github.com/koko1123/flow-go-1@v0.29.6/consensus/hotstuff/consumer.go (about) 1 package hotstuff 2 3 import ( 4 "github.com/koko1123/flow-go-1/consensus/hotstuff/model" 5 "github.com/koko1123/flow-go-1/model/flow" 6 ) 7 8 // FinalizationConsumer consumes outbound notifications produced by the finalization logic. 9 // Notifications represent finalization-specific state changes which are potentially relevant 10 // to the larger node. The notifications are emitted in the order in which the 11 // finalization algorithm makes the respective steps. 12 // 13 // Implementations must: 14 // - be concurrency safe 15 // - be non-blocking 16 // - handle repetition of the same events (with some processing overhead). 17 type FinalizationConsumer interface { 18 19 // OnBlockIncorporated notifications are produced by the Finalization Logic 20 // whenever a block is incorporated into the consensus state. 21 // Prerequisites: 22 // Implementation must be concurrency safe; Non-blocking; 23 // and must handle repetition of the same events (with some processing overhead). 24 OnBlockIncorporated(*model.Block) 25 26 // OnFinalizedBlock notifications are produced by the Finalization Logic whenever 27 // a block has been finalized. They are emitted in the order the blocks are finalized. 28 // Prerequisites: 29 // Implementation must be concurrency safe; Non-blocking; 30 // and must handle repetition of the same events (with some processing overhead). 31 OnFinalizedBlock(*model.Block) 32 33 // OnDoubleProposeDetected notifications are produced by the Finalization Logic 34 // whenever a double block proposal (equivocation) was detected. 35 // Prerequisites: 36 // Implementation must be concurrency safe; Non-blocking; 37 // and must handle repetition of the same events (with some processing overhead). 38 OnDoubleProposeDetected(*model.Block, *model.Block) 39 } 40 41 // Consumer consumes outbound notifications produced by HotStuff and its components. 42 // Notifications are consensus-internal state changes which are potentially relevant to 43 // the larger node in which HotStuff is running. The notifications are emitted 44 // in the order in which the HotStuff algorithm makes the respective steps. 45 // 46 // Implementations must: 47 // - be concurrency safe 48 // - be non-blocking 49 // - handle repetition of the same events (with some processing overhead). 50 type Consumer interface { 51 FinalizationConsumer 52 53 // OnEventProcessed notifications are produced by the EventHandler when it is done processing 54 // and hands control back to the EventLoop to wait for the next event. 55 // Prerequisites: 56 // Implementation must be concurrency safe; Non-blocking; 57 // and must handle repetition of the same events (with some processing overhead). 58 OnEventProcessed() 59 60 // OnReceiveVote notifications are produced by the EventHandler when it starts processing a vote. 61 // Prerequisites: 62 // Implementation must be concurrency safe; Non-blocking; 63 // and must handle repetition of the same events (with some processing overhead). 64 OnReceiveVote(currentView uint64, vote *model.Vote) 65 66 // OnReceiveProposal notifications are produced by the EventHandler when it starts processing a block. 67 // Prerequisites: 68 // Implementation must be concurrency safe; Non-blocking; 69 // and must handle repetition of the same events (with some processing overhead). 70 OnReceiveProposal(currentView uint64, proposal *model.Proposal) 71 72 // OnEnteringView notifications are produced by the EventHandler when it enters a new view. 73 // Prerequisites: 74 // Implementation must be concurrency safe; Non-blocking; 75 // and must handle repetition of the same events (with some processing overhead). 76 OnEnteringView(viewNumber uint64, leader flow.Identifier) 77 78 // OnQcTriggeredViewChange notifications are produced by PaceMaker when it moves to a new view 79 // based on processing a QC. The arguments specify the qc (first argument), which triggered 80 // the view change, and the newView to which the PaceMaker transitioned (second argument). 81 // Prerequisites: 82 // Implementation must be concurrency safe; Non-blocking; 83 // and must handle repetition of the same events (with some processing overhead). 84 OnQcTriggeredViewChange(qc *flow.QuorumCertificate, newView uint64) 85 86 // OnProposingBlock notifications are produced by the EventHandler when the replica, as 87 // leader for the respective view, proposing a block. 88 // Prerequisites: 89 // Implementation must be concurrency safe; Non-blocking; 90 // and must handle repetition of the same events (with some processing overhead). 91 OnProposingBlock(proposal *model.Proposal) 92 93 // OnVoting notifications are produced by the EventHandler when the replica votes for a block. 94 // Prerequisites: 95 // Implementation must be concurrency safe; Non-blocking; 96 // and must handle repetition of the same events (with some processing overhead). 97 OnVoting(vote *model.Vote) 98 99 // OnQcConstructedFromVotes notifications are produced by the VoteAggregator 100 // component, whenever it constructs a QC from votes. 101 // Prerequisites: 102 // Implementation must be concurrency safe; Non-blocking; 103 // and must handle repetition of the same events (with some processing overhead). 104 OnQcConstructedFromVotes(curView uint64, qc *flow.QuorumCertificate) 105 106 // OnStartingTimeout notifications are produced by PaceMaker. Such a notification indicates that the 107 // PaceMaker is now waiting for the system to (receive and) process blocks or votes. 108 // The specific timeout type is contained in the TimerInfo. 109 // Prerequisites: 110 // Implementation must be concurrency safe; Non-blocking; 111 // and must handle repetition of the same events (with some processing overhead). 112 OnStartingTimeout(*model.TimerInfo) 113 114 // OnReachedTimeout notifications are produced by PaceMaker. Such a notification indicates that the 115 // PaceMaker's timeout was processed by the system. The specific timeout type is contained in the TimerInfo. 116 // Prerequisites: 117 // Implementation must be concurrency safe; Non-blocking; 118 // and must handle repetition of the same events (with some processing overhead). 119 OnReachedTimeout(timeout *model.TimerInfo) 120 121 // OnQcIncorporated notifications are produced by ForkChoice 122 // whenever a quorum certificate is incorporated into the consensus state. 123 // Prerequisites: 124 // Implementation must be concurrency safe; Non-blocking; 125 // and must handle repetition of the same events (with some processing overhead). 126 OnQcIncorporated(*flow.QuorumCertificate) 127 128 // OnForkChoiceGenerated notifications are produced by ForkChoice whenever a fork choice is generated. 129 // The arguments specify the view (first argument) of the block which is to be built and the 130 // quorum certificate (second argument) that is supposed to be in the block. 131 // Prerequisites: 132 // Implementation must be concurrency safe; Non-blocking; 133 // and must handle repetition of the same events (with some processing overhead). 134 OnForkChoiceGenerated(uint64, *flow.QuorumCertificate) 135 136 // OnDoubleVotingDetected notifications are produced by the Vote Aggregation logic 137 // whenever a double voting (same voter voting for different blocks at the same view) was detected. 138 // Prerequisites: 139 // Implementation must be concurrency safe; Non-blocking; 140 // and must handle repetition of the same events (with some processing overhead). 141 OnDoubleVotingDetected(*model.Vote, *model.Vote) 142 143 // OnInvalidVoteDetected notifications are produced by the Vote Aggregation logic 144 // whenever an invalid vote was detected. 145 // Prerequisites: 146 // Implementation must be concurrency safe; Non-blocking; 147 // and must handle repetition of the same events (with some processing overhead). 148 OnInvalidVoteDetected(*model.Vote) 149 150 // OnVoteForInvalidBlockDetected notifications are produced by the Vote Aggregation logic 151 // whenever vote for invalid proposal was detected. 152 // Prerequisites: 153 // Implementation must be concurrency safe; Non-blocking; 154 // and must handle repetition of the same events (with some processing overhead). 155 OnVoteForInvalidBlockDetected(vote *model.Vote, invalidProposal *model.Proposal) 156 } 157 158 // QCCreatedConsumer consumes outbound notifications produced by HotStuff and its components. 159 // Notifications are consensus-internal state changes which are potentially relevant to 160 // the larger node in which HotStuff is running. The notifications are emitted 161 // in the order in which the HotStuff algorithm makes the respective steps. 162 // 163 // Implementations must: 164 // - be concurrency safe 165 // - be non-blocking 166 // - handle repetition of the same events (with some processing overhead). 167 type QCCreatedConsumer interface { 168 // OnQcConstructedFromVotes notifications are produced by the VoteAggregator 169 // component, whenever it constructs a QC from votes. 170 // Prerequisites: 171 // Implementation must be concurrency safe; Non-blocking; 172 // and must handle repetition of the same events (with some processing overhead). 173 OnQcConstructedFromVotes(*flow.QuorumCertificate) 174 }