use of org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProvider in project besu by hyperledger.
the class ThreadBesuNodeRunner method startNode.
@Override
public void startNode(final BesuNode node) {
if (MDC.get("node") != null) {
LOG.error("ThreadContext node is already set to {}", MDC.get("node"));
}
MDC.put("node", node.getName());
if (!node.getRunCommand().isEmpty()) {
throw new UnsupportedOperationException("commands are not supported with thread runner");
}
final StorageServiceImpl storageService = new StorageServiceImpl();
final SecurityModuleServiceImpl securityModuleService = new SecurityModuleServiceImpl();
final Path dataDir = node.homeDirectory();
final BesuConfiguration commonPluginConfiguration = new BesuConfigurationImpl(dataDir, dataDir.resolve(DATABASE_PATH));
final BesuPluginContextImpl besuPluginContext = besuPluginContextMap.computeIfAbsent(node, n -> buildPluginContext(node, storageService, securityModuleService, commonPluginConfiguration));
final ObservableMetricsSystem metricsSystem = MetricsSystemFactory.create(node.getMetricsConfiguration());
final List<EnodeURL> bootnodes = node.getConfiguration().getBootnodes().stream().map(EnodeURLImpl::fromURI).collect(Collectors.toList());
final NetworkName network = node.getNetwork() == null ? NetworkName.DEV : node.getNetwork();
final EthNetworkConfig.Builder networkConfigBuilder = new EthNetworkConfig.Builder(EthNetworkConfig.getNetworkConfig(network)).setBootNodes(bootnodes);
node.getConfiguration().getGenesisConfig().ifPresent(networkConfigBuilder::setGenesisConfig);
final EthNetworkConfig ethNetworkConfig = networkConfigBuilder.build();
final BesuControllerBuilder builder = new BesuController.Builder().fromEthNetworkConfig(ethNetworkConfig);
final KeyValueStorageProvider storageProvider = new KeyValueStorageProviderBuilder().withStorageFactory(storageService.getByName("rocksdb").get()).withCommonConfiguration(commonPluginConfiguration).withMetricsSystem(metricsSystem).build();
final TransactionPoolConfiguration txPoolConfig = ImmutableTransactionPoolConfiguration.builder().strictTransactionReplayProtectionEnabled(node.isStrictTxReplayProtectionEnabled()).build();
final int maxPeers = 25;
builder.synchronizerConfiguration(new SynchronizerConfiguration.Builder().build()).dataDirectory(node.homeDirectory()).miningParameters(node.getMiningParameters()).privacyParameters(node.getPrivacyParameters()).nodeKey(new NodeKey(new KeyPairSecurityModule(KeyPairUtil.loadKeyPair(dataDir)))).metricsSystem(metricsSystem).transactionPoolConfiguration(txPoolConfig).ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()).clock(Clock.systemUTC()).isRevertReasonEnabled(node.isRevertReasonEnabled()).storageProvider(storageProvider).gasLimitCalculator(GasLimitCalculator.constant()).pkiBlockCreationConfiguration(node.getPkiKeyStoreConfiguration().map(pkiConfig -> new PkiBlockCreationConfigurationProvider().load(pkiConfig))).evmConfiguration(EvmConfiguration.DEFAULT).maxPeers(maxPeers);
node.getGenesisConfig().map(GenesisConfigFile::fromConfig).ifPresent(builder::genesisConfigFile);
final BesuController besuController = builder.build();
final RunnerBuilder runnerBuilder = new RunnerBuilder();
runnerBuilder.permissioningConfiguration(node.getPermissioningConfiguration());
final Runner runner = runnerBuilder.vertx(Vertx.vertx()).besuController(besuController).ethNetworkConfig(ethNetworkConfig).discovery(node.isDiscoveryEnabled()).p2pAdvertisedHost(node.getHostName()).p2pListenPort(0).maxPeers(maxPeers).networkingConfiguration(node.getNetworkingConfiguration()).jsonRpcConfiguration(node.jsonRpcConfiguration()).webSocketConfiguration(node.webSocketConfiguration()).jsonRpcIpcConfiguration(node.jsonRpcIpcConfiguration()).dataDir(node.homeDirectory()).metricsSystem(metricsSystem).permissioningService(new PermissioningServiceImpl()).metricsConfiguration(node.getMetricsConfiguration()).p2pEnabled(node.isP2pEnabled()).p2pTLSConfiguration(node.getTLSConfiguration()).graphQLConfiguration(GraphQLConfiguration.createDefault()).staticNodes(node.getStaticNodes().stream().map(EnodeURLImpl::fromString).collect(Collectors.toList())).besuPluginContext(new BesuPluginContextImpl()).autoLogBloomCaching(false).storageProvider(storageProvider).forkIdSupplier(() -> besuController.getProtocolManager().getForkIdAsBytesList()).rpcEndpointService(new RpcEndpointServiceImpl()).build();
besuPluginContext.beforeExternalServices();
runner.startExternalServices();
besuPluginContext.addService(BesuEvents.class, new BesuEventsImpl(besuController.getProtocolContext().getBlockchain(), besuController.getProtocolManager().getBlockBroadcaster(), besuController.getTransactionPool(), besuController.getSyncState()));
besuPluginContext.startPlugins();
runner.startEthereumMainLoop();
besuRunners.put(node.getName(), runner);
MDC.remove("node");
}
Aggregations