LastValidatorPower -> LastValidator

This commit is contained in:
Jae Kwon 2018-10-21 15:28:14 -07:00
parent 015b829a54
commit 5416af8a7a
5 changed files with 16 additions and 16 deletions

View File

@ -19,8 +19,8 @@ var (
IntraTxCounterKey = []byte{0x02} // key for intra-block tx index IntraTxCounterKey = []byte{0x02} // key for intra-block tx index
// Last* values are const during a block. // Last* values are const during a block.
LastValidatorPowerKey = []byte{0x11} // prefix for each key to a validator index, for bonded validators LastValidatorKey = []byte{0x11} // prefix for each key to a validator index, for bonded validators
LastTotalPowerKey = []byte{0x12} // prefix for each key to a validator index, for bonded validators LastTotalPowerKey = []byte{0x12} // prefix for each key to a validator index, for bonded validators
ValidatorsKey = []byte{0x21} // prefix for each key to a validator ValidatorsKey = []byte{0x21} // prefix for each key to a validator
ValidatorsByConsAddrKey = []byte{0x22} // prefix for each key to a validator index, by pubkey ValidatorsByConsAddrKey = []byte{0x22} // prefix for each key to a validator index, by pubkey
@ -52,8 +52,8 @@ func GetValidatorByConsAddrKey(addr sdk.ConsAddress) []byte {
return append(ValidatorsByConsAddrKey, addr.Bytes()...) return append(ValidatorsByConsAddrKey, addr.Bytes()...)
} }
// Get the validator operator address from LastValidatorPowerKey // Get the validator operator address from LastValidatorKey
func AddressFromLastValidatorPowerKey(key []byte) []byte { func AddressFromLastValidatorKey(key []byte) []byte {
return key[1:] // remove prefix bytes return key[1:] // remove prefix bytes
} }
@ -67,8 +67,8 @@ func GetValidatorsByPowerIndexKey(validator types.Validator, pool types.Pool) []
} }
// get the bonded validator index key for an operator address // get the bonded validator index key for an operator address
func GetLastValidatorPowerKey(operator sdk.ValAddress) []byte { func GetLastValidatorKey(operator sdk.ValAddress) []byte {
return append(LastValidatorPowerKey, operator...) return append(LastValidatorKey, operator...)
} }
// get the power ranking of a validator // get the power ranking of a validator

View File

@ -30,10 +30,10 @@ func (k Keeper) IterateValidators(ctx sdk.Context, fn func(index int64, validato
// iterate through the active validator set and perform the provided function // iterate through the active validator set and perform the provided function
func (k Keeper) IterateValidatorsBonded(ctx sdk.Context, fn func(index int64, validator sdk.Validator) (stop bool)) { func (k Keeper) IterateValidatorsBonded(ctx sdk.Context, fn func(index int64, validator sdk.Validator) (stop bool)) {
store := ctx.KVStore(k.storeKey) store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, LastValidatorPowerKey) iterator := sdk.KVStorePrefixIterator(store, LastValidatorKey)
i := int64(0) i := int64(0)
for ; iterator.Valid(); iterator.Next() { for ; iterator.Valid(); iterator.Next() {
address := AddressFromLastValidatorPowerKey(iterator.Key()) address := AddressFromLastValidatorKey(iterator.Key())
validator, found := k.GetValidator(ctx, address) validator, found := k.GetValidator(ctx, address)
if !found { if !found {
panic(fmt.Sprintf("validator record not found for address: %v\n", address)) panic(fmt.Sprintf("validator record not found for address: %v\n", address))

View File

@ -12,7 +12,7 @@ import (
) )
// Apply and return accumulated updates to the bonded validator set. Also, // Apply and return accumulated updates to the bonded validator set. Also,
// * Updates the active bonded valset as keyed by LastValidatorPowerKey(). // * Updates the active bonded valset as keyed by LastValidatorKey().
// * Updates validator status' according to updated powers. // * Updates validator status' according to updated powers.
// * Updates the fee pool bonded vs loose tokens. // * Updates the fee pool bonded vs loose tokens.
// * Updates relevant indices. // * Updates relevant indices.
@ -29,7 +29,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
// Retrieve the last validator set. // Retrieve the last validator set.
// This persistent set is updated later in this function. // This persistent set is updated later in this function.
// (see LastValidatorPowerKey). // (see LastValidatorKey).
last := k.retrieveLastValidatorSet(ctx) last := k.retrieveLastValidatorSet(ctx)
// Iterate over validators, highest power to lowest. // Iterate over validators, highest power to lowest.
@ -81,7 +81,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
delete(last, operatorBytes) delete(last, operatorBytes)
// set the bonded validator index // set the bonded validator index
store.Set(GetLastValidatorPowerKey(operator), newPowerBytes) store.Set(GetLastValidatorKey(operator), newPowerBytes)
// keep count // keep count
count++ count++
@ -106,7 +106,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
} }
// delete from the bonded validator index // delete from the bonded validator index
store.Delete(GetLastValidatorPowerKey(operator)) store.Delete(GetLastValidatorKey(operator))
// update the validator set // update the validator set
updates = append(updates, validator.ABCIValidatorUpdateZero()) updates = append(updates, validator.ABCIValidatorUpdateZero())
@ -249,7 +249,7 @@ type validatorsByAddr map[[sdk.AddrLen]byte][]byte
func (k Keeper) retrieveLastValidatorSet(ctx sdk.Context) validatorsByAddr { func (k Keeper) retrieveLastValidatorSet(ctx sdk.Context) validatorsByAddr {
last := make(validatorsByAddr) last := make(validatorsByAddr)
store := ctx.KVStore(k.storeKey) store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, LastValidatorPowerKey) iterator := sdk.KVStorePrefixIterator(store, LastValidatorKey)
for ; iterator.Valid(); iterator.Next() { for ; iterator.Valid(); iterator.Next() {
var operator [sdk.AddrLen]byte var operator [sdk.AddrLen]byte
copy(operator[:], iterator.Key()[1:]) copy(operator[:], iterator.Key()[1:])

View File

@ -242,7 +242,7 @@ func (k Keeper) GetLastValidators(ctx sdk.Context) (validators []types.Validator
maxValidators := k.MaxValidators(ctx) maxValidators := k.MaxValidators(ctx)
validators = make([]types.Validator, maxValidators) validators = make([]types.Validator, maxValidators)
iterator := sdk.KVStorePrefixIterator(store, LastValidatorPowerKey) iterator := sdk.KVStorePrefixIterator(store, LastValidatorKey)
defer iterator.Close() defer iterator.Close()
i := 0 i := 0
@ -252,7 +252,7 @@ func (k Keeper) GetLastValidators(ctx sdk.Context) (validators []types.Validator
if i >= int(maxValidators) { if i >= int(maxValidators) {
panic("more validators than maxValidators found") panic("more validators than maxValidators found")
} }
address := AddressFromLastValidatorPowerKey(iterator.Key()) address := AddressFromLastValidatorKey(iterator.Key())
validator := k.mustGetValidator(ctx, address) validator := k.mustGetValidator(ctx, address)
validators[i] = validator validators[i] = validator

View File

@ -40,7 +40,7 @@ var (
GetDelegationsKey = keeper.GetDelegationsKey GetDelegationsKey = keeper.GetDelegationsKey
PoolKey = keeper.PoolKey PoolKey = keeper.PoolKey
IntraTxCounterKey = keeper.IntraTxCounterKey IntraTxCounterKey = keeper.IntraTxCounterKey
LastValidatorPowerKey = keeper.LastValidatorPowerKey LastValidatorKey = keeper.LastValidatorKey
LastTotalPowerKey = keeper.LastTotalPowerKey LastTotalPowerKey = keeper.LastTotalPowerKey
ValidatorsKey = keeper.ValidatorsKey ValidatorsKey = keeper.ValidatorsKey
ValidatorsByConsAddrKey = keeper.ValidatorsByConsAddrKey ValidatorsByConsAddrKey = keeper.ValidatorsByConsAddrKey