Search in sources :

Example 1 with BesuPluginContextImpl

use of org.hyperledger.besu.services.BesuPluginContextImpl in project besu by hyperledger.

the class Besu method main.

public static void main(final String... args) {
    final Logger logger = setupLogging();
    final BesuCommand besuCommand = new BesuCommand(logger, RlpBlockImporter::new, JsonBlockImporter::new, RlpBlockExporter::new, new RunnerBuilder(), new BesuController.Builder(), new BesuPluginContextImpl(), System.getenv());
    besuCommand.parse(new RunLast().andExit(SUCCESS_EXIT_CODE), besuCommand.exceptionHandler().andExit(ERROR_EXIT_CODE), System.in, args);
}
Also used : BesuPluginContextImpl(org.hyperledger.besu.services.BesuPluginContextImpl) BesuCommand(org.hyperledger.besu.cli.BesuCommand) BesuController(org.hyperledger.besu.controller.BesuController) JsonBlockImporter(org.hyperledger.besu.chainimport.JsonBlockImporter) RunLast(picocli.CommandLine.RunLast) RlpBlockImporter(org.hyperledger.besu.chainimport.RlpBlockImporter) RlpBlockExporter(org.hyperledger.besu.chainexport.RlpBlockExporter) Logger(org.slf4j.Logger)

Example 2 with BesuPluginContextImpl

use of org.hyperledger.besu.services.BesuPluginContextImpl 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)

Example 3 with BesuPluginContextImpl

use of org.hyperledger.besu.services.BesuPluginContextImpl in project besu by hyperledger.

the class ThreadBesuNodeRunner method buildPluginContext.

private BesuPluginContextImpl buildPluginContext(final BesuNode node, final StorageServiceImpl storageService, final SecurityModuleServiceImpl securityModuleService, final BesuConfiguration commonPluginConfiguration) {
    final CommandLine commandLine = new CommandLine(CommandSpec.create());
    final BesuPluginContextImpl besuPluginContext = new BesuPluginContextImpl();
    besuPluginContext.addService(StorageService.class, storageService);
    besuPluginContext.addService(SecurityModuleService.class, securityModuleService);
    besuPluginContext.addService(PicoCLIOptions.class, new PicoCLIOptionsImpl(commandLine));
    final Path pluginsPath = node.homeDirectory().resolve("plugins");
    final File pluginsDirFile = pluginsPath.toFile();
    if (!pluginsDirFile.isDirectory()) {
        pluginsDirFile.mkdirs();
        pluginsDirFile.deleteOnExit();
    }
    System.setProperty("besu.plugins.dir", pluginsPath.toString());
    besuPluginContext.registerPlugins(pluginsPath);
    commandLine.parseArgs(node.getConfiguration().getExtraCLIOptions().toArray(new String[0]));
    besuPluginContext.addService(BesuConfiguration.class, commonPluginConfiguration);
    // register built-in plugins
    new RocksDBPlugin().register(besuPluginContext);
    return besuPluginContext;
}
Also used : BesuPluginContextImpl(org.hyperledger.besu.services.BesuPluginContextImpl) Path(java.nio.file.Path) CommandLine(picocli.CommandLine) RocksDBPlugin(org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBPlugin) PicoCLIOptionsImpl(org.hyperledger.besu.services.PicoCLIOptionsImpl) GenesisConfigFile(org.hyperledger.besu.config.GenesisConfigFile) File(java.io.File)

Example 4 with BesuPluginContextImpl

use of org.hyperledger.besu.services.BesuPluginContextImpl in project besu by hyperledger.

the class ThreadBesuNodeRunner method stopNode.

@Override
public void stopNode(final BesuNode node) {
    final BesuPluginContextImpl pluginContext = besuPluginContextMap.remove(node);
    if (pluginContext != null) {
        pluginContext.stopPlugins();
    }
    node.stop();
    killRunner(node.getName());
}
Also used : BesuPluginContextImpl(org.hyperledger.besu.services.BesuPluginContextImpl)

Example 5 with BesuPluginContextImpl

use of org.hyperledger.besu.services.BesuPluginContextImpl in project besu by hyperledger.

the class RunnerTest method syncFromGenesis.

private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesisConfig) throws Exception {
    final Path dataDirAhead = temp.newFolder().toPath();
    final Path dbAhead = dataDirAhead.resolve("database");
    final int blockCount = 500;
    final NodeKey aheadDbNodeKey = NodeKeyUtils.createFrom(KeyPairUtil.loadKeyPair(dbAhead));
    final SynchronizerConfiguration syncConfigAhead = SynchronizerConfiguration.builder().syncMode(SyncMode.FULL).build();
    final ObservableMetricsSystem noOpMetricsSystem = new NoOpMetricsSystem();
    final BigInteger networkId = BigInteger.valueOf(2929);
    // Setup state with block data
    try (final BesuController controller = new MainnetBesuControllerBuilder().genesisConfigFile(genesisConfig).synchronizerConfiguration(syncConfigAhead).ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()).dataDirectory(dataDirAhead).networkId(networkId).miningParameters(new MiningParameters.Builder().miningEnabled(false).build()).nodeKey(aheadDbNodeKey).metricsSystem(noOpMetricsSystem).privacyParameters(PrivacyParameters.DEFAULT).clock(TestClock.fixed()).transactionPoolConfiguration(TransactionPoolConfiguration.DEFAULT).storageProvider(createKeyValueStorageProvider(dataDirAhead, dbAhead)).gasLimitCalculator(GasLimitCalculator.constant()).evmConfiguration(EvmConfiguration.DEFAULT).build()) {
        setupState(blockCount, controller.getProtocolSchedule(), controller.getProtocolContext());
    }
    // Setup Runner with blocks
    final BesuController controllerAhead = new MainnetBesuControllerBuilder().genesisConfigFile(genesisConfig).synchronizerConfiguration(syncConfigAhead).ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()).dataDirectory(dataDirAhead).networkId(networkId).miningParameters(new MiningParameters.Builder().miningEnabled(false).build()).nodeKey(aheadDbNodeKey).metricsSystem(noOpMetricsSystem).privacyParameters(PrivacyParameters.DEFAULT).clock(TestClock.fixed()).transactionPoolConfiguration(TransactionPoolConfiguration.DEFAULT).storageProvider(createKeyValueStorageProvider(dataDirAhead, dbAhead)).gasLimitCalculator(GasLimitCalculator.constant()).evmConfiguration(EvmConfiguration.DEFAULT).build();
    final String listenHost = InetAddress.getLoopbackAddress().getHostAddress();
    final JsonRpcConfiguration aheadJsonRpcConfiguration = jsonRpcConfiguration();
    final GraphQLConfiguration aheadGraphQLConfiguration = graphQLConfiguration();
    final WebSocketConfiguration aheadWebSocketConfiguration = wsRpcConfiguration();
    final JsonRpcIpcConfiguration aheadJsonRpcIpcConfiguration = new JsonRpcIpcConfiguration();
    final MetricsConfiguration aheadMetricsConfiguration = metricsConfiguration();
    final Path pidPath = temp.getRoot().toPath().resolve("pid");
    final RunnerBuilder runnerBuilder = new RunnerBuilder().vertx(vertx).discovery(true).p2pAdvertisedHost(listenHost).p2pListenPort(0).maxPeers(3).metricsSystem(noOpMetricsSystem).permissioningService(new PermissioningServiceImpl()).staticNodes(emptySet()).storageProvider(new InMemoryKeyValueStorageProvider()).forkIdSupplier(() -> Collections.singletonList(Bytes.EMPTY)).rpcEndpointService(new RpcEndpointServiceImpl());
    Runner runnerBehind = null;
    final Runner runnerAhead = runnerBuilder.besuController(controllerAhead).ethNetworkConfig(EthNetworkConfig.getNetworkConfig(DEV)).jsonRpcConfiguration(aheadJsonRpcConfiguration).graphQLConfiguration(aheadGraphQLConfiguration).webSocketConfiguration(aheadWebSocketConfiguration).jsonRpcIpcConfiguration(aheadJsonRpcIpcConfiguration).metricsConfiguration(aheadMetricsConfiguration).dataDir(dbAhead).pidPath(pidPath).besuPluginContext(new BesuPluginContextImpl()).forkIdSupplier(() -> controllerAhead.getProtocolManager().getForkIdAsBytesList()).rpcEndpointService(new RpcEndpointServiceImpl()).build();
    try {
        runnerAhead.startExternalServices();
        runnerAhead.startEthereumMainLoop();
        assertThat(pidPath.toFile()).exists();
        final SynchronizerConfiguration syncConfigBehind = SynchronizerConfiguration.builder().syncMode(mode).fastSyncPivotDistance(5).fastSyncMinimumPeerCount(1).build();
        final Path dataDirBehind = temp.newFolder().toPath();
        final JsonRpcConfiguration behindJsonRpcConfiguration = jsonRpcConfiguration();
        final GraphQLConfiguration behindGraphQLConfiguration = graphQLConfiguration();
        final WebSocketConfiguration behindWebSocketConfiguration = wsRpcConfiguration();
        final MetricsConfiguration behindMetricsConfiguration = metricsConfiguration();
        // Setup runner with no block data
        final BesuController controllerBehind = new MainnetBesuControllerBuilder().genesisConfigFile(genesisConfig).synchronizerConfiguration(syncConfigBehind).ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig()).dataDirectory(dataDirBehind).networkId(networkId).miningParameters(new MiningParameters.Builder().miningEnabled(false).build()).nodeKey(NodeKeyUtils.generate()).storageProvider(new InMemoryKeyValueStorageProvider()).metricsSystem(noOpMetricsSystem).privacyParameters(PrivacyParameters.DEFAULT).clock(TestClock.fixed()).transactionPoolConfiguration(TransactionPoolConfiguration.DEFAULT).gasLimitCalculator(GasLimitCalculator.constant()).evmConfiguration(EvmConfiguration.DEFAULT).build();
        final EnodeURL enode = runnerAhead.getLocalEnode().get();
        final EthNetworkConfig behindEthNetworkConfiguration = new EthNetworkConfig(EthNetworkConfig.jsonConfig(DEV), DEV.getNetworkId(), Collections.singletonList(enode), null);
        runnerBehind = runnerBuilder.besuController(controllerBehind).ethNetworkConfig(behindEthNetworkConfiguration).jsonRpcConfiguration(behindJsonRpcConfiguration).graphQLConfiguration(behindGraphQLConfiguration).webSocketConfiguration(behindWebSocketConfiguration).metricsConfiguration(behindMetricsConfiguration).dataDir(temp.newFolder().toPath()).metricsSystem(noOpMetricsSystem).forkIdSupplier(() -> controllerBehind.getProtocolManager().getForkIdAsBytesList()).build();
        runnerBehind.startExternalServices();
        runnerBehind.startEthereumMainLoop();
        final int behindJsonRpcPort = runnerBehind.getJsonRpcPort().get();
        final OkHttpClient client = new OkHttpClient();
        Awaitility.await().ignoreExceptions().atMost(5L, TimeUnit.MINUTES).untilAsserted(() -> {
            final String baseUrl = String.format("http://%s:%s", listenHost, behindJsonRpcPort);
            try (final Response resp = client.newCall(new Request.Builder().post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(7) + ",\"method\":\"eth_blockNumber\"}")).url(baseUrl).build()).execute()) {
                assertThat(resp.code()).isEqualTo(200);
                final Response syncingResp = client.newCall(new Request.Builder().post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(7) + ",\"method\":\"eth_syncing\"}")).url(baseUrl).build()).execute();
                assertThat(syncingResp.code()).isEqualTo(200);
                final int currentBlock = UInt256.fromHexString(new JsonObject(resp.body().string()).getString("result")).intValue();
                final JsonObject responseJson = new JsonObject(syncingResp.body().string());
                if (currentBlock < blockCount) {
                    // if not yet at blockCount, we should get a sync result from eth_syncing
                    assertThat(responseJson.getValue("result")).isInstanceOf(JsonObject.class);
                    final int syncResultCurrentBlock = UInt256.fromHexString(responseJson.getJsonObject("result").getString("currentBlock")).intValue();
                    assertThat(syncResultCurrentBlock).isLessThan(blockCount);
                }
                assertThat(currentBlock).isEqualTo(blockCount);
                resp.close();
                // when we have synced to blockCount, eth_syncing should return false
                final boolean syncResult = responseJson.getBoolean("result");
                assertThat(syncResult).isFalse();
                syncingResp.close();
            }
        });
        final Promise<String> promise = Promise.promise();
        final HttpClient httpClient = vertx.createHttpClient();
        httpClient.webSocket(runnerBehind.getWebSocketPort().get(), WebSocketConfiguration.DEFAULT_WEBSOCKET_HOST, "/", ws -> {
            ws.result().writeTextMessage("{\"id\": 1, \"method\": \"eth_subscribe\", \"params\": [\"syncing\"]}");
            ws.result().textMessageHandler(payload -> {
                final boolean matches = payload.equals("{\"jsonrpc\":\"2.0\",\"id\":2,\"result\":\"0x0\"}");
                if (matches) {
                    promise.complete(payload);
                } else {
                    promise.fail("Unexpected result: " + payload);
                }
            });
        });
        final Future<String> future = promise.future();
        Awaitility.await().catchUncaughtExceptions().atMost(5L, TimeUnit.MINUTES).until(future::isComplete);
    } finally {
        if (runnerBehind != null) {
            runnerBehind.close();
            runnerBehind.awaitStop();
        }
    }
}
Also used : BesuPluginContextImpl(org.hyperledger.besu.services.BesuPluginContextImpl) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) BesuController(org.hyperledger.besu.controller.BesuController) OkHttpClient(okhttp3.OkHttpClient) MainnetBesuControllerBuilder(org.hyperledger.besu.controller.MainnetBesuControllerBuilder) KeyValueStorageProviderBuilder(org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder) JsonObject(io.vertx.core.json.JsonObject) EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) MetricsConfiguration(org.hyperledger.besu.metrics.prometheus.MetricsConfiguration) MainnetBesuControllerBuilder(org.hyperledger.besu.controller.MainnetBesuControllerBuilder) InMemoryKeyValueStorageProvider(org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider) SynchronizerConfiguration(org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration) JsonRpcIpcConfiguration(org.hyperledger.besu.ethereum.api.jsonrpc.ipc.JsonRpcIpcConfiguration) NodeKey(org.hyperledger.besu.crypto.NodeKey) GraphQLConfiguration(org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration) Path(java.nio.file.Path) RpcEndpointServiceImpl(org.hyperledger.besu.services.RpcEndpointServiceImpl) JsonRpcConfiguration(org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration) WebSocketConfiguration(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration) Request(okhttp3.Request) Response(okhttp3.Response) PermissioningServiceImpl(org.hyperledger.besu.services.PermissioningServiceImpl) ObservableMetricsSystem(org.hyperledger.besu.metrics.ObservableMetricsSystem) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) HttpClient(io.vertx.core.http.HttpClient) OkHttpClient(okhttp3.OkHttpClient) BigInteger(java.math.BigInteger) EthNetworkConfig(org.hyperledger.besu.cli.config.EthNetworkConfig)

Aggregations

BesuPluginContextImpl (org.hyperledger.besu.services.BesuPluginContextImpl)5 Path (java.nio.file.Path)3 BesuController (org.hyperledger.besu.controller.BesuController)3 File (java.io.File)2 EthNetworkConfig (org.hyperledger.besu.cli.config.EthNetworkConfig)2 GenesisConfigFile (org.hyperledger.besu.config.GenesisConfigFile)2 NodeKey (org.hyperledger.besu.crypto.NodeKey)2 GraphQLConfiguration (org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration)2 SynchronizerConfiguration (org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration)2 KeyValueStorageProviderBuilder (org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStorageProviderBuilder)2 RocksDBPlugin (org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBPlugin)2 PicoCLIOptionsImpl (org.hyperledger.besu.services.PicoCLIOptionsImpl)2 Logger (org.slf4j.Logger)2 CommandLine (picocli.CommandLine)2 Vertx (io.vertx.core.Vertx)1 HttpClient (io.vertx.core.http.HttpClient)1 JsonObject (io.vertx.core.json.JsonObject)1 BigInteger (java.math.BigInteger)1 Clock (java.time.Clock)1 HashMap (java.util.HashMap)1