Merge PR #4966: Reuse ValidatorsPowerStoreIterator

This commit is contained in:
Xuefeng Zhu 2019-08-29 13:47:55 -07:00 committed by Alexander Bezobchuk
parent 10e49c1479
commit 4581ab342b
1 changed files with 3 additions and 5 deletions

View File

@ -235,11 +235,10 @@ func (k Keeper) GetValidators(ctx sdk.Context, maxRetrieve uint16) (validators [
// get the current group of bonded validators sorted by power-rank
func (k Keeper) GetBondedValidatorsByPower(ctx sdk.Context) []types.Validator {
store := ctx.KVStore(k.storeKey)
maxValidators := k.MaxValidators(ctx)
validators := make([]types.Validator, maxValidators)
iterator := sdk.KVStoreReversePrefixIterator(store, types.ValidatorsByPowerIndexKey)
iterator := k.ValidatorsPowerStoreIterator(ctx)
defer iterator.Close()
i := 0
@ -256,10 +255,9 @@ func (k Keeper) GetBondedValidatorsByPower(ctx sdk.Context) []types.Validator {
}
// returns an iterator for the current validator power store
func (k Keeper) ValidatorsPowerStoreIterator(ctx sdk.Context) (iterator sdk.Iterator) {
func (k Keeper) ValidatorsPowerStoreIterator(ctx sdk.Context) sdk.Iterator {
store := ctx.KVStore(k.storeKey)
iterator = sdk.KVStoreReversePrefixIterator(store, types.ValidatorsByPowerIndexKey)
return iterator
return sdk.KVStoreReversePrefixIterator(store, types.ValidatorsByPowerIndexKey)
}
//_______________________________________________________________________