Search in sources :

Example 1 with PkiQbftExtraData

use of org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraData in project besu by hyperledger.

the class ProposalPayloadValidator method validateCms.

private boolean validateCms(final Block block, final BftBlockInterface bftBlockInterface, final CmsValidator cmsValidator) {
    final PkiQbftExtraData pkiExtraData = (PkiQbftExtraData) bftBlockInterface.getExtraData(block.getHeader());
    final Hash hashWithoutCms = PkiQbftBlockHeaderFunctions.forCmsSignature((PkiQbftExtraDataCodec) bftExtraDataCodec).hash(block.getHeader());
    LOG.debug("Validating CMS with signed hash {} in block {}", hashWithoutCms, block.getHash());
    if (!cmsValidator.validate(pkiExtraData.getCms(), hashWithoutCms)) {
        LOG.info("{}: invalid CMS in block {}", ERROR_PREFIX, block.getHash());
        return false;
    } else {
        LOG.trace("Valid CMS in block {}", block.getHash());
        return true;
    }
}
Also used : Hash(org.hyperledger.besu.datatypes.Hash) PkiQbftExtraData(org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraData) PkiQbftExtraDataCodec(org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraDataCodec)

Example 2 with PkiQbftExtraData

use of org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraData in project besu by hyperledger.

the class PkiQbftBlockCreator method replaceCmsInBlock.

private Block replaceCmsInBlock(final Block block) {
    final BlockHeader blockHeader = block.getHeader();
    final Hash hashWithoutCms = PkiQbftBlockHeaderFunctions.forCmsSignature(pkiQbftExtraDataCodec).hash(block.getHeader());
    final Bytes cms = cmsCreator.create(hashWithoutCms);
    final BftExtraData previousExtraData = pkiQbftExtraDataCodec.decode(blockHeader);
    final BftExtraData substituteExtraData = new PkiQbftExtraData(previousExtraData, cms);
    final Bytes substituteExtraDataBytes = pkiQbftExtraDataCodec.encode(substituteExtraData);
    final BlockHeaderBuilder headerBuilder = BlockHeaderBuilder.fromHeader(blockHeader);
    headerBuilder.extraData(substituteExtraDataBytes).blockHeaderFunctions(BftBlockHeaderFunctions.forCommittedSeal(pkiQbftExtraDataCodec));
    final BlockHeader newHeader = headerBuilder.buildBlockHeader();
    LOG.debug("Created CMS with signed hash {} for block {}", hashWithoutCms, newHeader.getHash());
    return new Block(newHeader, block.getBody());
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Block(org.hyperledger.besu.ethereum.core.Block) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Hash(org.hyperledger.besu.datatypes.Hash) PkiQbftExtraData(org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraData) BlockHeaderBuilder(org.hyperledger.besu.ethereum.core.BlockHeaderBuilder) BftExtraData(org.hyperledger.besu.consensus.common.bft.BftExtraData)

Example 3 with PkiQbftExtraData

use of org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraData in project besu by hyperledger.

the class ProposalPayloadValidatorTest method createPkiProposalBlock.

public static Block createPkiProposalBlock(final List<Address> validators, final ConsensusRoundIdentifier roundId, final BftExtraDataCodec bftExtraDataCodec, final Bytes cms) {
    final Bytes extraData = bftExtraDataCodec.encode(new PkiQbftExtraData(Bytes.wrap(new byte[32]), Collections.emptyList(), Optional.empty(), roundId.getRoundNumber(), validators, cms));
    final BlockOptions blockOptions = BlockOptions.create().setExtraData(extraData).setBlockNumber(roundId.getSequenceNumber()).setBlockHeaderFunctions(BftBlockHeaderFunctions.forCommittedSeal(bftExtraDataCodec)).hasOmmers(false).hasTransactions(false);
    if (validators.size() > 0) {
        blockOptions.setCoinbase(validators.get(0));
    }
    return new BlockDataGenerator().block(blockOptions);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BlockOptions(org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions) PkiQbftExtraData(org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraData) BlockDataGenerator(org.hyperledger.besu.ethereum.core.BlockDataGenerator)

Example 4 with PkiQbftExtraData

use of org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraData in project besu by hyperledger.

the class PkiQbftBlockCreatorTest method cmsInProposedBlockHasValueCreatedByCmsCreator.

@Test
public void cmsInProposedBlockHasValueCreatedByCmsCreator() {
    createBlockBeingProposed();
    final Bytes cms = Bytes.random(32);
    when(cmsCreator.create(any(Bytes.class))).thenReturn(cms);
    final Block proposedBlock = pkiQbftBlockCreator.createBlock(1L);
    final PkiQbftExtraData proposedBlockExtraData = (PkiQbftExtraData) extraDataCodec.decodeRaw(proposedBlock.getHeader().getExtraData());
    assertThat(proposedBlockExtraData).isInstanceOf(PkiQbftExtraData.class);
    assertThat(proposedBlockExtraData.getCms()).isEqualTo(cms);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Block(org.hyperledger.besu.ethereum.core.Block) PkiQbftExtraData(org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraData) Test(org.junit.Test)

Aggregations

PkiQbftExtraData (org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraData)4 Bytes (org.apache.tuweni.bytes.Bytes)3 Hash (org.hyperledger.besu.datatypes.Hash)2 Block (org.hyperledger.besu.ethereum.core.Block)2 BftExtraData (org.hyperledger.besu.consensus.common.bft.BftExtraData)1 PkiQbftExtraDataCodec (org.hyperledger.besu.consensus.qbft.pki.PkiQbftExtraDataCodec)1 BlockDataGenerator (org.hyperledger.besu.ethereum.core.BlockDataGenerator)1 BlockOptions (org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 BlockHeaderBuilder (org.hyperledger.besu.ethereum.core.BlockHeaderBuilder)1 Test (org.junit.Test)1