Skip to content

Commit

Permalink
Merge pull request #116 from line/fix/missing_publickey_type
Browse files Browse the repository at this point in the history
add public-key type in sending ValidatorUpdate Tx
  • Loading branch information
shiki-tak authored Aug 20, 2020
2 parents 40a2944 + f869e87 commit 48cc715
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion abci/example/kvstore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
14 changes: 6 additions & 8 deletions abci/example/kvstore/persistent_kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 48cc715

Please sign in to comment.