Exemplo n.º 1
0
        public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
        {
            IEthModule ethModule = (IEthModule)await _rpcModuleProvider.Rent("eth_syncing", false);

            INetModule netModule = (INetModule)await _rpcModuleProvider.Rent("net_peerCount", false);

            try
            {
                long          netPeerCount = (long)netModule.net_peerCount().GetData();
                SyncingResult ethSyncing   = (SyncingResult)ethModule.eth_syncing().GetData();

                if (ethSyncing.IsSyncing == false && netPeerCount > 0)
                {
                    return(HealthCheckResult.Healthy(description: $"The node is now fully synced with a network, number of peers: {netPeerCount}"));
                }
                else if (ethSyncing.IsSyncing == false && netPeerCount == 0)
                {
                    return(HealthCheckResult.Unhealthy(description: $"The node has 0 peers connected"));
                }

                return(HealthCheckResult.Unhealthy(description: $"The node is still syncing, CurrentBlock: {ethSyncing.CurrentBlock}, HighestBlock: {ethSyncing.HighestBlock}, Peers: {netPeerCount}"));
            }
            catch (Exception ex)
            {
                return(new HealthCheckResult(context.Registration.FailureStatus, exception: ex));
            }
            finally
            {
                _rpcModuleProvider.Return("eth_syncing", ethModule);
                _rpcModuleProvider.Return("net_peerCount", netModule);
            }
        }
Exemplo n.º 2
0
 public TransactionPool(int maxElemCount, INetModule net, DistributorHashConfiguration configuration)
     : base(maxElemCount)
 {
     Contract.Requires(_net != null);
     Contract.Requires(configuration != null);
     _net          = net;
     _countReplics = configuration.CountReplics;
 }
Exemplo n.º 3
0
        public void NetPeerCountTest()
        {
            INetModule netModule = Substitute.For <INetModule>();

            netModule.net_peerCount().ReturnsForAnyArgs(x => ResultWrapper <BigInteger> .Success(new BigInteger(2)));
            JsonRpcResponse response = TestRequest <INetModule>(netModule, "net_peerCount");

            Assert.AreEqual("2", response.Result.ToString());
        }
Exemplo n.º 4
0
        public void NetVersionTest()
        {
            INetModule netModule = Substitute.For <INetModule>();

            netModule.net_version().ReturnsForAnyArgs(x => ResultWrapper <string> .Success("1"));
            JsonRpcSuccessResponse response = TestRequest(netModule, "net_version") as JsonRpcSuccessResponse;

            Assert.AreEqual(response?.Result, "1");
            Assert.IsNotInstanceOf <JsonRpcErrorResponse>(response);
        }
Exemplo n.º 5
0
 public TransactionExecutor(INetModule net, int countReplics)
 {
     _net   = net;
     _tasks = new List <Task>();
     for (int i = 0; i < countReplics; i++)
     {
         _tasks.Add(new Task(() => { }));
         _tasks[i].Start();
     }
 }
Exemplo n.º 6
0
        public void NetVersionTest()
        {
            INetModule netModule = Substitute.For <INetModule>();

            netModule.net_version().ReturnsForAnyArgs(x => ResultWrapper <string> .Success("1"));
            JsonRpcResponse response = TestRequest <INetModule>(netModule, "net_version");

            Assert.AreEqual(response.Result, "1");
            Assert.IsNull(response.Error);
            Assert.AreEqual("2.0", response.JsonRpc);
        }
Exemplo n.º 7
0
        public void NetPeerCountTest()
        {
            INetModule netModule = Substitute.For <INetModule>();

            netModule.net_peerCount().ReturnsForAnyArgs(x => ResultWrapper <BigInteger> .Success(new BigInteger(2)));
            JsonRpcResponse response = TestRequest <INetModule>(netModule, "net_peerCount");
            Quantity        quantity = new Quantity();

            quantity.FromJson(response.Result.ToString());
            Assert.AreEqual(quantity.AsNumber(), new UInt256(2));
        }
Exemplo n.º 8
0
        private void Initialize(INetModule netModule, IEthModule ethModule, IWeb3Module web3Module, IShhModule shhModule)
        {
            _modules = new[]
            {
                new ModuleInfo(ModuleType.Net, typeof(INetModule), netModule),
                new ModuleInfo(ModuleType.Eth, typeof(IEthModule), ethModule),
                new ModuleInfo(ModuleType.Web3, typeof(IWeb3Module), web3Module),
                new ModuleInfo(ModuleType.Shh, typeof(IShhModule), shhModule)
            };

            _enabledModules = _modules.Where(x => _configurationProvider.EnabledModules.Contains(x.ModuleType)).ToArray();
        }
Exemplo n.º 9
0
        public TransactionModule(QueueConfiguration configuration, INetModule net, TransactionConfiguration transactionConfiguration,
                                 DistributorHashConfiguration distributorHashConfiguration)
        {
            Contract.Requires(net != null);
            Contract.Requires(transactionConfiguration != null);
            Contract.Requires(distributorHashConfiguration != null);
            Contract.Requires(configuration != null);

            _queueConfiguration = configuration;
            _transactionPool    = new TransactionPool(transactionConfiguration.ElementsCount, net,
                                                      distributorHashConfiguration);
            CountReplics = distributorHashConfiguration.CountReplics;
            _net         = net;
            _queue       = GlobalQueue.Queue;
        }
Exemplo n.º 10
0
 public void Initialize()
 {
     _netModule = new NetModule(NullLogManager.Instance, Substitute.For <INetBridge>());
 }
Exemplo n.º 11
0
 public void Initialize()
 {
     _netModule = new NetModule(LimboLogs.Instance, Substitute.For <INetBridge>());
 }
Exemplo n.º 12
0
 public void Initialize()
 {
     _netModule = new NetModule(new JsonConfigProvider(), NullLogManager.Instance, new JsonSerializer(NullLogManager.Instance), Substitute.For <INetBridge>());
 }
Exemplo n.º 13
0
 public ModuleProvider(IConfigProvider configurationProvider, INetModule netModule, IEthModule ethModule, IWeb3Module web3Module, IShhModule shhModule)
 {
     _configurationProvider = configurationProvider.GetConfig <JsonRpcConfig>();
     Initialize(netModule, ethModule, web3Module, shhModule);
 }
Exemplo n.º 14
0
 public void Initialize()
 {
     _netModule = new NetModule(new JsonConfigProvider(), NullLogManager.Instance);
 }