Search in sources :

Example 1 with RetestethClock

use of org.hyperledger.besu.ethereum.retesteth.RetestethClock 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)

Aggregations

ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)1 PoWBlockCreator (org.hyperledger.besu.ethereum.blockcreation.PoWBlockCreator)1 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)1 Block (org.hyperledger.besu.ethereum.core.Block)1 BlockImporter (org.hyperledger.besu.ethereum.core.BlockImporter)1 HeaderValidationMode (org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode)1 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)1 RetestethClock (org.hyperledger.besu.ethereum.retesteth.RetestethClock)1