Skip to content

Commit

Permalink
fix: include own weight in threshold checks in update_state
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaMasych committed Sep 10, 2024
1 parent c1a689e commit 9807e83
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/party.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ impl<V: Value, VS: ValueSelector<V>> Party<V, VS> {
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;
}
}
Expand Down Expand Up @@ -554,7 +555,8 @@ impl<V: Value, VS: ValueSelector<V>> Party<V, VS> {
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;
}
}
Expand Down Expand Up @@ -586,7 +588,8 @@ impl<V: Value, VS: ValueSelector<V>> Party<V, VS> {
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;
}
}
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 9807e83

Please sign in to comment.