Skip to content

Commit

Permalink
Merge PR cosmos#4629: Emit Warning Events when Validator Misses Blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaSripal authored and alexanderbez committed Jun 28, 2019
1 parent a579156 commit f9dea98
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
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.
16 changes: 15 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`. 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,18 @@ 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(
NewEvent(
EventTypeLiveness,
NewAttribute(AttributeKeyAddress, consAddr),
NewAttribute(AttributeKeyMissedBlocks, signInfo.MissedBlocksCounter),
NewAttribute(AttributeKeyHeight, ctx.BlockHeight())
),
)
}
// 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
6 changes: 6 additions & 0 deletions docs/spec/slashing/06_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ The slashing module emits the following events/tags:

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

| Type | Attribute Key | Attribute Value |
|----------|---------------|-----------------------------|
| liveness | address | {validatorConsensusAddress} |
| liveness | missed_blocks | {missedBlocksCounter} |
| liveness | height | {blockHeight} |

## 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 @@ -184,6 +184,15 @@ func (k Keeper) HandleValidatorSignature(ctx sdk.Context, addr crypto.Address, p
}

if missed {
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeLiveness,
sdk.NewAttribute(types.AttributeKeyAddress, consAddr.String()),
sdk.NewAttribute(types.AttributeKeyMissedBlocks, fmt.Sprintf("%d", signInfo.MissedBlocksCounter)),
sdk.NewAttribute(types.AttributeKeyHeight, fmt.Sprintf("%d", height)),
),
)

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
13 changes: 8 additions & 5 deletions x/slashing/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package types

// Slashing module event types
var (
EventTypeSlash = "slash"
EventTypeSlash = "slash"
EventTypeLiveness = "liveness"

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

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

0 comments on commit f9dea98

Please sign in to comment.