public static IJsonRpcService BuildRpcService <T>(T module) where T : class, IModule { var moduleProvider = new TestRpcModuleProvider <T>(module); moduleProvider.Register <T>(module); IJsonRpcService service = new JsonRpcService(moduleProvider, NullLogManager.Instance); return(service); }
public static IJsonRpcService BuildRpcService <T>(T module, IReadOnlyCollection <JsonConverter>?converters = null) where T : class, IRpcModule { var moduleProvider = new TestRpcModuleProvider <T>(module); moduleProvider.Register(new SingletonModulePool <T>(new TestSingletonFactory <T>(module, converters), true)); IJsonRpcService service = new JsonRpcService(moduleProvider, LimboLogs.Instance); return(service); }
public static IJsonRpcService BuildRpcService <T>(T module) where T : class, IModule { var moduleProvider = new TestRpcModuleProvider <T>(module); moduleProvider.Register(new SingletonModulePool <T>(new SingletonFactory <T>(module), true)); IJsonRpcService service = new JsonRpcService(moduleProvider, LimboLogs.Instance); return(service); }
public static IJsonRpcService BuildRpcService <T>(T module) where T : class, IModule { var moduleProvider = new TestRpcModuleProvider <T>(module); moduleProvider.Register <T>(module); Newtonsoft.Json.JsonSerializer rpcSerializer = new Newtonsoft.Json.JsonSerializer(); IJsonRpcService service = new JsonRpcService(moduleProvider, Substitute.For <IConfigProvider>(), NullLogManager.Instance); return(service); }
/// <summary> /// Dispatch request to different services. /// </summary> /// <param name="service">The service to handle the context</param> /// <param name="context">The context for communication</param> /// <returns>Void</returns> public virtual async Task DispatchCall(JsonRpcService service, object context) { if (context is HttpListenerContext httpListenerContext) { await DispatchCall(service, httpListenerContext); } else { throw new InvalidOperationException("The context is not a HttpListenerContext"); } }
public JsonRpcWebSocketsModule( JsonRpcProcessor jsonRpcProcessor, JsonRpcService jsonRpcService, IJsonSerializer jsonSerializer, IJsonRpcLocalStats jsonRpcLocalStats) { _jsonRpcProcessor = jsonRpcProcessor; _jsonRpcService = jsonRpcService; _jsonSerializer = jsonSerializer; _jsonRpcLocalStats = jsonRpcLocalStats; }
/// <summary> /// Dispatch request to different services. /// </summary> /// <param name="service">The service to handle the context</param> /// <param name="context">The context for communication</param> /// <returns>Void</returns> public override async Task DispatchCall(JsonRpcService service, object context) { if (context is WebSocketContext webSocketContext) { await DispatchCall(service, webSocketContext); } else { throw new InvalidOperationException("The context is not a WebSocketContext"); } }
public JsonRpcWebSocketsClient(IWebSocketsClient client, JsonRpcProcessor jsonRpcProcessor, JsonRpcService jsonRpcService, IJsonSerializer jsonSerializer, IJsonRpcLocalStats jsonRpcLocalStats) { _client = client; _jsonRpcProcessor = jsonRpcProcessor; _jsonRpcService = jsonRpcService; _jsonSerializer = jsonSerializer; _jsonRpcLocalStats = jsonRpcLocalStats; }
public JsonRpcWebSocketsClient(IWebSocketsClient client, JsonRpcProcessor jsonRpcProcessor, JsonRpcService jsonRpcService, IJsonSerializer jsonSerializer, IJsonRpcLocalStats jsonRpcLocalStats) { _client = client; _jsonRpcProcessor = jsonRpcProcessor; _jsonRpcService = jsonRpcService; _jsonSerializer = jsonSerializer; _jsonRpcLocalStats = jsonRpcLocalStats; _jsonRpcContext = new JsonRpcContext(RpcEndpoint.WebSocket, this); }
private static JsonSerializer BuildSerializer <T>() { TraceModule module = new TraceModule(Substitute.For <IConfigProvider>(), NullLogManager.Instance, Substitute.For <IJsonSerializer>(), Substitute.For <ITracer>()); JsonSerializer serializer = new JsonSerializer(); IReadOnlyCollection <JsonConverter> converters = module.GetConverters(); foreach (JsonConverter converter in converters) { serializer.Converters.Add(converter); } foreach (JsonConverter converter in JsonRpcService.GetStandardConverters()) { serializer.Converters.Add(converter); } return(serializer); }
public TLCFIClientSessionJsonRpcHandler( TLCFIClientStateManager stateManager, TLCProxy tlcProxy, TLCFIClientSessionState sessionState, TwoWayTcpClient tcpClient, CancellationToken token) { _stateManager = stateManager; _tlcProxy = tlcProxy; _sessionCancellationToken = token; tcpClient.DataReceived += async(o, e) => { if (!_jsonRpcMethodRegex.IsMatch(e)) { return; } var result = _service?.HandleRpc(e); if (result != null) { await tcpClient.SendDataAsync(result, token); } }; _service = JsonRpcProcedureBinder.Default.GetInstanceService(this); }
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"); } } }
internal JsonRpcCallRequestReqRes(JsonRpcService client, string method, TReq parameters) : base(client, method, parameters) { }
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"); } } }
/// <summary> /// Dispatch request to different services. /// </summary> /// <param name="service">The service to handle the context</param> /// <param name="context">The http context</param> /// <returns>Void</returns> private async Task DispatchCall(JsonRpcService service, HttpListenerContext context) { var httpMethod = context.Request.HttpMethod.ToLower(); if (httpMethod != "post") { throw new ServerErrorException("Invalid http-method.", $"Invalid http-method:{httpMethod}"); } Logger.WriteVerbose($"Handle request [{httpMethod}]: {context.Request.Url}"); var requestData = ArrayPool <byte> .Shared.Rent((int)context.Request.ContentLength64); JsonRpcRequest[] requests; try { await ReadRequestDataAsync(context.Request.InputStream, requestData).ConfigureAwait(false); context.Request.InputStream.Close(); if (Logger.DebugMode) { var requestString = Encoding.UTF8.GetString(requestData); Logger.WriteDebug($"Receive request data:{requestString}"); } requests = await JsonRpcCodec.DecodeRequestsAsync(requestData).ConfigureAwait(false); } finally { ArrayPool <byte> .Shared.Return(requestData); } if (requests.Length == 1) { var request = requests[0]; var response = await GetResponseAsync(service, request).ConfigureAwait(false); await WriteResponse(context, response).ConfigureAwait(false); } else { //batch call. var responseList = new List <JsonRpcResponse>(); foreach (var request in requests) { var response = await GetResponseAsync(service, request).ConfigureAwait(false); if (response != null) { responseList.Add(response); } } if (responseList.Count > 0) { await WriteResponses(context, responseList.ToArray()).ConfigureAwait(false); } else { await WriteResultAsync(context).ConfigureAwait(false); } } }
internal JsonRpcCallNotificationReq(JsonRpcService client, string method, T parameters) : base(client, method, parameters) { }
internal JsonRpcCallNotification(JsonRpcService client, string method) : base(client, method, Empty.New) { }
/// <summary> /// Handle request request and get the response /// </summary> /// <param name="service">The service which will handle the request.</param> /// <param name="request">The request to handle.</param> /// <returns>The response for the request.</returns> protected async Task <JsonRpcResponse> GetResponseAsync(JsonRpcService service, JsonRpcRequest request) { JsonRpcResponse response = null; try { var rpcCall = service.GetRpcCall(request.Method); if (rpcCall == null) { throw new MethodNotFoundException($"Method: {request.Method} not found."); } var arguments = await JsonRpcCodec.DecodeArgumentsAsync(request.Params, rpcCall.Parameters).ConfigureAwait(false); //From here we got the response id. response = new JsonRpcResponse(request.Id); //The parser will add context into the args, so the final count is parameter count + 1. if (arguments.Length == rpcCall.Parameters.Count) { try { var result = await rpcCall.Call(arguments).ConfigureAwait(false); if (request.IsNotification) { return(null); } response.WriteResult(result); } catch (Exception ex) { var argumentString = new StringBuilder(); argumentString.Append(Environment.NewLine); var index = 0; foreach (var argument in arguments) { argumentString.AppendLine($"[{index}] {argument}"); } argumentString.Append(Environment.NewLine); Logger.WriteError($"Call method {rpcCall.Name} with args:{argumentString} error :{ex.Format()}"); response.WriteResult(new InternalErrorException()); } } else { throw new InvalidParamsException("Argument count is not matched"); } } catch (Exception ex) { response ??= new JsonRpcResponse(); if (ex is RpcException rpcException) { Logger.WriteError($"Handle request {request} error: {rpcException.Format()}"); response.WriteResult(rpcException); } else { Logger.WriteError($"Handle request {request} error: {ex.Format()}"); var serverError = new InternalErrorException(); response.WriteResult(serverError); } } return(response); }
public async Task Execute(CancellationToken cancellationToken) { IJsonRpcConfig jsonRpcConfig = _api.Config <IJsonRpcConfig>(); ILogger logger = _api.LogManager.GetClassLogger(); if (jsonRpcConfig.Enabled) { IInitConfig initConfig = _api.Config <IInitConfig>(); JsonRpcLocalStats jsonRpcLocalStats = new JsonRpcLocalStats( _api.Timestamper, jsonRpcConfig, _api.LogManager); JsonRpcService jsonRpcService = new JsonRpcService(_api.RpcModuleProvider, _api.LogManager); JsonRpcProcessor jsonRpcProcessor = new JsonRpcProcessor( jsonRpcService, _api.EthereumJsonSerializer, jsonRpcConfig, _api.FileSystem, _api.LogManager); if (initConfig.WebSocketsEnabled) { // TODO: I do not like passing both service and processor to any of the types JsonRpcWebSocketsModule?webSocketsModule = new JsonRpcWebSocketsModule( jsonRpcProcessor, jsonRpcService, _api.EthereumJsonSerializer, jsonRpcLocalStats); _api.WebSocketsManager !.AddModule(webSocketsModule, true); } Bootstrap.Instance.JsonRpcService = jsonRpcService; Bootstrap.Instance.LogManager = _api.LogManager; Bootstrap.Instance.JsonSerializer = _api.EthereumJsonSerializer; Bootstrap.Instance.JsonRpcLocalStats = jsonRpcLocalStats; var jsonRpcRunner = new JsonRpcRunner( jsonRpcProcessor, _api.WebSocketsManager, _api.ConfigProvider, _api.LogManager, _api); await jsonRpcRunner.Start(cancellationToken).ContinueWith(x => { if (x.IsFaulted && logger.IsError) { logger.Error("Error during jsonRpc runner start", x.Exception); } }); _api.DisposeStack.Push(Disposable.Create(() => jsonRpcRunner.StopAsync())); // do not await } else { if (logger.IsInfo) { logger.Info("Json RPC is disabled"); } } }
internal JsonRpcCallRequest(JsonRpcService client, string method) : base(client, method, Empty.New) { }
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"); } } }
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"); } } }