use of org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare in project besu by hyperledger.
the class RoundStateTest method invalidPriorPrepareMessagesAreDiscardedUponSubsequentProposal.
@Test
public void invalidPriorPrepareMessagesAreDiscardedUponSubsequentProposal() {
final Prepare firstPrepare = validatorMessageFactories.get(1).createPrepare(roundIdentifier, block.getHash());
final Prepare secondPrepare = validatorMessageFactories.get(2).createPrepare(roundIdentifier, block.getHash());
// RoundState has a quorum size of 3, meaning 1 proposal and 2 prepare are required to be
// 'prepared'.
final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator);
when(messageValidator.validateProposal(any())).thenReturn(true);
when(messageValidator.validatePrepare(firstPrepare)).thenReturn(true);
when(messageValidator.validatePrepare(secondPrepare)).thenReturn(false);
roundState.addPrepareMessage(firstPrepare);
roundState.addPrepareMessage(secondPrepare);
verify(messageValidator, never()).validatePrepare(any());
final Proposal proposal = validatorMessageFactories.get(0).createProposal(roundIdentifier, block, Collections.emptyList(), Collections.emptyList());
assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isFalse();
assertThat(roundState.isCommitted()).isFalse();
assertThat(roundState.constructPreparedCertificate()).isEmpty();
}
use of org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare in project besu by hyperledger.
the class PrepareValidatorTest method prepareSignedByANonValidatorFails.
@Test
public void prepareSignedByANonValidatorFails() {
final QbftNode nonValidator = QbftNode.create();
final Prepare msg = nonValidator.getMessageFactory().createPrepare(round, expectedHash);
assertThat(validator.validate(msg)).isFalse();
}
use of org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare in project besu by hyperledger.
the class ProposalValidatorTest method validationFailsIfRoundZeroHasNonEmptyPrepares.
@Test
public void validationFailsIfRoundZeroHasNonEmptyPrepares() {
final Prepare prepareMsg = validators.getMessageFactory(1).createPrepare(roundItems.get(ROUND_ID.ZERO).roundIdentifier, roundItems.get(ROUND_ID.ZERO).block.getHash());
final Proposal proposal = validators.getMessageFactory(0).createProposal(roundItems.get(ROUND_ID.ZERO).roundIdentifier, roundItems.get(ROUND_ID.ZERO).block, emptyList(), List.of(prepareMsg.getSignedPayload()));
assertThat(roundItems.get(ROUND_ID.ZERO).messageValidator.validate(proposal)).isFalse();
}
use of org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare in project besu by hyperledger.
the class QbftRound method sendPrepare.
private void sendPrepare(final Block block) {
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());
}
}
use of org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare in project besu by hyperledger.
the class QbftMessageTransmitter method multicastPrepare.
public void multicastPrepare(final ConsensusRoundIdentifier roundIdentifier, final Hash digest) {
try {
final Prepare data = messageFactory.createPrepare(roundIdentifier, digest);
final PrepareMessageData message = PrepareMessageData.create(data);
multicaster.send(message);
} catch (final SecurityModuleException e) {
LOG.warn("Failed to generate signature for Prepare (not sent): {} ", e.getMessage());
}
}
Aggregations