fix(x/slashing): Emit slashing event with the correct reason in SlashWithInfractionReason (backport #16784) (#16793)

This commit is contained in:
mergify[bot] 2023-06-30 20:32:34 +02:00 committed by GitHub
parent d681010fee
commit 398214f28d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/auth) [#16554](https://github.com/cosmos/cosmos-sdk/pull/16554) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking. * (x/auth) [#16554](https://github.com/cosmos/cosmos-sdk/pull/16554) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking.
* [#16588](https://github.com/cosmos/cosmos-sdk/pull/16588) Propogate the Snapshotter's failure to the caller, (it will create a empty snapshot silently before). * [#16588](https://github.com/cosmos/cosmos-sdk/pull/16588) Propogate the Snapshotter's failure to the caller, (it will create a empty snapshot silently before).
* (x/slashing) [#16784](https://github.com/cosmos/cosmos-sdk/pull/16784) Emit event with the correct reason in SlashWithInfractionReason.
## [v0.47.3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.3) - 2023-06-08 ## [v0.47.3](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.3) - 2023-06-08

View File

@ -79,12 +79,21 @@ func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, fraction sdk.De
// module to make the necessary validator changes. It specifies an intraction reason. // module to make the necessary validator changes. It specifies an intraction reason.
func (k Keeper) SlashWithInfractionReason(ctx sdk.Context, consAddr sdk.ConsAddress, fraction sdk.Dec, power, distributionHeight int64, infraction stakingtypes.Infraction) { func (k Keeper) SlashWithInfractionReason(ctx sdk.Context, consAddr sdk.ConsAddress, fraction sdk.Dec, power, distributionHeight int64, infraction stakingtypes.Infraction) {
coinsBurned := k.sk.SlashWithInfractionReason(ctx, consAddr, distributionHeight, power, fraction, infraction) coinsBurned := k.sk.SlashWithInfractionReason(ctx, consAddr, distributionHeight, power, fraction, infraction)
reasonAttr := sdk.NewAttribute(types.AttributeKeyReason, types.AttributeValueUnspecified)
switch infraction {
case stakingtypes.Infraction_INFRACTION_DOUBLE_SIGN:
reasonAttr = sdk.NewAttribute(types.AttributeKeyReason, types.AttributeValueDoubleSign)
case stakingtypes.Infraction_INFRACTION_DOWNTIME:
reasonAttr = sdk.NewAttribute(types.AttributeKeyReason, types.AttributeValueMissingSignature)
}
ctx.EventManager().EmitEvent( ctx.EventManager().EmitEvent(
sdk.NewEvent( sdk.NewEvent(
types.EventTypeSlash, types.EventTypeSlash,
sdk.NewAttribute(types.AttributeKeyAddress, consAddr.String()), sdk.NewAttribute(types.AttributeKeyAddress, consAddr.String()),
sdk.NewAttribute(types.AttributeKeyPower, fmt.Sprintf("%d", power)), sdk.NewAttribute(types.AttributeKeyPower, fmt.Sprintf("%d", power)),
sdk.NewAttribute(types.AttributeKeyReason, types.AttributeValueDoubleSign), reasonAttr,
sdk.NewAttribute(types.AttributeKeyBurnedCoins, coinsBurned.String()), sdk.NewAttribute(types.AttributeKeyBurnedCoins, coinsBurned.String()),
), ),
) )

View File

@ -13,6 +13,7 @@ const (
AttributeKeyMissedBlocks = "missed_blocks" AttributeKeyMissedBlocks = "missed_blocks"
AttributeKeyBurnedCoins = "burned_coins" AttributeKeyBurnedCoins = "burned_coins"
AttributeValueUnspecified = "unspecified"
AttributeValueDoubleSign = "double_sign" AttributeValueDoubleSign = "double_sign"
AttributeValueMissingSignature = "missing_signature" AttributeValueMissingSignature = "missing_signature"
) )