Skip to content

Commit

Permalink
fix: Use bytes instead of string comparison in delete validator queue…
Browse files Browse the repository at this point in the history
… (backport cosmos/cosmos-sdk#12303) (backport #1301) (#1309)

* 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>
(cherry picked from commit 1038a39)

# Conflicts:
#	CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Youngtaek Yoon <noreply@yoon.mailer.me>
  • Loading branch information
mergify[bot] and 0Tech committed Mar 29, 2024
1 parent a496d32 commit 506f8ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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

Expand Down
16 changes: 14 additions & 2 deletions x/staking/keeper/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down

0 comments on commit 506f8ff

Please sign in to comment.