Skip to content

Commit

Permalink
fix validator address prefix (#9212)
Browse files Browse the repository at this point in the history
Co-authored-by: Marko <[email protected]>
(cherry picked from commit c94e9eb)

# Conflicts:
#	x/staking/keeper/val_state_change.go
  • Loading branch information
yihuang authored and mergify-bot committed Apr 29, 2021
1 parent c6f53ef commit 4aa1148
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions x/staking/keeper/val_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,20 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
}

// fetch the old power bytes
<<<<<<< HEAD
var valAddrBytes [sdk.AddrLen]byte

copy(valAddrBytes[:], valAddr[:])
oldPowerBytes, found := last[valAddrBytes]
newPower := validator.ConsensusPower()
=======
valAddrStr, err := sdk.Bech32ifyAddressBytes(sdk.GetConfig().GetBech32ValidatorAddrPrefix(), valAddr)
if err != nil {
return nil, err
}
oldPowerBytes, found := last[valAddrStr]
newPower := validator.ConsensusPower(powerReduction)
>>>>>>> c94e9eb1b... fix validator address prefix (#9212)
newPowerBytes := k.cdc.MustMarshalBinaryBare(&gogotypes.Int64Value{Value: newPower})

// update the validator set if power has changed
Expand Down Expand Up @@ -350,9 +359,19 @@ func (k Keeper) getLastValidatorsByAddr(ctx sdk.Context) validatorsByAddr {
defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
<<<<<<< HEAD
var valAddr [sdk.AddrLen]byte
// extract the validator address from the key (prefix is 1-byte)
copy(valAddr[:], iterator.Key()[1:])
=======
// extract the validator address from the key (prefix is 1-byte, addrLen is 1-byte)
valAddr := types.AddressFromLastValidatorPowerKey(iterator.Key())
valAddrStr, err := sdk.Bech32ifyAddressBytes(sdk.GetConfig().GetBech32ValidatorAddrPrefix(), valAddr)
if err != nil {
return nil, err
}

>>>>>>> c94e9eb1b... fix validator address prefix (#9212)
powerBytes := iterator.Value()
last[valAddr] = make([]byte, len(powerBytes))
copy(last[valAddr], powerBytes)
Expand Down

0 comments on commit 4aa1148

Please sign in to comment.