Search in sources :

Example 1 with BlockProcessingOutputs

use of org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs 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 BlockProcessingOutputs

use of org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs 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 BlockProcessingOutputs

use of org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs in project besu by hyperledger.

the class RoundChangeManagerTest method setup.

@Before
public void setup() {
    validators.add(Util.publicKeyToAddress(proposerKey.getPublicKey()));
    validators.add(Util.publicKeyToAddress(validator1Key.getPublicKey()));
    validators.add(Util.publicKeyToAddress(validator2Key.getPublicKey()));
    final BlockValidator blockValidator = mock(BlockValidator.class);
    when(blockValidator.validateAndProcessBlock(any(), any(), any(), any())).thenReturn(new Result(new BlockProcessingOutputs(null, null)));
    final RoundChangePayloadValidator.MessageValidatorForHeightFactory messageValidatorFactory = mock(RoundChangePayloadValidator.MessageValidatorForHeightFactory.class);
    when(messageValidatorFactory.createAt(ri1)).thenAnswer(invocation -> new SignedDataValidator(validators, Util.publicKeyToAddress(proposerKey.getPublicKey()), ri1));
    when(messageValidatorFactory.createAt(ri2)).thenAnswer(invocation -> new SignedDataValidator(validators, Util.publicKeyToAddress(validator1Key.getPublicKey()), ri2));
    when(messageValidatorFactory.createAt(ri3)).thenAnswer(invocation -> new SignedDataValidator(validators, Util.publicKeyToAddress(validator2Key.getPublicKey()), ri3));
    final RoundChangeMessageValidator roundChangeMessageValidator = new RoundChangeMessageValidator(new RoundChangePayloadValidator(messageValidatorFactory, validators, BftHelpers.calculateRequiredValidatorQuorum(BftHelpers.calculateRequiredValidatorQuorum(validators.size())), 2), proposalConsistencyValidator, bftBlockInterface);
    manager = new RoundChangeManager(2, roundChangeMessageValidator);
    when(proposalConsistencyValidator.validateProposalMatchesBlock(any(), any(), any())).thenReturn(true);
}
Also used : BlockProcessingOutputs(org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs) RoundChangePayloadValidator(org.hyperledger.besu.consensus.ibft.validation.RoundChangePayloadValidator) RoundChangeMessageValidator(org.hyperledger.besu.consensus.ibft.validation.RoundChangeMessageValidator) SignedDataValidator(org.hyperledger.besu.consensus.ibft.validation.SignedDataValidator) BlockValidator(org.hyperledger.besu.ethereum.BlockValidator) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) Before(org.junit.Before)

Example 4 with BlockProcessingOutputs

use of org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs in project besu by hyperledger.

the class EngineNewPayloadTest method shouldReturnValid.

@Test
public void shouldReturnValid() {
    BlockHeader mockHeader = new BlockHeaderTestFixture().baseFeePerGas(Wei.ONE).buildHeader();
    when(blockchain.getBlockByHash(any())).thenReturn(Optional.empty());
    when(mergeCoordinator.getLatestValidAncestor(any(BlockHeader.class))).thenReturn(Optional.of(mockHash));
    when(mergeCoordinator.latestValidAncestorDescendsFromTerminal(any(BlockHeader.class))).thenReturn(true);
    when(mergeCoordinator.getOrSyncHeaderByHash(any(Hash.class))).thenReturn(Optional.of(mockHeader));
    when(mergeCoordinator.executeBlock(any())).thenReturn(new Result(new BlockProcessingOutputs(null, List.of())));
    var resp = resp(mockPayload(mockHeader, Collections.emptyList()));
    EnginePayloadStatusResult res = fromSuccessResp(resp);
    assertThat(res.getLatestValidHash().get()).isEqualTo(mockHeader.getHash());
    assertThat(res.getStatusAsString()).isEqualTo(VALID.name());
    assertThat(res.getError()).isNull();
}
Also used : BlockProcessingOutputs(org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs) BlockHeaderTestFixture(org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture) EnginePayloadStatusResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Hash(org.hyperledger.besu.datatypes.Hash) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) EnginePayloadStatusResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EnginePayloadStatusResult) Test(org.junit.Test)

Example 5 with BlockProcessingOutputs

use of org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs in project besu by hyperledger.

the class MessageValidatorTest method setup.

@Before
public void setup() {
    when(signedDataValidator.validateProposal(any())).thenReturn(true);
    when(signedDataValidator.validatePrepare(any())).thenReturn(true);
    when(signedDataValidator.validateCommit(any())).thenReturn(true);
    when(proposalBlockConsistencyValidator.validateProposalMatchesBlock(any(), any(), any())).thenReturn(true);
    BftContext mockBftCtx = mock(BftContext.class);
    when(mockBftCtx.as(Mockito.any())).thenReturn(mockBftCtx);
    protocolContext = new ProtocolContext(mock(MutableBlockchain.class), mock(WorldStateArchive.class), mockBftCtx);
    when(blockValidator.validateAndProcessBlock(any(), any(), any(), any())).thenReturn(new Result(new BlockProcessingOutputs(null, null)));
    when(roundChangeCertificateValidator.validateProposalMessageMatchesLatestPrepareCertificate(any(), any())).thenReturn(true);
    when(roundChangeCertificateValidator.validateRoundChangeMessagesAndEnsureTargetRoundMatchesRoot(any(), any())).thenReturn(true);
    messageValidator = new MessageValidator(signedDataValidator, proposalBlockConsistencyValidator, blockValidator, protocolContext, roundChangeCertificateValidator);
}
Also used : BlockProcessingOutputs(org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs) BftContext(org.hyperledger.besu.consensus.common.bft.BftContext) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Result(org.hyperledger.besu.ethereum.BlockValidator.Result) Before(org.junit.Before)

Aggregations

BlockProcessingOutputs (org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs)19 Result (org.hyperledger.besu.ethereum.BlockValidator.Result)19 Test (org.junit.Test)16 Block (org.hyperledger.besu.ethereum.core.Block)15 RoundChange (org.hyperledger.besu.consensus.qbft.messagewrappers.RoundChange)10 PreparedCertificate (org.hyperledger.besu.consensus.qbft.statemachine.PreparedCertificate)8 ValidationTestHelpers.createPreparedCertificate (org.hyperledger.besu.consensus.qbft.validation.ValidationTestHelpers.createPreparedCertificate)8 Proposal (org.hyperledger.besu.consensus.qbft.messagewrappers.Proposal)5 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)4 Hash (org.hyperledger.besu.datatypes.Hash)3 Before (org.junit.Before)3 Bytes (org.apache.tuweni.bytes.Bytes)2 QbftContext (org.hyperledger.besu.consensus.qbft.QbftContext)2 RoundChangePayload (org.hyperledger.besu.consensus.qbft.payload.RoundChangePayload)2 PkiQbftExtraDataCodec (org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraDataCodec)2 SECPSignature (org.hyperledger.besu.crypto.SECPSignature)2 BftContext (org.hyperledger.besu.consensus.common.bft.BftContext)1 RoundChangeMessageValidator (org.hyperledger.besu.consensus.ibft.validation.RoundChangeMessageValidator)1 RoundChangePayloadValidator (org.hyperledger.besu.consensus.ibft.validation.RoundChangePayloadValidator)1 SignedDataValidator (org.hyperledger.besu.consensus.ibft.validation.SignedDataValidator)1