Skip to content

Commit

Permalink
refactor(consensus): move code from select to handle_proposal (#2620)
Browse files Browse the repository at this point in the history
minimize the code inside of macros
  • Loading branch information
matan-starkware authored Dec 16, 2024
1 parent 9314006 commit 2602630
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions crates/sequencing/papyrus_consensus/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,8 @@ impl<ContextT: ConsensusContext> MultiHeightManager<ContextT> {
self.handle_message(
context, height, &mut shc, message, broadcast_channels).await?
},
Some(mut content_receiver) = proposal_receiver.next() => {
// Get the first message to verify the init was sent.
// TODO(guyn): add a timeout and panic, since StreamHandler should only send once
// the first message (message_id=0) has arrived.
let Some(first_part) = content_receiver.next().await else {
return Err(ConsensusError::InternalNetworkError(
"Proposal receiver closed".to_string(),
));
};
let proposal_init: ProposalInit = first_part.try_into()?;
self.handle_proposal(context, height, &mut shc, proposal_init, content_receiver).await?
Some(content_receiver) = proposal_receiver.next() => {
self.handle_proposal(context, height, &mut shc, content_receiver).await?
},
Some(shc_event) = shc_events.next() => {
shc.handle_event(context, shc_event).await?
Expand Down Expand Up @@ -241,9 +232,18 @@ impl<ContextT: ConsensusContext> MultiHeightManager<ContextT> {
context: &mut ContextT,
height: BlockNumber,
shc: &mut SingleHeightConsensus,
proposal_init: ProposalInit,
content_receiver: mpsc::Receiver<ContextT::ProposalPart>,
mut content_receiver: mpsc::Receiver<ContextT::ProposalPart>,
) -> Result<ShcReturn, ConsensusError> {
// Get the first message to verify the init was sent.
// TODO(guyn): add a timeout and panic, since StreamHandler should only send once
// the first message (message_id=0) has arrived.
let Some(first_part) = content_receiver.next().await else {
return Err(ConsensusError::InternalNetworkError(
"Proposal receiver closed".to_string(),
));
};
let proposal_init: ProposalInit = first_part.try_into()?;

if proposal_init.height != height {
debug!("Received a proposal for a different height or round. {:?}", proposal_init);
if proposal_init.height > height {
Expand Down

0 comments on commit 2602630

Please sign in to comment.