Esempio n. 1
0
        private void InitEthStats()
        {
            var config = _configProvider.GetConfig <IEthStatsConfig>();

            if (!config.Enabled)
            {
                if (_logger.IsInfo)
                {
                    _logger.Info($"ETH Stats integration is disabled.");
                }
                return;
            }

            var instanceId = $"{config.Name}-{Keccak.Compute(_enode.Info)}";

            if (_logger.IsInfo)
            {
                _logger.Info($"Initializing ETH Stats for the instance: {instanceId}, server: {config.Server}");
            }
            var          sender = new MessageSender(instanceId, _logManager);
            const int    reconnectionInterval = 5000;
            const string api                 = "no";
            const string client              = "0.1.1";
            const bool   canUpdateHistory    = false;
            var          node                = ClientVersion.Description;
            var          port                = _configProvider.GetConfig <IInitConfig>().P2PPort;
            var          network             = _specProvider.ChainId.ToString();
            var          protocol            = _syncConfig.FastSync ? "eth/63" : "eth/62";
            var          ethStatsClient      = new EthStatsClient(config.Server, reconnectionInterval, sender, _logManager);
            var          ethStatsIntegration = new EthStatsIntegration(config.Name, node, port, network, protocol, api, client,
                                                                       config.Contact, canUpdateHistory, config.Secret, ethStatsClient, sender, _blockTree, _peerManager,
                                                                       _logManager);

            Task.Run(() => ethStatsIntegration.InitAsync());
        }
Esempio n. 2
0
        public async Task Execute(CancellationToken _)
        {
            IEthStatsConfig ethStatsConfig = _context.Config <IEthStatsConfig>();

            if (!ethStatsConfig.Enabled)
            {
                return;
            }

            INetworkConfig networkConfig = _context.Config <INetworkConfig>();

            SubsystemStateChanged?.Invoke(this, new SubsystemStateEventArgs(EthereumSubsystemState.Initializing));

            if (_context.Enode == null)
            {
                throw new StepDependencyException(nameof(_context.Enode));
            }
            if (_context.SpecProvider == null)
            {
                throw new StepDependencyException(nameof(_context.SpecProvider));
            }

            string instanceId = $"{ethStatsConfig.Name}-{Keccak.Compute(_context.Enode.Info)}";

            if (_logger.IsInfo)
            {
                _logger.Info($"Initializing ETH Stats for the instance: {instanceId}, server: {ethStatsConfig.Server}");
            }
            MessageSender sender = new MessageSender(instanceId, _context.LogManager);
            const int     reconnectionInterval = 5000;
            const string  api              = "no";
            const string  client           = "0.1.1";
            const bool    canUpdateHistory = false;
            string        node             = ClientVersion.Description ?? string.Empty;
            int           port             = networkConfig.P2PPort;
            string        network          = _context.SpecProvider.ChainId.ToString();
            string        protocol         = "eth/65";

            EthStatsClient ethStatsClient = new EthStatsClient(
                ethStatsConfig.Server,
                reconnectionInterval,
                sender,
                _context.LogManager);

            EthStatsIntegration ethStatsIntegration = new EthStatsIntegration(
                ethStatsConfig.Name,
                node,
                port,
                network,
                protocol,
                api,
                client,
                ethStatsConfig.Contact,
                canUpdateHistory,
                ethStatsConfig.Secret,
                ethStatsClient,
                sender,
                _context.BlockTree,
                _context.PeerManager,
                _context.LogManager);

            await ethStatsIntegration.InitAsync();

            _context.DisposeStack.Push(ethStatsIntegration);
            // TODO: handle failure

            SubsystemStateChanged?.Invoke(this, new SubsystemStateEventArgs(EthereumSubsystemState.Running));
        }