Browse Source

return error if power is negative

Refs #1893
pull/1898/head
Anton Kaliaev 6 years ago
parent
commit
c1aeb08e4b
No known key found for this signature in database GPG Key ID: 7B6881D965918214
2 changed files with 14 additions and 0 deletions
  1. +4
    -0
      state/execution.go
  2. +10
    -0
      state/execution_test.go

+ 4
- 0
state/execution.go View File

@ -278,6 +278,10 @@ func updateValidators(currentSet *types.ValidatorSet, abciUpdates []abci.Validat
// these are tendermint types now
for _, valUpdate := range updates {
if valUpdate.VotingPower < 0 {
return fmt.Errorf("Voting power can't be negative %v", valUpdate)
}
address := valUpdate.Address
_, val := currentSet.GetByAddress(address)
if val == nil && valUpdate.VotingPower != 0 {


+ 10
- 0
state/execution_test.go View File

@ -201,6 +201,16 @@ func TestUpdateValidators(t *testing.T) {
types.NewValidatorSet([]*types.Validator{val1}),
true,
},
{
"adding a validator with negative power results in error",
types.NewValidatorSet([]*types.Validator{val1}),
[]abci.Validator{{[]byte{}, types.TM2PB.PubKey(pubkey2), -100}},
types.NewValidatorSet([]*types.Validator{val1}),
true,
},
}
for _, tc := range testCases {


Loading…
Cancel
Save