use of org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare 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());
}
use of org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare in project besu by hyperledger.
the class RoundChangeSignedDataValidatorTest method roundChangeInvalidPrepareMessageFromProposerFails.
@Test
public void roundChangeInvalidPrepareMessageFromProposerFails() {
final Prepare prepareMsg = validatorMessageFactory.createPrepare(currentRound, block.getHash());
final PreparedRoundArtifacts preparedRoundArtifacts = new PreparedRoundArtifacts(proposerMessageFactory.createProposal(currentRound, block, Optional.empty()), Lists.newArrayList(prepareMsg));
when(basicValidator.validateProposal(any())).thenReturn(true);
when(basicValidator.validatePrepare(any())).thenReturn(false);
final RoundChange msg = proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtifacts));
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse();
verify(basicValidator, times(1)).validatePrepare(prepareMsg.getSignedPayload());
verify(basicValidator, never()).validateCommit(any());
}
use of org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare in project besu by hyperledger.
the class RoundChangeSignedDataValidatorTest method roundChangeWithDuplicatedPreparesFails.
@Test
public void roundChangeWithDuplicatedPreparesFails() {
final RoundChangePayloadValidator validatorRequiringTwoPrepares = new RoundChangePayloadValidator(validatorFactory, validators, 2, chainHeight);
final Prepare prepareMsg = validatorMessageFactory.createPrepare(currentRound, block.getHash());
final PreparedRoundArtifacts preparedRoundArtifacts = new PreparedRoundArtifacts(proposerMessageFactory.createProposal(currentRound, block, Optional.empty()), Lists.newArrayList(prepareMsg, prepareMsg));
final PreparedCertificate prepareCertificate = preparedRoundArtifacts.getPreparedCertificate();
final RoundChange msg = proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtifacts));
when(basicValidator.validateProposal(prepareCertificate.getProposalPayload())).thenReturn(true);
when(basicValidator.validatePrepare(prepareMsg.getSignedPayload())).thenReturn(true);
assertThat(validatorRequiringTwoPrepares.validateRoundChange(msg.getSignedPayload())).isFalse();
}
use of org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare in project besu by hyperledger.
the class SignedDataValidatorTest method receivingPrepareFromProposerFails.
@Test
public void receivingPrepareFromProposerFails() {
final Proposal proposalMsg = proposerMessageFactory.createProposal(roundIdentifier, block, Optional.empty());
final Prepare prepareMsg = proposerMessageFactory.createPrepare(roundIdentifier, block.getHash());
assertThat(validator.validateProposal(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepare(prepareMsg.getSignedPayload())).isFalse();
}
use of org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare in project besu by hyperledger.
the class IbftRound method handleProposalMessage.
public void handleProposalMessage(final Proposal msg) {
LOG.debug("Received a proposal message. round={}", roundState.getRoundIdentifier());
final Block block = msg.getBlock();
if (updateStateWithProposedBlock(msg)) {
LOG.debug("Sending prepare message. round={}", roundState.getRoundIdentifier());
try {
final Prepare localPrepareMessage = messageFactory.createPrepare(getRoundIdentifier(), block.getHash());
peerIsPrepared(localPrepareMessage);
transmitter.multicastPrepare(localPrepareMessage.getRoundIdentifier(), localPrepareMessage.getDigest());
} catch (final SecurityModuleException e) {
LOG.warn("Failed to create a signed Prepare; {}", e.getMessage());
}
}
}
Aggregations