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

[Consensus 2.0] Small refactoring in scores for CommittedSubDag #17768

Merged
merged 4 commits into from
May 28, 2024

Conversation

akichidis
Copy link
Contributor

Description

Initialise the consensus scores in committed sub dag during construction. Also always pre-sort the blocks , that should be the default anyways either during commit or recover.

Test plan

CI


Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

Copy link

vercel bot commented May 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 28, 2024 0:57am
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview May 28, 2024 0:57am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview May 28, 2024 0:57am
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview May 28, 2024 0:57am

Copy link
Member

@mwtian mwtian left a comment

Choose a reason for hiding this comment

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

I know mutating CommittedSubDag just to set reputation scores is a bit weird. But sending reputation scores to linearizer just to construct CommittedSubDag does not seem the most ideal either. Have we settled on always sending a copy of reputation score with CommittedSubDag, or do we still want to only send a version of scores once? The setter way seems easier to only set the scores once.

@akichidis
Copy link
Contributor Author

I know mutating CommittedSubDag just to set reputation scores is a bit weird. But sending reputation scores to linearizer just to construct CommittedSubDag does not seem the most ideal either. Have we settled on always sending a copy of reputation score with CommittedSubDag, or do we still want to only send a version of scores once? The setter way seems easier to only set the scores once.

My preference is always to have as less mutation as possible as we seemed to touch the sub dag a couple of times after its construction and lots of things can go wrong there - I’ve realised that when I tried to refactor that code. Even if we decide to set the scores only once it’s still fine. Alternatively we can inject the leader schedule in the linearizer.

@arun-koshy
Copy link
Contributor

arun-koshy commented May 16, 2024

I like the safety provided by not mutating the subdag but I would still vote for keeping the setter method especially because I left a todo so that we only set the scores on leader schedule change. If we do set the scores only on each new version then passing the leader schedule in to the linearizer also would not work as we would have to do it at the commit observer level (that is how I saw it playing out originally atleast)

@akichidis
Copy link
Contributor Author

I like the safety provided by not mutating the subdag but I would still vote for keeping the setter method especially because I left a todo so that we only set the scores on leader schedule change. If we do set the scores only on each new version then passing the leader schedule in to the linearizer also would not work as we would have to do it at the commit observer level (that is how I saw it playing out originally atleast)

Yeah I thought that we can pass this info to the linearizer and set it it self only once when the scores change. Ok , shall I attempt to do that and if you guys still don’t like it we can pass on it?

@akichidis
Copy link
Contributor Author

I like the safety provided by not mutating the subdag but I would still vote for keeping the setter method especially because I left a todo so that we only set the scores on leader schedule change. If we do set the scores only on each new version then passing the leader schedule in to the linearizer also would not work as we would have to do it at the commit observer level (that is how I saw it playing out originally atleast)

Yeah I thought that we can pass this info to the linearizer and set it it self only once when the scores change. Ok , shall I attempt to do that and if you guys still don’t like it we can pass on it?

Oh I also realised that I somehow nuked your TODO @arun-koshy and never put it back - although I did have it on my mind. Apologies for that!

@mwtian
Copy link
Member

mwtian commented May 16, 2024

I think the main issue we have here and in the other PR (commit digest) is this mismatch: for output, we are using Commit as the internal commit data structure for persistence and certification, and CommittedSubDag as the in-memory only commit representation with blocks sent to Sui. But during construction, linearizer handle_commit() creates committed subdag first and returns it as output. I think we can do a refactor where linearizer returns Commit and maybe blocks. Then CommitObserver constructs CommittedSubDag before sending it to Sui. Doing this in linearizer may work too. I will take a look at the PR.

@akichidis
Copy link
Contributor Author

akichidis commented May 16, 2024

I think the main issue we have here and in the other PR (commit digest) is this mismatch: for output, we are using Commit as the internal commit data structure for persistence and certification, and CommittedSubDag as the in-memory only commit representation with blocks sent to Sui. But during construction, linearizer handle_commit() creates committed subdag first and returns it as output. I think we can do a refactor where linearizer returns Commit and maybe blocks. Then CommitObserver constructs CommittedSubDag before sending it to Sui. Doing this in linearizer may work too. I will take a look at the PR.

Yep that's the issue. I've ended up to similar conclusions and refactored how we construct the Commit & the committed subdag to be more coherent (see #17765). Hopefully this would make more sense now.

For this PR I've ended up moving things mostly to the linearizer. Please have another look @mwtian @arun-koshy

Copy link
Contributor

@arun-koshy arun-koshy left a comment

Choose a reason for hiding this comment

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

This works for me 👍🏽

@akichidis akichidis force-pushed the akichidis/consensus-mysticeti-subdag-digest branch from f516e8d to 0c4f61f Compare May 23, 2024 19:53
Base automatically changed from akichidis/consensus-mysticeti-subdag-digest to main May 23, 2024 22:49
@akichidis
Copy link
Contributor Author

@mwtian any comments before I get this merged?

Comment on lines 135 to 136
vec![],
); // We don't mind recovering the reputation scores
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
vec![],
); // We don't mind recovering the reputation scores
// We don't need to recover reputation scores for unscored_committed_subdags
vec![],
);

Comment on lines +117 to +120
/// Checks whether the dag state unscored sub dags list is empty. If yes then that means that
/// either (1) the system has just started and there is no unscored sub dag available (2) the
/// schedule has updated - new scores have been calculated. Both cases we consider as valid cases
/// where the schedule has been updated.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure (1) is a valid reason. DagState has to fully recover unscored commits before leader schedule can start to make decisions. Otherwise there can be a fork. Or are you seeing something else when starting consensus?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but if it's a fresh system then there are not sub dags to recover.

/// either (1) the system has just started and there is no unscored sub dag available (2) the
/// schedule has updated - new scores have been calculated. Both cases we consider as valid cases
/// where the schedule has been updated.
pub(crate) fn leader_schedule_updated(&self, dag_state: Arc<RwLock<DagState>>) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub(crate) fn leader_schedule_updated(&self, dag_state: Arc<RwLock<DagState>>) -> bool {
pub(crate) fn leader_schedule_updated(&self, dag_state: &RwLock<DagState>) -> bool {

// part of the first sub dag.
let schedule_updated = self
.leader_schedule
.leader_schedule_updated(self.dag_state.clone());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.leader_schedule_updated(self.dag_state.clone());
.leader_schedule_updated(&self.dag_state);

@akichidis akichidis merged commit 71c997e into main May 28, 2024
48 checks passed
@akichidis akichidis deleted the akichidis/consensus-mysticeti-update-scores-refactor branch May 28, 2024 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants