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

feat: add coins burned to slash event #9458

Merged
merged 18 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 0 additions & 9 deletions x/slashing/keeper/infractions.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,6 @@ func (k Keeper) HandleValidatorSignature(ctx sdk.Context, addr cryptotypes.Addre
// That's fine since this is just used to filter unbonding delegations & redelegations.
distributionHeight := height - sdk.ValidatorUpdateDelay - 1

ctx.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.AttributeValueMissingSignature),
sdk.NewAttribute(types.AttributeKeyJailed, consAddr.String()),
),
)
k.sk.Slash(ctx, consAddr, distributionHeight, power, k.SlashFractionDowntime(ctx))
k.sk.Jail(ctx, consAddr)

Expand Down
16 changes: 0 additions & 16 deletions x/slashing/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,12 @@ func (k Keeper) GetPubkey(ctx sdk.Context, a cryptotypes.Address) (cryptotypes.P
// Slash attempts to slash a validator. The slash is delegated to the staking
// module to make the necessary validator changes.
func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, fraction sdk.Dec, power, distributionHeight int64) {
ctx.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),
),
)

k.sk.Slash(ctx, consAddr, distributionHeight, power, fraction)
}

// Jail attempts to jail a validator. The slash is delegated to the staking module
// to make the necessary validator changes.
func (k Keeper) Jail(ctx sdk.Context, consAddr sdk.ConsAddress) {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeSlash,
sdk.NewAttribute(types.AttributeKeyJailed, consAddr.String()),
),
)

k.sk.Jail(ctx, consAddr)
}

Expand Down
16 changes: 7 additions & 9 deletions x/slashing/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ package types
// Slashing module event types
const (
EventTypeSlash = "slash"
EventTypeJailed = "jail"
EventTypeLiveness = "liveness"

AttributeKeyAddress = "address"
AttributeKeyHeight = "height"
AttributeKeyPower = "power"
AttributeKeyReason = "reason"
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
AttributeKeyJailed = "jailed"
AttributeKeyMissedBlocks = "missed_blocks"
AttributeKeyAddress = "address"
AttributeKeyHeight = "height"
AttributeKeyPower = "power"
AttributeKeyMissedBlocks = "missed_blocks"
AttributeKeyAmountSlashed = "amount_slashed"

AttributeValueDoubleSign = "double_sign"
AttributeValueMissingSignature = "missing_signature"
AttributeValueCategory = ModuleName
AttributeValueCategory = ModuleName
)
16 changes: 16 additions & 0 deletions x/staking/keeper/slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
types "github.com/cosmos/cosmos-sdk/x/staking/types"
)

Expand Down Expand Up @@ -140,6 +141,15 @@ func (k Keeper) Slash(ctx sdk.Context, consAddr sdk.ConsAddress, infractionHeigh
"slash_factor", slashFactor.String(),
"burned", tokensToBurn,
)
ctx.EventManager().EmitEvent(
sdk.NewEvent(
slashingtypes.EventTypeSlash,
sdk.NewAttribute(slashingtypes.AttributeKeyAddress, consAddr.String()),
sdk.NewAttribute(slashingtypes.AttributeKeyPower, fmt.Sprintf("%d", power)),
sdk.NewAttribute(slashingtypes.AttributeKeyAddress, consAddr.String()),
sdk.NewAttribute(slashingtypes.AttributeKeyAmountSlashed, tokensToBurn.String()),
),
)
}

// jail a validator
Expand All @@ -148,6 +158,12 @@ func (k Keeper) Jail(ctx sdk.Context, consAddr sdk.ConsAddress) {
k.jailValidator(ctx, validator)
logger := k.Logger(ctx)
logger.Info("validator jailed", "validator", consAddr)
ctx.EventManager().EmitEvent(
sdk.NewEvent(
slashingtypes.EventTypeJailed,
sdk.NewAttribute(slashingtypes.AttributeKeyAddress, consAddr.String()),
),
)
}

// unjail a validator
Expand Down