-
Notifications
You must be signed in to change notification settings - Fork 175
/
slashing_violation_consumer.go
46 lines (39 loc) · 1.3 KB
/
slashing_violation_consumer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package notifications
import (
"github.com/rs/zerolog"
"github.com/onflow/flow-go/consensus/hotstuff/model"
)
// SlashingViolationsConsumer is an implementation of the notifications consumer that logs a
// message for any slashable offences.
type SlashingViolationsConsumer struct {
NoopConsumer
log zerolog.Logger
}
func NewSlashingViolationsConsumer(log zerolog.Logger) *SlashingViolationsConsumer {
return &SlashingViolationsConsumer{
log: log,
}
}
func (c *SlashingViolationsConsumer) OnDoubleVotingDetected(vote1 *model.Vote, vote2 *model.Vote) {
c.log.Warn().
Uint64("vote_view", vote1.View).
Hex("voter_id", vote1.SignerID[:]).
Hex("voted_block_id1", vote1.BlockID[:]).
Hex("voted_block_id2", vote2.BlockID[:]).
Msg("OnDoubleVotingDetected")
}
func (c *SlashingViolationsConsumer) OnInvalidVoteDetected(vote *model.Vote) {
c.log.Warn().
Uint64("vote_view", vote.View).
Hex("voted_block_id", vote.BlockID[:]).
Hex("voter_id", vote.SignerID[:]).
Msg("OnInvalidVoteDetected")
}
func (c *SlashingViolationsConsumer) OnDoubleProposeDetected(block1 *model.Block, block2 *model.Block) {
c.log.Warn().
Hex("proposer_id", block1.ProposerID[:]).
Uint64("block_view", block1.View).
Hex("block_id1", block1.BlockID[:]).
Hex("block_id2", block2.BlockID[:]).
Msg("OnDoubleProposeDetected")
}