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