Skip to content

Commit

Permalink
LastValidatorPower -> LastValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
jaekwon committed Oct 21, 2018
1 parent 015b829 commit 5416af8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions x/stake/keeper/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var (
IntraTxCounterKey = []byte{0x02} // key for intra-block tx index

// Last* values are const during a block.
LastValidatorPowerKey = []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
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

ValidatorsKey = []byte{0x21} // prefix for each key to a validator
ValidatorsByConsAddrKey = []byte{0x22} // prefix for each key to a validator index, by pubkey
Expand Down Expand Up @@ -52,8 +52,8 @@ func GetValidatorByConsAddrKey(addr sdk.ConsAddress) []byte {
return append(ValidatorsByConsAddrKey, addr.Bytes()...)
}

// Get the validator operator address from LastValidatorPowerKey
func AddressFromLastValidatorPowerKey(key []byte) []byte {
// Get the validator operator address from LastValidatorKey
func AddressFromLastValidatorKey(key []byte) []byte {
return key[1:] // remove prefix bytes
}

Expand All @@ -67,8 +67,8 @@ func GetValidatorsByPowerIndexKey(validator types.Validator, pool types.Pool) []
}

// get the bonded validator index key for an operator address
func GetLastValidatorPowerKey(operator sdk.ValAddress) []byte {
return append(LastValidatorPowerKey, operator...)
func GetLastValidatorKey(operator sdk.ValAddress) []byte {
return append(LastValidatorKey, operator...)
}

// get the power ranking of a validator
Expand Down
4 changes: 2 additions & 2 deletions x/stake/keeper/sdk_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
func (k Keeper) IterateValidatorsBonded(ctx sdk.Context, fn func(index int64, validator sdk.Validator) (stop bool)) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, LastValidatorPowerKey)
iterator := sdk.KVStorePrefixIterator(store, LastValidatorKey)
i := int64(0)
for ; iterator.Valid(); iterator.Next() {
address := AddressFromLastValidatorPowerKey(iterator.Key())
address := AddressFromLastValidatorKey(iterator.Key())
validator, found := k.GetValidator(ctx, address)
if !found {
panic(fmt.Sprintf("validator record not found for address: %v\n", address))
Expand Down
10 changes: 5 additions & 5 deletions x/stake/keeper/val_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// 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 the fee pool bonded vs loose tokens.
// * Updates relevant indices.
Expand All @@ -29,7 +29,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab

// Retrieve the last validator set.
// This persistent set is updated later in this function.
// (see LastValidatorPowerKey).
// (see LastValidatorKey).
last := k.retrieveLastValidatorSet(ctx)

// Iterate over validators, highest power to lowest.
Expand Down Expand Up @@ -81,7 +81,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
delete(last, operatorBytes)

// set the bonded validator index
store.Set(GetLastValidatorPowerKey(operator), newPowerBytes)
store.Set(GetLastValidatorKey(operator), newPowerBytes)

// keep count
count++
Expand All @@ -106,7 +106,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
}

// delete from the bonded validator index
store.Delete(GetLastValidatorPowerKey(operator))
store.Delete(GetLastValidatorKey(operator))

// update the validator set
updates = append(updates, validator.ABCIValidatorUpdateZero())
Expand Down Expand Up @@ -249,7 +249,7 @@ type validatorsByAddr map[[sdk.AddrLen]byte][]byte
func (k Keeper) retrieveLastValidatorSet(ctx sdk.Context) validatorsByAddr {
last := make(validatorsByAddr)
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, LastValidatorPowerKey)
iterator := sdk.KVStorePrefixIterator(store, LastValidatorKey)
for ; iterator.Valid(); iterator.Next() {
var operator [sdk.AddrLen]byte
copy(operator[:], iterator.Key()[1:])
Expand Down
4 changes: 2 additions & 2 deletions x/stake/keeper/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (k Keeper) GetLastValidators(ctx sdk.Context) (validators []types.Validator
maxValidators := k.MaxValidators(ctx)
validators = make([]types.Validator, maxValidators)

iterator := sdk.KVStorePrefixIterator(store, LastValidatorPowerKey)
iterator := sdk.KVStorePrefixIterator(store, LastValidatorKey)
defer iterator.Close()

i := 0
Expand All @@ -252,7 +252,7 @@ func (k Keeper) GetLastValidators(ctx sdk.Context) (validators []types.Validator
if i >= int(maxValidators) {
panic("more validators than maxValidators found")
}
address := AddressFromLastValidatorPowerKey(iterator.Key())
address := AddressFromLastValidatorKey(iterator.Key())
validator := k.mustGetValidator(ctx, address)

validators[i] = validator
Expand Down
2 changes: 1 addition & 1 deletion x/stake/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var (
GetDelegationsKey = keeper.GetDelegationsKey
PoolKey = keeper.PoolKey
IntraTxCounterKey = keeper.IntraTxCounterKey
LastValidatorPowerKey = keeper.LastValidatorPowerKey
LastValidatorKey = keeper.LastValidatorKey
LastTotalPowerKey = keeper.LastTotalPowerKey
ValidatorsKey = keeper.ValidatorsKey
ValidatorsByConsAddrKey = keeper.ValidatorsByConsAddrKey
Expand Down

0 comments on commit 5416af8

Please sign in to comment.