Search in sources :

Example 1 with RoundExpiry

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));
}
Also used : RoundExpiry(org.hyperledger.besu.consensus.common.bft.events.RoundExpiry) Test(org.junit.Test)

Example 2 with RoundExpiry

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);
}
Also used : RoundExpiry(org.hyperledger.besu.consensus.common.bft.events.RoundExpiry)

Example 3 with RoundExpiry

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);
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) RoundChange(org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange) Prepare(org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare) IntegrationTestHelpers.createValidPreparedCertificate(org.hyperledger.besu.consensus.qbft.support.IntegrationTestHelpers.createValidPreparedCertificate) PreparedCertificate(org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate) RoundExpiry(org.hyperledger.besu.consensus.common.bft.events.RoundExpiry) Test(org.junit.jupiter.api.Test)

Example 4 with RoundExpiry

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();
}
Also used : NewChainHead(org.hyperledger.besu.consensus.common.bft.events.NewChainHead) RoundExpiry(org.hyperledger.besu.consensus.common.bft.events.RoundExpiry) Test(org.junit.jupiter.api.Test)

Example 5 with RoundExpiry

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());
}
Also used : RoundChangeMessageData(org.hyperledger.besu.consensus.ibft.messagedata.RoundChangeMessageData) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) Prepare(org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare) PreparedCertificate(org.hyperledger.besu.consensus.ibft.payload.PreparedCertificate) RoundChangeMessageData(org.hyperledger.besu.consensus.ibft.messagedata.RoundChangeMessageData) RoundExpiry(org.hyperledger.besu.consensus.common.bft.events.RoundExpiry) Test(org.junit.Test)

Aggregations

RoundExpiry (org.hyperledger.besu.consensus.common.bft.events.RoundExpiry)26 Test (org.junit.jupiter.api.Test)14 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)10 Test (org.junit.Test)10 RoundChange (org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange)5 RoundChange (org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange)4 NewChainHead (org.hyperledger.besu.consensus.common.bft.events.NewChainHead)3 BlockTimerExpiry (org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry)2 Prepare (org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare)2 Prepare (org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare)2 MessageData (org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData)2 ExecutorService (java.util.concurrent.ExecutorService)1 BftReceivedMessageEvent (org.hyperledger.besu.consensus.common.bft.events.BftReceivedMessageEvent)1 RoundChangeMessageData (org.hyperledger.besu.consensus.ibft.messagedata.RoundChangeMessageData)1 Proposal (org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal)1 PreparedCertificate (org.hyperledger.besu.consensus.ibft.payload.PreparedCertificate)1 PreparedRoundArtifacts (org.hyperledger.besu.consensus.ibft.statemachine.PreparedRoundArtifacts)1 IntegrationTestHelpers.createValidPreparedRoundArtifacts (org.hyperledger.besu.consensus.ibft.support.IntegrationTestHelpers.createValidPreparedRoundArtifacts)1 RoundChangeMessageData (org.hyperledger.besu.consensus.qbft.messagedata.RoundChangeMessageData)1 PreparedCertificate (org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate)1