-
Notifications
You must be signed in to change notification settings - Fork 178
/
log_consumer.go
156 lines (134 loc) · 4.26 KB
/
log_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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package notifications
import (
"github.com/rs/zerolog"
"github.com/onflow/flow-go/consensus/hotstuff/model"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/utils/logging"
)
// LogConsumer is an implementation of the notifications consumer that logs a
// message for each event.
type LogConsumer struct {
log zerolog.Logger
}
func NewLogConsumer(log zerolog.Logger) *LogConsumer {
lc := &LogConsumer{
log: log,
}
return lc
}
func (lc *LogConsumer) OnEventProcessed() {
lc.log.Debug().Msg("event processed")
}
func (lc *LogConsumer) OnBlockIncorporated(block *model.Block) {
lc.logBasicBlockData(lc.log.Debug(), block).
Msg("block incorporated")
}
func (lc *LogConsumer) OnFinalizedBlock(block *model.Block) {
lc.logBasicBlockData(lc.log.Debug(), block).
Msg("block finalized")
}
func (lc *LogConsumer) OnDoubleProposeDetected(block *model.Block, alt *model.Block) {
lc.log.Warn().
Uint64("block_view", block.View).
Hex("block_id", block.BlockID[:]).
Hex("alt_id", alt.BlockID[:]).
Hex("proposer_id", block.ProposerID[:]).
Msg("double proposal detected")
}
func (lc *LogConsumer) OnReceiveVote(currentView uint64, vote *model.Vote) {
lc.log.Debug().
Uint64("cur_view", currentView).
Uint64("vote_view", vote.View).
Hex("vote_id", vote.BlockID[:]).
Hex("voter_id", vote.SignerID[:]).
Msg("processing vote")
}
func (lc *LogConsumer) OnReceiveProposal(currentView uint64, proposal *model.Proposal) {
lc.logBasicBlockData(lc.log.Debug(), proposal.Block).
Uint64("cur_view", currentView).
Msg("processing proposal")
}
func (lc *LogConsumer) OnEnteringView(view uint64, leader flow.Identifier) {
lc.log.Debug().
Uint64("view", view).
Hex("leader", leader[:]).
Msg("view entered")
}
func (lc *LogConsumer) OnQcTriggeredViewChange(qc *flow.QuorumCertificate, newView uint64) {
lc.log.Debug().
Uint64("qc_view", qc.View).
Hex("qc_id", qc.BlockID[:]).
Uint64("new_view", newView).
Msg("QC triggered view change")
}
func (lc *LogConsumer) OnProposingBlock(block *model.Proposal) {
lc.logBasicBlockData(lc.log.Debug(), block.Block).
Msg("proposing block")
}
func (lc *LogConsumer) OnVoting(vote *model.Vote) {
lc.log.Debug().
Uint64("block_view", vote.View).
Hex("block_id", vote.BlockID[:]).
Msg("voting for block")
}
func (lc *LogConsumer) OnQcConstructedFromVotes(qc *flow.QuorumCertificate) {
lc.log.Debug().
Uint64("qc_view", qc.View).
Hex("qc_id", qc.BlockID[:]).
Msg("QC constructed from votes")
}
func (lc *LogConsumer) OnStartingTimeout(info *model.TimerInfo) {
lc.log.Debug().
Uint64("timeout_view", info.View).
Time("timeout_cutoff", info.StartTime.Add(info.Duration)).
Str("timeout_mode", info.Mode.String()).
Msg("timeout started")
}
func (lc *LogConsumer) OnReachedTimeout(info *model.TimerInfo) {
lc.log.Debug().
Uint64("timeout_view", info.View).
Time("timeout_cutoff", info.StartTime.Add(info.Duration)).
Str("timeout_mode", info.Mode.String()).
Msg("timeout reached")
}
func (lc *LogConsumer) OnQcIncorporated(qc *flow.QuorumCertificate) {
lc.log.Debug().
Uint64("qc_view", qc.View).
Hex("qc_id", qc.BlockID[:]).
Msg("QC incorporated")
}
func (lc *LogConsumer) OnForkChoiceGenerated(view uint64, qc *flow.QuorumCertificate) {
lc.log.Debug().
Uint64("proposal_view", view).
Uint64("qc_view", qc.View).
Hex("qc_id", qc.BlockID[:]).
Msg("fork choice generated")
}
func (lc *LogConsumer) OnDoubleVotingDetected(vote *model.Vote, alt *model.Vote) {
lc.log.Warn().
Uint64("vote_view", vote.View).
Hex("vote_id", vote.BlockID[:]).
Hex("alt_id", alt.BlockID[:]).
Hex("voter_id", vote.SignerID[:]).
Msg("double vote detected")
}
func (lc *LogConsumer) OnInvalidVoteDetected(vote *model.Vote) {
lc.log.Warn().
Uint64("vote_view", vote.View).
Hex("vote_id", vote.BlockID[:]).
Hex("voter_id", vote.SignerID[:]).
Msg("invalid vote detected")
}
func (lc *LogConsumer) logBasicBlockData(loggerEvent *zerolog.Event, block *model.Block) *zerolog.Event {
loggerEvent.
Uint64("block_view", block.View).
Hex("block_id", logging.ID(block.BlockID)).
Hex("proposer_id", logging.ID(block.ProposerID)).
Hex("payload_hash", logging.ID(block.PayloadHash))
if block.QC != nil {
loggerEvent.
Uint64("qc_view", block.QC.View).
Hex("qc_id", logging.ID(block.QC.BlockID))
}
return loggerEvent
}