-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
3 Skipped Deployments
|
consensus/core/src/linearizer.rs
Outdated
if context | ||
.protocol_config | ||
.consensus_linearizer_collect_subdag_v2() | ||
{ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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); | ||
} | ||
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
consensus/core/src/linearizer.rs
Outdated
if context | ||
.protocol_config | ||
.consensus_linearizer_collect_subdag_v2() | ||
{ |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
502e96f
to
7474966
Compare
@@ -53,8 +53,12 @@ impl CommitObserver { | |||
leader_schedule: Arc<LeaderSchedule>, | |||
) -> Self { | |||
let mut observer = Self { | |||
commit_interpreter: Linearizer::new( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
consensus/core/src/dag_state.rs
Outdated
.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"); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
consensus/core/src/linearizer.rs
Outdated
@@ -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>, |
There was a problem hiding this comment.
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!( |
There was a problem hiding this comment.
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());
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, | ||
); |
There was a problem hiding this comment.
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!( |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protocol changes LGTM
…est committed round per authority but only once we reach gc_round.
…all refactorings.
c3c0502
to
a9b2f85
Compare
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 blocksA100, A101, A102
, but blockA102
uses as ancestor blockA100
and never referencesA101
.A101
gets broadcasted and participate in the form of an FP certificate and referenced by others. With the current logic in Linearizer, ifA102
gets committed first, thenA101
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 thatA101
will get committed as well if it's> gc_round
. HavingGarbage 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.