Skip to content

Commit

Permalink
fix: use floating point numbers for calculating percentage in #checkS…
Browse files Browse the repository at this point in the history
…ignatures(SignedState) (#17027)

Signed-off-by: Tim Farber-Newman <[email protected]>
  • Loading branch information
timfn-hg authored Dec 12, 2024
1 parent e17e124 commit 48c6ade
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ private void checkSignatures(@NonNull final SignedState reservedState) {

// don't log an error if this is a freeze state. they are expected to lack signatures
if (reservedState.isFreezeState()) {
final double signingWeightPercent = (((double) reservedState.getSigningWeight())
/ ((double) reservedState.getAddressBook().getTotalWeight()))
* 100.0;

logger.info(
STATE_TO_DISK.getMarker(),
"""
Expand All @@ -219,10 +223,11 @@ private void checkSignatures(@NonNull final SignedState reservedState) {
reservedState.getRound(),
reservedState.getSigningWeight(),
reservedState.getAddressBook().getTotalWeight(),
reservedState.getSigningWeight()
/ reservedState.getAddressBook().getTotalWeight()
* 100.0);
signingWeightPercent);
} else {
final double signingWeight1Percent = (((double) signingWeight1) / ((double) totalWeight1)) * 100.0;
final double signingWeight2Percent = (((double) signingWeight2) / ((double) totalWeight2)) * 100.0;

logger.error(
EXCEPTION.getMarker(),
new InsufficientSignaturesPayload(
Expand All @@ -235,10 +240,10 @@ private void checkSignatures(@NonNull final SignedState reservedState) {
reservedState.getRound(),
signingWeight1,
totalWeight1,
signingWeight1 / totalWeight1 * 100.0,
signingWeight1Percent,
signingWeight2,
totalWeight2,
signingWeight2 / totalWeight2 * 100.0,
signingWeight2Percent,
Threshold.SUPER_MAJORITY.isSatisfiedBy(signingWeight1, totalWeight1),
Threshold.SUPER_MAJORITY.isSatisfiedBy(signingWeight2, totalWeight2)))));
}
Expand Down

0 comments on commit 48c6ade

Please sign in to comment.