Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Use seconds for IBFT block timer time unit (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
jframe authored Dec 19, 2018
1 parent 14abb2e commit c48604c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit c48604c

Please sign in to comment.