Search in sources :

Example 1 with PreparedCertificate

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();
}
Also used : BlockProcessingOutputs(org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs) RoundChange(org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange) Block(org.hyperledger.besu.ethereum.core.Block) ValidationTestHelpers.createPreparedCertificate(org.hyperledger.besu.consensus.qbft.validation.ValidationTestHelpers.createPreparedCertificate) PreparedCertificate(org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) Test(org.junit.Test)

Example 2 with PreparedCertificate

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();
}
Also used : BlockProcessingOutputs(org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs) RoundChange(org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange) Block(org.hyperledger.besu.ethereum.core.Block) ValidationTestHelpers.createPreparedCertificate(org.hyperledger.besu.consensus.qbft.validation.ValidationTestHelpers.createPreparedCertificate) PreparedCertificate(org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) Test(org.junit.Test)

Example 3 with PreparedCertificate

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()));
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) ValidatorPeer(org.hyperledger.besu.consensus.qbft.support.ValidatorPeer) SignedData(org.hyperledger.besu.consensus.common.bft.payload.SignedData) Block(org.hyperledger.besu.ethereum.core.Block) IntegrationTestHelpers.createValidPreparedCertificate(org.hyperledger.besu.consensus.qbft.support.IntegrationTestHelpers.createValidPreparedCertificate) PreparedCertificate(org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate) Test(org.junit.jupiter.api.Test)

Example 4 with PreparedCertificate

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();
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) ValidatorPeer(org.hyperledger.besu.consensus.qbft.support.ValidatorPeer) SignedData(org.hyperledger.besu.consensus.common.bft.payload.SignedData) Block(org.hyperledger.besu.ethereum.core.Block) IntegrationTestHelpers.createValidPreparedCertificate(org.hyperledger.besu.consensus.qbft.support.IntegrationTestHelpers.createValidPreparedCertificate) PreparedCertificate(org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate) Test(org.junit.jupiter.api.Test)

Example 5 with PreparedCertificate

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();
}
Also used : ConsensusRoundIdentifier(org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier) ValidatorPeer(org.hyperledger.besu.consensus.qbft.support.ValidatorPeer) PreparePayload(org.hyperledger.besu.consensus.qbft.payload.PreparePayload) SignedData(org.hyperledger.besu.consensus.common.bft.payload.SignedData) Block(org.hyperledger.besu.ethereum.core.Block) IntegrationTestHelpers.createValidPreparedCertificate(org.hyperledger.besu.consensus.qbft.support.IntegrationTestHelpers.createValidPreparedCertificate) PreparedCertificate(org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate) Test(org.junit.jupiter.api.Test)

Aggregations

PreparedCertificate (org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate)17 Block (org.hyperledger.besu.ethereum.core.Block)15 RoundChange (org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange)11 ValidationTestHelpers.createPreparedCertificate (org.hyperledger.besu.consensus.qbft.validation.ValidationTestHelpers.createPreparedCertificate)9 Result (org.hyperledger.besu.ethereum.BlockValidator.Result)9 Test (org.junit.Test)9 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)8 IntegrationTestHelpers.createValidPreparedCertificate (org.hyperledger.besu.consensus.qbft.support.IntegrationTestHelpers.createValidPreparedCertificate)8 BlockProcessingOutputs (org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs)8 Test (org.junit.jupiter.api.Test)8 SignedData (org.hyperledger.besu.consensus.common.bft.payload.SignedData)5 ValidatorPeer (org.hyperledger.besu.consensus.qbft.support.ValidatorPeer)4 Prepare (org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare)3 Proposal (org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal)2 RoundExpiry (org.hyperledger.besu.consensus.common.bft.events.RoundExpiry)1 Commit (org.hyperledger.besu.consensus.qbft.messagewrappers.Commit)1 PreparePayload (org.hyperledger.besu.consensus.qbft.payload.PreparePayload)1 RoundSpecificPeers (org.hyperledger.besu.consensus.qbft.support.RoundSpecificPeers)1