Skip to content

Commit

Permalink
feat: Optimize proposal part handling logic in received_proposal_part
Browse files Browse the repository at this point in the history
  • Loading branch information
varun-doshi committed Feb 7, 2025
1 parent 614a46c commit 43fddab
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions code/examples/channel/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,28 @@ impl State {
) -> eyre::Result<Option<ProposedValue<TestContext>>> {
let sequence = part.sequence;

if let Some(proposal) = part
.content
.clone()
.into_data()
.as_ref()
.and_then(|data| data.as_init())
{
// Check if the proposal is outdated
if proposal.height < self.current_height {
debug!(
height = %self.current_height,
round = %self.current_round,
part.height = %proposal.height,
part.round = %proposal.round,
part.sequence = %sequence,
"Received outdated proposal part, ignoring"
);

return Ok(None);
}
}

// Check if we have a full proposal
let Some(parts) = self.streams_map.insert(from, part) else {
return Ok(None);
Expand All @@ -141,20 +163,6 @@ impl State {
}
}

// Check if the proposal is outdated
if parts.height < self.current_height {
debug!(
height = %self.current_height,
round = %self.current_round,
part.height = %parts.height,
part.round = %parts.round,
part.sequence = %sequence,
"Received outdated proposal part, ignoring"
);

return Ok(None);
}

// Re-assemble the proposal from its parts
let value = assemble_value_from_parts(parts);

Expand Down

0 comments on commit 43fddab

Please sign in to comment.