Skip to content

R4R: Emit Warning Events when Validator Misses Blocks #4629

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

Merged
merged 12 commits into from
Jun 28, 2019
1 change: 1 addition & 0 deletions .pending/improvements/sdk/4629-Added-event-that-get
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4629 Added warning event that gets emitted if validator misses a block.
15 changes: 14 additions & 1 deletion docs/spec/slashing/04_begin_block.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ single slashing period is capped as described in [overview.md](overview.md) unde

## Uptime tracking

At the beginning of each block, we update the signing info for each validator and check if they've dipped below the liveness threshold over the tracked window. If so, they will be slashed by `LivenessSlashAmount` and will be Jailed for `LivenessJailPeriod`. Liveness slashes do NOT lead to a tombstombing.
At the beginning of each block, we update the signing info for each validator and check if they've dipped below the liveness threshold over the tracked window. If so, they will be slashed by `LivenessSlashAmount` and will be Jailed for `LivenessJailPeriod` and an event will be emitted. Liveness slashes do NOT lead to a tombstombing.

If a validator misses a block, a warning event will get emitted.

```
height := block.Height
Expand All @@ -108,6 +110,17 @@ for val in block.Validators:
signInfo.MissedBlocksCounter--
// else previous == val not in block.AbsentValidators, no change

// Emit warning events if Validator misses block
if val in block.AbsentValidators {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeSlash,
sdk.NewAttribute(types.AttributeKeyAddress, consAddr.String()),
sdk.NewAttribute(types.AttributeKeyMissedBlocks, fmt.Sprintf("%d", signInfo.MissedBlocksCounter)),
),
)
}

// validator must be active for at least SIGNED_BLOCKS_WINDOW
// before they can be automatically unbonded for failing to be
// included in 50% of the recent LastCommits
Expand Down
5 changes: 5 additions & 0 deletions docs/spec/slashing/06_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ The slashing module emits the following events/tags:

- [0] Only included if the validator is jailed.

| Type | Attribute Key | Attribute Value |
|-------|---------------|-----------------------------|
| slash | address | {validatorConsensusAddress} |
| slash | missed_blocks | {missedBlocksCounter} |

## Handlers

### MsgUnjail
Expand Down
2 changes: 1 addition & 1 deletion types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,4 @@ func (pst *thePast) getOp(ver int64) (Op, bool) {
return Op{}, false
}
return pst.ops[ver-1], true
}
}
9 changes: 9 additions & 0 deletions x/slashing/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,16 @@ func (k Keeper) HandleValidatorSignature(ctx sdk.Context, addr crypto.Address, p
// Array value at this index has not changed, no need to update counter
}

// Emit warning event if Validator misses block
if missed {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeSlash,
sdk.NewAttribute(types.AttributeKeyAddress, consAddr.String()),
sdk.NewAttribute(types.AttributeKeyMissedBlocks, fmt.Sprintf("%d", signInfo.MissedBlocksCounter)),
),
)

logger.Info(fmt.Sprintf("Absent validator %s (%v) at height %d, %d missed, threshold %d", addr, pubkey, height, signInfo.MissedBlocksCounter, k.MinSignedPerWindow(ctx)))
}

Expand Down
9 changes: 5 additions & 4 deletions x/slashing/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ package types
var (
EventTypeSlash = "slash"

AttributeKeyAddress = "address"
AttributeKeyPower = "power"
AttributeKeyReason = "reason"
AttributeKeyJailed = "jailed"
AttributeKeyAddress = "address"
AttributeKeyPower = "power"
AttributeKeyReason = "reason"
AttributeKeyJailed = "jailed"
AttributeKeyMissedBlocks = "missed_blocks"

AttributeValueDoubleSign = "double_sign"
AttributeValueMissingSignature = "missing_signature"
Expand Down