Search in sources :

Example 1 with EthProtocolConfiguration

use of org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration in project besu by hyperledger.

the class TransactionPoolFactoryTest method testDisconnect.

@Test
public void testDisconnect() {
    final ProtocolSchedule schedule = mock(ProtocolSchedule.class);
    final ProtocolContext context = mock(ProtocolContext.class);
    final MutableBlockchain blockchain = mock(MutableBlockchain.class);
    when(blockchain.getBlockByNumber(anyLong())).thenReturn(Optional.of(mock(Block.class)));
    when(blockchain.getBlockHashByNumber(anyLong())).thenReturn(Optional.of(mock(Hash.class)));
    when(context.getBlockchain()).thenReturn(blockchain);
    final EthPeers ethPeers = new EthPeers("ETH", TestClock.fixed(), new NoOpMetricsSystem(), 25);
    final EthContext ethContext = mock(EthContext.class);
    when(ethContext.getEthMessages()).thenReturn(mock(EthMessages.class));
    when(ethContext.getEthPeers()).thenReturn(ethPeers);
    final EthScheduler ethScheduler = mock(EthScheduler.class);
    when(ethContext.getScheduler()).thenReturn(ethScheduler);
    final SyncState state = mock(SyncState.class);
    final GasPricePendingTransactionsSorter pendingTransactions = mock(GasPricePendingTransactionsSorter.class);
    final PeerTransactionTracker peerTransactionTracker = mock(PeerTransactionTracker.class);
    final TransactionsMessageSender transactionsMessageSender = mock(TransactionsMessageSender.class);
    doNothing().when(transactionsMessageSender).sendTransactionsToPeer(any(EthPeer.class));
    final NewPooledTransactionHashesMessageSender newPooledTransactionHashesMessageSender = mock(NewPooledTransactionHashesMessageSender.class);
    final TransactionPool pool = TransactionPoolFactory.createTransactionPool(schedule, context, ethContext, new NoOpMetricsSystem(), state, new MiningParameters.Builder().minTransactionGasPrice(Wei.ONE).build(), ImmutableTransactionPoolConfiguration.of(1, 1, 1, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP, TransactionPoolConfiguration.ETH65_TRX_ANNOUNCED_BUFFERING_PERIOD, TransactionPoolConfiguration.DEFAULT_RPC_TX_FEE_CAP, TransactionPoolConfiguration.DEFAULT_STRICT_TX_REPLAY_PROTECTION_ENABLED), pendingTransactions, peerTransactionTracker, transactionsMessageSender, newPooledTransactionHashesMessageSender);
    final EthProtocolManager ethProtocolManager = new EthProtocolManager(blockchain, BigInteger.ONE, mock(WorldStateArchive.class), pool, new EthProtocolConfiguration(5, 5, 5, 5, 5, false), ethPeers, mock(EthMessages.class), ethContext, Collections.emptyList(), true, mock(EthScheduler.class), mock(ForkIdManager.class));
    final RespondingEthPeer ethPeer = RespondingEthPeer.builder().ethProtocolManager(ethProtocolManager).build();
    assertThat(ethPeer.getEthPeer()).isNotNull();
    assertThat(ethPeer.getEthPeer().isDisconnected()).isFalse();
    ethPeer.disconnect(DisconnectMessage.DisconnectReason.CLIENT_QUITTING);
    verify(peerTransactionTracker, times(1)).onDisconnect(ethPeer.getEthPeer());
}
Also used : EthContext(org.hyperledger.besu.ethereum.eth.manager.EthContext) EthMessages(org.hyperledger.besu.ethereum.eth.manager.EthMessages) EthPeer(org.hyperledger.besu.ethereum.eth.manager.EthPeer) RespondingEthPeer(org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer) RespondingEthPeer(org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer) EthPeers(org.hyperledger.besu.ethereum.eth.manager.EthPeers) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) EthProtocolConfiguration(org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration) ForkIdManager(org.hyperledger.besu.ethereum.eth.manager.ForkIdManager) MiningParameters(org.hyperledger.besu.ethereum.core.MiningParameters) EthProtocolManager(org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager) EthScheduler(org.hyperledger.besu.ethereum.eth.manager.EthScheduler) SyncState(org.hyperledger.besu.ethereum.eth.sync.state.SyncState) WorldStateArchive(org.hyperledger.besu.ethereum.worldstate.WorldStateArchive) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) GasPricePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter) Test(org.junit.Test)

Example 2 with EthProtocolConfiguration

use of org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration in project besu by hyperledger.

the class EthProtocolOptionsTest method parsesValidEwpMaxGetNodeDataOptions.

@Test
public void parsesValidEwpMaxGetNodeDataOptions() {
    final TestBesuCommand cmd = parseCommand("--Xewp-max-get-node-data", "16");
    final EthProtocolOptions options = getOptionsFromBesuCommand(cmd);
    final EthProtocolConfiguration config = options.toDomainObject();
    assertThat(config.getMaxGetNodeData()).isEqualTo(16);
    assertThat(commandOutput.toString(UTF_8)).isEmpty();
    assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
Also used : EthProtocolOptions(org.hyperledger.besu.cli.options.unstable.EthProtocolOptions) EthProtocolConfiguration(org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration) Test(org.junit.Test)

Example 3 with EthProtocolConfiguration

use of org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration in project besu by hyperledger.

the class EthProtocolOptionsTest method parsesValidEwpMaxGetBodiesOptions.

@Test
public void parsesValidEwpMaxGetBodiesOptions() {
    final TestBesuCommand cmd = parseCommand("--Xewp-max-get-bodies", "14");
    final EthProtocolOptions options = getOptionsFromBesuCommand(cmd);
    final EthProtocolConfiguration config = options.toDomainObject();
    assertThat(config.getMaxGetBlockBodies()).isEqualTo(14);
    assertThat(commandOutput.toString(UTF_8)).isEmpty();
    assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
Also used : EthProtocolOptions(org.hyperledger.besu.cli.options.unstable.EthProtocolOptions) EthProtocolConfiguration(org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration) Test(org.junit.Test)

Example 4 with EthProtocolConfiguration

use of org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration in project besu by hyperledger.

the class EthProtocolOptionsTest method parsesValidEwpMaxGetHeadersOptions.

@Test
public void parsesValidEwpMaxGetHeadersOptions() {
    final TestBesuCommand cmd = parseCommand("--Xewp-max-get-headers", "13");
    final EthProtocolOptions options = getOptionsFromBesuCommand(cmd);
    final EthProtocolConfiguration config = options.toDomainObject();
    assertThat(config.getMaxGetBlockHeaders()).isEqualTo(13);
    assertThat(commandOutput.toString(UTF_8)).isEmpty();
    assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
Also used : EthProtocolOptions(org.hyperledger.besu.cli.options.unstable.EthProtocolOptions) EthProtocolConfiguration(org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration) Test(org.junit.Test)

Example 5 with EthProtocolConfiguration

use of org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration 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");
}
Also used : BesuPluginContextImpl(org.hyperledger.besu.services.BesuPluginContextImpl) KeyPairUtil(org.hyperledger.besu.crypto.KeyPairUtil) EnodeURLImpl(org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl) LoggerFactory(org.slf4j.LoggerFactory) RocksDBPlugin(org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBPlugin) Runner(org.hyperledger.besu.Runner) NetworkName(org.hyperledger.besu.cli.config.NetworkName) GenesisConfigFile(org.hyperledger.besu.config.GenesisConfigFile) Map(java.util.Map) BesuPluginContextImpl(org.hyperledger.besu.services.BesuPluginContextImpl) Path(java.nio.file.Path) CommandLine(picocli.CommandLine) SecurityModuleService(org.hyperledger.besu.plugin.services.SecurityModuleService) EthProtocolConfiguration(org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration) PkiBlockCreationConfigurationProvider(org.hyperledger.besu.consensus.qbft.pki.PkiBlockCreationConfigurationProvider) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PicoCLIOptions(org.hyperledger.besu.plugin.services.PicoCLIOptions) DATABASE_PATH(org.hyperledger.besu.controller.BesuController.DATABASE_PATH) EvmConfiguration(org.hyperledger.besu.evm.internal.EvmConfiguration) Collectors(java.util.stream.Collectors) BesuConfigurationImpl(org.hyperledger.besu.services.BesuConfigurationImpl) List(java.util.List) TransactionPoolConfiguration(org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration) KeyValueStorageProvider(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProvider) BesuConfiguration(org.hyperledger.besu.plugin.services.BesuConfiguration) BesuEventsImpl(org.hyperledger.besu.services.BesuEventsImpl) GasLimitCalculator(org.hyperledger.besu.ethereum.GasLimitCalculator) NodeKey(org.hyperledger.besu.crypto.NodeKey) BesuEvents(org.hyperledger.besu.plugin.services.BesuEvents) KeyPairSecurityModule(org.hyperledger.besu.crypto.KeyPairSecurityModule) ImmutableTransactionPoolConfiguration(org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration) EthNetworkConfig(org.hyperledger.besu.cli.config.EthNetworkConfig) BesuControllerBuilder(org.hyperledger.besu.controller.BesuControllerBuilder) HashMap(java.util.HashMap) SynchronizerConfiguration(org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration) RunnerBuilder(org.hyperledger.besu.RunnerBuilder) BesuController(org.hyperledger.besu.controller.BesuController) StorageService(org.hyperledger.besu.plugin.services.StorageService) HashSet(java.util.HashSet) PermissioningServiceImpl(org.hyperledger.besu.services.PermissioningServiceImpl) RpcEndpointServiceImpl(org.hyperledger.besu.services.RpcEndpointServiceImpl) Logger(org.slf4j.Logger) MetricsSystemFactory(org.hyperledger.besu.metrics.MetricsSystemFactory) SecurityModuleServiceImpl(org.hyperledger.besu.services.SecurityModuleServiceImpl) StorageServiceImpl(org.hyperledger.besu.services.StorageServiceImpl) KeyValueStorageProviderBuilder(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder) Vertx(io.vertx.core.Vertx) GraphQLConfiguration(org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration) File(java.io.File) EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) PicoCLIOptionsImpl(org.hyperledger.besu.services.PicoCLIOptionsImpl) ObservableMetricsSystem(org.hyperledger.besu.metrics.ObservableMetricsSystem) MDC(org.slf4j.MDC) Clock(java.time.Clock) CommandSpec(picocli.CommandLine.Model.CommandSpec) Runner(org.hyperledger.besu.Runner) NetworkName(org.hyperledger.besu.cli.config.NetworkName) BesuController(org.hyperledger.besu.controller.BesuController) KeyValueStorageProvider(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProvider) TransactionPoolConfiguration(org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration) ImmutableTransactionPoolConfiguration(org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration) BesuControllerBuilder(org.hyperledger.besu.controller.BesuControllerBuilder) RunnerBuilder(org.hyperledger.besu.RunnerBuilder) KeyValueStorageProviderBuilder(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder) BesuEventsImpl(org.hyperledger.besu.services.BesuEventsImpl) BesuControllerBuilder(org.hyperledger.besu.controller.BesuControllerBuilder) KeyValueStorageProviderBuilder(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder) EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) RunnerBuilder(org.hyperledger.besu.RunnerBuilder) SecurityModuleServiceImpl(org.hyperledger.besu.services.SecurityModuleServiceImpl) NodeKey(org.hyperledger.besu.crypto.NodeKey) StorageServiceImpl(org.hyperledger.besu.services.StorageServiceImpl) Path(java.nio.file.Path) PkiBlockCreationConfigurationProvider(org.hyperledger.besu.consensus.qbft.pki.PkiBlockCreationConfigurationProvider) RpcEndpointServiceImpl(org.hyperledger.besu.services.RpcEndpointServiceImpl) BesuConfiguration(org.hyperledger.besu.plugin.services.BesuConfiguration) EnodeURLImpl(org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl) PermissioningServiceImpl(org.hyperledger.besu.services.PermissioningServiceImpl) ObservableMetricsSystem(org.hyperledger.besu.metrics.ObservableMetricsSystem) KeyPairSecurityModule(org.hyperledger.besu.crypto.KeyPairSecurityModule) EthNetworkConfig(org.hyperledger.besu.cli.config.EthNetworkConfig) BesuConfigurationImpl(org.hyperledger.besu.services.BesuConfigurationImpl)

Aggregations

EthProtocolConfiguration (org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration)9 Test (org.junit.Test)8 HashSet (java.util.HashSet)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 EthProtocolOptions (org.hyperledger.besu.cli.options.unstable.EthProtocolOptions)4 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)4 MutableBlockchain (org.hyperledger.besu.ethereum.chain.MutableBlockchain)4 MiningParameters (org.hyperledger.besu.ethereum.core.MiningParameters)4 Lists (com.google.common.collect.Lists)3 BigInteger (java.math.BigInteger)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 Optional (java.util.Optional)3 Set (java.util.Set)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExecutionException (java.util.concurrent.ExecutionException)3 ExecutorService (java.util.concurrent.ExecutorService)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3