Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(x/slashing/keeper): hoist non-changing addresses parsing out of redelegation loop (backport #18035) #18037

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions x/staking/keeper/slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -308,16 +318,6 @@ func (k Keeper) SlashRedelegation(ctx context.Context, srcValidator types.Valida
continue
}

valDstAddr, err := k.validatorAddressCodec.StringToBytes(redelegation.ValidatorDstAddress)
if err != nil {
panic(err)
}

delegatorAddress, err := k.authKeeper.AddressCodec().StringToBytes(redelegation.DelegatorAddress)
if err != nil {
panic(err)
}

delegation, err := k.GetDelegation(ctx, delegatorAddress, valDstAddr)
if err != nil {
// If deleted, delegation has zero shares, and we can't unbond any more
Expand Down
Loading