-
Notifications
You must be signed in to change notification settings - Fork 174
/
slashing_violation_consumer.go
60 lines (52 loc) · 1.81 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package notifications
import (
"github.com/rs/zerolog"
"github.com/onflow/flow-go/consensus/hotstuff/model"
"github.com/onflow/flow-go/utils/logging"
)
// SlashingViolationsConsumer is an implementation of the notifications consumer that logs a
// message for any slashable offenses.
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[:]).
Bool(logging.KeySuspicious, true).
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[:]).
Bool(logging.KeySuspicious, true).
Msg("OnInvalidVoteDetected")
}
func (c *SlashingViolationsConsumer) OnVoteForInvalidBlockDetected(vote *model.Vote, proposal *model.Proposal) {
c.log.Warn().
Uint64("vote_view", vote.View).
Hex("voted_block_id", vote.BlockID[:]).
Hex("voter_id", vote.SignerID[:]).
Hex("proposer_id", proposal.Block.ProposerID[:]).
Bool(logging.KeySuspicious, true).
Msg("OnVoteForInvalidBlockDetected")
}
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[:]).
Bool(logging.KeySuspicious, true).
Msg("OnDoubleProposeDetected")
}