[Timeout(12000)] // just to make sure we are not on infinite loop on steps because of incorrect dependencies
        public async Task Smoke_cancel(string chainSpecPath)
        {
            Type type1 = typeof(ITxPoolConfig);
            Type type2 = typeof(INetworkConfig);
            Type type3 = typeof(IKeyStoreConfig);
            Type type4 = typeof(IDbConfig);
            Type type5 = typeof(IStatsConfig);
            Type type6 = typeof(IKafkaConfig);
            Type type7 = typeof(IEthStatsConfig);
            Type type8 = typeof(ISyncConfig);
            Type type9 = typeof(IBloomConfig);

            var configProvider = new ConfigProvider();

            configProvider.AddSource(new ConfigSource(chainSpecPath));

            Console.WriteLine(type1.Name);
            Console.WriteLine(type2.Name);
            Console.WriteLine(type3.Name);
            Console.WriteLine(type4.Name);
            Console.WriteLine(type5.Name);
            Console.WriteLine(type6.Name);
            Console.WriteLine(type7.Name);
            Console.WriteLine(type8.Name);
            Console.WriteLine(type9.Name);

            var tempPath = Path.Combine(Path.GetTempPath(), "test_" + Guid.NewGuid());

            Directory.CreateDirectory(tempPath);

            try
            {
                configProvider.GetConfig <IInitConfig>().BaseDbPath = tempPath;

                EthereumRunner runner = new EthereumRunner(
                    new RpcModuleProvider(new JsonRpcConfig(), LimboLogs.Instance),
                    configProvider,
                    NUnitLogManager.Instance,
                    Substitute.For <IGrpcServer>(),
                    Substitute.For <INdmConsumerChannelManager>(),
                    Substitute.For <INdmDataPublisher>(),
                    Substitute.For <INdmInitializer>(),
                    Substitute.For <IWebSocketsManager>(),
                    new EthereumJsonSerializer(),
                    Substitute.For <IMonitoringService>());

                CancellationTokenSource cts = new CancellationTokenSource();
                Task task = runner.Start(cts.Token);

                cts.Cancel();

                await task;
            }
            finally
            {
                // rocks db still has a lock on a file called "LOCK".
                Directory.Delete(tempPath, true);
            }
        }
Ejemplo n.º 2
0
        [Timeout(120000)] // just to make sure we are not on infinite loop on steps because of incorrect dependencies
        public async Task Smoke(string chainSpecPath)
        {
            Type type1 = typeof(ITxPoolConfig);
            Type type2 = typeof(INetworkConfig);
            Type type3 = typeof(IKeyStoreConfig);
            Type type4 = typeof(IDbConfig);
            Type type5 = typeof(IStatsConfig);
            Type type6 = typeof(IKafkaConfig);
            Type type7 = typeof(IEthStatsConfig);
            Type type8 = typeof(ISyncConfig);
            Type type9 = typeof(IBloomConfig);

            var configProvider = new ConfigProvider();

            configProvider.AddSource(new ConfigSource(chainSpecPath));

            Console.WriteLine(type1.Name);
            Console.WriteLine(type2.Name);
            Console.WriteLine(type3.Name);
            Console.WriteLine(type4.Name);
            Console.WriteLine(type5.Name);
            Console.WriteLine(type6.Name);
            Console.WriteLine(type7.Name);
            Console.WriteLine(type8.Name);
            Console.WriteLine(type9.Name);

            EthereumRunner runner = new EthereumRunner(
                new RpcModuleProvider(new JsonRpcConfig(), LimboLogs.Instance),
                configProvider,
                LimboLogs.Instance,
                Substitute.For <IGrpcServer>(),
                Substitute.For <INdmConsumerChannelManager>(),
                Substitute.For <INdmDataPublisher>(),
                Substitute.For <INdmInitializer>(),
                Substitute.For <IWebSocketsManager>(),
                new EthereumJsonSerializer(), Substitute.For <IMonitoringService>());

            await runner.Start();

            await runner.StopAsync();
        }
Ejemplo n.º 3
0
        private static void Run(string[] args)
        {
            _logger.Info("Nethermind starting initialization.");

            AppDomain.CurrentDomain.ProcessExit += CurrentDomainOnProcessExit;
            IFileSystem fileSystem = new FileSystem();;

            PluginLoader pluginLoader = new PluginLoader(
                "plugins", fileSystem, typeof(CliquePlugin), typeof(EthashPlugin), typeof(NethDevPlugin));

            pluginLoader.Load(SimpleConsoleLogManager.Instance);

            Type configurationType         = typeof(IConfig);
            IEnumerable <Type> configTypes = new TypeDiscovery().FindNethermindTypes(configurationType)
                                             .Where(ct => ct.IsInterface);

            CommandLineApplication app = new CommandLineApplication {
                Name = "Nethermind.Runner"
            };

            app.HelpOption("-?|-h|--help");
            app.VersionOption("-v|--version", () => ClientVersion.Version, () => ClientVersion.Description);

            GlobalDiagnosticsContext.Set("version", ClientVersion.Version);

            CommandOption dataDir            = app.Option("-dd|--datadir <dataDir>", "data directory", CommandOptionType.SingleValue);
            CommandOption configFile         = app.Option("-c|--config <configFile>", "config file path", CommandOptionType.SingleValue);
            CommandOption dbBasePath         = app.Option("-d|--baseDbPath <baseDbPath>", "base db path", CommandOptionType.SingleValue);
            CommandOption logLevelOverride   = app.Option("-l|--log <logLevel>", "log level", CommandOptionType.SingleValue);
            CommandOption configsDirectory   = app.Option("-cd|--configsDirectory <configsDirectory>", "configs directory", CommandOptionType.SingleValue);
            CommandOption loggerConfigSource = app.Option("-lcs|--loggerConfigSource <loggerConfigSource>", "path to the NLog config file", CommandOptionType.SingleValue);

            foreach (Type configType in configTypes.OrderBy(c => c.Name))
            {
                if (configType == null)
                {
                    continue;
                }

                ConfigCategoryAttribute?typeLevel = configType.GetCustomAttribute <ConfigCategoryAttribute>();
                if (typeLevel?.HiddenFromDocs ?? false)
                {
                    continue;
                }

                foreach (PropertyInfo propertyInfo in configType
                         .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                         .OrderBy(p => p.Name))
                {
                    ConfigItemAttribute?configItemAttribute = propertyInfo.GetCustomAttribute <ConfigItemAttribute>();
                    if (!(configItemAttribute?.HiddenFromDocs ?? false))
                    {
                        app.Option($"--{configType.Name.Substring(1).Replace("Config", String.Empty)}.{propertyInfo.Name}", $"{(configItemAttribute == null ? "<missing documentation>" : configItemAttribute.Description + $" (DEFAULT: {configItemAttribute.DefaultValue})" ?? "<missing documentation>")}", CommandOptionType.SingleValue);
                    }
                }
            }

            ManualResetEventSlim appClosed = new ManualResetEventSlim(true);

            app.OnExecute(async() =>
            {
                appClosed.Reset();
                IConfigProvider configProvider = BuildConfigProvider(app, loggerConfigSource, logLevelOverride, configsDirectory, configFile);
                IInitConfig initConfig         = configProvider.GetConfig <IInitConfig>();
                IKeyStoreConfig keyStoreConfig = configProvider.GetConfig <IKeyStoreConfig>();

                Console.Title           = initConfig.LogFileName;
                Console.CancelKeyPress += ConsoleOnCancelKeyPress;

                SetFinalDataDirectory(dataDir.HasValue() ? dataDir.Value() : null, initConfig, keyStoreConfig);
                NLogManager logManager = new(initConfig.LogFileName, initConfig.LogDirectory);

                _logger = logManager.GetClassLogger();
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Nethermind version: {ClientVersion.Description}");
                }

                ConfigureSeqLogger(configProvider);
                SetFinalDbPath(dbBasePath.HasValue() ? dbBasePath.Value() : null, initConfig);
                LogMemoryConfiguration();

                EthereumJsonSerializer serializer = new();
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Nethermind config:{Environment.NewLine}{serializer.Serialize(initConfig, true)}{Environment.NewLine}");
                }

                ApiBuilder apiBuilder        = new(configProvider, logManager);
                INethermindApi nethermindApi = apiBuilder.Create();
                foreach (Type pluginType in pluginLoader.PluginTypes)
                {
                    if (Activator.CreateInstance(pluginType) is INethermindPlugin plugin)
                    {
                        nethermindApi.Plugins.Add(plugin);
                    }
                }

                EthereumRunner ethereumRunner = new EthereumRunner(nethermindApi);
                await ethereumRunner.Start(_processCloseCancellationSource.Token).ContinueWith(x =>
                {
                    if (x.IsFaulted && _logger.IsError)
                    {
                        _logger.Error("Error during ethereum runner start", x.Exception);
                    }
                });

                await Task.WhenAny(_cancelKeySource.Task, _processExit.Task);

                _logger.Info("Closing, please wait until all functions are stopped properly...");
                await ethereumRunner.StopAsync();
                _logger.Info("All done, goodbye!");
                appClosed.Set();

                return(0);
            });

            app.Execute(args);
            appClosed.Wait();
        }
Ejemplo n.º 4
0
 public void SmokeTest()
 {
     EthereumRunner runner = new EthereumRunner(new RpcModuleProvider(new JsonRpcConfig()), new JsonConfigProvider(), NullLogManager.Instance);
 }
Ejemplo n.º 5
0
        private static async Task SmokeTest(ConfigProvider configProvider, int testIndex, int basePort, bool cancel = false)
        {
            Type type1 = typeof(ITxPoolConfig);
            Type type2 = typeof(INetworkConfig);
            Type type3 = typeof(IKeyStoreConfig);
            Type type4 = typeof(IDbConfig);
            Type type6 = typeof(IKafkaConfig);
            Type type7 = typeof(IEthStatsConfig);
            Type type8 = typeof(ISyncConfig);
            Type type9 = typeof(IBloomConfig);

            Console.WriteLine(type1.Name);
            Console.WriteLine(type2.Name);
            Console.WriteLine(type3.Name);
            Console.WriteLine(type4.Name);
            Console.WriteLine(type6.Name);
            Console.WriteLine(type7.Name);
            Console.WriteLine(type8.Name);
            Console.WriteLine(type9.Name);

            var tempPath = TempPath.GetTempDirectory();

            Directory.CreateDirectory(tempPath.Path);

            Exception exception = null;

            try
            {
                IInitConfig initConfig = configProvider.GetConfig <IInitConfig>();
                initConfig.BaseDbPath    = tempPath.Path;
                initConfig.ChainSpecPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, initConfig.ChainSpecPath);

                INetworkConfig networkConfig = configProvider.GetConfig <INetworkConfig>();
                int            port          = basePort + testIndex;
                networkConfig.P2PPort       = port;
                networkConfig.DiscoveryPort = port;

                INethermindApi nethermindApi = new ApiBuilder(configProvider, TestLogManager.Instance).Create();
                nethermindApi.RpcModuleProvider = new RpcModuleProvider(new FileSystem(), new JsonRpcConfig(), TestLogManager.Instance);
                EthereumRunner runner = new EthereumRunner(nethermindApi);

                using CancellationTokenSource cts = new CancellationTokenSource();

                try
                {
                    Task task = runner.Start(cts.Token);
                    if (cancel)
                    {
                        cts.Cancel();
                    }

                    await task;
                }
                catch (Exception e)
                {
                    exception = e;
                }
                finally
                {
                    try
                    {
                        await runner.StopAsync();
                    }
                    catch (Exception e)
                    {
                        if (exception != null)
                        {
                            await TestContext.Error.WriteLineAsync(e.ToString());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
            finally
            {
                try
                {
                    tempPath.Dispose();
                }
                catch (Exception e)
                {
                    if (exception != null)
                    {
                        await TestContext.Error.WriteLineAsync(e.ToString());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }