Search in sources :

Example 1 with HeaderValidationMode

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());
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) BlockImporter(org.hyperledger.besu.ethereum.core.BlockImporter) BlockchainReferenceTestCaseSpec(org.hyperledger.besu.ethereum.referencetests.BlockchainReferenceTestCaseSpec) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) RLPException(org.hyperledger.besu.ethereum.rlp.RLPException) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) HeaderValidationMode(org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode)

Example 2 with HeaderValidationMode

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;
}
Also used : HeaderValidationMode(org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode)

Example 3 with HeaderValidationMode

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);
}
Also used : RetestethClock(org.hyperledger.besu.ethereum.retesteth.RetestethClock) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) PoWBlockCreator(org.hyperledger.besu.ethereum.blockcreation.PoWBlockCreator) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) HeaderValidationMode(org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode) BlockImporter(org.hyperledger.besu.ethereum.core.BlockImporter)

Example 4 with 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();
}
Also used : HeaderValidationMode(org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode) Test(org.junit.Test)

Aggregations

HeaderValidationMode (org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode)4 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)2 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)2 Block (org.hyperledger.besu.ethereum.core.Block)2 BlockImporter (org.hyperledger.besu.ethereum.core.BlockImporter)2 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)2 PoWBlockCreator (org.hyperledger.besu.ethereum.blockcreation.PoWBlockCreator)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)1 ProtocolSpec (org.hyperledger.besu.ethereum.mainnet.ProtocolSpec)1 BlockchainReferenceTestCaseSpec (org.hyperledger.besu.ethereum.referencetests.BlockchainReferenceTestCaseSpec)1 RetestethClock (org.hyperledger.besu.ethereum.retesteth.RetestethClock)1 RLPException (org.hyperledger.besu.ethereum.rlp.RLPException)1 Test (org.junit.Test)1