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] Linearizer to use commit up to gc_round #20250

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

akichidis
Copy link
Contributor

@akichidis akichidis commented Nov 13, 2024

Description

Currently when committing/collecting the sub dag we always stop the recursion when we come across the highest committed round for an authority. This works well, but with the upcoming Fast Path changes it can lead to uncommitted FP certificates in the presence of blocks that don't form a proper hash chain.

This could be done if for example an authority A produces blocks A100, A101, A102 , but block A102 uses as ancestor block A100 and never references A101. A101 gets broadcasted and participate in the form of an FP certificate and referenced by others. With the current logic in Linearizer, if A102 gets committed first, then A101 will never get committed as part of subsequent DAG sequencing as we always stop our recursion to the highest committed round. With the new logic we ensure that A101 will get committed as well if it's > gc_round. Having Garbage Collection allows us to limit the recursion depth making the process efficient enough and knowing that we'll not attempt to keep committing blocks too far in the past. Using a reasonable depth (ex 50 - 60) for production shouldn't cause performance troubles.

To achieve the above DagState has been refactored to keep a global commit state of blocks. When we linearise the DAG across commits we do not re-commit previously committed blocks.

The new changes are guarded behind a feature flag and can only be enabled if GC is enabled.

Test plan

CI/PT


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:
  • REST API:

Copy link

vercel bot commented Nov 13, 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 Dec 19, 2024 4:02pm
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Dec 19, 2024 4:02pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Dec 19, 2024 4:02pm
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Dec 19, 2024 4:02pm

@akichidis akichidis temporarily deployed to sui-typescript-aws-kms-test-env November 13, 2024 13:25 — with GitHub Actions Inactive
Comment on lines 152 to 159
if context
.protocol_config
.consensus_linearizer_collect_subdag_v2()
{
Copy link
Contributor Author

@akichidis akichidis Nov 13, 2024

Choose a reason for hiding this comment

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

Decided to split completely the new/previous logic to make things safer during transition. Will clean up after deploy.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal as you will clean it up, but from a diff perspective changing the two spots alone that use the new behavior does seem safer/easier to review and you can keep the comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I thought that it would be cleaner to review the logic as whole separately before/after rather than having to navigate through various points that enable different code paths. But if you believe it's tougher to review then I am happy to reconsider on this.

// When reaching zero will exist anyways as all commits are indexed starting from 1.
index = index.saturating_sub(1);
}
}
Copy link
Contributor Author

@akichidis akichidis Nov 13, 2024

Choose a reason for hiding this comment

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

Alternatively, we could retrieve all committed sub-dags within the index range (last_commit_index - gc_depth ... last_commit_index) to restore the commit status for blocks above the gc_round. This approach would avoid iterations and would function correctly without additional computation.
However, the reason this approach guarantees sufficient data restoration is less intuitive, and may be more error-prone in the event of future refactoring. Therefore, I opted for the above approach, which is more straightforward to reason about and ensures clearer correctness. Performance gains with the alternative method are likely negligible.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should just read from store in range and then do the same processing in memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you should just read from store in range

how far back though? I can do some range reads and process in batch, but I am not sure of the gains.

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 could be done if for example an authority A produces blocks A100, A101, A102 , but block A102 uses as ancestor block A100 and never references A101

This should be considered as Byzantine behavior if we do see this as we currently always link the previous rounds block?

// When reaching zero will exist anyways as all commits are indexed starting from 1.
index = index.saturating_sub(1);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should just read from store in range and then do the same processing in memory.

@@ -970,6 +1037,21 @@ impl DagState {
}
}

struct BlockInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

BlockInfo seems odd because it contains the block itself? Unless you plan on adding more to this struct maybe BlockWithCommitStatus or BlockWithStatus?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am aware that @mwtian will most probably re-use this struct with additional info for Fast Path, that's why kept the BlockInfo

Comment on lines 152 to 159
if context
.protocol_config
.consensus_linearizer_collect_subdag_v2()
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal as you will clean it up, but from a diff perspective changing the two spots alone that use the new behavior does seem safer/easier to review and you can keep the comments.

// Enables the new logic for collecting the subdag in the consensus linearizer. The new logic does not stop the recursion at the highest
// committed round for each authority, but allows to commit uncommitted blocks up to gc round (excluded) for that authority.
#[serde(skip_serializing_if = "is_false")]
consensus_linearizer_collect_subdag_v2: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: consensus_linearize_subdag_v2

@@ -53,8 +53,12 @@ impl CommitObserver {
leader_schedule: Arc<LeaderSchedule>,
) -> Self {
let mut observer = Self {
commit_interpreter: Linearizer::new(
Copy link
Member

Choose a reason for hiding this comment

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

nit: why reorder this field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In order to be able to clone first (so could provide it in Linearizer) and pass it as parameter later

.scan_commits((index..=index).into())
.unwrap_or_else(|e| panic!("Failed to read from storage: {:?}", e));
let Some(commit) = commits.first() else {
info!("Recovering finished, no more commits to recover");
Copy link
Member

Choose a reason for hiding this comment

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

index should be logged as well.

});

// When reaching zero will exist anyways as all commits are indexed starting from 1.
index = index.saturating_sub(1);
Copy link
Member

Choose a reason for hiding this comment

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

Just break if index is <= 1?

@@ -46,16 +59,19 @@ pub(crate) struct Linearizer {
/// In memory block store representing the dag state
dag_state: Arc<RwLock<DagState>>,
leader_schedule: Arc<LeaderSchedule>,
context: Arc<Context>,
Copy link
Member

Choose a reason for hiding this comment

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

nit: let's keep context first in fields / args by default.


for ancestor in ancestors {
buffer.push(ancestor.clone());
assert!(
Copy link
Member

Choose a reason for hiding this comment

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

Why not combine the dag_state.set_committed(&ancestor.reference()) asserts and call it after to_commit.push(x.clone());?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you please clarify a little bit more on this? Do you suggest moving the dag_state.set_committed(&ancestor.reference()) after the to_commit.push(x.clone()); ? That would not give desired results given that we do BFS here. I mean, if we don't mark the blocks as committed here then we'll revisit them and try to re-commit them. Unless I am totally misunderstanding what you mean.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good.

leader_block.clone(),
last_committed_rounds,
&mut dag_state,
);
Copy link
Member

Choose a reason for hiding this comment

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

I think we discussed this before but it seems better to drop dag_state here.


for ancestor in ancestors {
buffer.push(ancestor.clone());
assert!(
Copy link
Member

Choose a reason for hiding this comment

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

Sounds good.

let res = self.feature_flags.consensus_linearize_subdag_v2;
assert!(
!res || self.gc_depth() > 0,
"The consensus linearize sub dag V2 requires GC to be enabled"
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

Copy link
Contributor

@mystenmark mystenmark left a comment

Choose a reason for hiding this comment

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

protocol changes LGTM

@akichidis akichidis force-pushed the akichidis/consensus-commit-rule-modify branch from c3c0502 to a9b2f85 Compare December 19, 2024 15:58
@akichidis akichidis requested a review from a team as a code owner December 19, 2024 15:58
@akichidis akichidis temporarily deployed to sui-typescript-aws-kms-test-env December 19, 2024 15:58 — with GitHub Actions Inactive
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.

4 participants