Search in sources :

Example 6 with Block

use of org.hyperledger.besu.ethereum.core.Block 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 7 with Block

use of org.hyperledger.besu.ethereum.core.Block 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 8 with Block

use of org.hyperledger.besu.ethereum.core.Block in project besu by hyperledger.

the class PkiQbftBlockCreatorTest method cmsIsCreatedWithCorrectHashingFunction.

@Test
public void cmsIsCreatedWithCorrectHashingFunction() {
    final Block block = createBlockBeingProposed();
    final Hash expectedHashForCmsCreation = PkiQbftBlockHeaderFunctions.forCmsSignature(extraDataCodec).hash(block.getHeader());
    when(cmsCreator.create(any(Bytes.class))).thenReturn(Bytes.random(32));
    pkiQbftBlockCreator.createBlock(1L);
    verify(cmsCreator).create(eq(expectedHashForCmsCreation));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Block(org.hyperledger.besu.ethereum.core.Block) Hash(org.hyperledger.besu.datatypes.Hash) Test(org.junit.Test)

Example 9 with Block

use of org.hyperledger.besu.ethereum.core.Block in project besu by hyperledger.

the class PkiQbftBlockCreatorTest method createBlockBeingProposed.

private Block createBlockBeingProposed() {
    final BftExtraData originalExtraData = createExtraData(blockHeaderBuilder.buildHeader(), extraDataCodec);
    final BlockHeader blockHeaderWithExtraData = blockHeaderBuilder.extraData(extraDataCodec.encode(originalExtraData)).buildHeader();
    final Block block = new Block(blockHeaderWithExtraData, new BlockBody(Collections.emptyList(), Collections.emptyList()));
    when(blockCreator.createBlock(eq(1L))).thenReturn(block);
    return block;
}
Also used : BlockBody(org.hyperledger.besu.ethereum.core.BlockBody) Block(org.hyperledger.besu.ethereum.core.Block) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData)

Example 10 with Block

use of org.hyperledger.besu.ethereum.core.Block in project besu by hyperledger.

the class ProposalPayloadValidator method validate.

public boolean validate(final SignedData<ProposalPayload> signedPayload) {
    if (!signedPayload.getAuthor().equals(expectedProposer)) {
        LOG.info("{}: proposal created by non-proposer", ERROR_PREFIX);
        return false;
    }
    final ProposalPayload payload = signedPayload.getPayload();
    if (!payload.getRoundIdentifier().equals(targetRound)) {
        LOG.info("{}: proposal is not for expected round", ERROR_PREFIX);
        return false;
    }
    final Block block = payload.getProposedBlock();
    if (!validateBlock(block)) {
        return false;
    }
    if (block.getHeader().getNumber() != payload.getRoundIdentifier().getSequenceNumber()) {
        LOG.info("{}: block number does not match sequence number", ERROR_PREFIX);
        return false;
    }
    if (cmsValidator.isPresent()) {
        return validateCms(block, protocolContext.getConsensusContext(QbftContext.class).getBlockInterface(), cmsValidator.get());
    }
    return true;
}
Also used : ProposalPayload(org.hyperledger.besu.consensus.qbft.payload.ProposalPayload) Block(org.hyperledger.besu.ethereum.core.Block)

Aggregations

Block (org.hyperledger.besu.ethereum.core.Block)425 Test (org.junit.Test)236 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)118 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)91 List (java.util.List)57 Hash (org.hyperledger.besu.datatypes.Hash)54 TransactionReceipt (org.hyperledger.besu.ethereum.core.TransactionReceipt)52 BlockBody (org.hyperledger.besu.ethereum.core.BlockBody)47 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)40 ArrayList (java.util.ArrayList)37 Test (org.junit.jupiter.api.Test)37 ConsensusRoundIdentifier (org.hyperledger.besu.consensus.common.bft.ConsensusRoundIdentifier)36 Transaction (org.hyperledger.besu.ethereum.core.Transaction)34 RespondingEthPeer (org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer)34 Optional (java.util.Optional)33 Bytes (org.apache.tuweni.bytes.Bytes)33 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)31 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)31 Address (org.hyperledger.besu.datatypes.Address)28 Difficulty (org.hyperledger.besu.ethereum.core.Difficulty)28