From 7a7ca4b68410d5a95397406721b66b566eff1e1b Mon Sep 17 00:00:00 2001 From: catbref Date: Tue, 7 Jan 2020 14:23:09 +0000 Subject: [PATCH] Fix rounding issue when checking whether tx meets approval threshold --- src/main/java/org/qora/group/Group.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/qora/group/Group.java b/src/main/java/org/qora/group/Group.java index 6d3de7db..bb182b60 100644 --- a/src/main/java/org/qora/group/Group.java +++ b/src/main/java/org/qora/group/Group.java @@ -62,7 +62,11 @@ public class Group { if (!this.isPercentage) return currentApprovals >= this.value; - return currentApprovals >= (totalAdmins * this.value / 100); + // Multiply currentApprovals by 100 instead of dividing right-hand-side by 100 to prevent rounding errors! + // Examples using 2 current approvals, 4 total admins, 60% threshold: + // WRONG: 2 >= 4 * 60 / 100, i.e. 2 >= (240 / 100) which rounds to: 2 >= 2, returns true + // RIGHT: 2 * 100 >= 4 * 60, i.e. 200 >= 240, returns false + return (currentApprovals * 100) >= (totalAdmins * this.value); } }