Search in sources :

Example 1 with RoundChange

use of org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange in project besu by hyperledger.

the class ProposalValidatorTest method validationFailsIfRoundZeroHasNonEmptyRoundChanges.

@Test
public void validationFailsIfRoundZeroHasNonEmptyRoundChanges() {
    final RoundChange roundChange = validators.getMessageFactory(1).createRoundChange(roundItems.get(ROUND_ID.ZERO).roundIdentifier, Optional.empty());
    final Proposal proposal = validators.getMessageFactory(0).createProposal(roundItems.get(ROUND_ID.ZERO).roundIdentifier, roundItems.get(ROUND_ID.ZERO).block, List.of(roundChange.getSignedPayload()), emptyList());
    assertThat(roundItems.get(ROUND_ID.ZERO).messageValidator.validate(proposal)).isFalse();
}
Also used : RoundChange(org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange) Proposal(org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal) Test(org.junit.Test)

Example 2 with RoundChange

use of org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange in project besu by hyperledger.

the class RoundChangeMessageValidatorTest method roundChangeWithNoPiggyBackedDataIsValid.

@Test
public void roundChangeWithNoPiggyBackedDataIsValid() {
    when(payloadValidator.validate(any())).thenReturn(true);
    messageValidator = new RoundChangeMessageValidator(payloadValidator, BftHelpers.calculateRequiredValidatorQuorum(VALIDATOR_COUNT), CHAIN_HEIGHT, validators.getNodeAddresses(), blockValidator, protocolContext);
    for (int i = 0; i < VALIDATOR_COUNT; i++) {
        final RoundChange message = validators.getMessageFactory(i).createRoundChange(targetRound, Optional.empty());
        assertThat(messageValidator.validate(message)).isTrue();
    }
}
Also used : RoundChange(org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange) Test(org.junit.Test)

Example 3 with RoundChange

use of org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange in project besu by hyperledger.

the class RoundChangeMessageValidatorTest method invalidEmbeddedPayloadFailsValidation.

@Test
public void invalidEmbeddedPayloadFailsValidation() {
    when(payloadValidator.validate(any())).thenReturn(false);
    messageValidator = new RoundChangeMessageValidator(payloadValidator, BftHelpers.calculateRequiredValidatorQuorum(VALIDATOR_COUNT), CHAIN_HEIGHT, validators.getNodeAddresses(), blockValidator, protocolContext);
    final RoundChange message = validators.getMessageFactory(0).createRoundChange(targetRound, Optional.empty());
    assertThat(messageValidator.validate(message)).isFalse();
}
Also used : RoundChange(org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange) Test(org.junit.Test)

Example 4 with RoundChange

use of org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange 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 5 with RoundChange

use of org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange 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)

Aggregations

RoundChange (org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange)31 Test (org.junit.Test)19 Block (org.hyperledger.besu.ethereum.core.Block)15 PreparedCertificate (org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate)11 Result (org.hyperledger.besu.ethereum.BlockValidator.Result)11 BlockProcessingOutputs (org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs)10 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)9 ValidationTestHelpers.createPreparedCertificate (org.hyperledger.besu.consensus.qbft.validation.ValidationTestHelpers.createPreparedCertificate)9 Test (org.junit.jupiter.api.Test)7 RoundExpiry (org.hyperledger.besu.consensus.common.bft.events.RoundExpiry)5 Prepare (org.hyperledger.besu.consensus.qbft.messagewrappers.Prepare)5 Proposal (org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal)4 QbftExtraDataCodec (org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec)2 RoundChangeMessageData (org.hyperledger.besu.consensus.qbft.messagedata.RoundChangeMessageData)2 RoundChangePayload (org.hyperledger.besu.consensus.qbft.payload.RoundChangePayload)2 IntegrationTestHelpers.createValidPreparedCertificate (org.hyperledger.besu.consensus.qbft.support.IntegrationTestHelpers.createValidPreparedCertificate)2 SECPSignature (org.hyperledger.besu.crypto.SECPSignature)2 SecurityModuleException (org.hyperledger.besu.plugin.services.securitymodule.SecurityModuleException)2 BftExtraData (org.hyperledger.besu.consensus.common.bft.BftExtraData)1 BlockTimerExpiry (org.hyperledger.besu.consensus.common.bft.events.BlockTimerExpiry)1