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): minor refactor of the manager #208

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

matan-starkware
Copy link
Contributor

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

  1. Separate fn for handling cached messages per height
  2. Return errors instead of panic when receiving messages

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

Attention: Patch coverage is 58.82353% with 14 lines in your changes missing coverage. Please review.

Project coverage is 76.84%. Comparing base (fe93a3b) to head (c4043fa).
Report is 1 commits behind head on main.

Files Patch % Lines
crates/sequencing/papyrus_consensus/src/manager.rs 60.60% 11 Missing and 2 partials ⚠️
crates/papyrus_protobuf/src/converters/mod.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #208      +/-   ##
==========================================
- Coverage   76.89%   76.84%   -0.05%     
==========================================
  Files         316      316              
  Lines       34504    34550      +46     
  Branches    34504    34550      +46     
==========================================
+ Hits        26532    26551      +19     
- Misses       5687     5708      +21     
- Partials     2285     2291       +6     

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

@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/manager_refactor branch from 7901f10 to abab918 Compare July 30, 2024 15:50
@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/manager_refactor branch from abab918 to ebe634e Compare July 31, 2024 07:32
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 3 of 3 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ShahakShama)

@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/manager_refactor branch from ebe634e to 884a740 Compare July 31, 2024 12:29
@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/manager_refactor branch from 884a740 to eb71c2a Compare July 31, 2024 14:23
@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/manager_refactor branch from eb71c2a to 3db8a0c Compare August 1, 2024 08:55
@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/manager_refactor branch from 3db8a0c to 91452bf Compare August 1, 2024 10:19
@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/manager_refactor branch from 91452bf to aef0f05 Compare August 1, 2024 10:38
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch from f3c4fd1 to b143026 Compare August 1, 2024 13:14
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/manager_refactor branch from aef0f05 to b58b015 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 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @matan-starkware)


crates/sequencing/papyrus_consensus/src/manager.rs line 81 at r2 (raw file):

            // TODO(matan): We need to figure out an actual cacheing strategy under 2 constraints:
            // 1. Malicious - must be capped so a malicious peer can't DoS us.

DoS -> DDoS


crates/sequencing/papyrus_consensus/src/manager.rs line 115 at r2 (raw file):

    fn get_current_height_messages(&mut self, height: BlockNumber) -> Vec<ConsensusMessage> {
        let mut current_height_messages = Vec::new();
        for msg in std::mem::take(&mut self.cached_messages) {

Try to remove just the problematic messages, instead of recreating the entire vector.
Plus, consider using a different data structure (maybe HashSet, or HashMap between height and a vector of ConsensusMessages and then finding all of them is much easier)


crates/sequencing/papyrus_consensus/src/manager.rs line 117 at r2 (raw file):

        for msg in std::mem::take(&mut self.cached_messages) {
            match height.0.cmp(&msg.height()) {
                std::cmp::Ordering::Less => self.cached_messages.push(msg),

IDK why, but logically it makes more sense to put msg.height() in the left of the comparison. I guess it's because it changs this arm into Greater, which means you're saying "This message is higher than the current height", which makes more sense since the current height is constant during this entire function and what's changing is msg


crates/sequencing/papyrus_consensus/src/types.rs line 167 at r2 (raw file):

    Canceled(#[from] oneshot::Canceled),
    #[error(transparent)]
    ProtobufConversionError(#[from] ProtobufConversionError),

This should be handled by reporting the relevant peer and then continuing on (maybe voting nil on the proposal if the sending peer is the proposer). For now put a TODO to handle this error internally

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: all files reviewed, 4 unresolved discussions (waiting on @ShahakShama)


crates/sequencing/papyrus_consensus/src/manager.rs line 81 at r2 (raw file):

Previously, ShahakShama wrote…

DoS -> DDoS

Why? A single malicious node could potentially send me so many messages that I OOM. There is no need for this to be a distributed attack.


crates/sequencing/papyrus_consensus/src/manager.rs line 115 at r2 (raw file):

Previously, ShahakShama wrote…

Try to remove just the problematic messages, instead of recreating the entire vector.
Plus, consider using a different data structure (maybe HashSet, or HashMap between height and a vector of ConsensusMessages and then finding all of them is much easier)

I intentionally went for a simple solution here (with Dan't support). I am not trying to optimize this since we know that this is not the final solution. This is just a solution for the sake of our early simulations. I'd rather just wait till we implement the real solution which is still under debate.


crates/sequencing/papyrus_consensus/src/manager.rs line 117 at r2 (raw file):

Previously, ShahakShama wrote…

IDK why, but logically it makes more sense to put msg.height() in the left of the comparison. I guess it's because it changs this arm into Greater, which means you're saying "This message is higher than the current height", which makes more sense since the current height is constant during this entire function and what's changing is msg

Done.


crates/sequencing/papyrus_consensus/src/types.rs line 167 at r2 (raw file):

Previously, ShahakShama wrote…

This should be handled by reporting the relevant peer and then continuing on (maybe voting nil on the proposal if the sending peer is the proposer). For now put a TODO to handle this error internally

Reviewable isn't highlighting, but I presume you are talking about InvalidProposal? If so you are basically describing the current milestone that Asmaa just wrote (code is already under review with me). I'll just leave this alone then, ok?

@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch from b143026 to 0ce80cd Compare August 4, 2024 08:37
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/manager_refactor branch from b58b015 to 5c9631d Compare August 4, 2024 08:37
@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 force-pushed the matan/consensus/m3/manager_refactor branch 2 times, most recently from 422a210 to 043a3d9 Compare 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.

:lgtm:

Reviewed 3 of 5 files at r3, 3 of 3 files at r4, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @matan-starkware)


crates/sequencing/papyrus_consensus/src/manager.rs line 115 at r2 (raw file):

Previously, matan-starkware wrote…

I intentionally went for a simple solution here (with Dan't support). I am not trying to optimize this since we know that this is not the final solution. This is just a solution for the sake of our early simulations. I'd rather just wait till we implement the real solution which is still under debate.

But my suggestion is as simple as your suggestion.
Unblocking for now, but I think it's worth doing this change or at least putting a TODO


crates/sequencing/papyrus_consensus/src/types.rs line 167 at r2 (raw file):

Previously, matan-starkware wrote…

Reviewable isn't highlighting, but I presume you are talking about InvalidProposal? If so you are basically describing the current milestone that Asmaa just wrote (code is already under review with me). I'll just leave this alone then, ok?

No, I'm talking about ProtobufConversionError, but I guess the same applies for InvalidProposal
You can leave this alone if you want

@matan-starkware matan-starkware force-pushed the matan/consensus/m3/create_manager branch from dd1cdfa to 0321499 Compare August 4, 2024 11:09
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/manager_refactor branch 2 times, most recently from 7a1ee5e to 7e69e4d Compare August 4, 2024 11:23
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 5 files reviewed, 1 unresolved discussion (waiting on @ShahakShama)


crates/sequencing/papyrus_consensus/src/manager.rs line 115 at r2 (raw file):

Previously, ShahakShama wrote…

But my suggestion is as simple as your suggestion.
Unblocking for now, but I think it's worth doing this change or at least putting a TODO

Took your map suggestion


crates/sequencing/papyrus_consensus/src/types.rs line 167 at r2 (raw file):

Previously, ShahakShama wrote…

No, I'm talking about ProtobufConversionError, but I guess the same applies for InvalidProposal
You can leave this alone if you want

I can't do anything with a protobuf conversion error (besides ReportSender to network). IDK if this is a proposal or a prevote, idk what height this is for, idk who sent it. Consensus proper must ignore.

I'll update the manager though to use report sender and add a TODO since at some point we will want the SHC to also start reporting errors.

@matan-starkware matan-starkware force-pushed the matan/consensus/m3/manager_refactor branch from 7e69e4d to 1bcc292 Compare August 4, 2024 11:36
@matan-starkware matan-starkware changed the base branch from matan/consensus/m3/create_manager to main August 4, 2024 11:36
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/manager_refactor branch 2 times, most recently from 09c5e8f to 5736f92 Compare August 5, 2024 10:16
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 1 of 4 files at r5, 1 of 1 files at r6, all commit messages.
Reviewable status: 3 of 5 files reviewed, 1 unresolved discussion (waiting on @matan-starkware and @ShahakShama)


crates/sequencing/papyrus_consensus/src/manager.rs line 82 at r6 (raw file):

                    self.cached_messages
                        .entry(message.height())
                        .or_insert(Vec::new())

.or_default()

Code quote:

.or_insert(Vec::new())

1. Separate fn for handling cached messages per height
2. Return errors instead of panic when receiving messages
@matan-starkware matan-starkware force-pushed the matan/consensus/m3/manager_refactor branch from 5736f92 to c4043fa Compare August 5, 2024 10:47
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: 3 of 5 files reviewed, 1 unresolved discussion (waiting on @asmaastarkware and @ShahakShama)


crates/sequencing/papyrus_consensus/src/manager.rs line 82 at r6 (raw file):

Previously, asmaastarkware (asmaa-starkware) wrote…

.or_default()

Done.

@asmaastarkware asmaastarkware self-requested a review August 5, 2024 10:52
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 2 of 4 files at r5, 1 of 1 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ShahakShama)

@matan-starkware
Copy link
Contributor Author

matan-starkware commented Aug 5, 2024

Merge activity

@matan-starkware matan-starkware merged commit 51e19e3 into main Aug 5, 2024
21 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 7, 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