github.com/koko1123/flow-go-1@v0.29.6/consensus/hotstuff/notifications/slashing_violation_consumer.go (about) 1 package notifications 2 3 import ( 4 "github.com/rs/zerolog" 5 6 "github.com/koko1123/flow-go-1/consensus/hotstuff/model" 7 "github.com/koko1123/flow-go-1/utils/logging" 8 ) 9 10 // SlashingViolationsConsumer is an implementation of the notifications consumer that logs a 11 // message for any slashable offenses. 12 type SlashingViolationsConsumer struct { 13 NoopConsumer 14 log zerolog.Logger 15 } 16 17 func NewSlashingViolationsConsumer(log zerolog.Logger) *SlashingViolationsConsumer { 18 return &SlashingViolationsConsumer{ 19 log: log, 20 } 21 } 22 23 func (c *SlashingViolationsConsumer) OnDoubleVotingDetected(vote1 *model.Vote, vote2 *model.Vote) { 24 c.log.Warn(). 25 Uint64("vote_view", vote1.View). 26 Hex("voter_id", vote1.SignerID[:]). 27 Hex("voted_block_id1", vote1.BlockID[:]). 28 Hex("voted_block_id2", vote2.BlockID[:]). 29 Bool(logging.KeySuspicious, true). 30 Msg("OnDoubleVotingDetected") 31 } 32 33 func (c *SlashingViolationsConsumer) OnInvalidVoteDetected(vote *model.Vote) { 34 c.log.Warn(). 35 Uint64("vote_view", vote.View). 36 Hex("voted_block_id", vote.BlockID[:]). 37 Hex("voter_id", vote.SignerID[:]). 38 Bool(logging.KeySuspicious, true). 39 Msg("OnInvalidVoteDetected") 40 } 41 42 func (c *SlashingViolationsConsumer) OnVoteForInvalidBlockDetected(vote *model.Vote, proposal *model.Proposal) { 43 c.log.Warn(). 44 Uint64("vote_view", vote.View). 45 Hex("voted_block_id", vote.BlockID[:]). 46 Hex("voter_id", vote.SignerID[:]). 47 Hex("proposer_id", proposal.Block.ProposerID[:]). 48 Bool(logging.KeySuspicious, true). 49 Msg("OnVoteForInvalidBlockDetected") 50 } 51 52 func (c *SlashingViolationsConsumer) OnDoubleProposeDetected(block1 *model.Block, block2 *model.Block) { 53 c.log.Warn(). 54 Hex("proposer_id", block1.ProposerID[:]). 55 Uint64("block_view", block1.View). 56 Hex("block_id1", block1.BlockID[:]). 57 Hex("block_id2", block2.BlockID[:]). 58 Bool(logging.KeySuspicious, true). 59 Msg("OnDoubleProposeDetected") 60 }