Skip to content

Commit

Permalink
nit
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoffranca committed Jan 20, 2025
1 parent f1f8b1a commit da72237
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 49 deletions.
46 changes: 37 additions & 9 deletions node/components/bft/src/chonky_bft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,46 @@ impl StateMachine {
if self
.high_commit_qc
.as_ref()
.map_or(false, |old| old.view().number >= qc.view().number)
.map_or(false, |cur| cur.view().number < qc.view().number)
{
return Ok(());
tracing::debug!(
"ChonkyBFT replica - Processing newer CommitQC: current view {}, QC view {}",
self.view_number.0,
qc.view().number.0,
);

self.high_commit_qc = Some(qc.clone());
self.save_block(ctx, qc).await.wrap("save_block()")?;
}

tracing::debug!(
"ChonkyBFT replica - Processing newer CommitQC: current view: {}, QC view: {}",
self.view_number.0,
qc.view().number.0,
);
Ok(())
}

pub(crate) async fn process_timeout_qc(
&mut self,
ctx: &ctx::Ctx,
qc: &validator::TimeoutQC,
) -> ctx::Result<()> {
if let Some(high_qc) = qc.high_qc() {
self.process_commit_qc(ctx, high_qc)
.await
.wrap("process_commit_qc()")?;
}

if self
.high_timeout_qc
.as_ref()
.map_or(true, |old| old.view.number < qc.view.number)
{
tracing::debug!(
"ChonkyBFT replica - Processing newer TimeoutQC: current view {}, QC view {}",
self.view_number.0,
qc.view.number.0,
);

self.high_timeout_qc = Some(qc.clone());
}

self.high_commit_qc = Some(qc.clone());
self.save_block(ctx, qc).await.wrap("save_block()")
Ok(())
}
}
18 changes: 4 additions & 14 deletions node/components/bft/src/chonky_bft/new_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,10 @@ impl StateMachine {
.process_commit_qc(ctx, qc)
.await
.wrap("process_commit_qc()")?,
validator::ProposalJustification::Timeout(qc) => {
if let Some(high_qc) = qc.high_qc() {
self.process_commit_qc(ctx, high_qc)
.await
.wrap("process_commit_qc()")?;
}
if self
.high_timeout_qc
.as_ref()
.map_or(true, |old| old.view.number < qc.view.number)
{
self.high_timeout_qc = Some(qc.clone());
}
}
validator::ProposalJustification::Timeout(qc) => self
.process_timeout_qc(ctx, qc)
.await
.wrap("process_timeout_qc()")?,
};

// If the message is for a future view, we need to start a new view.
Expand Down
18 changes: 4 additions & 14 deletions node/components/bft/src/chonky_bft/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,10 @@ impl StateMachine {
.process_commit_qc(ctx, qc)
.await
.wrap("process_commit_qc()")?,
validator::ProposalJustification::Timeout(qc) => {
if let Some(high_qc) = qc.high_qc() {
self.process_commit_qc(ctx, high_qc)
.await
.wrap("process_commit_qc()")?;
}
if self
.high_timeout_qc
.as_ref()
.map_or(true, |old| old.view.number < qc.view.number)
{
self.high_timeout_qc = Some(qc.clone());
}
}
validator::ProposalJustification::Timeout(qc) => self
.process_timeout_qc(ctx, qc)
.await
.wrap("process_timeout_qc()")?,
};

// Backup our state.
Expand Down
15 changes: 3 additions & 12 deletions node/components/bft/src/chonky_bft/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,9 @@ impl StateMachine {
);

// We update our state with the new timeout QC.
if let Some(commit_qc) = timeout_qc.high_qc() {
self.process_commit_qc(ctx, commit_qc)
.await
.wrap("process_commit_qc()")?;
}
if self
.high_timeout_qc
.as_ref()
.map_or(true, |old| old.view.number < timeout_qc.view.number)
{
self.high_timeout_qc = Some(timeout_qc.clone());
}
self.process_timeout_qc(ctx, &timeout_qc)
.await
.wrap("process_timeout_qc()")?;

// Start a new view.
self.start_new_view(ctx, message.view.number.next()).await?;
Expand Down

0 comments on commit da72237

Please sign in to comment.