use of org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration in project besu by hyperledger.
the class RunnerBuilder method build.
public Runner build() {
Preconditions.checkNotNull(besuController);
final DiscoveryConfiguration discoveryConfiguration = DiscoveryConfiguration.create().setBindHost(p2pListenInterface).setBindPort(p2pListenPort).setAdvertisedHost(p2pAdvertisedHost);
if (discovery) {
final List<EnodeURL> bootstrap;
if (ethNetworkConfig.getBootNodes() == null) {
bootstrap = EthNetworkConfig.getNetworkConfig(NetworkName.MAINNET).getBootNodes();
} else {
bootstrap = ethNetworkConfig.getBootNodes();
}
discoveryConfiguration.setBootnodes(bootstrap);
discoveryConfiguration.setDnsDiscoveryURL(ethNetworkConfig.getDnsDiscoveryUrl());
} else {
discoveryConfiguration.setActive(false);
}
final NodeKey nodeKey = besuController.getNodeKey();
final SubProtocolConfiguration subProtocolConfiguration = besuController.getSubProtocolConfiguration();
final ProtocolSchedule protocolSchedule = besuController.getProtocolSchedule();
final ProtocolContext context = besuController.getProtocolContext();
final List<SubProtocol> subProtocols = subProtocolConfiguration.getSubProtocols();
final List<ProtocolManager> protocolManagers = subProtocolConfiguration.getProtocolManagers();
final Set<Capability> supportedCapabilities = protocolManagers.stream().flatMap(protocolManager -> protocolManager.getSupportedCapabilities().stream()).collect(Collectors.toSet());
final RlpxConfiguration rlpxConfiguration = RlpxConfiguration.create().setBindHost(p2pListenInterface).setBindPort(p2pListenPort).setMaxPeers(maxPeers).setSupportedProtocols(subProtocols).setClientId(BesuInfo.nodeName(identityString)).setLimitRemoteWireConnectionsEnabled(limitRemoteWireConnectionsEnabled).setFractionRemoteWireConnectionsAllowed(fractionRemoteConnectionsAllowed);
networkingConfiguration.setRlpx(rlpxConfiguration).setDiscovery(discoveryConfiguration);
final PeerPermissionsDenylist bannedNodes = PeerPermissionsDenylist.create();
bannedNodeIds.forEach(bannedNodes::add);
final List<EnodeURL> bootnodes = discoveryConfiguration.getBootnodes();
final Synchronizer synchronizer = besuController.getSynchronizer();
final TransactionSimulator transactionSimulator = new TransactionSimulator(context.getBlockchain(), context.getWorldStateArchive(), protocolSchedule);
final Bytes localNodeId = nodeKey.getPublicKey().getEncodedBytes();
final Optional<NodePermissioningController> nodePermissioningController = buildNodePermissioningController(bootnodes, synchronizer, transactionSimulator, localNodeId, context.getBlockchain());
final PeerPermissions peerPermissions = nodePermissioningController.map(nodePC -> new PeerPermissionsAdapter(nodePC, bootnodes, context.getBlockchain())).map(nodePerms -> PeerPermissions.combine(nodePerms, bannedNodes)).orElse(bannedNodes);
LOG.info("Detecting NAT service.");
final boolean fallbackEnabled = natMethod == NatMethod.AUTO || natMethodFallbackEnabled;
final NatService natService = new NatService(buildNatManager(natMethod), fallbackEnabled);
final NetworkBuilder inactiveNetwork = caps -> new NoopP2PNetwork();
final NetworkBuilder activeNetwork = caps -> DefaultP2PNetwork.builder().vertx(vertx).nodeKey(nodeKey).config(networkingConfiguration).peerPermissions(peerPermissions).metricsSystem(metricsSystem).supportedCapabilities(caps).natService(natService).randomPeerPriority(randomPeerPriority).storageProvider(storageProvider).forkIdSupplier(forkIdSupplier).p2pTLSConfiguration(p2pTLSConfiguration).build();
final NetworkRunner networkRunner = NetworkRunner.builder().protocolManagers(protocolManagers).subProtocols(subProtocols).network(p2pEnabled ? activeNetwork : inactiveNetwork).metricsSystem(metricsSystem).build();
final P2PNetwork network = networkRunner.getNetwork();
// ForkId in Ethereum Node Record needs updating when we transition to a new protocol spec
context.getBlockchain().observeBlockAdded(blockAddedEvent -> {
if (protocolSchedule.streamMilestoneBlocks().anyMatch(blockNumber -> blockNumber == blockAddedEvent.getBlock().getHeader().getNumber())) {
network.updateNodeRecord();
}
});
nodePermissioningController.ifPresent(n -> n.setInsufficientPeersPermissioningProvider(new InsufficientPeersPermissioningProvider(network, bootnodes)));
final TransactionPool transactionPool = besuController.getTransactionPool();
final MiningCoordinator miningCoordinator = besuController.getMiningCoordinator();
final BlockchainQueries blockchainQueries = new BlockchainQueries(context.getBlockchain(), context.getWorldStateArchive(), Optional.of(dataDir.resolve(CACHE_PATH)), Optional.of(besuController.getProtocolManager().ethContext().getScheduler()), apiConfiguration);
final PrivacyParameters privacyParameters = besuController.getPrivacyParameters();
final FilterManager filterManager = new FilterManagerBuilder().blockchainQueries(blockchainQueries).transactionPool(transactionPool).privacyParameters(privacyParameters).build();
vertx.deployVerticle(filterManager);
createPrivateTransactionObserver(filterManager, privacyParameters);
final P2PNetwork peerNetwork = networkRunner.getNetwork();
final MiningParameters miningParameters = besuController.getMiningParameters();
Optional<StratumServer> stratumServer = Optional.empty();
if (miningParameters.isStratumMiningEnabled()) {
var powMiningCoordinator = miningCoordinator;
if (miningCoordinator instanceof TransitionCoordinator) {
LOG.debug("fetching powMiningCoordinator from TransitionCoordinator");
powMiningCoordinator = ((TransitionCoordinator) miningCoordinator).getPreMergeObject();
}
stratumServer = Optional.of(new StratumServer(vertx, powMiningCoordinator, miningParameters.getStratumPort(), miningParameters.getStratumNetworkInterface(), miningParameters.getStratumExtranonce(), metricsSystem));
miningCoordinator.addEthHashObserver(stratumServer.get());
LOG.debug("added ethash observer: {}", stratumServer.get());
}
sanitizePeers(network, staticNodes).map(DefaultPeer::fromEnodeURL).forEach(peerNetwork::addMaintainedConnectionPeer);
final Optional<NodeLocalConfigPermissioningController> nodeLocalConfigPermissioningController = nodePermissioningController.flatMap(NodePermissioningController::localConfigController);
final Optional<AccountPermissioningController> accountPermissioningController = buildAccountPermissioningController(permissioningConfiguration, besuController, transactionSimulator, context.getBlockchain());
final Optional<AccountLocalConfigPermissioningController> accountLocalConfigPermissioningController = accountPermissioningController.flatMap(AccountPermissioningController::getAccountLocalConfigPermissioningController);
Optional<JsonRpcHttpService> jsonRpcHttpService = Optional.empty();
if (jsonRpcConfiguration.isEnabled()) {
final Map<String, JsonRpcMethod> nonEngineMethods = jsonRpcMethods(protocolSchedule, context, besuController, peerNetwork, blockchainQueries, synchronizer, transactionPool, miningCoordinator, metricsSystem, supportedCapabilities, jsonRpcConfiguration.getRpcApis().stream().filter(apiGroup -> !apiGroup.toLowerCase().startsWith("engine")).collect(Collectors.toList()), filterManager, accountLocalConfigPermissioningController, nodeLocalConfigPermissioningController, privacyParameters, jsonRpcConfiguration, webSocketConfiguration, metricsConfiguration, natService, besuPluginContext.getNamedPlugins(), dataDir, rpcEndpointServiceImpl);
jsonRpcHttpService = Optional.of(new JsonRpcHttpService(vertx, dataDir, jsonRpcConfiguration, metricsSystem, natService, nonEngineMethods, new HealthService(new LivenessCheck()), new HealthService(new ReadinessCheck(peerNetwork, synchronizer))));
}
Optional<JsonRpcService> engineJsonRpcService = Optional.empty();
if (engineJsonRpcConfiguration.isPresent() && engineJsonRpcConfiguration.get().isEnabled()) {
final Map<String, JsonRpcMethod> engineMethods = jsonRpcMethods(protocolSchedule, context, besuController, peerNetwork, blockchainQueries, synchronizer, transactionPool, miningCoordinator, metricsSystem, supportedCapabilities, engineJsonRpcConfiguration.get().getRpcApis(), filterManager, accountLocalConfigPermissioningController, nodeLocalConfigPermissioningController, privacyParameters, engineJsonRpcConfiguration.get(), webSocketConfiguration, metricsConfiguration, natService, besuPluginContext.getNamedPlugins(), dataDir, rpcEndpointServiceImpl);
Optional<AuthenticationService> authToUse = engineJsonRpcConfiguration.get().isAuthenticationEnabled() ? Optional.of(new EngineAuthService(vertx, Optional.ofNullable(engineJsonRpcConfiguration.get().getAuthenticationPublicKeyFile()), dataDir)) : Optional.empty();
WebSocketConfiguration engineSocketConfig = webSocketConfiguration.isEnabled() ? webSocketConfiguration : WebSocketConfiguration.createEngineDefault();
engineJsonRpcService = Optional.of(new JsonRpcService(vertx, dataDir, engineJsonRpcConfiguration.orElse(JsonRpcConfiguration.createEngineDefault()), metricsSystem, natService, engineMethods, Optional.ofNullable(engineSocketConfig), besuController.getProtocolManager().ethContext().getScheduler(), authToUse, new HealthService(new LivenessCheck()), new HealthService(new ReadinessCheck(peerNetwork, synchronizer))));
}
Optional<GraphQLHttpService> graphQLHttpService = Optional.empty();
if (graphQLConfiguration.isEnabled()) {
final GraphQLDataFetchers fetchers = new GraphQLDataFetchers(supportedCapabilities, privacyParameters.getGoQuorumPrivacyParameters());
final Map<GraphQLContextType, Object> graphQlContextMap = new ConcurrentHashMap<>();
graphQlContextMap.putIfAbsent(GraphQLContextType.BLOCKCHAIN_QUERIES, blockchainQueries);
graphQlContextMap.putIfAbsent(GraphQLContextType.PROTOCOL_SCHEDULE, protocolSchedule);
graphQlContextMap.putIfAbsent(GraphQLContextType.TRANSACTION_POOL, transactionPool);
graphQlContextMap.putIfAbsent(GraphQLContextType.MINING_COORDINATOR, miningCoordinator);
graphQlContextMap.putIfAbsent(GraphQLContextType.SYNCHRONIZER, synchronizer);
final GraphQL graphQL;
try {
graphQL = GraphQLProvider.buildGraphQL(fetchers);
} catch (final IOException ioe) {
throw new RuntimeException(ioe);
}
graphQLHttpService = Optional.of(new GraphQLHttpService(vertx, dataDir, graphQLConfiguration, graphQL, graphQlContextMap, besuController.getProtocolManager().ethContext().getScheduler()));
}
Optional<WebSocketService> webSocketService = Optional.empty();
if (webSocketConfiguration.isEnabled()) {
final Map<String, JsonRpcMethod> nonEngineMethods = jsonRpcMethods(protocolSchedule, context, besuController, peerNetwork, blockchainQueries, synchronizer, transactionPool, miningCoordinator, metricsSystem, supportedCapabilities, webSocketConfiguration.getRpcApis().stream().filter(apiGroup -> !apiGroup.toLowerCase().startsWith("engine")).collect(Collectors.toList()), filterManager, accountLocalConfigPermissioningController, nodeLocalConfigPermissioningController, privacyParameters, jsonRpcConfiguration, webSocketConfiguration, metricsConfiguration, natService, besuPluginContext.getNamedPlugins(), dataDir, rpcEndpointServiceImpl);
final SubscriptionManager subscriptionManager = createSubscriptionManager(vertx, transactionPool, blockchainQueries);
createLogsSubscriptionService(context.getBlockchain(), context.getWorldStateArchive(), subscriptionManager, privacyParameters);
createNewBlockHeadersSubscriptionService(context.getBlockchain(), blockchainQueries, subscriptionManager);
createSyncingSubscriptionService(synchronizer, subscriptionManager);
webSocketService = Optional.of(createWebsocketService(vertx, webSocketConfiguration, subscriptionManager, nonEngineMethods, privacyParameters, protocolSchedule, blockchainQueries, DefaultAuthenticationService.create(vertx, webSocketConfiguration), metricsSystem));
createPrivateTransactionObserver(subscriptionManager, privacyParameters);
}
Optional<MetricsService> metricsService = createMetricsService(vertx, metricsConfiguration);
final Optional<EthStatsService> ethStatsService;
if (!Strings.isNullOrEmpty(ethstatsUrl)) {
ethStatsService = Optional.of(new EthStatsService(NetstatsUrl.fromParams(ethstatsUrl, ethstatsContact), blockchainQueries, besuController.getProtocolManager(), transactionPool, miningCoordinator, besuController.getSyncState(), vertx, BesuInfo.nodeName(identityString), besuController.getGenesisConfigOptions(), network));
} else {
ethStatsService = Optional.empty();
}
final Optional<JsonRpcIpcService> jsonRpcIpcService;
if (jsonRpcIpcConfiguration.isEnabled()) {
Map<String, JsonRpcMethod> ipcMethods = jsonRpcMethods(protocolSchedule, context, besuController, peerNetwork, blockchainQueries, synchronizer, transactionPool, miningCoordinator, metricsSystem, supportedCapabilities, jsonRpcIpcConfiguration.getEnabledApis().stream().filter(apiGroup -> !apiGroup.toLowerCase().startsWith("engine")).collect(Collectors.toList()), filterManager, accountLocalConfigPermissioningController, nodeLocalConfigPermissioningController, privacyParameters, jsonRpcConfiguration, webSocketConfiguration, metricsConfiguration, natService, besuPluginContext.getNamedPlugins(), dataDir, rpcEndpointServiceImpl);
jsonRpcIpcService = Optional.of(new JsonRpcIpcService(vertx, jsonRpcIpcConfiguration.getPath(), new JsonRpcExecutor(new BaseJsonRpcProcessor(), ipcMethods)));
} else {
jsonRpcIpcService = Optional.empty();
}
return new Runner(vertx, networkRunner, natService, jsonRpcHttpService, engineJsonRpcService, graphQLHttpService, webSocketService, jsonRpcIpcService, stratumServer, metricsService, ethStatsService, besuController, dataDir, pidPath, autoLogBloomCaching ? blockchainQueries.getTransactionLogBloomCacher() : Optional.empty(), context.getBlockchain());
}
use of org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration in project besu by hyperledger.
the class QbftBesuControllerBuilder method createSubProtocolConfiguration.
@Override
protected SubProtocolConfiguration createSubProtocolConfiguration(final EthProtocolManager ethProtocolManager, final Optional<SnapProtocolManager> maybeSnapProtocolManager) {
final SubProtocolConfiguration subProtocolConfiguration = new SubProtocolConfiguration().withSubProtocol(EthProtocol.get(), ethProtocolManager).withSubProtocol(Istanbul100SubProtocol.get(), new BftProtocolManager(bftEventQueue, peers, Istanbul100SubProtocol.ISTANBUL_100, Istanbul100SubProtocol.get().getName()));
maybeSnapProtocolManager.ifPresent(snapProtocolManager -> {
subProtocolConfiguration.withSubProtocol(SnapProtocol.get(), snapProtocolManager);
});
return subProtocolConfiguration;
}
use of org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration in project besu by hyperledger.
the class BesuControllerBuilder method createSubProtocolConfiguration.
protected SubProtocolConfiguration createSubProtocolConfiguration(final EthProtocolManager ethProtocolManager, final Optional<SnapProtocolManager> maybeSnapProtocolManager) {
final SubProtocolConfiguration subProtocolConfiguration = new SubProtocolConfiguration().withSubProtocol(EthProtocol.get(), ethProtocolManager);
maybeSnapProtocolManager.ifPresent(snapProtocolManager -> subProtocolConfiguration.withSubProtocol(SnapProtocol.get(), snapProtocolManager));
return subProtocolConfiguration;
}
use of org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration in project besu by hyperledger.
the class BesuControllerBuilder method build.
public BesuController build() {
checkNotNull(genesisConfig, "Missing genesis config");
checkNotNull(syncConfig, "Missing sync config");
checkNotNull(ethereumWireProtocolConfiguration, "Missing ethereum protocol configuration");
checkNotNull(networkId, "Missing network ID");
checkNotNull(miningParameters, "Missing mining parameters");
checkNotNull(metricsSystem, "Missing metrics system");
checkNotNull(privacyParameters, "Missing privacy parameters");
// Why do we need this?
checkNotNull(dataDirectory, "Missing data directory");
checkNotNull(clock, "Missing clock");
checkNotNull(transactionPoolConfiguration, "Missing transaction pool configuration");
checkNotNull(nodeKey, "Missing node key");
checkNotNull(storageProvider, "Must supply a storage provider");
checkNotNull(gasLimitCalculator, "Missing gas limit calculator");
checkNotNull(evmConfiguration, "Missing evm config");
prepForBuild();
final ProtocolSchedule protocolSchedule = createProtocolSchedule();
final GenesisState genesisState = GenesisState.fromConfig(genesisConfig, protocolSchedule);
final WorldStateStorage worldStateStorage = storageProvider.createWorldStateStorage(dataStorageConfiguration.getDataStorageFormat());
final BlockchainStorage blockchainStorage = storageProvider.createBlockchainStorage(protocolSchedule);
final MutableBlockchain blockchain = DefaultBlockchain.createMutable(genesisState.getBlock(), blockchainStorage, metricsSystem, reorgLoggingThreshold, dataDirectory.toString());
final WorldStateArchive worldStateArchive = createWorldStateArchive(worldStateStorage, blockchain);
if (blockchain.getChainHeadBlockNumber() < 1) {
genesisState.writeStateTo(worldStateArchive.getMutable());
}
final ProtocolContext protocolContext = createProtocolContext(blockchain, worldStateArchive, protocolSchedule, this::createConsensusContext);
validateContext(protocolContext);
protocolSchedule.setPublicWorldStateArchiveForPrivacyBlockProcessor(protocolContext.getWorldStateArchive());
Optional<Pruner> maybePruner = Optional.empty();
if (isPruningEnabled) {
if (!storageProvider.isWorldStateIterable()) {
LOG.warn("Cannot enable pruning with current database version. Disabling. Resync to get the latest database version or disable pruning explicitly on the command line to remove this warning.");
} else if (dataStorageConfiguration.getDataStorageFormat().equals(DataStorageFormat.BONSAI)) {
LOG.warn("Cannot enable pruning with Bonsai data storage format. Disabling. Change the data storage format or disable pruning explicitly on the command line to remove this warning.");
} else {
maybePruner = Optional.of(new Pruner(new MarkSweepPruner(((DefaultWorldStateArchive) worldStateArchive).getWorldStateStorage(), blockchain, storageProvider.getStorageBySegmentIdentifier(KeyValueSegmentIdentifier.PRUNING_STATE), metricsSystem), blockchain, prunerConfiguration));
}
}
final EthPeers ethPeers = new EthPeers(getSupportedProtocol(), clock, metricsSystem, maxPeers, messagePermissioningProviders);
final EthMessages ethMessages = new EthMessages();
final EthMessages snapMessages = new EthMessages();
final EthScheduler scheduler = new EthScheduler(syncConfig.getDownloaderParallelism(), syncConfig.getTransactionsParallelism(), syncConfig.getComputationParallelism(), metricsSystem);
final GenesisConfigOptions configOptions = genesisConfig.getConfigOptions(genesisConfigOverrides);
Optional<Checkpoint> checkpoint = Optional.empty();
if (configOptions.getCheckpointOptions().isValid()) {
checkpoint = Optional.of(ImmutableCheckpoint.builder().blockHash(Hash.fromHexString(// NOSONAR
configOptions.getCheckpointOptions().getHash().get())).blockNumber(configOptions.getCheckpointOptions().getNumber().getAsLong()).totalDifficulty(Difficulty.fromHexString(configOptions.getCheckpointOptions().getTotalDifficulty().get())).build());
}
final EthContext ethContext = new EthContext(ethPeers, ethMessages, snapMessages, scheduler);
final boolean fastSyncEnabled = !SyncMode.isFullSync(syncConfig.getSyncMode());
final SyncState syncState = new SyncState(blockchain, ethPeers, fastSyncEnabled, checkpoint);
syncState.subscribeTTDReached(new PandaPrinter());
final TransactionPool transactionPool = TransactionPoolFactory.createTransactionPool(protocolSchedule, protocolContext, ethContext, clock, metricsSystem, syncState, miningParameters, transactionPoolConfiguration);
final List<PeerValidator> peerValidators = createPeerValidators(protocolSchedule);
final EthProtocolManager ethProtocolManager = createEthProtocolManager(protocolContext, fastSyncEnabled, transactionPool, ethereumWireProtocolConfiguration, ethPeers, ethContext, ethMessages, scheduler, peerValidators);
final Optional<SnapProtocolManager> maybeSnapProtocolManager = createSnapProtocolManager(peerValidators, ethPeers, snapMessages, worldStateArchive);
final PivotBlockSelector pivotBlockSelector = createPivotSelector(protocolContext);
final Synchronizer synchronizer = createSynchronizer(protocolSchedule, worldStateStorage, protocolContext, maybePruner, ethContext, syncState, ethProtocolManager, pivotBlockSelector);
final MiningCoordinator miningCoordinator = createMiningCoordinator(protocolSchedule, protocolContext, transactionPool, miningParameters, syncState, ethProtocolManager);
final PluginServiceFactory additionalPluginServices = createAdditionalPluginServices(blockchain, protocolContext);
final SubProtocolConfiguration subProtocolConfiguration = createSubProtocolConfiguration(ethProtocolManager, maybeSnapProtocolManager);
final JsonRpcMethods additionalJsonRpcMethodFactory = createAdditionalJsonRpcMethodFactory(protocolContext);
final List<Closeable> closeables = new ArrayList<>();
closeables.add(storageProvider);
if (privacyParameters.getPrivateStorageProvider() != null) {
closeables.add(privacyParameters.getPrivateStorageProvider());
}
return new BesuController(protocolSchedule, protocolContext, ethProtocolManager, configOptionsSupplier.get(), subProtocolConfiguration, synchronizer, syncState, transactionPool, miningCoordinator, privacyParameters, miningParameters, additionalJsonRpcMethodFactory, nodeKey, closeables, additionalPluginServices);
}
use of org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration in project besu by hyperledger.
the class IbftBesuControllerBuilder method createSubProtocolConfiguration.
@Override
protected SubProtocolConfiguration createSubProtocolConfiguration(final EthProtocolManager ethProtocolManager, final Optional<SnapProtocolManager> maybeSnapProtocolManager) {
final SubProtocolConfiguration subProtocolConfiguration = new SubProtocolConfiguration().withSubProtocol(EthProtocol.get(), ethProtocolManager).withSubProtocol(IbftSubProtocol.get(), new BftProtocolManager(bftEventQueue, peers, IbftSubProtocol.IBFV1, IbftSubProtocol.get().getName()));
maybeSnapProtocolManager.ifPresent(snapProtocolManager -> {
subProtocolConfiguration.withSubProtocol(SnapProtocol.get(), snapProtocolManager);
});
return subProtocolConfiguration;
}
Aggregations