From 733f629d4b8a6fdc79b01784b4ce2afef3490849 Mon Sep 17 00:00:00 2001 From: William Chong Date: Tue, 21 Jun 2022 23:20:58 +0800 Subject: [PATCH] fix : Use bytes instead of string comparison in delete validator queue --- CHANGELOG.md | 1 + x/staking/keeper/validator.go | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3f0df662cad..8656e8929563 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/authz) [#12184](https://github.com/cosmos/cosmos-sdk/pull/12184) Fix MsgExec not verifying the validity of nested messages. * (x/crisis) [#12208](https://github.com/cosmos/cosmos-sdk/pull/12208) Fix progress index of crisis invariant assertion logs. * (types) [#12229](https://github.com/cosmos/cosmos-sdk/pull/12229) Increase sdk.Dec maxApproxRootIterations to 300 +* (x/staking) [#12303](https://github.com/cosmos/cosmos-sdk/pull/12303) Use bytes instead of string comparison in delete validator queue ## [v0.46.0-rc1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0-rc1) - 2022-05-23 diff --git a/x/staking/keeper/validator.go b/x/staking/keeper/validator.go index 556280575e86..2a55ef43e571 100644 --- a/x/staking/keeper/validator.go +++ b/x/staking/keeper/validator.go @@ -380,9 +380,21 @@ func (k Keeper) DeleteValidatorQueue(ctx sdk.Context, val types.Validator) { addrs := k.GetUnbondingValidators(ctx, val.UnbondingTime, val.UnbondingHeight) newAddrs := []string{} + // since address string may change due to Bech32 prefix change, we parse the addresses into bytes + // format for normalization + deletingAddr, err := sdk.ValAddressFromBech32(val.OperatorAddress) + if err != nil { + panic(err) + } + for _, addr := range addrs { - if addr != val.OperatorAddress { - newAddrs = append(newAddrs, addr) + storedAddr, err := sdk.ValAddressFromBech32(addr) + if err != nil { + // even if we don't panic here, it will panic in UnbondAllMatureValidators at unbond time + panic(err) + } + if !storedAddr.Equals(deletingAddr) { + newAddrs = append(newAddrs, storedAddr.String()) } }