diff --git a/config/src/main/java/tech/pegasys/pantheon/config/IbftConfigOptions.java b/config/src/main/java/tech/pegasys/pantheon/config/IbftConfigOptions.java index bf1febc117..4bb943c965 100644 --- a/config/src/main/java/tech/pegasys/pantheon/config/IbftConfigOptions.java +++ b/config/src/main/java/tech/pegasys/pantheon/config/IbftConfigOptions.java @@ -20,7 +20,7 @@ public class IbftConfigOptions { private static final long DEFAULT_EPOCH_LENGTH = 30_000; private static final int DEFAULT_BLOCK_PERIOD_SECONDS = 1; - private static final int DEFAULT_ROUND_EXPIRY_MILLISECONDS = 10000; + private static final int DEFAULT_ROUND_EXPIRY_SECONDS = 1; private final JsonObject ibftConfigRoot; @@ -36,7 +36,7 @@ public class IbftConfigOptions { return ibftConfigRoot.getInteger("blockperiodseconds", DEFAULT_BLOCK_PERIOD_SECONDS); } - public int getRequestTimeoutMillis() { - return ibftConfigRoot.getInteger("requesttimeout", DEFAULT_ROUND_EXPIRY_MILLISECONDS); + public int getRequestTimeoutSeconds() { + return ibftConfigRoot.getInteger("requesttimeoutseconds", DEFAULT_ROUND_EXPIRY_SECONDS); } } diff --git a/config/src/test/java/tech/pegasys/pantheon/config/IbftConfigOptionsTest.java b/config/src/test/java/tech/pegasys/pantheon/config/IbftConfigOptionsTest.java index 9ed52d2356..18add31e3a 100644 --- a/config/src/test/java/tech/pegasys/pantheon/config/IbftConfigOptionsTest.java +++ b/config/src/test/java/tech/pegasys/pantheon/config/IbftConfigOptionsTest.java @@ -25,7 +25,7 @@ public class IbftConfigOptionsTest { private static final int EXPECTED_DEFAULT_EPOCH_LENGTH = 30_000; private static final int EXPECTED_DEFAULT_BLOCK_PERIOD = 1; - private static final int EXPECTED_DEFAULT_REQUEST_TIMEOUT = 10_000; + private static final int EXPECTED_DEFAULT_REQUEST_TIMEOUT = 1; @Test public void shouldGetEpochLengthFromConfig() { @@ -64,19 +64,19 @@ public class IbftConfigOptionsTest { @Test public void shouldGetRequestTimeoutFromConfig() { - final IbftConfigOptions config = fromConfigOptions(singletonMap("RequestTimeout", 5)); - assertThat(config.getRequestTimeoutMillis()).isEqualTo(5); + final IbftConfigOptions config = fromConfigOptions(singletonMap("RequestTimeoutSeconds", 5)); + assertThat(config.getRequestTimeoutSeconds()).isEqualTo(5); } @Test public void shouldFallbackToDefaultRequestTimeout() { final IbftConfigOptions config = fromConfigOptions(emptyMap()); - assertThat(config.getRequestTimeoutMillis()).isEqualTo(EXPECTED_DEFAULT_REQUEST_TIMEOUT); + assertThat(config.getRequestTimeoutSeconds()).isEqualTo(EXPECTED_DEFAULT_REQUEST_TIMEOUT); } @Test public void shouldGetDefaultRequestTimeoutFromDefaultConfig() { - assertThat(IbftConfigOptions.DEFAULT.getRequestTimeoutMillis()) + assertThat(IbftConfigOptions.DEFAULT.getRequestTimeoutSeconds()) .isEqualTo(EXPECTED_DEFAULT_REQUEST_TIMEOUT); } diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftProcessor.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftProcessor.java index 11b04d08f5..70944906cb 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftProcessor.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftProcessor.java @@ -23,6 +23,7 @@ import org.apache.logging.log4j.Logger; /** Execution context for draining queued ibft events and applying them to a maintained state */ public class IbftProcessor implements Runnable { + private static final Logger LOG = LogManager.getLogger(); private final IbftEventQueue incomingQueue; @@ -35,18 +36,18 @@ public class IbftProcessor implements Runnable { * Construct a new IbftProcessor * * @param incomingQueue The event queue from which to drain new events - * @param baseRoundExpiryMillis The expiry time in milliseconds of round 0 + * @param baseRoundExpirySeconds The expiry time in milliseconds of round 0 * @param stateMachine an IbftStateMachine ready to process events and maintain state */ public IbftProcessor( final IbftEventQueue incomingQueue, - final int baseRoundExpiryMillis, + final int baseRoundExpirySeconds, final IbftStateMachine stateMachine) { // Spawning the round timer with a single thread as we should never have more than 1 timer in // flight at a time this( incomingQueue, - baseRoundExpiryMillis, + baseRoundExpirySeconds, stateMachine, Executors.newSingleThreadScheduledExecutor()); } @@ -54,13 +55,14 @@ public class IbftProcessor implements Runnable { @VisibleForTesting IbftProcessor( final IbftEventQueue incomingQueue, - final int baseRoundExpiryMillis, + final int baseRoundExpirySeconds, final IbftStateMachine stateMachine, final ScheduledExecutorService roundTimerExecutor) { this.incomingQueue = incomingQueue; this.roundTimerExecutor = roundTimerExecutor; - this.roundTimer = new RoundTimer(incomingQueue, baseRoundExpiryMillis, roundTimerExecutor); + this.roundTimer = + new RoundTimer(incomingQueue, baseRoundExpirySeconds * 1000, roundTimerExecutor); this.stateMachine = stateMachine; } diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/RoundTimer.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/RoundTimer.java index 970299296c..50f6a74543 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/RoundTimer.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/RoundTimer.java @@ -30,17 +30,17 @@ public class RoundTimer { * Construct a RoundTimer with primed executor service ready to start timers * * @param queue The queue in which to put round expiry events - * @param baseExpiryMillis The initial round length for round 0 + * @param baseExpirySeconds The initial round length for round 0 * @param timerExecutor executor service that timers can be scheduled with */ public RoundTimer( final IbftEventQueue queue, - final long baseExpiryMillis, + final long baseExpirySeconds, final ScheduledExecutorService timerExecutor) { this.queue = queue; this.timerExecutor = timerExecutor; this.currentTimerTask = Optional.empty(); - this.baseExpiryMillis = baseExpiryMillis; + this.baseExpiryMillis = baseExpirySeconds * 1000; } /** Cancels the current running round timer if there is one */ diff --git a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/RoundTimerTest.java b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/RoundTimerTest.java index 9b31a82681..dcf75f91dd 100644 --- a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/RoundTimerTest.java +++ b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/RoundTimerTest.java @@ -59,22 +59,22 @@ public class RoundTimerTest { @Test public void startTimerSchedulesTimerCorrectlyForRound0() { - checkTimerForRound(0, 1); + checkTimerForRound(0, 1000); } @Test public void startTimerSchedulesTimerCorrectlyForRound1() { - checkTimerForRound(1, 2); + checkTimerForRound(1, 2000); } @Test public void startTimerSchedulesTimerCorrectlyForRound2() { - checkTimerForRound(2, 4); + checkTimerForRound(2, 4000); } @Test public void startTimerSchedulesTimerCorrectlyForRound3() { - checkTimerForRound(3, 8); + checkTimerForRound(3, 8000); } private void checkTimerForRound(final int roundNumber, final long timeout) { diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java index 42597ec8fe..693746d7ff 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java @@ -187,7 +187,7 @@ public class IbftPantheonController implements PantheonController { final IbftStateMachine ibftStateMachine = new IbftStateMachine(blockCreatorFactory); final IbftProcessor ibftProcessor = - new IbftProcessor(ibftEventQueue, ibftConfig.getRequestTimeoutMillis(), ibftStateMachine); + new IbftProcessor(ibftEventQueue, ibftConfig.getRequestTimeoutSeconds(), ibftStateMachine); final ExecutorService processorExecutor = Executors.newSingleThreadExecutor(); processorExecutor.submit(ibftProcessor); diff --git a/pantheon/src/test/resources/ibftlegacy_genesis.json b/pantheon/src/test/resources/ibftlegacy_genesis.json index 870a49f48e..84a297fd19 100644 --- a/pantheon/src/test/resources/ibftlegacy_genesis.json +++ b/pantheon/src/test/resources/ibftlegacy_genesis.json @@ -10,7 +10,7 @@ "ibft": { "epochLength": 30000, "blockPeriodSeconds" : 1, - "requestTimeout": 10000 + "requestTimeoutSeconds": 10 } }, "nonce": "0x0",