diff --git a/x/distribution/keeper/delegation.go b/x/distribution/keeper/delegation.go index 8183d95b1a54..4132976ef640 100644 --- a/x/distribution/keeper/delegation.go +++ b/x/distribution/keeper/delegation.go @@ -77,6 +77,7 @@ func (k Keeper) WithdrawDelegationReward(ctx sdk.Context, delegatorAddr sdk.AccA return types.ErrNoDelegationDistInfo(k.codespace) } + // TODO: Reconcile with duplicate code in getDelegatorRewardsAll. height := ctx.BlockHeight() bondedTokens := k.stakeKeeper.TotalPower(ctx) feePool := k.GetFeePool(ctx) @@ -125,6 +126,7 @@ func (k Keeper) getDelegatorRewardsAll(ctx sdk.Context, delAddr sdk.AccAddress, bondedTokens := k.stakeKeeper.TotalPower(ctx) // iterate over all the delegations + // TODO: Reconcile with duplicate code in WithdrawDelegationReward. operationAtDelegation := func(_ int64, del sdk.Delegation) (stop bool) { feePool := k.GetFeePool(ctx) valAddr := del.GetValidator() diff --git a/x/stake/keeper/key.go b/x/stake/keeper/key.go index d5f2fc9d9e33..91ea7d709cde 100644 --- a/x/stake/keeper/key.go +++ b/x/stake/keeper/key.go @@ -61,7 +61,7 @@ func GetValidatorsByPowerIndexKey(validator types.Validator, pool types.Pool) [] } // get the bonded validator index key for an operator address -func GetBondedValidatorIndexKey(operator sdk.ValAddress) []byte { +func GetValidatorsBondedIndexKey(operator sdk.ValAddress) []byte { return append(ValidatorsBondedIndexKey, operator...) } diff --git a/x/stake/keeper/val_state_change.go b/x/stake/keeper/val_state_change.go index e123bb2b0a8e..2c832a8ad2b7 100644 --- a/x/stake/keeper/val_state_change.go +++ b/x/stake/keeper/val_state_change.go @@ -11,7 +11,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/stake/types" ) -// Apply and return accumulated updates to the bonded validator set +// Apply and return accumulated updates to the bonded validator set. Also, +// * Updates the active bonded valset as keyed by GetValidatorsBondedIndexKey(). +// * Updates validator status' according to updated powers. +// * Updates the fee pool bonded vs loose tokens. +// * Updates relevant indices. // // CONTRACT: Only validators with non-zero power or zero-power that were bonded // at the previous block height or were removed from the validator set entirely @@ -21,7 +25,9 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab store := ctx.KVStore(k.storeKey) maxValidators := k.GetParams(ctx).MaxValidators - // retrieve last validator set + // Retrieve the last validator set. + // This persistent set is updated later in this function. + // (see GetValidatorsBondedIndexKey()). last := k.retrieveLastValidatorSet(ctx) // iterate over validators, highest power to lowest @@ -73,7 +79,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab delete(last, operatorBytes) // set the bonded validator index - store.Set(GetBondedValidatorIndexKey(operator), newPowerBytes) + store.Set(GetValidatorsBondedIndexKey(operator), newPowerBytes) // keep count count++ @@ -98,7 +104,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab } // delete from the bonded validator index - store.Delete(GetBondedValidatorIndexKey(operator)) + store.Delete(GetValidatorsBondedIndexKey(operator)) // update the validator set updates = append(updates, validator.ABCIValidatorUpdateZero())