예제 #1
0
        public StartGrpcProducer(EthereumRunnerContext context)
        {
            _context = context;
            EthereumSubsystemState newState = _context.Config <IGrpcConfig>().Enabled
                ? EthereumSubsystemState.AwaitingInitialization
                : EthereumSubsystemState.Disabled;

            SubsystemStateChanged?.Invoke(this, new SubsystemStateEventArgs(newState));
        }
예제 #2
0
        public StartKafkaProducer(EthereumRunnerContext context)
        {
            _context = context;
            _logger  = context.LogManager.GetClassLogger();
            EthereumSubsystemState newState = _context.Config <IKafkaConfig>().Enabled
                ? EthereumSubsystemState.AwaitingInitialization
                : EthereumSubsystemState.Disabled;

            SubsystemStateChanged?.Invoke(this, new SubsystemStateEventArgs(newState));
        }
예제 #3
0
        public Task Execute(CancellationToken _)
        {
            IGrpcConfig grpcConfig = _context.Config <IGrpcConfig>();

            if (grpcConfig.Enabled)
            {
                SubsystemStateChanged?.Invoke(this, new SubsystemStateEventArgs(EthereumSubsystemState.Initializing));

                GrpcProducer grpcProducer = new GrpcProducer(_context.GrpcServer);
                _context.Producers.Add(grpcProducer);

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

            return(Task.CompletedTask);
        }
예제 #4
0
        public Task Execute()
        {
            IInitConfig initConfig = _context.Config <IInitConfig>();

            if (initConfig.IsMining)
            {
                BuildProducer();
                if (_context.BlockProducer == null)
                {
                    throw new StepDependencyException(nameof(_context.BlockProducer));
                }

                _context.BlockProducer.Start();

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

            return(Task.CompletedTask);
        }
예제 #5
0
        public virtual Task Execute()
        {
            if (_context.RpcModuleProvider == null)
            {
                throw new StepDependencyException(nameof(_context.RpcModuleProvider));
            }

            ILogger        logger        = _context.LogManager.GetClassLogger();
            IJsonRpcConfig jsonRpcConfig = _context.Config <IJsonRpcConfig>();

            if (!jsonRpcConfig.Enabled)
            {
                return(Task.CompletedTask);
            }

            // 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(CliModuleLoader)})");
            }

            IInitConfig    initConfig = _context.Config <IInitConfig>();
            INdmConfig     ndmConfig  = _context.Config <INdmConfig>();
            IJsonRpcConfig rpcConfig  = _context.Config <IJsonRpcConfig>();

            if (ndmConfig.Enabled && !(_context.NdmInitializer is null) && ndmConfig.ProxyEnabled)
            {
                EthModuleProxyFactory proxyFactory = new EthModuleProxyFactory(_context.EthJsonRpcClientProxy, _context.Wallet);
                _context.RpcModuleProvider.Register(new SingletonModulePool <IEthModule>(proxyFactory, true));
                if (logger.IsInfo)
                {
                    logger.Info("Enabled JSON RPC Proxy for NDM.");
                }
            }
            else
            {
                EthModuleFactory ethModuleFactory = new EthModuleFactory(_context.DbProvider, _context.TxPool, _context.Wallet, _context.BlockTree,
                                                                         _context.EthereumEcdsa, _context.MainBlockProcessor, _context.ReceiptStorage, _context.SpecProvider, rpcConfig, _context.BloomStorage, _context.LogManager);
                _context.RpcModuleProvider.Register(new BoundedModulePool <IEthModule>(8, ethModuleFactory));
            }

            ProofModuleFactory proofModuleFactory = new ProofModuleFactory(_context.DbProvider, _context.BlockTree, _context.RecoveryStep, _context.ReceiptStorage, _context.SpecProvider, _context.LogManager);

            _context.RpcModuleProvider.Register(new BoundedModulePool <IProofModule>(2, proofModuleFactory));

            DebugModuleFactory debugModuleFactory = new DebugModuleFactory(_context.DbProvider, _context.BlockTree, _context.BlockValidator, _context.RecoveryStep, _context.RewardCalculatorSource, _context.ReceiptStorage, _context.ConfigProvider, _context.SpecProvider, _context.LogManager);

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

            TraceModuleFactory traceModuleFactory = new TraceModuleFactory(_context.DbProvider, _context.BlockTree, _context.RecoveryStep, _context.RewardCalculatorSource, _context.ReceiptStorage, _context.SpecProvider, _context.LogManager);

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

            if (initConfig.EnableUnsecuredDevWallet)
            {
                PersonalBridge personalBridge = new PersonalBridge(_context.EthereumEcdsa, _context.Wallet);
                PersonalModule personalModule = new PersonalModule(personalBridge, _context.LogManager);
                _context.RpcModuleProvider.Register(new SingletonModulePool <IPersonalModule>(personalModule, true));
            }

            AdminModule adminModule = new AdminModule(_context.PeerManager, _context.StaticNodesManager);

            _context.RpcModuleProvider.Register(new SingletonModulePool <IAdminModule>(adminModule, true));

            TxPoolModule txPoolModule = new TxPoolModule(_context.LogManager, _context.TxPoolInfoProvider);

            _context.RpcModuleProvider.Register(new SingletonModulePool <ITxPoolModule>(txPoolModule, true));

            NetModule netModule = new NetModule(_context.LogManager, new NetBridge(_context.Enode, _context.SyncServer, _context.PeerManager));

            _context.RpcModuleProvider.Register(new SingletonModulePool <INetModule>(netModule, true));

            ParityModule parityModule = new ParityModule(_context.EthereumEcdsa, _context.TxPool, _context.BlockTree, _context.ReceiptStorage, _context.LogManager);

            _context.RpcModuleProvider.Register(new SingletonModulePool <IParityModule>(parityModule, true));

            SubsystemStateChanged?.Invoke(this, new SubsystemStateEventArgs(EthereumSubsystemState.Running));
            return(Task.CompletedTask);
        }
예제 #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));
        }