From c1aeb08e4bcebf8a8641cae054b67c5d9acc8c54 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Wed, 4 Jul 2018 13:21:29 +0400 Subject: [PATCH] return error if power is negative Refs #1893 --- state/execution.go | 4 ++++ state/execution_test.go | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/state/execution.go b/state/execution.go index a36cbfb72..941053316 100644 --- a/state/execution.go +++ b/state/execution.go @@ -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 { diff --git a/state/execution_test.go b/state/execution_test.go index 6b8a7e9e6..5e0072c30 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -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 {