From 78454941872c1e87104bbf0c60a5e60c83640f68 Mon Sep 17 00:00:00 2001 From: tmohay <37158202+rain-on@users.noreply.github.com> Date: Mon, 26 Nov 2018 08:53:47 +1100 Subject: [PATCH] Minor repairs to clique block scheduling (#308) Clique was using integer arithmetic to calculate how much "wiggle" delay should be added when the proposer is "out of turn". This would mean when an odd number of validators was in use, the max delay would be 250ms less than the expected value. --- .../clique/blockcreation/CliqueBlockScheduler.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockScheduler.java b/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockScheduler.java index db0507864d..9def5ea0c0 100644 --- a/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockScheduler.java +++ b/consensus/clique/src/main/java/tech/pegasys/pantheon/consensus/clique/blockcreation/CliqueBlockScheduler.java @@ -29,6 +29,7 @@ public class CliqueBlockScheduler extends DefaultBlockScheduler { private final VoteTallyCache voteTallyCache; private final Address localNodeAddress; + private final Random r = new Random(); public CliqueBlockScheduler( final Clock clock, @@ -64,8 +65,8 @@ public class CliqueBlockScheduler extends DefaultBlockScheduler { private int calculatorOutOfTurnDelay(final ValidatorProvider validators) { final int countSigners = validators.getCurrentValidators().size(); - final int maxDelay = ((countSigners / 2) + 1) * OUT_OF_TURN_DELAY_MULTIPLIER_MILLIS; - final Random r = new Random(); - return r.nextInt(maxDelay + 1); + final double multiplier = (countSigners / 2d) + 1; + final int maxDelay = (int) (multiplier * OUT_OF_TURN_DELAY_MULTIPLIER_MILLIS); + return r.nextInt(maxDelay) + 1; } }