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

tutorial: Optimize proposal part handling logic in received_proposal_part #830

Open
1 task
romac opened this issue Feb 5, 2025 · 2 comments · May be fixed by #837
Open
1 task

tutorial: Optimize proposal part handling logic in received_proposal_part #830

romac opened this issue Feb 5, 2025 · 2 comments · May be fixed by #837
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation good first issue Good for newcomers
Milestone

Comments

@romac
Copy link
Member

romac commented Feb 5, 2025

Summary

The current implementation checks for full proposal before validating height, which is inefficient as outdated parts are still being inserted into the map.

    pub fn received_proposal_part(
        &mut self,
        from: PeerId,
        part: StreamMessage<ProposalPart>,
    ) -> Option<ProposedValue<TestContext>> {
        let sequence = part.sequence;

        // Check if we have a full proposal
        let parts = self.streams_map.insert(from, part)?;

        // Check if the proposal is outdated
        if parts.height < self.current_height {

Action items

  • Reorder checks to validate height before inserting into streams_map
        // Check if the part is outdated
        if part.height < self.current_height {
            debug!(
                height = %self.current_height,
                round = %self.current_round,
                part.height = %parts.height,
                part.round = %parts.round,
                part.sequence = %part.sequence,
                "Received outdated proposal part, ignoring"
            );

            return None;
        }

        // Check if we have a full proposal
        let parts = self.streams_map.insert(from, part)?;

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

        self.undecided_proposals
            .insert((value.height, value.round), value.clone());

        Some(value)
    }
@romac romac added bug Something isn't working documentation Improvements or additions to documentation good first issue Good for newcomers labels Feb 5, 2025
@romac romac added this to the Phase 5 milestone Feb 5, 2025
@varun-doshi
Copy link
Contributor

I'd like to take this one

@romac
Copy link
Member Author

romac commented Feb 6, 2025

@varun-doshi Awesome, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants