diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/BlockTimer.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/BlockTimer.java index 66cae85bee..636116061f 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/BlockTimer.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/BlockTimer.java @@ -33,19 +33,19 @@ public class BlockTimer { * Construct a BlockTimer with primed executor service ready to start timers * * @param queue The queue in which to put block expiry events - * @param minimumTimeBetweenBlocksMillis Minimum timestamp difference between blocks + * @param minimumTimeBetweenBlocksSeconds Minimum timestamp difference between blocks * @param timerExecutor Executor service that timers can be scheduled with * @param clock System clock */ public BlockTimer( final IbftEventQueue queue, - final long minimumTimeBetweenBlocksMillis, + final long minimumTimeBetweenBlocksSeconds, final ScheduledExecutorService timerExecutor, final Clock clock) { this.queue = queue; this.timerExecutor = timerExecutor; this.currentTimerTask = Optional.empty(); - this.minimumTimeBetweenBlocksMillis = minimumTimeBetweenBlocksMillis; + this.minimumTimeBetweenBlocksMillis = minimumTimeBetweenBlocksSeconds * 1000; this.clock = clock; } 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 4c752a3b74..26579c8878 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 @@ -62,9 +62,7 @@ public IbftProcessor( final ScheduledExecutorService roundTimerExecutor) { this.incomingQueue = incomingQueue; this.roundTimerExecutor = roundTimerExecutor; - - this.roundTimer = - new RoundTimer(incomingQueue, baseRoundExpirySeconds * 1000, roundTimerExecutor); + this.roundTimer = new RoundTimer(incomingQueue, baseRoundExpirySeconds, roundTimerExecutor); this.stateMachine = stateMachine; } diff --git a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/BlockTimerTest.java b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/BlockTimerTest.java index 08f9a4a1d3..fd4b561f80 100644 --- a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/BlockTimerTest.java +++ b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/BlockTimerTest.java @@ -57,7 +57,7 @@ public void initialise() { @Test public void cancelTimerCancelsWhenNoTimer() { - final BlockTimer timer = new BlockTimer(mockQueue, 15_000, mockExecutorService, mockClock); + final BlockTimer timer = new BlockTimer(mockQueue, 15, mockExecutorService, mockClock); // Starts with nothing running assertThat(timer.isRunning()).isFalse(); // cancel shouldn't die if there's nothing running @@ -68,14 +68,14 @@ public void cancelTimerCancelsWhenNoTimer() { @Test public void startTimerSchedulesCorrectlyWhenExpiryIsInTheFuture() { - final long MINIMAL_TIME_BETWEEN_BLOCKS_MILLIS = 15_000; + final long MINIMAL_TIME_BETWEEN_BLOCKS_SECONDS = 15; final long NOW_MILLIS = 505_000L; final long BLOCK_TIME_STAMP = 500L; final long EXPECTED_DELAY = 10_000L; final BlockTimer timer = new BlockTimer( - mockQueue, MINIMAL_TIME_BETWEEN_BLOCKS_MILLIS, mockExecutorService, mockClock); + mockQueue, MINIMAL_TIME_BETWEEN_BLOCKS_SECONDS, mockExecutorService, mockClock); when(mockClock.millis()).thenReturn(NOW_MILLIS); @@ -96,8 +96,7 @@ public void startTimerSchedulesCorrectlyWhenExpiryIsInTheFuture() { @Test public void aBlockTimerExpiryEventIsAddedToTheQueueOnExpiry() { - - final long MINIMAL_TIME_BETWEEN_BLOCKS_MILLIS = 1_000; + final long MINIMAL_TIME_BETWEEN_BLOCKS_SECONDS = 1; final long NOW_MILLIS = 300_500L; final long BLOCK_TIME_STAMP = 300; final long EXPECTED_DELAY = 500; @@ -112,7 +111,7 @@ public void aBlockTimerExpiryEventIsAddedToTheQueueOnExpiry() { final BlockTimer timer = new BlockTimer( mockQueue, - MINIMAL_TIME_BETWEEN_BLOCKS_MILLIS, + MINIMAL_TIME_BETWEEN_BLOCKS_SECONDS, Executors.newSingleThreadScheduledExecutor(), mockClock); timer.startTimer(round, header); @@ -135,13 +134,13 @@ public void aBlockTimerExpiryEventIsAddedToTheQueueOnExpiry() { @Test public void eventIsImmediatelyAddedToTheQueueIfAbsoluteExpiryIsEqualToNow() { - final long MINIMAL_TIME_BETWEEN_BLOCKS_MILLIS = 15_000; + final long MINIMAL_TIME_BETWEEN_BLOCKS_SECONDS = 15; final long NOW_MILLIS = 515_000L; final long BLOCK_TIME_STAMP = 500; final BlockTimer timer = new BlockTimer( - mockQueue, MINIMAL_TIME_BETWEEN_BLOCKS_MILLIS, mockExecutorService, mockClock); + mockQueue, MINIMAL_TIME_BETWEEN_BLOCKS_SECONDS, mockExecutorService, mockClock); when(mockClock.millis()).thenReturn(NOW_MILLIS); @@ -163,13 +162,13 @@ public void eventIsImmediatelyAddedToTheQueueIfAbsoluteExpiryIsEqualToNow() { @Test public void eventIsImmediatelyAddedToTheQueueIfAbsoluteExpiryIsInThePast() { - final long MINIMAL_TIME_BETWEEN_BLOCKS_MILLIS = 15_000; + final long MINIMAL_TIME_BETWEEN_BLOCKS_SECONDS = 15; final long NOW_MILLIS = 520_000L; final long BLOCK_TIME_STAMP = 500L; final BlockTimer timer = new BlockTimer( - mockQueue, MINIMAL_TIME_BETWEEN_BLOCKS_MILLIS, mockExecutorService, mockClock); + mockQueue, MINIMAL_TIME_BETWEEN_BLOCKS_SECONDS, mockExecutorService, mockClock); when(mockClock.millis()).thenReturn(NOW_MILLIS); @@ -191,13 +190,13 @@ public void eventIsImmediatelyAddedToTheQueueIfAbsoluteExpiryIsInThePast() { @Test public void startTimerCancelsExistingTimer() { - final long MINIMAL_TIME_BETWEEN_BLOCKS_MILLIS = 15_0000; + final long MINIMAL_TIME_BETWEEN_BLOCKS_SECONDS = 15; final long NOW_MILLIS = 500_000L; final long BLOCK_TIME_STAMP = 500L; final BlockTimer timer = new BlockTimer( - mockQueue, MINIMAL_TIME_BETWEEN_BLOCKS_MILLIS, mockExecutorService, mockClock); + mockQueue, MINIMAL_TIME_BETWEEN_BLOCKS_SECONDS, mockExecutorService, mockClock); when(mockClock.millis()).thenReturn(NOW_MILLIS); @@ -218,13 +217,13 @@ public void startTimerCancelsExistingTimer() { @Test public void runningFollowsTheStateOfTheTimer() { - final long MINIMAL_TIME_BETWEEN_BLOCKS_MILLIS = 15_0000; + final long MINIMAL_TIME_BETWEEN_BLOCKS_SECONDS = 15; final long NOW_MILLIS = 500_000L; final long BLOCK_TIME_STAMP = 500L; final BlockTimer timer = new BlockTimer( - mockQueue, MINIMAL_TIME_BETWEEN_BLOCKS_MILLIS, mockExecutorService, mockClock); + mockQueue, MINIMAL_TIME_BETWEEN_BLOCKS_SECONDS, mockExecutorService, mockClock); when(mockClock.millis()).thenReturn(NOW_MILLIS);