@@ -35,11 +35,11 @@ pub struct OnInboundMessage<TConsensusSpec: ConsensusSpec> {
3535 leader_strategy : TConsensusSpec :: LeaderStrategy ,
3636 pacemaker : PaceMakerHandle ,
3737 vote_signing_service : TConsensusSpec :: SignatureService ,
38- rx_hotstuff_message : mpsc:: Receiver < ( TConsensusSpec :: Addr , HotstuffMessage ) > ,
38+ pub rx_hotstuff_message : mpsc:: Receiver < ( TConsensusSpec :: Addr , HotstuffMessage ) > ,
3939 tx_outbound_message : mpsc:: Sender < ( TConsensusSpec :: Addr , HotstuffMessage ) > ,
4040 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 > ,
4343 shutdown : ShutdownSignal ,
4444}
4545
@@ -73,32 +73,6 @@ where TConsensusSpec: ConsensusSpec
7373 }
7474 }
7575
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-
10276 pub async fn discard ( & mut self ) {
10377 loop {
10478 tokio:: select! {
@@ -123,7 +97,15 @@ where TConsensusSpec: ConsensusSpec
12397 ) -> Result < ( ) , HotStuffError > {
12498 match msg {
12599 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+ } ) ?;
127109 } ,
128110 msg => self
129111 . tx_msg_ready
@@ -135,7 +117,19 @@ where TConsensusSpec: ConsensusSpec
135117 Ok ( ( ) )
136118 }
137119
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 (
139133 & self ,
140134 current_height : NodeHeight ,
141135 proposal : ProposalMessage ,
@@ -160,16 +154,7 @@ where TConsensusSpec: ConsensusSpec
160154 return Ok ( ( ) ) ;
161155 }
162156
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 {
173158 // Block not ready
174159 return Ok ( ( ) ) ;
175160 } ;
@@ -184,7 +169,7 @@ where TConsensusSpec: ConsensusSpec
184169 Ok ( ( ) )
185170 }
186171
187- async fn check_if_parked_blocks_ready (
172+ pub async fn check_if_parked_blocks_ready (
188173 & self ,
189174 current_height : NodeHeight ,
190175 transaction_id : & TransactionId ,
@@ -301,7 +286,7 @@ where TConsensusSpec: ConsensusSpec
301286 }
302287}
303288
304- struct MessageBuffer < TAddr > {
289+ pub struct MessageBuffer < TAddr > {
305290 buffer : BTreeMap < NodeHeight , VecDeque < ( TAddr , HotstuffMessage ) > > ,
306291 rx_msg_ready : mpsc:: UnboundedReceiver < ( TAddr , HotstuffMessage ) > ,
307292}
0 commit comments