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;
}
}
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());
}
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);
}
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);
}
Aggregations