Exemple #1
0
        private void RegisterJsonRpcModules()
        {
            IJsonRpcConfig jsonRpcConfig = _configProvider.GetConfig <IJsonRpcConfig>();

            if (!jsonRpcConfig.Enabled)
            {
                return;
            }

            // the following line needs to be called in order to make sure that the CLI library is referenced from runner and built alongside
            if (_logger.IsDebug)
            {
                _logger.Debug($"Resolving CLI ({nameof(Cli.CliModuleLoader)})");
            }

            EthModuleFactory ethModuleFactory = new EthModuleFactory(_dbProvider, _txPool, _wallet, _blockTree, _ethereumEcdsa, _blockProcessor, _receiptStorage, _specProvider, _logManager);

            _rpcModuleProvider.Register(new BoundedModulePool <IEthModule>(8, ethModuleFactory));

            DebugModuleFactory debugModuleFactory = new DebugModuleFactory(_dbProvider, _blockTree, _blockValidator, _recoveryStep, _rewardCalculator, _receiptStorage, _configProvider, _specProvider, _logManager);

            _rpcModuleProvider.Register(new BoundedModulePool <IDebugModule>(8, debugModuleFactory));

            TraceModuleFactory traceModuleFactory = new TraceModuleFactory(_dbProvider, _txPool, _blockTree, _blockValidator, _ethereumEcdsa, _recoveryStep, _rewardCalculator, _receiptStorage, _specProvider, _logManager);

            _rpcModuleProvider.Register(new BoundedModulePool <ITraceModule>(8, traceModuleFactory));

            if (_sealValidator is CliqueSealValidator)
            {
                CliqueModule cliqueModule = new CliqueModule(_logManager, new CliqueBridge(_blockProducer as ICliqueBlockProducer, _snapshotManager, _blockTree));
                _rpcModuleProvider.Register(new SingletonModulePool <ICliqueModule>(cliqueModule));
            }

            if (_initConfig.EnableUnsecuredDevWallet)
            {
                PersonalBridge personalBridge = new PersonalBridge(_ethereumEcdsa, _wallet);
                PersonalModule personalModule = new PersonalModule(personalBridge, _logManager);
                _rpcModuleProvider.Register(new SingletonModulePool <IPersonalModule>(personalModule));
            }

            AdminModule adminModule = new AdminModule(_logManager, _peerManager, _staticNodesManager);

            _rpcModuleProvider.Register(new SingletonModulePool <IAdminModule>(adminModule));

            TxPoolModule txPoolModule = new TxPoolModule(_logManager, _txPoolInfoProvider);

            _rpcModuleProvider.Register(new SingletonModulePool <ITxPoolModule>(txPoolModule));

            NetModule netModule = new NetModule(_logManager, new NetBridge(_enode, _syncServer, _peerManager));

            _rpcModuleProvider.Register(new SingletonModulePool <INetModule>(netModule));

            ParityModule parityModule = new ParityModule(_ethereumEcdsa, _txPool, _logManager);

            _rpcModuleProvider.Register(new SingletonModulePool <IParityModule>(parityModule));
        }
Exemple #2
0
 public static void RegisterSingle <T>(
     this IRpcModuleProvider rpcModuleProvider,
     T module,
     bool allowExclusive = true)
     where T : IRpcModule
 {
     rpcModuleProvider.Register(new SingletonModulePool <T>(module, allowExclusive));
 }
Exemple #3
0
 public static void RegisterBounded <T>(
     this IRpcModuleProvider rpcModuleProvider,
     ModuleFactoryBase <T> factory,
     int maxCount,
     int timeout)
     where T : IRpcModule
 {
     rpcModuleProvider.Register(new BoundedModulePool <T>(factory, maxCount, timeout));
 }
Exemple #4
0
        protected async Task StartRunners(IConfigProvider configProvider)
        {
            var initParams = configProvider.GetConfig <IInitConfig>();
            var logManager = new NLogManager(initParams.LogFileName, initParams.LogDirectory);
            IRpcModuleProvider rpcModuleProvider = initParams.JsonRpcEnabled
                ? new RpcModuleProvider(configProvider.GetConfig <IJsonRpcConfig>())
                : (IRpcModuleProvider)NullModuleProvider.Instance;

            _ethereumRunner = new EthereumRunner(rpcModuleProvider, configProvider, logManager);
            await _ethereumRunner.Start().ContinueWith(x =>
            {
                if (x.IsFaulted && Logger.IsError)
                {
                    Logger.Error("Error during ethereum runner start", x.Exception);
                }
            });

            if (initParams.JsonRpcEnabled)
            {
                var serializer = new UnforgivingJsonSerializer();
                rpcModuleProvider.Register <IShhModule>(new ShhModule(configProvider, logManager, serializer));
                rpcModuleProvider.Register <IWeb3Module>(new Web3Module(configProvider, logManager, serializer));

                Bootstrap.Instance.JsonRpcService = new JsonRpcService(rpcModuleProvider, configProvider, logManager);
                Bootstrap.Instance.LogManager     = logManager;
                Bootstrap.Instance.JsonSerializer = serializer;
                _jsonRpcRunner = new JsonRpcRunner(configProvider, rpcModuleProvider, logManager);
                await _jsonRpcRunner.Start().ContinueWith(x =>
                {
                    if (x.IsFaulted && Logger.IsError)
                    {
                        Logger.Error("Error during jsonRpc runner start", x.Exception);
                    }
                });
            }
            else
            {
                if (Logger.IsInfo)
                {
                    Logger.Info("Json RPC is disabled");
                }
            }
        }
Exemple #5
0
        protected async Task StartRunners(IConfigProvider configProvider)
        {
            IInitConfig        initConfig        = configProvider.GetConfig <IInitConfig>();
            IJsonRpcConfig     jsonRpcConfig     = configProvider.GetConfig <IJsonRpcConfig>();
            var                metricsParams     = configProvider.GetConfig <IMetricsConfig>();
            var                logManager        = new NLogManager(initConfig.LogFileName, initConfig.LogDirectory);
            IRpcModuleProvider rpcModuleProvider = jsonRpcConfig.Enabled
                ? new RpcModuleProvider(configProvider.GetConfig <IJsonRpcConfig>(), logManager)
                : (IRpcModuleProvider)NullModuleProvider.Instance;
            var jsonSerializer    = new EthereumJsonSerializer();
            var webSocketsManager = new WebSocketsManager();

            INdmDataPublisher          ndmDataPublisher          = null;
            INdmConsumerChannelManager ndmConsumerChannelManager = null;
            INdmInitializer            ndmInitializer            = null;
            var ndmConfig  = configProvider.GetConfig <INdmConfig>();
            var ndmEnabled = ndmConfig.Enabled;

            if (ndmEnabled)
            {
                ndmDataPublisher          = new NdmDataPublisher();
                ndmConsumerChannelManager = new NdmConsumerChannelManager();
                var initializerName = ndmConfig.InitializerName;
                if (Logger.IsInfo)
                {
                    Logger.Info($"NDM initializer: {initializerName}");
                }
                var ndmInitializerType = AppDomain.CurrentDomain.GetAssemblies()
                                         .SelectMany(a => a.GetTypes())
                                         .FirstOrDefault(t =>
                                                         t.GetCustomAttribute <NdmInitializerAttribute>()?.Name == initializerName);
                var ndmModule          = new NdmModule();
                var ndmConsumersModule = new NdmConsumersModule();
                ndmInitializer = new NdmInitializerFactory(ndmInitializerType, ndmModule, ndmConsumersModule,
                                                           logManager).CreateOrFail();
            }

            var        grpcConfig = configProvider.GetConfig <IGrpcConfig>();
            GrpcServer grpcServer = null;

            if (grpcConfig.Enabled)
            {
                grpcServer = new GrpcServer(jsonSerializer, logManager);
                if (ndmEnabled)
                {
                    ndmConsumerChannelManager.Add(new GrpcNdmConsumerChannel(grpcServer));
                }

                _grpcRunner = new GrpcRunner(grpcServer, grpcConfig, logManager);
                await _grpcRunner.Start().ContinueWith(x =>
                {
                    if (x.IsFaulted && Logger.IsError)
                    {
                        Logger.Error("Error during GRPC runner start", x.Exception);
                    }
                });
            }

            if (initConfig.WebSocketsEnabled)
            {
                if (ndmEnabled)
                {
                    webSocketsManager.AddModule(new NdmWebSocketsModule(ndmConsumerChannelManager, ndmDataPublisher,
                                                                        jsonSerializer));
                }
            }

            _ethereumRunner = new EthereumRunner(rpcModuleProvider, configProvider, logManager, grpcServer,
                                                 ndmConsumerChannelManager, ndmDataPublisher, ndmInitializer, webSocketsManager, jsonSerializer);
            await _ethereumRunner.Start().ContinueWith(x =>
            {
                if (x.IsFaulted && Logger.IsError)
                {
                    Logger.Error("Error during ethereum runner start", x.Exception);
                }
            });

            if (jsonRpcConfig.Enabled)
            {
                rpcModuleProvider.Register(new SingletonModulePool <IWeb3Module>(new Web3Module(logManager)));
                var jsonRpcService   = new JsonRpcService(rpcModuleProvider, logManager);
                var jsonRpcProcessor = new JsonRpcProcessor(jsonRpcService, jsonSerializer, logManager);
                if (initConfig.WebSocketsEnabled)
                {
                    webSocketsManager.AddModule(new JsonRpcWebSocketsModule(jsonRpcProcessor, jsonSerializer));
                }

                Bootstrap.Instance.JsonRpcService = jsonRpcService;
                Bootstrap.Instance.LogManager     = logManager;
                Bootstrap.Instance.JsonSerializer = jsonSerializer;
                _jsonRpcRunner = new JsonRpcRunner(configProvider, rpcModuleProvider, logManager, jsonRpcProcessor,
                                                   webSocketsManager);
                await _jsonRpcRunner.Start().ContinueWith(x =>
                {
                    if (x.IsFaulted && Logger.IsError)
                    {
                        Logger.Error("Error during jsonRpc runner start", x.Exception);
                    }
                });
            }
            else
            {
                if (Logger.IsInfo)
                {
                    Logger.Info("Json RPC is disabled");
                }
            }

            if (metricsParams.Enabled)
            {
                var intervalSeconds = metricsParams.IntervalSeconds;
                _monitoringService = new MonitoringService(new MetricsUpdater(intervalSeconds),
                                                           metricsParams.PushGatewayUrl, ClientVersion.Description,
                                                           metricsParams.NodeName, intervalSeconds, logManager);
                await _monitoringService.StartAsync().ContinueWith(x =>
                {
                    if (x.IsFaulted && Logger.IsError)
                    {
                        Logger.Error("Error during starting a monitoring.", x.Exception);
                    }
                });
            }
            else
            {
                if (Logger.IsInfo)
                {
                    Logger.Info("Monitoring is disabled");
                }
            }
        }
Exemple #6
0
        protected async Task StartRunners(IConfigProvider configProvider)
        {
            IInitConfig        initConfig        = configProvider.GetConfig <IInitConfig>();
            IJsonRpcConfig     jsonRpcConfig     = configProvider.GetConfig <IJsonRpcConfig>();
            IMetricsConfig     metricsConfig     = configProvider.GetConfig <IMetricsConfig>();
            NLogManager        logManager        = new NLogManager(initConfig.LogFileName, initConfig.LogDirectory);
            IRpcModuleProvider rpcModuleProvider = jsonRpcConfig.Enabled
                ? new RpcModuleProvider(configProvider.GetConfig <IJsonRpcConfig>(), logManager)
                : (IRpcModuleProvider)NullModuleProvider.Instance;
            EthereumJsonSerializer jsonSerializer    = new EthereumJsonSerializer();
            WebSocketsManager      webSocketsManager = new WebSocketsManager();

            if (!string.IsNullOrEmpty(metricsConfig.NodeName))
            {
                logManager.SetGlobalVariable("nodeName", metricsConfig.NodeName);
            }

            if (metricsConfig.Enabled)
            {
                Metrics.Version = VersionToMetrics.ConvertToNumber(ClientVersion.Version);
                MetricsUpdater metricsUpdater = new MetricsUpdater(metricsConfig);
                _monitoringService = new MonitoringService(metricsUpdater, metricsConfig, logManager);
                _monitoringService.RegisterMetrics(typeof(Nethermind.Blockchain.Metrics));
                _monitoringService.RegisterMetrics(typeof(Nethermind.Db.Metrics));
                _monitoringService.RegisterMetrics(typeof(Nethermind.Evm.Metrics));
                _monitoringService.RegisterMetrics(typeof(Nethermind.JsonRpc.Metrics));
                _monitoringService.RegisterMetrics(typeof(Nethermind.Trie.Metrics));
                _monitoringService.RegisterMetrics(typeof(Nethermind.Network.Metrics));
                _monitoringService.RegisterMetrics(typeof(Nethermind.Synchronization.Metrics));
                _monitoringService.RegisterMetrics(typeof(Nethermind.TxPool.Metrics));
                _monitoringService.RegisterMetrics(typeof(Metrics));

                await _monitoringService.StartAsync().ContinueWith(x =>
                {
                    if (x.IsFaulted && (_logger?.IsError ?? false))
                    {
                        _logger !.Error("Error during starting a monitoring.", x.Exception);
                    }
                });
            }
            else
            {
                if (_logger?.IsInfo ?? false)
                {
                    _logger !.Info("Grafana / Prometheus metrics are disabled in configuration");
                }
            }

            IGrpcConfig grpcConfig = configProvider.GetConfig <IGrpcConfig>();
            GrpcServer? grpcServer = null;

            if (grpcConfig.Enabled)
            {
                grpcServer  = new GrpcServer(jsonSerializer, logManager);
                _grpcRunner = new GrpcRunner(grpcServer, grpcConfig, logManager);
                await _grpcRunner.Start().ContinueWith(x =>
                {
                    if (x.IsFaulted && (_logger?.IsError ?? false))
                    {
                        _logger !.Error("Error during GRPC runner start", x.Exception);
                    }
                });
            }

            INdmDataPublisher?         ndmDataPublisher          = null;
            INdmConsumerChannelManager?ndmConsumerChannelManager = null;
            INdmInitializer?           ndmInitializer            = null;
            INdmConfig ndmConfig  = configProvider.GetConfig <INdmConfig>();
            bool       ndmEnabled = ndmConfig.Enabled;

            if (ndmEnabled)
            {
                ndmDataPublisher          = new NdmDataPublisher();
                ndmConsumerChannelManager = new NdmConsumerChannelManager();
                string initializerName = ndmConfig.InitializerName;
                if (_logger?.IsInfo ?? false)
                {
                    _logger !.Info($"NDM initializer: {initializerName}");
                }
                Type ndmInitializerType = AppDomain.CurrentDomain.GetAssemblies()
                                          .SelectMany(a => a.GetTypes())
                                          .FirstOrDefault(t =>
                                                          t.GetCustomAttribute <NdmInitializerAttribute>()?.Name == initializerName);
                NdmModule          ndmModule          = new NdmModule();
                NdmConsumersModule ndmConsumersModule = new NdmConsumersModule();
                ndmInitializer = new NdmInitializerFactory(ndmInitializerType, ndmModule, ndmConsumersModule, logManager).CreateOrFail();

                if (grpcServer != null)
                {
                    ndmConsumerChannelManager.Add(new GrpcNdmConsumerChannel(grpcServer));
                }

                webSocketsManager.AddModule(new NdmWebSocketsModule(ndmConsumerChannelManager, ndmDataPublisher, jsonSerializer));
            }

            _ethereumRunner = new EthereumRunner(
                rpcModuleProvider,
                configProvider,
                logManager,
                grpcServer,
                ndmConsumerChannelManager,
                ndmDataPublisher,
                ndmInitializer,
                webSocketsManager,
                jsonSerializer,
                _monitoringService);

            await _ethereumRunner.Start().ContinueWith(x =>
            {
                if (x.IsFaulted && (_logger?.IsError ?? false))
                {
                    _logger !.Error("Error during ethereum runner start", x.Exception);
                }
            });

            if (jsonRpcConfig.Enabled)
            {
                rpcModuleProvider.Register(new SingletonModulePool <IWeb3Module>(new Web3Module(logManager), true));
                JsonRpcService   jsonRpcService   = new JsonRpcService(rpcModuleProvider, logManager);
                JsonRpcProcessor jsonRpcProcessor = new JsonRpcProcessor(jsonRpcService, jsonSerializer, jsonRpcConfig, new FileSystem(), logManager);
                if (initConfig.WebSocketsEnabled)
                {
                    webSocketsManager.AddModule(new JsonRpcWebSocketsModule(jsonRpcProcessor, jsonSerializer), true);
                }

                Bootstrap.Instance.JsonRpcService = jsonRpcService;
                Bootstrap.Instance.LogManager     = logManager;
                Bootstrap.Instance.JsonSerializer = jsonSerializer;
                _jsonRpcRunner = new JsonRpcRunner(configProvider, rpcModuleProvider, logManager, jsonRpcProcessor, webSocketsManager);
                await _jsonRpcRunner.Start().ContinueWith(x =>
                {
                    if (x.IsFaulted && (_logger?.IsError ?? false))
                    {
                        _logger !.Error("Error during jsonRpc runner start", x.Exception);
                    }
                });
            }
            else
            {
                if (_logger?.IsInfo ?? false)
                {
                    _logger !.Info("Json RPC is disabled");
                }
            }
        }
Exemple #7
0
        private void RegisterJsonRpcModules()
        {
            if (!_initConfig.JsonRpcEnabled)
            {
                return;
            }

            if (_logger.IsDebug)
            {
                _logger.Debug($"Resolving CLI ({nameof(Cli.CliModuleLoader)})");
            }

            IReadOnlyDbProvider rpcDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            AlternativeChain    rpcChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, _transactionPool, _receiptStorage);

            ITracer        tracer        = new Tracer(rpcChain.Processor, _receiptStorage, _blockTree, _dbProvider.TraceDb);
            IFilterStore   filterStore   = new FilterStore();
            IFilterManager filterManager = new FilterManager(filterStore, _blockProcessor, _transactionPool, _logManager);

            RpcState rpcState = new RpcState(_blockTree, _specProvider, rpcDbProvider, _logManager);

            //creating blockchain bridge
            var blockchainBridge = new BlockchainBridge(
                rpcState.StateReader,
                rpcState.StateProvider,
                rpcState.StorageProvider,
                rpcState.BlockTree,
                _transactionPool,
                _transactionPoolInfoProvider,
                _receiptStorage,
                filterStore,
                filterManager,
                _wallet,
                rpcState.TransactionProcessor);

            TransactionPool debugTransactionPool = new TransactionPool(new PersistentTransactionStorage(_dbProvider.PendingTxsDb, _specProvider),
                                                                       new PendingTransactionThresholdValidator(_initConfig.ObsoletePendingTransactionInterval, _initConfig.RemovePendingTransactionInterval),
                                                                       _timestamp,
                                                                       _ethereumEcdsa,
                                                                       _specProvider,
                                                                       _logManager,
                                                                       _initConfig.RemovePendingTransactionInterval,
                                                                       _initConfig.PeerNotificationThreshold);

            var debugReceiptStorage             = new PersistentReceiptStorage(_dbProvider.ReceiptsDb, _specProvider);
            AlternativeChain    debugChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, debugTransactionPool, debugReceiptStorage);
            IReadOnlyDbProvider debugDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            var debugBridge = new DebugBridge(_configProvider, debugDbProvider, tracer, debugChain.Processor);

            EthModule module = new EthModule(_jsonSerializer, _configProvider, _logManager, blockchainBridge);

            _rpcModuleProvider.Register <IEthModule>(module);

            DebugModule debugModule = new DebugModule(_configProvider, _logManager, debugBridge, _jsonSerializer);

            _rpcModuleProvider.Register <IDebugModule>(debugModule);

            if (_sealer is CliqueSealer)
            {
                CliqueModule cliqueModule = new CliqueModule(_configProvider, _logManager, _jsonSerializer, new CliqueBridge(_blockProducer as ICliqueBlockProducer, _snapshotManager, _blockTree));
                _rpcModuleProvider.Register <ICliqueModule>(cliqueModule);
            }

            if (_initConfig.EnableUnsecuredDevWallet)
            {
                PersonalBridge personalBridge = new PersonalBridge(_wallet);
                PersonalModule personalModule = new PersonalModule(personalBridge, _configProvider, _logManager, _jsonSerializer);
                _rpcModuleProvider.Register <IPersonalModule>(personalModule);
            }

            AdminModule adminModule = new AdminModule(_configProvider, _logManager, _jsonSerializer);

            _rpcModuleProvider.Register <IAdminModule>(adminModule);

            TxPoolModule txPoolModule = new TxPoolModule(_configProvider, _logManager, _jsonSerializer, blockchainBridge);

            _rpcModuleProvider.Register <ITxPoolModule>(txPoolModule);

            if (_initConfig.NetworkEnabled && _initConfig.SynchronizationEnabled)
            {
                NetModule netModule = new NetModule(_configProvider, _logManager, _jsonSerializer, new NetBridge(_enode, _syncManager, _peerManager));
                _rpcModuleProvider.Register <INetModule>(netModule);
            }

            TraceModule traceModule = new TraceModule(_configProvider, _logManager, _jsonSerializer, tracer);

            _rpcModuleProvider.Register <ITraceModule>(traceModule);
        }
        private void RegisterJsonRpcModules()
        {
            if (!_initConfig.JsonRpcEnabled)
            {
                return;
            }

            if (_logger.IsDebug)
            {
                _logger.Debug($"Resolving CLI ({nameof(Cli.CliModuleLoader)})");
            }

            IReadOnlyDbProvider rpcDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            AlternativeChain    rpcChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, _txPool, _receiptStorage);

            ITracer        tracer        = new Tracer(rpcChain.Processor, _receiptStorage, new ReadOnlyBlockTree(_blockTree), _dbProvider.TraceDb);
            IFilterStore   filterStore   = new FilterStore();
            IFilterManager filterManager = new FilterManager(filterStore, _blockProcessor, _txPool, _logManager);

            RpcState rpcState = new RpcState(_blockTree, _specProvider, rpcDbProvider, _logManager);

            //creating blockchain bridge
            var blockchainBridge = new BlockchainBridge(
                rpcState.StateReader,
                rpcState.StateProvider,
                rpcState.StorageProvider,
                rpcState.BlockTree,
                _txPool,
                _transactionPoolInfoProvider,
                _receiptStorage,
                filterStore,
                filterManager,
                _wallet,
                rpcState.TransactionProcessor,
                _ethereumEcdsa);

            AlternativeChain    debugChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, NullTxPool.Instance, NullReceiptStorage.Instance);
            IReadOnlyDbProvider debugDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            var debugBridge = new DebugBridge(_configProvider, debugDbProvider, tracer, debugChain.Processor);

            EthModule module = new EthModule(_logManager, blockchainBridge);

            _rpcModuleProvider.Register <IEthModule>(module);

            DebugModule debugModule = new DebugModule(_logManager, debugBridge);

            _rpcModuleProvider.Register <IDebugModule>(debugModule);

            if (_sealValidator is CliqueSealValidator)
            {
                CliqueModule cliqueModule = new CliqueModule(_logManager, new CliqueBridge(_blockProducer as ICliqueBlockProducer, _snapshotManager, _blockTree));
                _rpcModuleProvider.Register <ICliqueModule>(cliqueModule);
            }

            if (_initConfig.EnableUnsecuredDevWallet)
            {
                PersonalBridge personalBridge = new PersonalBridge(_ethereumEcdsa, _wallet);
                PersonalModule personalModule = new PersonalModule(personalBridge, _logManager);
                _rpcModuleProvider.Register <IPersonalModule>(personalModule);
            }

            AdminModule adminModule = new AdminModule(_logManager, _peerManager, _staticNodesManager);

            _rpcModuleProvider.Register <IAdminModule>(adminModule);

            TxPoolModule txPoolModule = new TxPoolModule(_logManager, blockchainBridge);

            _rpcModuleProvider.Register <ITxPoolModule>(txPoolModule);

            NetModule netModule = new NetModule(_logManager, new NetBridge(_enode, _syncServer, _peerManager));

            _rpcModuleProvider.Register <INetModule>(netModule);

            TraceModule traceModule = new TraceModule(blockchainBridge, _logManager, tracer);

            _rpcModuleProvider.Register <ITraceModule>(traceModule);
        }
        protected async Task StartRunners(IConfigProvider configProvider)
        {
            var initParams    = configProvider.GetConfig <IInitConfig>();
            var metricsParams = configProvider.GetConfig <IMetricsConfig>();
            var logManager    = new NLogManager(initParams.LogFileName, initParams.LogDirectory);
            IRpcModuleProvider rpcModuleProvider = initParams.JsonRpcEnabled
                ? new RpcModuleProvider(configProvider.GetConfig <IJsonRpcConfig>())
                : (IRpcModuleProvider)NullModuleProvider.Instance;
            var webSocketsManager = new WebSocketsManager();

            _ethereumRunner = new EthereumRunner(rpcModuleProvider, configProvider, logManager);
            await _ethereumRunner.Start().ContinueWith(x =>
            {
                if (x.IsFaulted && Logger.IsError)
                {
                    Logger.Error("Error during ethereum runner start", x.Exception);
                }
            });

            if (initParams.JsonRpcEnabled)
            {
                var serializer = new EthereumJsonSerializer();
                rpcModuleProvider.Register <IWeb3Module>(new Web3Module(logManager));
                var jsonRpcService   = new JsonRpcService(rpcModuleProvider, logManager);
                var jsonRpcProcessor = new JsonRpcProcessor(jsonRpcService, serializer, logManager);
                webSocketsManager.AddModule(new JsonRpcWebSocketsModule(jsonRpcProcessor, serializer));
                Bootstrap.Instance.JsonRpcService = jsonRpcService;
                Bootstrap.Instance.LogManager     = logManager;
                Bootstrap.Instance.JsonSerializer = serializer;
                _jsonRpcRunner = new JsonRpcRunner(configProvider, rpcModuleProvider, logManager, jsonRpcProcessor,
                                                   webSocketsManager);
                await _jsonRpcRunner.Start().ContinueWith(x =>
                {
                    if (x.IsFaulted && Logger.IsError)
                    {
                        Logger.Error("Error during jsonRpc runner start", x.Exception);
                    }
                });
            }
            else
            {
                if (Logger.IsInfo)
                {
                    Logger.Info("Json RPC is disabled");
                }
            }

            if (metricsParams.MetricsEnabled)
            {
                var intervalSeconds = metricsParams.MetricsIntervalSeconds;
                _monitoringService = new MonitoringService(new MetricsUpdater(intervalSeconds),
                                                           metricsParams.MetricsPushGatewayUrl, ClientVersion.Description,
                                                           metricsParams.NodeName, intervalSeconds, logManager);
                await _monitoringService.StartAsync().ContinueWith(x =>
                {
                    if (x.IsFaulted && Logger.IsError)
                    {
                        Logger.Error("Error during starting a monitoring.", x.Exception);
                    }
                });
            }
            else
            {
                if (Logger.IsInfo)
                {
                    Logger.Info("Monitoring is disabled");
                }
            }
        }
Exemple #10
0
        protected async Task StartRunners(IConfigProvider configProvider)
        {
            var initParams    = configProvider.GetConfig <IInitConfig>();
            var metricsParams = configProvider.GetConfig <IMetricsConfig>();
            var logManager    = new NLogManager(initParams.LogFileName, initParams.LogDirectory);
            IRpcModuleProvider rpcModuleProvider = initParams.JsonRpcEnabled
                ? new RpcModuleProvider(configProvider.GetConfig <IJsonRpcConfig>())
                : (IRpcModuleProvider)NullModuleProvider.Instance;
            var webSocketsManager = new WebSocketsManager();

            INdmDataPublisher          ndmDataPublisher          = null;
            INdmConsumerChannelManager ndmConsumerChannelManager = null;
            INdmInitializer            ndmInitializer            = null;
            var ndmConfig  = configProvider.GetConfig <INdmConfig>();
            var ndmEnabled = ndmConfig.Enabled;

            if (ndmEnabled)
            {
                ndmDataPublisher          = new NdmDataPublisher();
                ndmConsumerChannelManager = new NdmConsumerChannelManager();
                ndmInitializer            = new NdmInitializerFactory(logManager)
                                            .CreateOrFail(ndmConfig.InitializerName, ndmConfig.PluginsPath);
            }

            var         grpcConfig  = configProvider.GetConfig <IGrpcConfig>();
            GrpcService grpcService = null;

            if (grpcConfig.Enabled)
            {
                grpcService = new GrpcService(logManager);
                if (ndmEnabled)
                {
                    ndmConsumerChannelManager.Add(new GrpcNdmConsumerChannel(grpcService));
                }

                _grpcRunner = new GrpcRunner(grpcService, grpcConfig, logManager);
                await _grpcRunner.Start().ContinueWith(x =>
                {
                    if (x.IsFaulted && Logger.IsError)
                    {
                        Logger.Error("Error during GRPC runner start", x.Exception);
                    }
                });
            }

            GrpcClient grpcClient       = null;
            var        grpcClientConfig = configProvider.GetConfig <IGrpcClientConfig>();

            if (grpcClientConfig.Enabled)
            {
                grpcClient        = new GrpcClient(grpcClientConfig, new EthereumJsonSerializer(), logManager);
                _grpcClientRunner = new GrpcClientRunner(grpcClient, grpcClientConfig, logManager);
                await Task.Factory.StartNew(() => _grpcClientRunner.Start().ContinueWith(x =>
                {
                    if (x.IsFaulted && Logger.IsError)
                    {
                        Logger.Error("Error during GRPC client runner start", x.Exception);
                    }
                }));
            }

            _ethereumRunner = new EthereumRunner(rpcModuleProvider, configProvider, logManager, grpcService, grpcClient,
                                                 ndmConsumerChannelManager, ndmDataPublisher, ndmInitializer);
            await _ethereumRunner.Start().ContinueWith(x =>
            {
                if (x.IsFaulted && Logger.IsError)
                {
                    Logger.Error("Error during ethereum runner start", x.Exception);
                }
            });

            if (initParams.JsonRpcEnabled)
            {
                var serializer = new EthereumJsonSerializer();
                rpcModuleProvider.Register <IWeb3Module>(new Web3Module(logManager));
                var jsonRpcService   = new JsonRpcService(rpcModuleProvider, logManager);
                var jsonRpcProcessor = new JsonRpcProcessor(jsonRpcService, serializer, logManager);
                webSocketsManager.AddModule(new JsonRpcWebSocketsModule(jsonRpcProcessor, serializer));
                if (ndmEnabled)
                {
                    webSocketsManager.AddModule(new NdmWebSocketsModule(ndmConsumerChannelManager, ndmDataPublisher));
                }

                Bootstrap.Instance.JsonRpcService = jsonRpcService;
                Bootstrap.Instance.LogManager     = logManager;
                Bootstrap.Instance.JsonSerializer = serializer;
                _jsonRpcRunner = new JsonRpcRunner(configProvider, rpcModuleProvider, logManager, jsonRpcProcessor,
                                                   webSocketsManager);
                await _jsonRpcRunner.Start().ContinueWith(x =>
                {
                    if (x.IsFaulted && Logger.IsError)
                    {
                        Logger.Error("Error during jsonRpc runner start", x.Exception);
                    }
                });
            }
            else
            {
                if (Logger.IsInfo)
                {
                    Logger.Info("Json RPC is disabled");
                }
            }

            if (metricsParams.MetricsEnabled)
            {
                var intervalSeconds = metricsParams.MetricsIntervalSeconds;
                _monitoringService = new MonitoringService(new MetricsUpdater(intervalSeconds),
                                                           metricsParams.MetricsPushGatewayUrl, ClientVersion.Description,
                                                           metricsParams.NodeName, intervalSeconds, logManager);
                await _monitoringService.StartAsync().ContinueWith(x =>
                {
                    if (x.IsFaulted && Logger.IsError)
                    {
                        Logger.Error("Error during starting a monitoring.", x.Exception);
                    }
                });
            }
            else
            {
                if (Logger.IsInfo)
                {
                    Logger.Info("Monitoring is disabled");
                }
            }
        }
        private void RegisterJsonRpcModules()
        {
            if (!_initConfig.JsonRpcEnabled)
            {
                return;
            }

            IReadOnlyDbProvider rpcDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            AlternativeChain    rpcChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, _transactionPool, _receiptStorage);

            ITracer        tracer        = new Tracer(rpcChain.Processor, _receiptStorage, _blockTree, _dbProvider.TraceDb);
            IFilterStore   filterStore   = new FilterStore();
            IFilterManager filterManager = new FilterManager(filterStore, _blockProcessor, _transactionPool, _logManager);

            _wallet = HiveEnabled ? (IWallet) new HiveWallet() : new DevWallet(_logManager);
            RpcState rpcState = new RpcState(_blockTree, _specProvider, rpcDbProvider, _logManager);

            //creating blockchain bridge
            var blockchainBridge = new BlockchainBridge(
                _ethereumSigner,
                rpcState.StateProvider,
                rpcState.BlockTree,
                _transactionPool,
                _transactionPoolInfoProvider,
                _receiptStorage,
                filterStore,
                filterManager,
                _wallet,
                rpcState.TransactionProcessor);

            TransactionPool debugTransactionPool = new TransactionPool(new PersistentTransactionStorage(_dbProvider.PendingTxsDb, _specProvider),
                                                                       new PendingTransactionThresholdValidator(_initConfig.ObsoletePendingTransactionInterval, _initConfig.RemovePendingTransactionInterval),
                                                                       _timestamp,
                                                                       _ethereumSigner,
                                                                       _logManager,
                                                                       _initConfig.RemovePendingTransactionInterval,
                                                                       _initConfig.PeerNotificationThreshold);

            var debugReceiptStorage             = new PersistentReceiptStorage(_dbProvider.ReceiptsDb, _specProvider);
            AlternativeChain    debugChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, debugTransactionPool, debugReceiptStorage);
            IReadOnlyDbProvider debugDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            var debugBridge = new DebugBridge(debugDbProvider, tracer, debugChain.Processor);

            JsonRpcModelMapper mapper = new JsonRpcModelMapper();

            EthModule module = new EthModule(_jsonSerializer, _configProvider, mapper, _logManager, blockchainBridge);

            _rpcModuleProvider.Register <IEthModule>(module);

            DebugModule debugModule = new DebugModule(_configProvider, _logManager, debugBridge, mapper, _jsonSerializer);

            _rpcModuleProvider.Register <IDebugModule>(debugModule);

            if (_sealEngine is CliqueSealEngine)
            {
                CliqueModule cliqueModule = new CliqueModule(_configProvider, _logManager, _jsonSerializer, new CliqueBridge(_blockProducer as CliqueBlockProducer, _blockTree));
                _rpcModuleProvider.Register <ICliqueModule>(cliqueModule);
            }

            AdminModule adminModule = new AdminModule(_configProvider, _logManager, _jsonSerializer);

            _rpcModuleProvider.Register <IAdminModule>(adminModule);

            TxPoolModule txPoolModule = new TxPoolModule(_configProvider, _logManager, _jsonSerializer, blockchainBridge, mapper);

            _rpcModuleProvider.Register <ITxPoolModule>(txPoolModule);

            if (_initConfig.NetworkEnabled && _initConfig.SynchronizationEnabled)
            {
                NetModule netModule = new NetModule(_configProvider, _logManager, _jsonSerializer, new NetBridge(_syncManager));
                _rpcModuleProvider.Register <INetModule>(netModule);
            }

            TraceModule traceModule = new TraceModule(_configProvider, _logManager, _jsonSerializer, tracer);

            _rpcModuleProvider.Register <ITraceModule>(traceModule);

            _rpcModuleProvider.Register <INethmModule>(new NethmModule(_configProvider, _logManager, _jsonSerializer, _enode));
        }