Update IbftConfig Fields (#422)

The RequestTimeout field in the IbftConfig has been updated to be
"RequestTimeoutSeconds".
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
tmohay 6 years ago committed by GitHub
parent 9c20477a6a
commit 913c4b2039
  1. 6
      config/src/main/java/tech/pegasys/pantheon/config/IbftConfigOptions.java
  2. 10
      config/src/test/java/tech/pegasys/pantheon/config/IbftConfigOptionsTest.java
  3. 12
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftProcessor.java
  4. 6
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/RoundTimer.java
  5. 8
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/RoundTimerTest.java
  6. 2
      pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java
  7. 2
      pantheon/src/test/resources/ibftlegacy_genesis.json

@ -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);
}
}

@ -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);
}

@ -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;
}

@ -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 */

@ -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) {

@ -187,7 +187,7 @@ public class IbftPantheonController implements PantheonController<IbftContext> {
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);

@ -10,7 +10,7 @@
"ibft": {
"epochLength": 30000,
"blockPeriodSeconds" : 1,
"requestTimeout": 10000
"requestTimeoutSeconds": 10
}
},
"nonce": "0x0",

Loading…
Cancel
Save