Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Optimize proposal part handling logic in received_proposal_part #837

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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