From 4aa1148bd3ac2a2ffd2f5025db9133dad80b7187 Mon Sep 17 00:00:00 2001 From: yihuang Date: Thu, 29 Apr 2021 15:11:32 +0800 Subject: [PATCH] fix validator address prefix (#9212) Co-authored-by: Marko (cherry picked from commit c94e9eb1bb76d388df5d3d1b12d6759273762884) # Conflicts: # x/staking/keeper/val_state_change.go --- x/staking/keeper/val_state_change.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/x/staking/keeper/val_state_change.go b/x/staking/keeper/val_state_change.go index f06994f44f70..1cbe21723b78 100644 --- a/x/staking/keeper/val_state_change.go +++ b/x/staking/keeper/val_state_change.go @@ -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 @@ -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)