Skip to content

Commit

Permalink
fix(x/slashing/keeper): hoist non-changing addresses parsing out of r…
Browse files Browse the repository at this point in the history
…edelegation loop (#18035)

(cherry picked from commit 7d7d490)

# Conflicts:
#	x/staking/keeper/slash.go
  • Loading branch information
odeke-em authored and mergify[bot] committed Oct 10, 2023
1 parent 8ab33f5 commit 904a6c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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
15 changes: 15 additions & 0 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)

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This definition of valDstAddr is never used.
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)

Check failure on line 293 in x/staking/keeper/slash.go

View workflow job for this annotation

GitHub Actions / dependency-review

delegatorAddress declared and not used

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This definition of delegatorAddress is never used.
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,6 +318,7 @@ func (k Keeper) SlashRedelegation(ctx context.Context, srcValidator types.Valida
continue
}

<<<<<<< HEAD

Check failure on line 321 in x/staking/keeper/slash.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected statement, found '<<'
valDstAddr, err := k.validatorAddressCodec.StringToBytes(redelegation.ValidatorDstAddress)
if err != nil {
panic(err)
Expand All @@ -319,6 +330,10 @@ func (k Keeper) SlashRedelegation(ctx context.Context, srcValidator types.Valida
}

delegation, err := k.GetDelegation(ctx, delegatorAddress, valDstAddr)
=======

Check failure on line 333 in x/staking/keeper/slash.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected statement, found '=='
// 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))

Check failure on line 336 in x/staking/keeper/slash.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'
if err != nil {
// If deleted, delegation has zero shares, and we can't unbond any more
continue
Expand Down

0 comments on commit 904a6c9

Please sign in to comment.