github.com/onflow/flow-go@v0.33.17/consensus/hotstuff/notifications/slashing_violation_consumer.go (about) 1 package notifications 2 3 import ( 4 "github.com/rs/zerolog" 5 6 "github.com/onflow/flow-go/consensus/hotstuff" 7 "github.com/onflow/flow-go/consensus/hotstuff/model" 8 "github.com/onflow/flow-go/model/flow" 9 "github.com/onflow/flow-go/utils/logging" 10 ) 11 12 // SlashingViolationsConsumer is an implementation of the notifications consumer that logs a 13 // message for any slashable offenses. 14 type SlashingViolationsConsumer struct { 15 log zerolog.Logger 16 } 17 18 var _ hotstuff.ProposalViolationConsumer = (*SlashingViolationsConsumer)(nil) 19 var _ hotstuff.VoteAggregationViolationConsumer = (*SlashingViolationsConsumer)(nil) 20 var _ hotstuff.TimeoutAggregationViolationConsumer = (*SlashingViolationsConsumer)(nil) 21 22 func NewSlashingViolationsConsumer(log zerolog.Logger) *SlashingViolationsConsumer { 23 return &SlashingViolationsConsumer{ 24 log: log, 25 } 26 } 27 func (c *SlashingViolationsConsumer) OnInvalidBlockDetected(err flow.Slashable[model.InvalidProposalError]) { 28 block := err.Message.InvalidProposal.Block 29 c.log.Warn(). 30 Bool(logging.KeySuspicious, true). 31 Hex("origin_id", err.OriginID[:]). 32 Hex("proposer_id", block.ProposerID[:]). 33 Uint64("block_view", block.View). 34 Hex("block_id", block.BlockID[:]). 35 Hex("block_payloadhash", block.PayloadHash[:]). 36 Time("block_timestamp", block.Timestamp). 37 Msgf("OnInvalidBlockDetected: %s", err.Message.Error()) 38 } 39 40 func (c *SlashingViolationsConsumer) OnDoubleVotingDetected(vote1 *model.Vote, vote2 *model.Vote) { 41 c.log.Warn(). 42 Uint64("vote_view", vote1.View). 43 Hex("voter_id", vote1.SignerID[:]). 44 Hex("voted_block_id1", vote1.BlockID[:]). 45 Hex("voted_block_id2", vote2.BlockID[:]). 46 Bool(logging.KeySuspicious, true). 47 Msg("OnDoubleVotingDetected") 48 } 49 50 func (c *SlashingViolationsConsumer) OnInvalidVoteDetected(err model.InvalidVoteError) { 51 vote := err.Vote 52 c.log.Warn(). 53 Uint64("vote_view", vote.View). 54 Hex("voted_block_id", vote.BlockID[:]). 55 Hex("voter_id", vote.SignerID[:]). 56 Str("err", err.Error()). 57 Bool(logging.KeySuspicious, true). 58 Msg("OnInvalidVoteDetected") 59 } 60 61 func (c *SlashingViolationsConsumer) OnDoubleTimeoutDetected(timeout *model.TimeoutObject, altTimeout *model.TimeoutObject) { 62 c.log.Warn(). 63 Bool(logging.KeySuspicious, true). 64 Hex("timeout_creator", timeout.SignerID[:]). 65 Uint64("timeout_view", timeout.View). 66 Hex("timeout_id1", logging.ID(timeout.ID())). 67 Hex("timeout_id2", logging.ID(altTimeout.ID())). 68 Msg("OnDoubleTimeoutDetected") 69 } 70 71 func (c *SlashingViolationsConsumer) OnInvalidTimeoutDetected(err model.InvalidTimeoutError) { 72 timeout := err.Timeout 73 c.log.Warn(). 74 Uint64("timeout_view", timeout.View). 75 Hex("signer_id", timeout.SignerID[:]). 76 Str("err", err.Error()). 77 Bool(logging.KeySuspicious, true). 78 Msg("OnInvalidTimeoutDetected") 79 } 80 81 func (c *SlashingViolationsConsumer) OnVoteForInvalidBlockDetected(vote *model.Vote, proposal *model.Proposal) { 82 c.log.Warn(). 83 Uint64("vote_view", vote.View). 84 Hex("voted_block_id", vote.BlockID[:]). 85 Hex("voter_id", vote.SignerID[:]). 86 Hex("proposer_id", proposal.Block.ProposerID[:]). 87 Bool(logging.KeySuspicious, true). 88 Msg("OnVoteForInvalidBlockDetected") 89 } 90 91 func (c *SlashingViolationsConsumer) OnDoubleProposeDetected(block1 *model.Block, block2 *model.Block) { 92 c.log.Warn(). 93 Hex("proposer_id", block1.ProposerID[:]). 94 Uint64("block_view", block1.View). 95 Hex("block_id1", block1.BlockID[:]). 96 Hex("block_id2", block2.BlockID[:]). 97 Bool(logging.KeySuspicious, true). 98 Msg("OnDoubleProposeDetected") 99 }