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.
tmohay 6 years ago committed by GitHub
parent 8401db496c
commit 7845494187
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      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 VoteTallyCache voteTallyCache;
private final Address localNodeAddress; private final Address localNodeAddress;
private final Random r = new Random();
public CliqueBlockScheduler( public CliqueBlockScheduler(
final Clock clock, final Clock clock,
@ -64,8 +65,8 @@ public class CliqueBlockScheduler extends DefaultBlockScheduler {
private int calculatorOutOfTurnDelay(final ValidatorProvider validators) { private int calculatorOutOfTurnDelay(final ValidatorProvider validators) {
final int countSigners = validators.getCurrentValidators().size(); final int countSigners = validators.getCurrentValidators().size();
final int maxDelay = ((countSigners / 2) + 1) * OUT_OF_TURN_DELAY_MULTIPLIER_MILLIS; final double multiplier = (countSigners / 2d) + 1;
final Random r = new Random(); final int maxDelay = (int) (multiplier * OUT_OF_TURN_DELAY_MULTIPLIER_MILLIS);
return r.nextInt(maxDelay + 1); return r.nextInt(maxDelay) + 1;
} }
} }

Loading…
Cancel
Save