Skip to content

Commit

Permalink
Merge pull request AleoNet#2875 from AleoHQ/avoid_race_quorum_thresho…
Browse files Browse the repository at this point in the history
…ld_reached

Avoid race condition reaching quorum threshold
  • Loading branch information
howardwu authored Dec 6, 2023
2 parents 872d76a + 341db05 commit be21b76
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions node/bft/src/primary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,9 +1297,19 @@ impl<N: Network> Primary<N> {
bail!("Round {batch_round} is too far in the past")
}

// Determine if quorum threshold is reached on the batch round.
let is_quorum_threshold_reached = {
let certificates = self.storage.get_certificates_for_round(batch_round);
let authors = certificates.iter().map(BatchCertificate::author).collect();
let previous_committee = self.ledger.get_previous_committee_for_round(batch_round)?;
previous_committee.is_quorum_threshold_reached(&authors)
};

// Check if our primary should move to the next round.
// TODO (howardwu): Re-evaluate whether we need to guard this to increment after quorum threshold is reached.
let is_behind_schedule = batch_round > self.current_round();
// Note: Checking that quorum threshold is reached is important for mitigating a race condition,
// whereby Narwhal requires 2f+1, however the BFT only requires f+1. Without this check, the primary
// will advance to the next round assuming f+1, not 2f+1, which can lead to a network stall.
let is_behind_schedule = is_quorum_threshold_reached && batch_round > self.current_round();
// Check if our primary is far behind the peer.
let is_peer_far_in_future = batch_round > self.current_round() + self.storage.max_gc_rounds();
// If our primary is far behind the peer, update our committee to the batch round.
Expand Down

0 comments on commit be21b76

Please sign in to comment.