Search in sources :

Example 1 with IncrementingNonceGenerator

use of org.hyperledger.besu.ethereum.blockcreation.IncrementingNonceGenerator in project besu by hyperledger.

the class RetestethContext method buildContext.

private boolean buildContext(final String genesisConfigString, final String sealEngine, final Optional<Long> clockTime) {
    final ObjectNode genesisConfig = normalizeKeys(JsonUtil.objectNodeFromString(genesisConfigString));
    retestethClock = new RetestethClock();
    clockTime.ifPresent(retestethClock::resetTime);
    final MetricsSystem metricsSystem = new NoOpMetricsSystem();
    final JsonGenesisConfigOptions jsonGenesisConfigOptions = JsonGenesisConfigOptions.fromJsonObject(JsonUtil.getObjectNode(genesisConfig, "config").get());
    protocolSchedule = MainnetProtocolSchedule.fromConfig(jsonGenesisConfigOptions, EvmConfiguration.DEFAULT);
    if ("NoReward".equalsIgnoreCase(sealEngine)) {
        protocolSchedule = new NoRewardProtocolScheduleWrapper(protocolSchedule);
    }
    blockHeaderFunctions = ScheduleBasedBlockHeaderFunctions.create(protocolSchedule);
    final GenesisState genesisState = GenesisState.fromJson(genesisConfigString, protocolSchedule);
    coinbase = genesisState.getBlock().getHeader().getCoinbase();
    extraData = genesisState.getBlock().getHeader().getExtraData();
    final WorldStateArchive worldStateArchive = new DefaultWorldStateArchive(new WorldStateKeyValueStorage(new InMemoryKeyValueStorage()), new WorldStatePreimageKeyValueStorage(new InMemoryKeyValueStorage()));
    final MutableWorldState worldState = worldStateArchive.getMutable();
    genesisState.writeStateTo(worldState);
    blockchain = createInMemoryBlockchain(genesisState.getBlock());
    protocolContext = new ProtocolContext(blockchain, worldStateArchive, null);
    blockchainQueries = new BlockchainQueries(blockchain, worldStateArchive, ethScheduler);
    final String sealengine = JsonUtil.getString(genesisConfig, "sealengine", "");
    headerValidationMode = "NoProof".equals(sealengine) || "NoReward".equals(sealEngine) ? HeaderValidationMode.LIGHT : HeaderValidationMode.FULL;
    final Iterable<Long> nonceGenerator = new IncrementingNonceGenerator(0);
    poWSolver = ("NoProof".equals(sealengine) || "NoReward".equals(sealEngine)) ? new PoWSolver(nonceGenerator, NO_WORK_HASHER, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator(), 1000, 8) : new PoWSolver(nonceGenerator, PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator(), 1000, 8);
    blockReplay = new BlockReplay(protocolSchedule, blockchainQueries.getBlockchain(), blockchainQueries.getWorldStateArchive());
    // mining support
    final EthPeers ethPeers = new EthPeers("reteseth", retestethClock, metricsSystem, 0);
    final SyncState syncState = new SyncState(blockchain, ethPeers);
    ethScheduler = new EthScheduler(1, 1, 1, 1, metricsSystem);
    final EthContext ethContext = new EthContext(ethPeers, new EthMessages(), ethScheduler);
    final TransactionPoolConfiguration transactionPoolConfiguration = ImmutableTransactionPoolConfiguration.builder().build();
    transactionPool = TransactionPoolFactory.createTransactionPool(protocolSchedule, protocolContext, ethContext, retestethClock, metricsSystem, syncState, new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).build(), transactionPoolConfiguration);
    if (LOG.isTraceEnabled()) {
        LOG.trace("Genesis Block {} ", genesisState.getBlock());
    }
    return true;
}
Also used : GenesisState(org.hyperledger.besu.ethereum.chain.GenesisState) EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) TransactionPoolConfiguration(org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration) ImmutableTransactionPoolConfiguration(org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration) EpochCalculator(org.hyperledger.besu.ethereum.mainnet.EpochCalculator) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) WorldStatePreimageKeyValueStorage(org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage) WorldStateKeyValueStorage(org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) SyncState(org.hyperledger.besu.ethereum.eth.sync.state.SyncState) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) EthMessages(org.hyperledger.besu.ethereum.eth.manager.EthMessages) DefaultWorldStateArchive(org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InMemoryKeyValueStorage(org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage) BlockReplay(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay) EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) JsonGenesisConfigOptions(org.hyperledger.besu.config.JsonGenesisConfigOptions) DefaultWorldStateArchive(org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) IncrementingNonceGenerator(org.hyperledger.besu.ethereum.blockcreation.IncrementingNonceGenerator) PoWSolver(org.hyperledger.besu.ethereum.mainnet.PoWSolver)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 JsonGenesisConfigOptions (org.hyperledger.besu.config.JsonGenesisConfigOptions)1 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)1 BlockReplay (org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay)1 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)1 IncrementingNonceGenerator (org.hyperledger.besu.ethereum.blockcreation.IncrementingNonceGenerator)1 GenesisState (org.hyperledger.besu.ethereum.chain.GenesisState)1 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)1 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)1 EthMessages (org.hyperledger.besu.ethereum.eth.manager.EthMessages)1 EthPeers (org.hyperledger.besu.ethereum.eth.manager.EthPeers)1 EthScheduler (org.hyperledger.besu.ethereum.eth.manager.EthScheduler)1 SyncState (org.hyperledger.besu.ethereum.eth.sync.state.SyncState)1 ImmutableTransactionPoolConfiguration (org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration)1 TransactionPoolConfiguration (org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration)1 EpochCalculator (org.hyperledger.besu.ethereum.mainnet.EpochCalculator)1 PoWSolver (org.hyperledger.besu.ethereum.mainnet.PoWSolver)1 WorldStateKeyValueStorage (org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage)1 WorldStatePreimageKeyValueStorage (org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage)1 DefaultWorldStateArchive (org.hyperledger.besu.ethereum.worldstate.DefaultWorldStateArchive)1