fix(x/slashing/keeper): hoist non-changing addresses parsing out of redelegation loop (backport #18035) (#18037)
Co-authored-by: Emmanuel T Odeke <emmanuel@orijtech.com> Co-authored-by: marbar3778 <marbar3778@yahoo.com>
This commit is contained in:
parent
8ab33f58d7
commit
1f7ec34374
@ -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
|
||||
|
||||
@ -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,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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user