use of org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode in project besu by hyperledger.
the class BlockchainReferenceTestTools method executeTest.
public static void executeTest(final BlockchainReferenceTestCaseSpec spec) {
final BlockHeader genesisBlockHeader = spec.getGenesisBlockHeader();
final MutableWorldState worldState = spec.getWorldStateArchive().getMutable(genesisBlockHeader.getStateRoot(), genesisBlockHeader.getHash()).get();
assertThat(worldState.rootHash()).isEqualTo(genesisBlockHeader.getStateRoot());
final ProtocolSchedule schedule = REFERENCE_TEST_PROTOCOL_SCHEDULES.getByName(spec.getNetwork());
final MutableBlockchain blockchain = spec.getBlockchain();
final ProtocolContext context = spec.getProtocolContext();
for (final BlockchainReferenceTestCaseSpec.CandidateBlock candidateBlock : spec.getCandidateBlocks()) {
if (!candidateBlock.isExecutable()) {
return;
}
try {
final Block block = candidateBlock.getBlock();
final ProtocolSpec protocolSpec = schedule.getByBlockNumber(block.getHeader().getNumber());
final BlockImporter blockImporter = protocolSpec.getBlockImporter();
final HeaderValidationMode validationMode = "NoProof".equalsIgnoreCase(spec.getSealEngine()) ? HeaderValidationMode.LIGHT : HeaderValidationMode.FULL;
final boolean imported = blockImporter.importBlock(context, block, validationMode, validationMode);
assertThat(imported).isEqualTo(candidateBlock.isValid());
} catch (final RLPException e) {
assertThat(candidateBlock.isValid()).isFalse();
}
}
Assertions.assertThat(blockchain.getChainHeadHash()).isEqualTo(spec.getLastBlockHash());
}
use of org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode in project besu by hyperledger.
the class FastSyncValidationPolicy method getValidationModeForNextBlock.
@Override
public HeaderValidationMode getValidationModeForNextBlock() {
final HeaderValidationMode mode = Math.random() < targetFullValidationRate ? fullValidationMode : lightValidationMode;
fastSyncValidationCounter.labels(mode.name()).inc();
return mode;
}
use of org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode in project besu by hyperledger.
the class TestMineBlocks method mineNewBlock.
private boolean mineNewBlock() {
final RetestethClock retesethClock = context.getRetestethClock();
final ProtocolSchedule protocolSchedule = context.getProtocolSchedule();
final ProtocolContext protocolContext = context.getProtocolContext();
final MutableBlockchain blockchain = context.getBlockchain();
final HeaderValidationMode headerValidationMode = context.getHeaderValidationMode();
final PoWBlockCreator blockCreator = new PoWBlockCreator(context.getCoinbase(), () -> Optional.of(10_000_000L), header -> context.getExtraData(), context.getTransactionPool().getPendingTransactions(), protocolContext, protocolSchedule, context.getEthHashSolver(), Wei.ZERO, 0.0, blockchain.getChainHeadHeader());
final Block block = blockCreator.createBlock(retesethClock.instant().getEpochSecond());
// advance clock so next mine won't hit the same timestamp
retesethClock.advanceSeconds(1);
final BlockImporter blockImporter = protocolSchedule.getByBlockNumber(blockchain.getChainHeadBlockNumber()).getBlockImporter();
return blockImporter.importBlock(protocolContext, block, headerValidationMode, headerValidationMode);
}
use of org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode in project besu by hyperledger.
the class FastSyncValidationPolicyTest method shouldEventuallyUseBothModesWhenValidationPolicyIsHalf.
@Test
public void shouldEventuallyUseBothModesWhenValidationPolicyIsHalf() {
final FastSyncValidationPolicy policy = new FastSyncValidationPolicy(0.5f, LIGHT, FULL, NO_OP_LABELLED_1_COUNTER);
boolean seenLight = false;
boolean seenFull = false;
// we're probably more likely to get intermittent failures from the hard drive failing...
for (int i = 0; i < Integer.MAX_VALUE && (!seenLight || !seenFull); i++) {
final HeaderValidationMode mode = policy.getValidationModeForNextBlock();
if (mode == LIGHT) {
seenLight = true;
} else if (mode == FULL) {
seenFull = true;
} else {
fail("Unexpected validation mode " + mode);
}
}
assertThat(seenLight).describedAs("used light validation").isTrue();
assertThat(seenFull).describedAs("used full validation").isTrue();
}
Aggregations