public void Eth_stats_disabled_by_default(string configFile)
        {
            ConfigProvider  configProvider = GetConfigProviderFromFile(configFile);
            IEthStatsConfig config         = configProvider.GetConfig <IEthStatsConfig>();

            Assert.AreEqual(config.Enabled, false);
        }
Exemple #2
0
        public Task Init(INethermindApi nethermindApi)
        {
            _api = nethermindApi;
            var(getFromAPi, _) = _api.ForInit;
            _ethStatsConfig    = getFromAPi.Config <IEthStatsConfig>();

            IInitConfig initConfig = getFromAPi.Config <IInitConfig>();

            _isOn   = _ethStatsConfig.Enabled;
            _logger = getFromAPi.LogManager.GetClassLogger();

            if (!_isOn)
            {
                if (!initConfig.WebSocketsEnabled)
                {
                    _logger.Warn($"{nameof(EthStatsPlugin)} disabled due to {nameof(initConfig.WebSocketsEnabled)} set to false");
                }
                else
                {
                    _logger.Warn($"{nameof(EthStatsPlugin)} plugin disabled due to {nameof(EthStatsConfig)} settings set to false");
                }
            }

            return(Task.CompletedTask);
        }
        public void Ethstats_values_are_correct(string configFile, string host)
        {
            ConfigProvider  configProvider = GetConfigProviderFromFile(configFile);
            IEthStatsConfig config         = configProvider.GetConfig <IEthStatsConfig>();

            Assert.AreEqual(host, config.Server);
        }
 public void Init_eth_stats_plugin_does_not_throw_exception(bool enabled)
 {
     StatsConfig = new EthStatsConfig()
     {
         Enabled = enabled
     };
     Assert.DoesNotThrowAsync(async() => await _plugin.Init(_context));
     Assert.DoesNotThrowAsync(async() => await _plugin.InitNetworkProtocol());
     Assert.DoesNotThrowAsync(async() => await _plugin.InitRpcModules());
     Assert.DoesNotThrowAsync(async() => await _plugin.DisposeAsync());
 }
        public async Task Execute(CancellationToken _)
        {
            IEthStatsConfig ethStatsConfig = _get.Config <IEthStatsConfig>();

            if (!ethStatsConfig.Enabled)
            {
                return;
            }

            INetworkConfig networkConfig = _get.Config <INetworkConfig>();
            IInitConfig    initConfig    = _get.Config <IInitConfig>();

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

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

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

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

            EthStatsIntegration ethStatsIntegration = new(
                ethStatsConfig.Name,
                node,
                port,
                network,
                protocol,
                api,
                client,
                ethStatsConfig.Contact,
                canUpdateHistory,
                ethStatsConfig.Secret,
                ethStatsClient,
                sender,
                _get.TxPool,
                _get.BlockTree,
                _get.PeerManager,
                _get.GasPriceOracle,
                _get.EthSyncingInfo !,
                initConfig.IsMining,
                _get.LogManager);

            await ethStatsIntegration.InitAsync();

            _get.DisposeStack.Push(ethStatsIntegration);
            // TODO: handle failure
        }
Exemple #6
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));
        }