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());
}
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());
}
}
Aggregations