Merge PR #4966: Reuse ValidatorsPowerStoreIterator
This commit is contained in:
parent
10e49c1479
commit
4581ab342b
|
@ -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)
|
||||
}
|
||||
|
||||
//_______________________________________________________________________
|
||||
|
|
Loading…
Reference in New Issue