From 904a6c9aafe6edb104f857171e6f74e93301fe58 Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Tue, 10 Oct 2023 03:15:00 -0700 Subject: [PATCH] fix(x/slashing/keeper): hoist non-changing addresses parsing out of redelegation loop (#18035) (cherry picked from commit 7d7d4907f4cf1f52b97267ade488fd39fe029f8a) # Conflicts: # x/staking/keeper/slash.go --- CHANGELOG.md | 1 + x/staking/keeper/slash.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1730605f5b3e..368fe0e59646 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (x/staking/keeper) [#18035](https://github.com/cosmos/cosmos-sdk/pull/18035) Hoisted out of the redelegation loop, the non-changing validator and delegator addresses parsing. * (keyring) [#17913](https://github.com/cosmos/cosmos-sdk/pull/17913) Add `NewAutoCLIKeyring` for creating an AutoCLI keyring from a SDK keyring. ### Bug Fixes diff --git a/x/staking/keeper/slash.go b/x/staking/keeper/slash.go index 7429e0753220..37c88da0ec3f 100644 --- a/x/staking/keeper/slash.go +++ b/x/staking/keeper/slash.go @@ -285,6 +285,16 @@ func (k Keeper) SlashRedelegation(ctx context.Context, srcValidator types.Valida totalSlashAmount = math.ZeroInt() bondedBurnedAmount, notBondedBurnedAmount := math.ZeroInt(), math.ZeroInt() + valDstAddr, err := k.validatorAddressCodec.StringToBytes(redelegation.ValidatorDstAddress) + if err != nil { + return math.ZeroInt(), fmt.Errorf("SlashRedelegation: could not parse validator destination address: %w", err) + } + + delegatorAddress, err := k.authKeeper.AddressCodec().StringToBytes(redelegation.DelegatorAddress) + if err != nil { + return math.ZeroInt(), fmt.Errorf("SlashRedelegation: could not parse delegator address: %w", err) + } + // perform slashing on all entries within the redelegation for _, entry := range redelegation.Entries { // If redelegation started before this height, stake didn't contribute to infraction @@ -308,6 +318,7 @@ func (k Keeper) SlashRedelegation(ctx context.Context, srcValidator types.Valida continue } +<<<<<<< HEAD valDstAddr, err := k.validatorAddressCodec.StringToBytes(redelegation.ValidatorDstAddress) if err != nil { panic(err) @@ -319,6 +330,10 @@ func (k Keeper) SlashRedelegation(ctx context.Context, srcValidator types.Valida } delegation, err := k.GetDelegation(ctx, delegatorAddress, valDstAddr) +======= + // Delegations can be dynamic hence need to be looked up on every redelegation entry loop. + delegation, err := k.Delegations.Get(ctx, collections.Join(sdk.AccAddress(delegatorAddress), sdk.ValAddress(valDstAddr))) +>>>>>>> 7d7d4907f (fix(x/slashing/keeper): hoist non-changing addresses parsing out of redelegation loop (#18035)) if err != nil { // If deleted, delegation has zero shares, and we can't unbond any more continue