From d36dda026748c8ababeb5cfd3890ad22bd39fd6d Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Fri, 6 Jul 2018 20:29:39 -0400 Subject: [PATCH] address cwgoes comments --- x/stake/keeper/validator.go | 12 ++++++++---- x/stake/keeper/validator_test.go | 3 +-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/x/stake/keeper/validator.go b/x/stake/keeper/validator.go index bd5ee4a62..233c7b6e8 100644 --- a/x/stake/keeper/validator.go +++ b/x/stake/keeper/validator.go @@ -303,7 +303,7 @@ func (k Keeper) UpdateBondedValidators(ctx sdk.Context, // TODO benchmark if we should read the current power and not write if it's the same if bondedValidatorsCount == int(maxValidators) { // is cliff validator k.setCliffValidator(ctx, validator, k.GetPool(ctx)) - } else { + } else if len(oldCliffValidatorAddr) > 0 { k.clearCliffValidator(ctx) } break @@ -409,10 +409,14 @@ func (k Keeper) UpdateBondedValidatorsFull(ctx sdk.Context) { validator = k.bondValidator(ctx, validator) } - if validator.Revoked && validator.Status() == sdk.Bonded { - panic(fmt.Sprintf("revoked validator cannot be bonded, address: %v\n", ownerAddr)) + if !validator.Revoked { + bondedValidatorsCount++ + } else { + if validator.Status() == sdk.Bonded { + panic(fmt.Sprintf("revoked validator cannot be bonded, address: %v\n", ownerAddr)) + } } - bondedValidatorsCount++ + iterator.Next() } iterator.Close() diff --git a/x/stake/keeper/validator_test.go b/x/stake/keeper/validator_test.go index f29fba7eb..41aca3ea5 100644 --- a/x/stake/keeper/validator_test.go +++ b/x/stake/keeper/validator_test.go @@ -634,8 +634,7 @@ func TestGetTendermintUpdatesInserted(t *testing.T) { require.Equal(t, validators[4].ABCIValidator(), updates[0]) } -//TODO why is this called NotValidatorCliff? -func TestGetTendermintUpdatesNotValidatorCliff(t *testing.T) { +func TestGetTendermintUpdatesWithCliffValidator(t *testing.T) { ctx, _, keeper := CreateTestInput(t, false, 1000) params := types.DefaultParams() params.MaxValidators = 2