@@ -35,11 +35,11 @@ pub struct OnInboundMessage<TConsensusSpec: ConsensusSpec> {
35
35
leader_strategy : TConsensusSpec :: LeaderStrategy ,
36
36
pacemaker : PaceMakerHandle ,
37
37
vote_signing_service : TConsensusSpec :: SignatureService ,
38
- rx_hotstuff_message : mpsc:: Receiver < ( TConsensusSpec :: Addr , HotstuffMessage ) > ,
38
+ pub rx_hotstuff_message : mpsc:: Receiver < ( TConsensusSpec :: Addr , HotstuffMessage ) > ,
39
39
tx_outbound_message : mpsc:: Sender < ( TConsensusSpec :: Addr , HotstuffMessage ) > ,
40
40
tx_msg_ready : mpsc:: UnboundedSender < ( TConsensusSpec :: Addr , HotstuffMessage ) > ,
41
- rx_new_transactions : mpsc:: Receiver < TransactionId > ,
42
- message_buffer : MessageBuffer < TConsensusSpec :: Addr > ,
41
+ pub rx_new_transactions : mpsc:: Receiver < TransactionId > ,
42
+ pub message_buffer : MessageBuffer < TConsensusSpec :: Addr > ,
43
43
shutdown : ShutdownSignal ,
44
44
}
45
45
@@ -73,32 +73,6 @@ where TConsensusSpec: ConsensusSpec
73
73
}
74
74
}
75
75
76
- pub async fn next ( & mut self , current_height : NodeHeight ) -> IncomingMessageResult < TConsensusSpec :: Addr > {
77
- loop {
78
- tokio:: select! {
79
- biased;
80
-
81
- _ = self . shutdown. wait( ) => { break Ok ( None ) ; }
82
-
83
- msg_or_sync = self . message_buffer. next( current_height) => {
84
- break msg_or_sync;
85
- } ,
86
-
87
- Some ( ( from, msg) ) = self . rx_hotstuff_message. recv( ) => {
88
- if let Err ( err) = self . handle_hotstuff_message( current_height, from, msg) . await {
89
- error!( target: LOG_TARGET , "Error handling message: {}" , err) ;
90
- }
91
- } ,
92
-
93
- Some ( tx_id) = self . rx_new_transactions. recv( ) => {
94
- if let Err ( err) = self . check_if_parked_blocks_ready( current_height, & tx_id) . await {
95
- error!( target: LOG_TARGET , "Error checking parked blocks: {}" , err) ;
96
- }
97
- } ,
98
- }
99
- }
100
- }
101
-
102
76
pub async fn discard ( & mut self ) {
103
77
loop {
104
78
tokio:: select! {
@@ -123,7 +97,15 @@ where TConsensusSpec: ConsensusSpec
123
97
) -> Result < ( ) , HotStuffError > {
124
98
match msg {
125
99
HotstuffMessage :: Proposal ( msg) => {
126
- self . process_proposal ( current_height, msg) . await ?;
100
+ self . process_local_proposal ( current_height, msg) . await ?;
101
+ } ,
102
+ HotstuffMessage :: ForeignProposal ( ref proposal) => {
103
+ self . check_proposal ( proposal. block . clone ( ) ) . await ?;
104
+ self . tx_msg_ready
105
+ . send ( ( from, msg) )
106
+ . map_err ( |_| HotStuffError :: InternalChannelClosed {
107
+ context : "tx_msg_ready in InboundMessageWorker::handle_hotstuff_message" ,
108
+ } ) ?;
127
109
} ,
128
110
msg => self
129
111
. tx_msg_ready
@@ -135,7 +117,19 @@ where TConsensusSpec: ConsensusSpec
135
117
Ok ( ( ) )
136
118
}
137
119
138
- async fn process_proposal (
120
+ async fn check_proposal ( & self , block : Block ) -> Result < Option < Block > , HotStuffError > {
121
+ check_hash_and_height ( & block) ?;
122
+ let committee_for_block = self
123
+ . epoch_manager
124
+ . get_committee_by_validator_public_key ( block. epoch ( ) , block. proposed_by ( ) )
125
+ . await ?;
126
+ check_proposed_by_leader ( & self . leader_strategy , & committee_for_block, & block) ?;
127
+ check_signature ( & block) ?;
128
+ check_quorum_certificate :: < TConsensusSpec > ( & block, & self . vote_signing_service , & self . epoch_manager ) . await ?;
129
+ self . handle_missing_transactions ( block) . await
130
+ }
131
+
132
+ async fn process_local_proposal (
139
133
& self ,
140
134
current_height : NodeHeight ,
141
135
proposal : ProposalMessage ,
@@ -160,16 +154,7 @@ where TConsensusSpec: ConsensusSpec
160
154
return Ok ( ( ) ) ;
161
155
}
162
156
163
- check_hash_and_height ( & block) ?;
164
- let committee_for_block = self
165
- . epoch_manager
166
- . get_committee_by_validator_public_key ( block. epoch ( ) , block. proposed_by ( ) )
167
- . await ?;
168
- check_proposed_by_leader ( & self . leader_strategy , & committee_for_block, & block) ?;
169
- check_signature ( & block) ?;
170
- check_quorum_certificate :: < TConsensusSpec > ( & block, & self . vote_signing_service , & self . epoch_manager ) . await ?;
171
-
172
- let Some ( ready_block) = self . handle_missing_transactions ( block) . await ? else {
157
+ let Some ( ready_block) = self . check_proposal ( block) . await ? else {
173
158
// Block not ready
174
159
return Ok ( ( ) ) ;
175
160
} ;
@@ -184,7 +169,7 @@ where TConsensusSpec: ConsensusSpec
184
169
Ok ( ( ) )
185
170
}
186
171
187
- async fn check_if_parked_blocks_ready (
172
+ pub async fn check_if_parked_blocks_ready (
188
173
& self ,
189
174
current_height : NodeHeight ,
190
175
transaction_id : & TransactionId ,
@@ -301,7 +286,7 @@ where TConsensusSpec: ConsensusSpec
301
286
}
302
287
}
303
288
304
- struct MessageBuffer < TAddr > {
289
+ pub struct MessageBuffer < TAddr > {
305
290
buffer : BTreeMap < NodeHeight , VecDeque < ( TAddr , HotstuffMessage ) > > ,
306
291
rx_msg_ready : mpsc:: UnboundedReceiver < ( TAddr , HotstuffMessage ) > ,
307
292
}
0 commit comments