use of org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate in project besu by hyperledger.
the class RoundChangeMessageValidatorTest method validationFailsIfPreparesContainsDifferentRoundToBlock.
@Test
public void validationFailsIfPreparesContainsDifferentRoundToBlock() {
when(blockValidator.validateAndProcessBlock(any(), any(), eq(HeaderValidationMode.LIGHT), eq(HeaderValidationMode.FULL))).thenReturn(new Result(new BlockProcessingOutputs(null, null)));
when(payloadValidator.validate(any())).thenReturn(true);
messageValidator = new RoundChangeMessageValidator(payloadValidator, BftHelpers.calculateRequiredValidatorQuorum(VALIDATOR_COUNT), CHAIN_HEIGHT, validators.getNodeAddresses(), blockValidator, protocolContext);
final Block block = ProposedBlockHelpers.createProposalBlock(Collections.emptyList(), roundIdentifier, bftExtraDataEncoder);
final PreparedCertificate prepCert = new PreparedCertificate(block, validators.getNodes().stream().map(n -> n.getMessageFactory().createPrepare(ConsensusRoundHelpers.createFrom(roundIdentifier, 0, -1), block.getHash()).getSignedPayload()).collect(Collectors.toList()), roundIdentifier.getRoundNumber());
final RoundChange message = validators.getMessageFactory(0).createRoundChange(targetRound, Optional.of(prepCert));
assertThat(messageValidator.validate(message)).isFalse();
}
use of org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate in project besu by hyperledger.
the class RoundChangeMessageValidatorTest method prepareFromNonValidatorFails.
@Test
public void prepareFromNonValidatorFails() {
when(blockValidator.validateAndProcessBlock(any(), any(), eq(HeaderValidationMode.LIGHT), eq(HeaderValidationMode.FULL))).thenReturn(new Result(new BlockProcessingOutputs(null, null)));
when(payloadValidator.validate(any())).thenReturn(true);
messageValidator = new RoundChangeMessageValidator(payloadValidator, BftHelpers.calculateRequiredValidatorQuorum(VALIDATOR_COUNT), CHAIN_HEIGHT, validators.getNodeAddresses(), blockValidator, protocolContext);
final QbftNode nonValidator = QbftNode.create();
final Block block = ProposedBlockHelpers.createProposalBlock(Collections.emptyList(), roundIdentifier, bftExtraDataEncoder);
final PreparedCertificate prepCert = createPreparedCertificate(block, roundIdentifier, validators.getNode(0), validators.getNode(1), nonValidator);
final RoundChange message = validators.getMessageFactory(0).createRoundChange(targetRound, Optional.of(prepCert));
assertThat(messageValidator.validate(message)).isFalse();
}
use of org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate in project besu by hyperledger.
the class ReceivedFutureProposalTest method proposalWithPrepareCertificateResultsInNewRoundStartingWithExpectedBlock.
@Test
public void proposalWithPrepareCertificateResultsInNewRoundStartingWithExpectedBlock() {
final Block initialBlock = context.createBlockForProposalFromChainHead(15, peers.getProposer().getNodeAddress());
final Block reproposedBlock = context.createBlockForProposalFromChainHead(15, peers.getProposer().getNodeAddress());
final ConsensusRoundIdentifier nextRoundId = new ConsensusRoundIdentifier(1, 1);
final PreparedCertificate preparedRoundArtifacts = createValidPreparedCertificate(context, roundId, initialBlock);
final List<SignedData<RoundChangePayload>> roundChanges = peers.createSignedRoundChangePayload(nextRoundId, preparedRoundArtifacts);
final List<SignedData<PreparePayload>> prepares = peers.createSignedPreparePayloadOfAllPeers(roundId, initialBlock.getHash());
final ValidatorPeer nextProposer = context.roundSpecificPeers(nextRoundId).getProposer();
nextProposer.injectProposalForFutureRound(nextRoundId, roundChanges, prepares, reproposedBlock);
peers.verifyMessagesReceived(localNodeMessageFactory.createPrepare(nextRoundId, reproposedBlock.getHash()));
}
use of org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate in project besu by hyperledger.
the class ReceivedFutureProposalTest method futureProposalWithInsufficientPreparesDoesNotTriggerNextRound.
@Test
public void futureProposalWithInsufficientPreparesDoesNotTriggerNextRound() {
final Block initialBlock = context.createBlockForProposalFromChainHead(15, peers.getProposer().getNodeAddress());
final Block reproposedBlock = context.createBlockForProposalFromChainHead(15, peers.getProposer().getNodeAddress());
final ConsensusRoundIdentifier nextRoundId = new ConsensusRoundIdentifier(1, 1);
final PreparedCertificate preparedRoundArtifacts = createValidPreparedCertificate(context, roundId, initialBlock);
final List<SignedData<RoundChangePayload>> roundChanges = peers.createSignedRoundChangePayload(nextRoundId, preparedRoundArtifacts);
final List<SignedData<PreparePayload>> prepares = peers.createSignedPreparePayloadOfAllPeers(roundId, initialBlock.getHash());
final ValidatorPeer nextProposer = context.roundSpecificPeers(nextRoundId).getProposer();
nextProposer.injectProposalForFutureRound(nextRoundId, roundChanges, prepares.subList(0, 2), reproposedBlock);
peers.verifyNoMessagesReceived();
}
use of org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate in project besu by hyperledger.
the class ReceivedFutureProposalTest method futureProposalWithInvalidPrepareDoesNotTriggerNextRound.
@Test
public void futureProposalWithInvalidPrepareDoesNotTriggerNextRound() {
final Block initialBlock = context.createBlockForProposalFromChainHead(15, peers.getProposer().getNodeAddress());
final Block reproposedBlock = context.createBlockForProposalFromChainHead(15);
final ConsensusRoundIdentifier nextRoundId = new ConsensusRoundIdentifier(1, 1);
final PreparedCertificate preparedRoundArtifacts = createValidPreparedCertificate(context, roundId, initialBlock);
final List<SignedData<RoundChangePayload>> roundChanges = peers.createSignedRoundChangePayload(nextRoundId, preparedRoundArtifacts);
List<SignedData<PreparePayload>> prepares = peers.createSignedPreparePayloadOfAllPeers(roundId, initialBlock.getHash());
prepares = prepares.stream().filter(p -> !p.getAuthor().equals(peers.getFirstNonProposer().getNodeAddress())).collect(Collectors.toList());
final SignedData<PreparePayload> invalidPrepare = peers.getFirstNonProposer().getMessageFactory().createPrepare(nextRoundId, initialBlock.getHash()).getSignedPayload();
prepares.add(invalidPrepare);
final ValidatorPeer nextProposer = context.roundSpecificPeers(nextRoundId).getProposer();
nextProposer.injectProposalForFutureRound(nextRoundId, roundChanges, prepares, reproposedBlock);
peers.verifyNoMessagesReceived();
}
Aggregations