-
Notifications
You must be signed in to change notification settings - Fork 176
/
slashing_violation_consumer.go
99 lines (88 loc) · 3.39 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package notifications
import (
"github.com/rs/zerolog"
"github.com/onflow/flow-go/consensus/hotstuff"
"github.com/onflow/flow-go/consensus/hotstuff/model"
"github.com/onflow/flow-go/model/flow"
"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 {
log zerolog.Logger
}
var _ hotstuff.ProposalViolationConsumer = (*SlashingViolationsConsumer)(nil)
var _ hotstuff.VoteAggregationViolationConsumer = (*SlashingViolationsConsumer)(nil)
var _ hotstuff.TimeoutAggregationViolationConsumer = (*SlashingViolationsConsumer)(nil)
func NewSlashingViolationsConsumer(log zerolog.Logger) *SlashingViolationsConsumer {
return &SlashingViolationsConsumer{
log: log,
}
}
func (c *SlashingViolationsConsumer) OnInvalidBlockDetected(err flow.Slashable[model.InvalidProposalError]) {
block := err.Message.InvalidProposal.Block
c.log.Warn().
Bool(logging.KeySuspicious, true).
Hex("origin_id", err.OriginID[:]).
Hex("proposer_id", block.ProposerID[:]).
Uint64("block_view", block.View).
Hex("block_id", block.BlockID[:]).
Hex("block_payloadhash", block.PayloadHash[:]).
Time("block_timestamp", block.Timestamp).
Msgf("OnInvalidBlockDetected: %s", err.Message.Error())
}
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(err model.InvalidVoteError) {
vote := err.Vote
c.log.Warn().
Uint64("vote_view", vote.View).
Hex("voted_block_id", vote.BlockID[:]).
Hex("voter_id", vote.SignerID[:]).
Str("err", err.Error()).
Bool(logging.KeySuspicious, true).
Msg("OnInvalidVoteDetected")
}
func (c *SlashingViolationsConsumer) OnDoubleTimeoutDetected(timeout *model.TimeoutObject, altTimeout *model.TimeoutObject) {
c.log.Warn().
Bool(logging.KeySuspicious, true).
Hex("timeout_creator", timeout.SignerID[:]).
Uint64("timeout_view", timeout.View).
Hex("timeout_id1", logging.ID(timeout.ID())).
Hex("timeout_id2", logging.ID(altTimeout.ID())).
Msg("OnDoubleTimeoutDetected")
}
func (c *SlashingViolationsConsumer) OnInvalidTimeoutDetected(err model.InvalidTimeoutError) {
timeout := err.Timeout
c.log.Warn().
Uint64("timeout_view", timeout.View).
Hex("signer_id", timeout.SignerID[:]).
Str("err", err.Error()).
Bool(logging.KeySuspicious, true).
Msg("OnInvalidTimeoutDetected")
}
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")
}