From f869e878a8242157a886f98ee3a98ef403dd33db Mon Sep 17 00:00:00 2001 From: "shiki.takahashi" Date: Wed, 12 Aug 2020 17:20:07 +0900 Subject: [PATCH] add public-key type in sending ValidatorUpdate Tx --- abci/example/kvstore/README.md | 2 +- abci/example/kvstore/persistent_kvstore.go | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/abci/example/kvstore/README.md b/abci/example/kvstore/README.md index bed81a598..de0460390 100644 --- a/abci/example/kvstore/README.md +++ b/abci/example/kvstore/README.md @@ -22,7 +22,7 @@ and the Handshake allows any necessary blocks to be replayed. Validator set changes are effected using the following transaction format: ``` -"val:pubkey1!power1,pubkey2!power2,pubkey3!power3" +"val:composite!pubkey1!power1,composite!pubkey2!power2,composite!pubkey3!power3" ``` where `pubkeyN` is a base64-encoded 32-byte ed25519 key and `powerN` is a new voting power for the validator with `pubkeyN` (possibly a new one). diff --git a/abci/example/kvstore/persistent_kvstore.go b/abci/example/kvstore/persistent_kvstore.go index d9dae5e99..598f5960d 100644 --- a/abci/example/kvstore/persistent_kvstore.go +++ b/abci/example/kvstore/persistent_kvstore.go @@ -166,26 +166,25 @@ func (app *PersistentKVStoreApplication) Validators() (validators []types.Valida func MakeValSetChangeTx(pubkey types.PubKey, power int64) []byte { pubStr := base64.StdEncoding.EncodeToString(pubkey.Data) - return []byte(fmt.Sprintf("val:%s!%d", pubStr, power)) + return []byte(fmt.Sprintf("val:%s!%s!%d", pubkey.Type, pubStr, power)) } func isValidatorTx(tx []byte) bool { return strings.HasPrefix(string(tx), ValidatorSetChangePrefix) } -// format is "val:pubkey!power" +// format is "val:keytype!pubkey!power" // pubkey is a base64-encoded 32-byte ed25519 key func (app *PersistentKVStoreApplication) execValidatorTx(tx []byte) types.ResponseDeliverTx { tx = tx[len(ValidatorSetChangePrefix):] - //get the pubkey and power pubKeyAndPower := strings.Split(string(tx), "!") - if len(pubKeyAndPower) != 2 { + if len(pubKeyAndPower) != 3 { return types.ResponseDeliverTx{ Code: code.CodeTypeEncodingError, - Log: fmt.Sprintf("Expected 'pubkey!power'. Got %v", pubKeyAndPower)} + Log: fmt.Sprintf("Expected 'keytype!pubkey!power'. Got %v", pubKeyAndPower)} } - pubkeyS, powerS := pubKeyAndPower[0], pubKeyAndPower[1] + keytype, pubkeyS, powerS := pubKeyAndPower[0], pubKeyAndPower[1], pubKeyAndPower[2] // decode the pubkey pubkey, err := base64.StdEncoding.DecodeString(pubkeyS) @@ -204,8 +203,7 @@ func (app *PersistentKVStoreApplication) execValidatorTx(tx []byte) types.Respon } // update - // TODO The type of public key to be restored should be kept its original type. - return app.updateValidator(types.NewValidatorUpdate(tmtypes.ABCIPubKeyTypeComposite, pubkey, power)) + return app.updateValidator(types.NewValidatorUpdate(keytype, pubkey, power)) } // add, update, or remove a validator