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

refactor(consensus): create manager which encapsulates messages cached between heights #200

Merged
merged 1 commit into from
Aug 4, 2024

Conversation

matan-starkware
Copy link
Contributor

@matan-starkware matan-starkware commented Jul 30, 2024

This change is Reviewable

@matan-starkware
Copy link
Contributor Author

matan-starkware commented Jul 30, 2024

Copy link

codecov bot commented Jul 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.91%. Comparing base (fe8efb4) to head (0321499).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #200      +/-   ##
==========================================
+ Coverage   76.88%   76.91%   +0.03%     
==========================================
  Files         312      313       +1     
  Lines       34445    34448       +3     
  Branches    34445    34448       +3     
==========================================
+ Hits        26482    26496      +14     
+ Misses       5681     5665      -16     
- Partials     2282     2287       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@asmaastarkware asmaastarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @matan-starkware)

@matan-starkware matan-starkware force-pushed the matan/consensus/m3/network_receiver_generic branch from f50d408 to 63a79b9 Compare July 30, 2024 13:57
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch from c698a12 to cf37628 Compare July 30, 2024 13:57
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch from cf37628 to f55d15e Compare July 30, 2024 15:50
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/network_receiver_generic branch from 63a79b9 to 4d7d319 Compare July 31, 2024 07:31
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch from f55d15e to b178c8e Compare July 31, 2024 07:31
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/network_receiver_generic branch from 4d7d319 to 69f6412 Compare July 31, 2024 12:29
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch from b178c8e to f06ec08 Compare July 31, 2024 12:29
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/network_receiver_generic branch from 69f6412 to 240bd76 Compare July 31, 2024 14:23
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch from f06ec08 to 00833b3 Compare July 31, 2024 14:23
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/network_receiver_generic branch from 240bd76 to e44b622 Compare August 1, 2024 08:55
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch from 00833b3 to 3e510b3 Compare August 1, 2024 08:55
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/network_receiver_generic branch from e44b622 to 58392fa Compare August 1, 2024 10:18
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch from 3e510b3 to 2787166 Compare August 1, 2024 10:19
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/network_receiver_generic branch from 58392fa to c85cf92 Compare August 1, 2024 10:37
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch from 2787166 to f3c4fd1 Compare August 1, 2024 10:37
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/network_receiver_generic branch from c85cf92 to 502e872 Compare August 1, 2024 13:14
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch from f3c4fd1 to b143026 Compare August 1, 2024 13:14
Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 2 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: 3 of 4 files reviewed, 4 unresolved discussions (waiting on @asmaastarkware and @matan-starkware)


crates/sequencing/papyrus_consensus/src/lib.rs line 57 at r3 (raw file):

    loop {
        let decision = manager
            .run_height(&mut context, current_height, validator_id, &mut network_receiver)

Add TODO to support failed rounds (unless the plan is that run_height will run several rounds until it reaches a decision)


crates/sequencing/papyrus_consensus/src/manager.rs line 26 at r3 (raw file):

use crate::ProposalWrapper;

/// Used run Tendermint. Handles issues which are not explicitly part of the single height consensus

WDYM "Used run Tendermint"? Try to improve this sentence


crates/sequencing/papyrus_consensus/src/manager_test.rs line 27 at r3 (raw file):

#[derive(Debug, PartialEq, Clone)]
pub struct TestBlock {
    pub content: Vec<Transaction>,

Why not use something simpler than Transaction, like u64?


crates/sequencing/papyrus_consensus/src/manager_test.rs line 117 at r3 (raw file):

#[tokio::test]
async fn run_multiple_heights() {

rename to run_multiple_heights_unordered

@matan-starkware matan-starkware force-pushed the matan/consensus/m3/network_receiver_generic branch from 502e872 to 3d4cb10 Compare August 4, 2024 08:37
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch from b143026 to 0ce80cd Compare August 4, 2024 08:37
Copy link
Contributor Author

@matan-starkware matan-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 4 files reviewed, 4 unresolved discussions (waiting on @asmaastarkware and @ShahakShama)


crates/sequencing/papyrus_consensus/src/lib.rs line 57 at r3 (raw file):

Previously, ShahakShama wrote…

Add TODO to support failed rounds (unless the plan is that run_height will run several rounds until it reaches a decision)

A height contains multiple rounds. This is something the manager doesn't need to consider.


crates/sequencing/papyrus_consensus/src/manager.rs line 26 at r3 (raw file):

Previously, ShahakShama wrote…

WDYM "Used run Tendermint"? Try to improve this sentence

Done.


crates/sequencing/papyrus_consensus/src/manager_test.rs line 27 at r3 (raw file):

Previously, ShahakShama wrote…

Why not use something simpler than Transaction, like u64?

Because we don't support streaming yet. We have the Proposal ConsensusMessage which includes the field for Transaction. When we support streaming I will instead make us generic on:

ConsensusStreamMessage: From<ProposalInit> + From<ProposalFin>

I tried faking this genericness now and it lead to a lot of ugly code, so I'd prefer to have the complexity in my test until we have streaming.


crates/sequencing/papyrus_consensus/src/manager_test.rs line 117 at r3 (raw file):

Previously, ShahakShama wrote…

rename to run_multiple_heights_unordered

Done.

@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch 2 times, most recently from afcfd46 to dd1cdfa Compare August 4, 2024 09:05
@matan-starkware matan-starkware changed the base branch from matan/consensus/m3/network_receiver_generic to main August 4, 2024 09:05
Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 2 files at r2, 2 of 2 files at r4, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @asmaastarkware and @matan-starkware)


crates/sequencing/papyrus_consensus/src/manager.rs line 28 at r5 (raw file):

/// Runs Tendermint repeatedly across different heights. Handles issues which are not explicitly
/// part of the single height consensus algorithm (e.g. messages from future heights).
pub struct Manager {

Consider renaming to HeightManager or MultiHeightManager


crates/sequencing/papyrus_consensus/src/manager.rs line 29 at r5 (raw file):

/// part of the single height consensus algorithm (e.g. messages from future heights).
pub struct Manager {
    cached_messages: Vec<ConsensusMessage>,

Change this to HashMap<Height, Vec>. Then cleaning it up will be much more efficient


crates/sequencing/papyrus_consensus/src/manager.rs line 70 at r5 (raw file):

        let mut current_height_messages = Vec::new();
        for msg in std::mem::take(&mut self.cached_messages) {
            match height.0.cmp(&msg.height()) {

Change the ordering of cmp here so that it will be clearer what's going on in the match arms. You should have in the left the thing that's always changing and in the right the constant thing

Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @asmaastarkware and @matan-starkware)

@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch from dd1cdfa to 0321499 Compare August 4, 2024 11:09
Copy link
Contributor Author

@matan-starkware matan-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 4 files reviewed, all discussions resolved (waiting on @asmaastarkware and @ShahakShama)


crates/sequencing/papyrus_consensus/src/manager.rs line 29 at r5 (raw file):

Previously, ShahakShama wrote…

Change this to HashMap<Height, Vec>. Then cleaning it up will be much more efficient

Sure, but I consider this to be part of the refactor (next PR). I'd like to keep this one just moving the existing code.


crates/sequencing/papyrus_consensus/src/manager.rs line 70 at r5 (raw file):

Previously, ShahakShama wrote…

Change the ordering of cmp here so that it will be clearer what's going on in the match arms. You should have in the left the thing that's always changing and in the right the constant thing

You put this comment in 208 earlier and I already did it, so to avoid conflicts I'll just leave it there.

Copy link
Contributor

@asmaastarkware asmaastarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @matan-starkware)

@matan-starkware
Copy link
Contributor Author

matan-starkware commented Aug 4, 2024

Merge activity

@matan-starkware matan-starkware merged commit d1e801a into main Aug 4, 2024
20 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants