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): Emit slashing event with the correct reason in SlashWithInfractionReason #16784

Merged
merged 4 commits into from
Jun 30, 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 @@ -71,6 +71,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (x/slashing) [#16784](https://github.com/cosmos/cosmos-sdk/pull/16784) Emit event with the correct reason in SlashWithInfractionReason.
* (x/auth/vesting) [#16733](https://github.com/cosmos/cosmos-sdk/pull/16733) panic on overflowing and negative EndTimes when creating a PeriodicVestingAccount
* [#16547](https://github.com/cosmos/cosmos-sdk/pull/16547) Ensure a transaction's gas limit cannot exceed the block gas limit.
* (x/auth/types) [#16554](https://github.com/cosmos/cosmos-sdk/pull/16554) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking.
Expand Down
10 changes: 9 additions & 1 deletion x/slashing/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,21 @@ func (k Keeper) SlashWithInfractionReason(ctx context.Context, consAddr sdk.Cons
return err
}

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)
}

sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeSlash,
sdk.NewAttribute(types.AttributeKeyAddress, consAddr.String()),
sdk.NewAttribute(types.AttributeKeyPower, fmt.Sprintf("%d", power)),
sdk.NewAttribute(types.AttributeKeyReason, types.AttributeValueDoubleSign),
reasonAttr,
sdk.NewAttribute(types.AttributeKeyBurnedCoins, coinsBurned.String()),
),
)
Expand Down
1 change: 1 addition & 0 deletions x/slashing/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
AttributeKeyMissedBlocks = "missed_blocks"
AttributeKeyBurnedCoins = "burned_coins"

AttributeValueUnspecified = "unspecified"
AttributeValueDoubleSign = "double_sign"
AttributeValueMissingSignature = "missing_signature"
)