use of org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator in project besu by hyperledger.
the class RlpBlockImporter method validateBlock.
private void validateBlock(final ProtocolSpec protocolSpec, final ProtocolContext context, final BlockHeader previousHeader, final BlockHeader header, final boolean skipPowValidation) {
final BlockHeaderValidator blockHeaderValidator = protocolSpec.getBlockHeaderValidator();
final boolean validHeader = blockHeaderValidator.validateHeader(header, previousHeader, context, skipPowValidation ? HeaderValidationMode.LIGHT_DETACHED_ONLY : HeaderValidationMode.DETACHED_ONLY);
if (!validHeader) {
throw new IllegalStateException("Invalid header at block number " + header.getNumber() + ".");
}
}
use of org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator in project besu by hyperledger.
the class QbftBlockHeaderValidationRulesetFactoryTest method bftValidateHeaderFailsOnCoinbaseData.
@Test
public void bftValidateHeaderFailsOnCoinbaseData() {
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final Address nonProposerAddress = Util.publicKeyToAddress(NodeKeyUtils.generate().getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
final BlockHeader parentHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(1, proposerNodeKey, validators, null, Optional.empty()).buildHeader();
final BlockHeader blockHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(2, proposerNodeKey, validators, parentHeader, Optional.empty()).coinbase(nonProposerAddress).buildHeader();
final BlockHeaderValidator validator = getBlockHeaderValidator();
assertThat(validator.validateHeader(blockHeader, parentHeader, protocolContext(validators), HeaderValidationMode.FULL)).isFalse();
}
use of org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator in project besu by hyperledger.
the class QbftBlockHeaderValidationRulesetFactoryTest method bftValidateHeaderIgnoresOmmersValue.
@Test
public void bftValidateHeaderIgnoresOmmersValue() {
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
final BlockHeader parentHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(1, proposerNodeKey, validators, null, Optional.empty()).buildHeader();
final BlockHeader blockHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(2, proposerNodeKey, validators, parentHeader, builder -> builder.ommersHash(Hash.EMPTY_TRIE_HASH), Optional.empty()).buildHeader();
final BlockHeaderValidator validator = getBlockHeaderValidator();
assertThat(validator.validateHeader(blockHeader, parentHeader, protocolContext(validators), HeaderValidationMode.FULL)).isTrue();
}
use of org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator in project besu by hyperledger.
the class QbftBlockHeaderValidationRulesetFactoryTest method bftValidateHeaderFailsOnGasUsage.
@Test
public void bftValidateHeaderFailsOnGasUsage() {
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
final BlockHeader parentHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(1, proposerNodeKey, validators, null, Optional.empty()).buildHeader();
final BlockHeader blockHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(2, proposerNodeKey, validators, parentHeader, Optional.empty()).gasLimit(5_000).gasUsed(6_000).buildHeader();
final BlockHeaderValidator validator = getBlockHeaderValidator();
assertThat(validator.validateHeader(blockHeader, parentHeader, protocolContext(validators), HeaderValidationMode.FULL)).isFalse();
}
use of org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator in project besu by hyperledger.
the class QbftBlockHeaderValidationRulesetFactoryTest method bftValidateHeaderFailsOnAncestor.
@Test
public void bftValidateHeaderFailsOnAncestor() {
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
final BlockHeader parentHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(1, proposerNodeKey, validators, null, Optional.empty()).buildHeader();
final BlockHeader blockHeader = QbftBlockHeaderUtils.createPresetHeaderBuilder(2, proposerNodeKey, validators, null, Optional.empty()).buildHeader();
final BlockHeaderValidator validator = getBlockHeaderValidator();
assertThat(validator.validateHeader(blockHeader, parentHeader, protocolContext(validators), HeaderValidationMode.FULL)).isFalse();
}
Aggregations