Search in sources :

Example 1 with RoundChangeMessageData

use of org.hyperledger.besu.consensus.qbft.messagedata.RoundChangeMessageData in project besu by hyperledger.

the class QbftBlockHeightManagerTest method preparedCertificateIncludedInRoundChangeMessageOnRoundTimeoutExpired.

@Test
public void preparedCertificateIncludedInRoundChangeMessageOnRoundTimeoutExpired() {
    when(finalState.isLocalNodeProposerForRound(any())).thenReturn(true);
    final QbftBlockHeightManager manager = new QbftBlockHeightManager(headerTestFixture.buildHeader(), finalState, roundChangeManager, roundFactory, clock, messageValidatorFactory, messageFactory);
    // Trigger a Proposal creation.
    manager.handleBlockTimerExpiry(roundIdentifier);
    final Prepare localPrepare = messageFactory.createPrepare(roundIdentifier, createdBlock.getHash());
    final Prepare firstPrepare = validatorMessageFactory.get(0).createPrepare(roundIdentifier, Hash.fromHexStringLenient("0"));
    final Prepare secondPrepare = validatorMessageFactory.get(1).createPrepare(roundIdentifier, Hash.fromHexStringLenient("0"));
    final Prepare thirdPrepare = validatorMessageFactory.get(2).createPrepare(roundIdentifier, Hash.fromHexStringLenient("0"));
    manager.handlePreparePayload(firstPrepare);
    manager.handlePreparePayload(secondPrepare);
    manager.handlePreparePayload(thirdPrepare);
    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;
    final RoundChange receivedRoundChange = roundChange.decode(bftExtraDataCodec);
    Assertions.assertThat(receivedRoundChange.getPreparedRoundMetadata()).isNotEmpty();
    assertThat(receivedRoundChange.getPrepares()).containsOnly(localPrepare.getSignedPayload(), firstPrepare.getSignedPayload(), secondPrepare.getSignedPayload(), thirdPrepare.getSignedPayload());
}
Also used : RoundChange(org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange) RoundChangeMessageData(org.hyperledger.besu.consensus.qbft.messagedata.RoundChangeMessageData) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) Prepare(org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare) RoundChangeMessageData(org.hyperledger.besu.consensus.qbft.messagedata.RoundChangeMessageData) RoundExpiry(org.hyperledger.besu.consensus.common.bft.events.RoundExpiry) Test(org.junit.Test)

Example 2 with RoundChangeMessageData

use of org.hyperledger.besu.consensus.qbft.messagedata.RoundChangeMessageData in project besu by hyperledger.

the class QbftMessageTransmitter method multicastRoundChange.

public void multicastRoundChange(final ConsensusRoundIdentifier roundIdentifier, final Optional<PreparedCertificate> preparedRoundCertificate) {
    try {
        final RoundChange data = messageFactory.createRoundChange(roundIdentifier, preparedRoundCertificate);
        final RoundChangeMessageData message = RoundChangeMessageData.create(data);
        multicaster.send(message);
    } catch (final SecurityModuleException e) {
        LOG.warn("Failed to generate signature for RoundChange (not sent): {} ", e.getMessage());
    }
}
Also used : RoundChange(org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange) SecurityModuleException(org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException) RoundChangeMessageData(org.hyperledger.besu.consensus.qbft.messagedata.RoundChangeMessageData)

Aggregations

RoundChangeMessageData (org.hyperledger.besu.consensus.qbft.messagedata.RoundChangeMessageData)2 RoundChange (org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange)2 RoundExpiry (org.hyperledger.besu.consensus.common.bft.events.RoundExpiry)1 Prepare (org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare)1 MessageData (org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData)1 SecurityModuleException (org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException)1 Test (org.junit.Test)1