Skip to content

Commit

Permalink
Update naming (BondedValidatorIndex->ValidatorsBondedIndex) and add s…
Browse files Browse the repository at this point in the history
…ome comments
  • Loading branch information
jaekwon committed Oct 21, 2018
1 parent c88fc48 commit 3fa5778
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions x/distribution/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion x/stake/keeper/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}

Expand Down
14 changes: 10 additions & 4 deletions x/stake/keeper/val_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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++
Expand All @@ -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())
Expand Down

0 comments on commit 3fa5778

Please sign in to comment.