use of org.hyperledger.besu.consensus.common.bft.events.RoundExpiry in project besu by hyperledger.
the class QbftBlockHeightManagerTest method onRoundTimerExpiryANewRoundIsCreatedWithAnIncrementedRoundNumber.
@Test
public void onRoundTimerExpiryANewRoundIsCreatedWithAnIncrementedRoundNumber() {
final QbftBlockHeightManager manager = new QbftBlockHeightManager(headerTestFixture.buildHeader(), finalState, roundChangeManager, roundFactory, clock, messageValidatorFactory, messageFactory);
manager.handleBlockTimerExpiry(roundIdentifier);
verify(roundFactory).createNewRound(any(), eq(0));
manager.roundExpired(new RoundExpiry(roundIdentifier));
verify(roundFactory).createNewRound(any(), eq(1));
}
use of org.hyperledger.besu.consensus.common.bft.events.RoundExpiry in project besu by hyperledger.
the class RoundTimer method startTimer.
/**
* Starts a timer for the supplied round cancelling any previously active round timer
*
* @param round The round identifier which this timer is tracking
*/
public synchronized void startTimer(final ConsensusRoundIdentifier round) {
cancelTimer();
final long expiryTime = baseExpiryMillis * (long) Math.pow(2, round.getRoundNumber());
final Runnable newTimerRunnable = () -> queue.add(new RoundExpiry(round));
final ScheduledFuture<?> newTimerTask = bftExecutors.scheduleTask(newTimerRunnable, expiryTime, TimeUnit.MILLISECONDS);
currentTimerTask = Optional.of(newTimerTask);
}
use of org.hyperledger.besu.consensus.common.bft.events.RoundExpiry in project besu by hyperledger.
the class RoundChangeTest method roundChangeHasPopulatedCertificateIfQuorumPrepareMessagesAndProposalAreReceived.
@Test
public void roundChangeHasPopulatedCertificateIfQuorumPrepareMessagesAndProposalAreReceived() {
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1);
final Prepare localPrepareMessage = localNodeMessageFactory.createPrepare(roundId, blockToPropose.getHash());
peers.getProposer().injectProposal(roundId, blockToPropose);
final Prepare p0 = peers.getProposer().injectPrepare(roundId, blockToPropose.getHash());
peers.clearReceivedMessages();
final Prepare p1 = peers.getNonProposing(0).injectPrepare(roundId, blockToPropose.getHash());
peers.clearReceivedMessages();
final Prepare p2 = peers.getNonProposing(1).injectPrepare(roundId, blockToPropose.getHash());
peers.clearReceivedMessages();
final RoundChange expectedTxRoundChange = localNodeMessageFactory.createRoundChange(targetRound, Optional.of(new PreparedCertificate(blockToPropose, List.of(localPrepareMessage, p0, p1, p2).stream().map(Prepare::getSignedPayload).collect(Collectors.toList()), roundId.getRoundNumber())));
context.getController().handleRoundExpiry(new RoundExpiry(roundId));
peers.verifyMessagesReceived(expectedTxRoundChange);
}
use of org.hyperledger.besu.consensus.common.bft.events.RoundExpiry in project besu by hyperledger.
the class LocalNodeIsProposerTest method nodeDoesNotSendRoundChangeIfRoundTimesOutAfterBlockImportButBeforeNewBlock.
@Test
public void nodeDoesNotSendRoundChangeIfRoundTimesOutAfterBlockImportButBeforeNewBlock() {
peers.verifyMessagesReceived(expectedTxProposal, expectedTxPrepare);
peers.getNonProposing(0).injectCommit(roundId, expectedProposedBlock);
assertThat(context.getBlockchain().getChainHeadBlockNumber()).isEqualTo(0);
peers.verifyNoMessagesReceived();
peers.getNonProposing(1).injectCommit(roundId, expectedProposedBlock);
assertThat(context.getBlockchain().getChainHeadBlockNumber()).isEqualTo(1);
peers.verifyNoMessagesReceived();
context.getController().handleRoundExpiry(new RoundExpiry(roundId));
peers.verifyNoMessagesReceived();
context.getController().handleNewBlockEvent(new NewChainHead(expectedProposedBlock.getHeader()));
peers.verifyNoMessagesReceived();
}
use of org.hyperledger.besu.consensus.common.bft.events.RoundExpiry in project besu by hyperledger.
the class IbftBlockHeightManagerTest method preparedCertificateIncludedInRoundChangeMessageOnRoundTimeoutExpired.
@Test
public void preparedCertificateIncludedInRoundChangeMessageOnRoundTimeoutExpired() {
final IbftBlockHeightManager manager = new IbftBlockHeightManager(headerTestFixture.buildHeader(), finalState, roundChangeManager, roundFactory, clock, messageValidatorFactory, messageFactory);
// Trigger a Proposal creation.
manager.handleBlockTimerExpiry(roundIdentifier);
final Prepare firstPrepare = validatorMessageFactory.get(0).createPrepare(roundIdentifier, Hash.fromHexStringLenient("0"));
final Prepare secondPrepare = validatorMessageFactory.get(1).createPrepare(roundIdentifier, Hash.fromHexStringLenient("0"));
manager.handlePreparePayload(firstPrepare);
manager.handlePreparePayload(secondPrepare);
manager.roundExpired(new RoundExpiry(roundIdentifier));
verify(validatorMulticaster, times(1)).send(sentMessageArgCaptor.capture());
final MessageData capturedMessageData = sentMessageArgCaptor.getValue();
assertThat(capturedMessageData).isInstanceOf(RoundChangeMessageData.class);
final RoundChangeMessageData roundChange = (RoundChangeMessageData) capturedMessageData;
Optional<PreparedCertificate> preparedCert = roundChange.decode().getPreparedCertificate();
Assertions.assertThat(preparedCert).isNotEmpty();
assertThat(preparedCert.get().getPreparePayloads()).containsOnly(firstPrepare.getSignedPayload(), secondPrepare.getSignedPayload());
}
Aggregations