From 9807e8348c1cde36ce58c06ed17f3aa337daa63a Mon Sep 17 00:00:00 2001 From: Nikita Masych Date: Tue, 10 Sep 2024 14:22:03 +0300 Subject: [PATCH] fix: include own weight in threshold checks in update_state --- src/party.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/party.rs b/src/party.rs index ffaab31..62772eb 100644 --- a/src/party.rs +++ b/src/party.rs @@ -474,7 +474,8 @@ impl> Party { self.messages_1b_weight += self.cfg.party_weights[routing.sender as usize] as u128; - if self.messages_1b_weight >= self.cfg.threshold { + let self_weight = self.cfg.party_weights[self.id as usize] as u128; + if self.messages_1b_weight >= self.cfg.threshold - self_weight { self.status = PartyStatus::Passed1b; } } @@ -554,7 +555,8 @@ impl> Party { self.cfg.party_weights[routing.sender as usize] as u128, ); - if self.messages_2av_state.get_weight() >= self.cfg.threshold { + let self_weight = self.cfg.party_weights[self.id as usize] as u128; + if self.messages_2av_state.get_weight() >= self.cfg.threshold - self_weight { self.status = PartyStatus::Passed2av; } } @@ -586,7 +588,8 @@ impl> Party { self.cfg.party_weights[routing.sender as usize] as u128, ); - if self.messages_2b_state.get_weight() >= self.cfg.threshold { + let self_weight = self.cfg.party_weights[self.id as usize] as u128; + if self.messages_2b_state.get_weight() >= self.cfg.threshold - self_weight { self.status = PartyStatus::Passed2b; } } @@ -1143,7 +1146,7 @@ pub(crate) mod tests { #[tokio::test] async fn test_ballot_faulty_party() { - let cfg = BPConConfig::with_default_timeouts(vec![1, 1, 1, 1], 2); + let cfg = BPConConfig::with_default_timeouts(vec![1, 1, 1, 1], 3); let (mut parties, mut channels) = create_parties(cfg);