Skip to content

Commit

Permalink
Port "light-client: Optimize voting power calculation by breaking the…
Browse files Browse the repository at this point in the history
… loop when we have enough voting power" (tendermint-rs#1395) (#25)
  • Loading branch information
romac authored Apr 25, 2024
1 parent 394382b commit 5f5d86b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `[cometbft-light-client-verifer]` Optimizing voting power calculation by breaking the loop when we have enough voting power ([#19](https://github.com/cometbft/cometbft-rs/issues/19)).
9 changes: 6 additions & 3 deletions light-client-verifier/src/operations/voting_power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl<V: signature::Verifier> VotingPowerCalculator for ProvidedVotingPowerCalcul
trust_threshold: TrustThreshold,
) -> Result<VotingPowerTally, VerificationError> {
let signatures = &signed_header.commit.signatures;
let total_voting_power = self.total_power_of(validator_set);

let mut tallied_voting_power = 0_u64;
let mut seen_validators = HashSet::new();
Expand Down Expand Up @@ -185,12 +186,14 @@ impl<V: signature::Verifier> VotingPowerCalculator for ProvidedVotingPowerCalcul
// to measure validator availability.
}

// TODO: Break out of the loop when we have enough voting power.
// See https://github.com/informalsystems/tendermint-rs/issues/235
// Break out of the loop when we have enough voting power.
if trust_threshold.is_enough_power(tallied_voting_power, total_voting_power) {
break;
}
}

let voting_power = VotingPowerTally {
total: self.total_power_of(validator_set),
total: total_voting_power,
tallied: tallied_voting_power,
trust_threshold,
};
Expand Down

0 comments on commit 5f5d86b

Please sign in to comment.