From e95887cc561ea41e2e5f417886df4b65aee2b8da Mon Sep 17 00:00:00 2001 From: ungaro Date: Sat, 24 Aug 2024 10:16:38 -0400 Subject: [PATCH 1/3] fix imprecision in is_round_reached function --- node/bft/tests/common/primary.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/node/bft/tests/common/primary.rs b/node/bft/tests/common/primary.rs index 5825cf09a1..7beddfeb6e 100644 --- a/node/bft/tests/common/primary.rs +++ b/node/bft/tests/common/primary.rs @@ -278,9 +278,11 @@ impl TestNetwork { sleep(Duration::from_millis(100)).await; } - // Checks if at least 2f + 1 nodes have reached the given round. + /// Checks if a Byzantine fault-tolerant quorum of validators has reached the given round. + /// Assuming `N = 3f + 1 + k`, where `0 <= k < 3`, + /// then `N - f = 2f + 1 + k = N - (N-1)/3`. pub fn is_round_reached(&self, round: u64) -> bool { - let quorum_threshold = self.validators.len() / 2 + 1; + let quorum_threshold = self.validators.len() - (self.validators.len() - 1) / 3; self.validators.values().filter(|v| v.primary.current_round() >= round).count() >= quorum_threshold } From 778fa0a88ef18ff8e4d89652a84c7bd05894873c Mon Sep 17 00:00:00 2001 From: ungaro Date: Sat, 24 Aug 2024 10:31:39 -0400 Subject: [PATCH 2/3] better comment --- node/bft/tests/common/primary.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/bft/tests/common/primary.rs b/node/bft/tests/common/primary.rs index 7beddfeb6e..1ad9829568 100644 --- a/node/bft/tests/common/primary.rs +++ b/node/bft/tests/common/primary.rs @@ -279,8 +279,8 @@ impl TestNetwork { } /// Checks if a Byzantine fault-tolerant quorum of validators has reached the given round. - /// Assuming `N = 3f + 1 + k`, where `0 <= k < 3`, - /// then `N - f = 2f + 1 + k = N - (N-1)/3`. + /// Assuming `N = 3f + 1 + k`, where `0 <= k < 3`, and '/' denotes integer division, + /// then `N - (N-1)/3 = 2N/3 + 1 = 2f + 1 + (2k+2)/3 = 2f + 1 + k = N - f`. pub fn is_round_reached(&self, round: u64) -> bool { let quorum_threshold = self.validators.len() - (self.validators.len() - 1) / 3; self.validators.values().filter(|v| v.primary.current_round() >= round).count() >= quorum_threshold From eb20644cd53986935416452e3691ca87ecb965f0 Mon Sep 17 00:00:00 2001 From: ungaro Date: Sat, 24 Aug 2024 11:00:22 -0400 Subject: [PATCH 3/3] remove unnecessary use of doc comment --- node/bft/tests/common/primary.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/node/bft/tests/common/primary.rs b/node/bft/tests/common/primary.rs index 1ad9829568..fd0cde9e5c 100644 --- a/node/bft/tests/common/primary.rs +++ b/node/bft/tests/common/primary.rs @@ -278,9 +278,9 @@ impl TestNetwork { sleep(Duration::from_millis(100)).await; } - /// Checks if a Byzantine fault-tolerant quorum of validators has reached the given round. - /// Assuming `N = 3f + 1 + k`, where `0 <= k < 3`, and '/' denotes integer division, - /// then `N - (N-1)/3 = 2N/3 + 1 = 2f + 1 + (2k+2)/3 = 2f + 1 + k = N - f`. + // Checks if a Byzantine fault-tolerant quorum of validators has reached the given round. + // Assuming `N = 3f + 1 + k`, where `0 <= k < 3`, and '/' denotes integer division, + // then `N - (N-1)/3 = 2N/3 + 1 = 2f + 1 + (2k+2)/3 = 2f + 1 + k = N - f`. pub fn is_round_reached(&self, round: u64) -> bool { let quorum_threshold = self.validators.len() - (self.validators.len() - 1) / 3; self.validators.values().filter(|v| v.primary.current_round() >= round).count() >= quorum_threshold