From 1038a394c9cbb7b21740b438cdda8b40b4db4c1a Mon Sep 17 00:00:00 2001 From: Youngtaek Yoon Date: Tue, 26 Mar 2024 12:30:54 +0000 Subject: [PATCH] fix: Use bytes instead of string comparison in delete validator queue (backport cosmos/cosmos-sdk#12303) (#1301) * fix : Use bytes instead of string comparison in delete validator queue (#12303) * Update CHANGELOG.md * Update CHANGELOG.md --------- Co-authored-by: William Chong <6198816+williamchong@users.noreply.github.com> --- 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 fa54a1c1cb..4cbb973ea6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (sec) [\#1302](https://github.com/Finschia/finschia-sdk/pull/1302) remove map iteration non-determinism with keys + sorting * (client) [\#1303](https://github.com/Finschia/finschia-sdk/pull/1303) fix possible overflow in BuildUnsignedTx * (types) [\#1299](https://github.com/Finschia/finschia-sdk/pull/1299) add missing nil checks +* (x/staking) [\#1301](https://github.com/Finschia/finschia-sdk/pull/1301) Use bytes instead of string comparison in delete validator queue (backport cosmos/cosmos-sdk#12303) ### Removed diff --git a/x/staking/keeper/validator.go b/x/staking/keeper/validator.go index a10de577d8..9c5e5fd003 100644 --- a/x/staking/keeper/validator.go +++ b/x/staking/keeper/validator.go @@ -375,9 +375,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()) } }