fix(x/slashing/keeper): hoist non-changing addresses parsing out of redelegation loop (#18035)
This commit is contained in:
@@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||||||
|
|
||||||
### Improvements
|
### 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.
|
* (keyring) [#17913](https://github.com/cosmos/cosmos-sdk/pull/17913) Add `NewAutoCLIKeyring` for creating an AutoCLI keyring from a SDK keyring.
|
||||||
* (codec) [#17913](https://github.com/cosmos/cosmos-sdk/pull/17913) `codectypes.NewAnyWithValue` supports proto v2 messages.
|
* (codec) [#17913](https://github.com/cosmos/cosmos-sdk/pull/17913) `codectypes.NewAnyWithValue` supports proto v2 messages.
|
||||||
* (client) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) Add `client.Context{}.WithAddressCodec`, `WithValidatorAddressCodec`, `WithConsensusAddressCodec` to provide address codecs to the client context. See the [UPGRADING.md](./UPGRADING.md) for more details.
|
* (client) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) Add `client.Context{}.WithAddressCodec`, `WithValidatorAddressCodec`, `WithConsensusAddressCodec` to provide address codecs to the client context. See the [UPGRADING.md](./UPGRADING.md) for more details.
|
||||||
|
|||||||
+11
-10
@@ -287,6 +287,16 @@ func (k Keeper) SlashRedelegation(ctx context.Context, srcValidator types.Valida
|
|||||||
totalSlashAmount = math.ZeroInt()
|
totalSlashAmount = math.ZeroInt()
|
||||||
bondedBurnedAmount, notBondedBurnedAmount := math.ZeroInt(), 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
|
// perform slashing on all entries within the redelegation
|
||||||
for _, entry := range redelegation.Entries {
|
for _, entry := range redelegation.Entries {
|
||||||
// If redelegation started before this height, stake didn't contribute to infraction
|
// If redelegation started before this height, stake didn't contribute to infraction
|
||||||
@@ -310,16 +320,7 @@ func (k Keeper) SlashRedelegation(ctx context.Context, srcValidator types.Valida
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
valDstAddr, err := k.validatorAddressCodec.StringToBytes(redelegation.ValidatorDstAddress)
|
// Delegations can be dynamic hence need to be looked up on every redelegation entry loop.
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
delegatorAddress, err := k.authKeeper.AddressCodec().StringToBytes(redelegation.DelegatorAddress)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
delegation, err := k.Delegations.Get(ctx, collections.Join(sdk.AccAddress(delegatorAddress), sdk.ValAddress(valDstAddr)))
|
delegation, err := k.Delegations.Get(ctx, collections.Join(sdk.AccAddress(delegatorAddress), sdk.ValAddress(valDstAddr)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If deleted, delegation has zero shares, and we can't unbond any more
|
// If deleted, delegation has zero shares, and we can't unbond any more
|
||||||
|
|||||||
Reference in New Issue
Block a user