Exemplo n.º 1
0
        private void RegisterJsonRpcModules()
        {
            IJsonRpcConfig jsonRpcConfig = _configProvider.GetConfig <IJsonRpcConfig>();

            if (!jsonRpcConfig.Enabled)
            {
                return;
            }

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

            EthModuleFactory ethModuleFactory = new EthModuleFactory(_dbProvider, _txPool, _wallet, _blockTree, _ethereumEcdsa, _blockProcessor, _receiptStorage, _specProvider, _logManager);

            _rpcModuleProvider.Register(new BoundedModulePool <IEthModule>(8, ethModuleFactory));

            DebugModuleFactory debugModuleFactory = new DebugModuleFactory(_dbProvider, _blockTree, _blockValidator, _recoveryStep, _rewardCalculator, _receiptStorage, _configProvider, _specProvider, _logManager);

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

            TraceModuleFactory traceModuleFactory = new TraceModuleFactory(_dbProvider, _txPool, _blockTree, _blockValidator, _ethereumEcdsa, _recoveryStep, _rewardCalculator, _receiptStorage, _specProvider, _logManager);

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

            if (_sealValidator is CliqueSealValidator)
            {
                CliqueModule cliqueModule = new CliqueModule(_logManager, new CliqueBridge(_blockProducer as ICliqueBlockProducer, _snapshotManager, _blockTree));
                _rpcModuleProvider.Register(new SingletonModulePool <ICliqueModule>(cliqueModule));
            }

            if (_initConfig.EnableUnsecuredDevWallet)
            {
                PersonalBridge personalBridge = new PersonalBridge(_ethereumEcdsa, _wallet);
                PersonalModule personalModule = new PersonalModule(personalBridge, _logManager);
                _rpcModuleProvider.Register(new SingletonModulePool <IPersonalModule>(personalModule));
            }

            AdminModule adminModule = new AdminModule(_logManager, _peerManager, _staticNodesManager);

            _rpcModuleProvider.Register(new SingletonModulePool <IAdminModule>(adminModule));

            TxPoolModule txPoolModule = new TxPoolModule(_logManager, _txPoolInfoProvider);

            _rpcModuleProvider.Register(new SingletonModulePool <ITxPoolModule>(txPoolModule));

            NetModule netModule = new NetModule(_logManager, new NetBridge(_enode, _syncServer, _peerManager));

            _rpcModuleProvider.Register(new SingletonModulePool <INetModule>(netModule));

            ParityModule parityModule = new ParityModule(_ethereumEcdsa, _txPool, _logManager);

            _rpcModuleProvider.Register(new SingletonModulePool <IParityModule>(parityModule));
        }
Exemplo n.º 2
0
        private void RegisterJsonRpcModules()
        {
            if (!_initConfig.JsonRpcEnabled)
            {
                return;
            }

            if (_logger.IsDebug)
            {
                _logger.Debug($"Resolving CLI ({nameof(Cli.CliModuleLoader)})");
            }

            IReadOnlyDbProvider rpcDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            AlternativeChain    rpcChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, _transactionPool, _receiptStorage);

            ITracer        tracer        = new Tracer(rpcChain.Processor, _receiptStorage, _blockTree, _dbProvider.TraceDb);
            IFilterStore   filterStore   = new FilterStore();
            IFilterManager filterManager = new FilterManager(filterStore, _blockProcessor, _transactionPool, _logManager);

            RpcState rpcState = new RpcState(_blockTree, _specProvider, rpcDbProvider, _logManager);

            //creating blockchain bridge
            var blockchainBridge = new BlockchainBridge(
                rpcState.StateReader,
                rpcState.StateProvider,
                rpcState.StorageProvider,
                rpcState.BlockTree,
                _transactionPool,
                _transactionPoolInfoProvider,
                _receiptStorage,
                filterStore,
                filterManager,
                _wallet,
                rpcState.TransactionProcessor);

            TransactionPool debugTransactionPool = new TransactionPool(new PersistentTransactionStorage(_dbProvider.PendingTxsDb, _specProvider),
                                                                       new PendingTransactionThresholdValidator(_initConfig.ObsoletePendingTransactionInterval, _initConfig.RemovePendingTransactionInterval),
                                                                       _timestamp,
                                                                       _ethereumEcdsa,
                                                                       _specProvider,
                                                                       _logManager,
                                                                       _initConfig.RemovePendingTransactionInterval,
                                                                       _initConfig.PeerNotificationThreshold);

            var debugReceiptStorage             = new PersistentReceiptStorage(_dbProvider.ReceiptsDb, _specProvider);
            AlternativeChain    debugChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, debugTransactionPool, debugReceiptStorage);
            IReadOnlyDbProvider debugDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            var debugBridge = new DebugBridge(_configProvider, debugDbProvider, tracer, debugChain.Processor);

            EthModule module = new EthModule(_jsonSerializer, _configProvider, _logManager, blockchainBridge);

            _rpcModuleProvider.Register <IEthModule>(module);

            DebugModule debugModule = new DebugModule(_configProvider, _logManager, debugBridge, _jsonSerializer);

            _rpcModuleProvider.Register <IDebugModule>(debugModule);

            if (_sealer is CliqueSealer)
            {
                CliqueModule cliqueModule = new CliqueModule(_configProvider, _logManager, _jsonSerializer, new CliqueBridge(_blockProducer as ICliqueBlockProducer, _snapshotManager, _blockTree));
                _rpcModuleProvider.Register <ICliqueModule>(cliqueModule);
            }

            if (_initConfig.EnableUnsecuredDevWallet)
            {
                PersonalBridge personalBridge = new PersonalBridge(_wallet);
                PersonalModule personalModule = new PersonalModule(personalBridge, _configProvider, _logManager, _jsonSerializer);
                _rpcModuleProvider.Register <IPersonalModule>(personalModule);
            }

            AdminModule adminModule = new AdminModule(_configProvider, _logManager, _jsonSerializer);

            _rpcModuleProvider.Register <IAdminModule>(adminModule);

            TxPoolModule txPoolModule = new TxPoolModule(_configProvider, _logManager, _jsonSerializer, blockchainBridge);

            _rpcModuleProvider.Register <ITxPoolModule>(txPoolModule);

            if (_initConfig.NetworkEnabled && _initConfig.SynchronizationEnabled)
            {
                NetModule netModule = new NetModule(_configProvider, _logManager, _jsonSerializer, new NetBridge(_enode, _syncManager, _peerManager));
                _rpcModuleProvider.Register <INetModule>(netModule);
            }

            TraceModule traceModule = new TraceModule(_configProvider, _logManager, _jsonSerializer, tracer);

            _rpcModuleProvider.Register <ITraceModule>(traceModule);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        private void RegisterJsonRpcModules()
        {
            if (!_initConfig.JsonRpcEnabled)
            {
                return;
            }

            if (_logger.IsDebug)
            {
                _logger.Debug($"Resolving CLI ({nameof(Cli.CliModuleLoader)})");
            }

            IReadOnlyDbProvider rpcDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            AlternativeChain    rpcChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, _txPool, _receiptStorage);

            ITracer        tracer        = new Tracer(rpcChain.Processor, _receiptStorage, new ReadOnlyBlockTree(_blockTree), _dbProvider.TraceDb);
            IFilterStore   filterStore   = new FilterStore();
            IFilterManager filterManager = new FilterManager(filterStore, _blockProcessor, _txPool, _logManager);

            RpcState rpcState = new RpcState(_blockTree, _specProvider, rpcDbProvider, _logManager);

            //creating blockchain bridge
            var blockchainBridge = new BlockchainBridge(
                rpcState.StateReader,
                rpcState.StateProvider,
                rpcState.StorageProvider,
                rpcState.BlockTree,
                _txPool,
                _transactionPoolInfoProvider,
                _receiptStorage,
                filterStore,
                filterManager,
                _wallet,
                rpcState.TransactionProcessor,
                _ethereumEcdsa);

            AlternativeChain    debugChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, NullTxPool.Instance, NullReceiptStorage.Instance);
            IReadOnlyDbProvider debugDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            var debugBridge = new DebugBridge(_configProvider, debugDbProvider, tracer, debugChain.Processor);

            EthModule module = new EthModule(_logManager, blockchainBridge);

            _rpcModuleProvider.Register <IEthModule>(module);

            DebugModule debugModule = new DebugModule(_logManager, debugBridge);

            _rpcModuleProvider.Register <IDebugModule>(debugModule);

            if (_sealValidator is CliqueSealValidator)
            {
                CliqueModule cliqueModule = new CliqueModule(_logManager, new CliqueBridge(_blockProducer as ICliqueBlockProducer, _snapshotManager, _blockTree));
                _rpcModuleProvider.Register <ICliqueModule>(cliqueModule);
            }

            if (_initConfig.EnableUnsecuredDevWallet)
            {
                PersonalBridge personalBridge = new PersonalBridge(_ethereumEcdsa, _wallet);
                PersonalModule personalModule = new PersonalModule(personalBridge, _logManager);
                _rpcModuleProvider.Register <IPersonalModule>(personalModule);
            }

            AdminModule adminModule = new AdminModule(_logManager, _peerManager, _staticNodesManager);

            _rpcModuleProvider.Register <IAdminModule>(adminModule);

            TxPoolModule txPoolModule = new TxPoolModule(_logManager, blockchainBridge);

            _rpcModuleProvider.Register <ITxPoolModule>(txPoolModule);

            NetModule netModule = new NetModule(_logManager, new NetBridge(_enode, _syncServer, _peerManager));

            _rpcModuleProvider.Register <INetModule>(netModule);

            TraceModule traceModule = new TraceModule(blockchainBridge, _logManager, tracer);

            _rpcModuleProvider.Register <ITraceModule>(traceModule);
        }
Exemplo n.º 5
0
        public virtual Task Execute(CancellationToken cancellationToken)
        {
            if (_api.RpcModuleProvider == null)
            {
                throw new StepDependencyException(nameof(_api.RpcModuleProvider));
            }
            if (_api.TxPool == null)
            {
                throw new StepDependencyException(nameof(_api.TxPool));
            }
            if (_api.BlockTree == null)
            {
                throw new StepDependencyException(nameof(_api.BlockTree));
            }
            if (_api.Wallet == null)
            {
                throw new StepDependencyException(nameof(_api.Wallet));
            }
            if (_api.SpecProvider == null)
            {
                throw new StepDependencyException(nameof(_api.SpecProvider));
            }
            if (_api.TxSender == null)
            {
                throw new StepDependencyException(nameof(_api.TxSender));
            }

            ILogger        logger        = _api.LogManager.GetClassLogger();
            IJsonRpcConfig jsonRpcConfig = _api.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     = _api.Config <IInitConfig>();
            INdmConfig      ndmConfig      = _api.Config <INdmConfig>();
            IJsonRpcConfig  rpcConfig      = _api.Config <IJsonRpcConfig>();
            IBaselineConfig baselineConfig = _api.Config <IBaselineConfig>();
            IVaultConfig    vaultConfig    = _api.Config <IVaultConfig>();
            INetworkConfig  networkConfig  = _api.Config <INetworkConfig>();

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

            ProofModuleFactory proofModuleFactory = new ProofModuleFactory(_api.DbProvider, _api.BlockTree, _api.RecoveryStep, _api.ReceiptFinder, _api.SpecProvider, _api.LogManager);

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

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

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

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

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

            PersonalModule personalModule = new PersonalModule(
                _api.EthereumEcdsa,
                _api.Wallet,
                _api.LogManager);

            _api.RpcModuleProvider.Register(new SingletonModulePool <IPersonalModule>(personalModule, true));

            AdminModule adminModule = new AdminModule(_api.BlockTree, networkConfig, _api.PeerManager, _api.StaticNodesManager, _api.Enode, initConfig.BaseDbPath);

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

            LogFinder logFinder = new LogFinder(
                _api.BlockTree,
                _api.ReceiptFinder,
                _api.BloomStorage,
                _api.LogManager,
                new ReceiptsRecovery(), 1024);

            if (baselineConfig.Enabled)
            {
                IDbProvider  dbProvider  = _api.DbProvider !;
                IStateReader stateReader = new StateReader(dbProvider.StateDb, dbProvider.CodeDb, _api.LogManager);

                BaselineModuleFactory baselineModuleFactory = new BaselineModuleFactory(
                    _api.TxSender,
                    stateReader,
                    logFinder,
                    _api.BlockTree,
                    _api.AbiEncoder,
                    _api.FileSystem,
                    _api.LogManager);

                _api.RpcModuleProvider.Register(new SingletonModulePool <IBaselineModule>(baselineModuleFactory, true));
                if (logger?.IsInfo ?? false)
                {
                    logger !.Info($"Baseline RPC Module has been enabled");
                }
            }

            TxPoolModule txPoolModule = new TxPoolModule(_api.BlockTree, _api.TxPoolInfoProvider, _api.LogManager);

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


            if (vaultConfig.Enabled)
            {
                VaultService vaultService = new VaultService(vaultConfig, _api.LogManager);
                VaultModule  vaultModule  = new VaultModule(vaultService, _api.LogManager);
                _api.RpcModuleProvider.Register(new SingletonModulePool <IVaultModule>(vaultModule, true));
                if (logger?.IsInfo ?? false)
                {
                    logger !.Info($"Vault RPC Module has been enabled");
                }
            }

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

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

            ParityModule parityModule = new ParityModule(
                _api.EthereumEcdsa,
                _api.TxPool,
                _api.BlockTree,
                _api.ReceiptFinder,
                _api.Enode,
                _api.EngineSignerStore,
                _api.KeyStore,
                _api.LogManager);

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

            return(Task.CompletedTask);
        }
Exemplo n.º 6
0
        private void RegisterJsonRpcModules()
        {
            if (!_initConfig.JsonRpcEnabled)
            {
                return;
            }

            IReadOnlyDbProvider rpcDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            AlternativeChain    rpcChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, _transactionPool, _receiptStorage);

            ITracer        tracer        = new Tracer(rpcChain.Processor, _receiptStorage, _blockTree, _dbProvider.TraceDb);
            IFilterStore   filterStore   = new FilterStore();
            IFilterManager filterManager = new FilterManager(filterStore, _blockProcessor, _transactionPool, _logManager);

            _wallet = HiveEnabled ? (IWallet) new HiveWallet() : new DevWallet(_logManager);
            RpcState rpcState = new RpcState(_blockTree, _specProvider, rpcDbProvider, _logManager);

            //creating blockchain bridge
            var blockchainBridge = new BlockchainBridge(
                _ethereumSigner,
                rpcState.StateProvider,
                rpcState.BlockTree,
                _transactionPool,
                _transactionPoolInfoProvider,
                _receiptStorage,
                filterStore,
                filterManager,
                _wallet,
                rpcState.TransactionProcessor);

            TransactionPool debugTransactionPool = new TransactionPool(new PersistentTransactionStorage(_dbProvider.PendingTxsDb, _specProvider),
                                                                       new PendingTransactionThresholdValidator(_initConfig.ObsoletePendingTransactionInterval, _initConfig.RemovePendingTransactionInterval),
                                                                       _timestamp,
                                                                       _ethereumSigner,
                                                                       _logManager,
                                                                       _initConfig.RemovePendingTransactionInterval,
                                                                       _initConfig.PeerNotificationThreshold);

            var debugReceiptStorage             = new PersistentReceiptStorage(_dbProvider.ReceiptsDb, _specProvider);
            AlternativeChain    debugChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, debugTransactionPool, debugReceiptStorage);
            IReadOnlyDbProvider debugDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            var debugBridge = new DebugBridge(debugDbProvider, tracer, debugChain.Processor);

            JsonRpcModelMapper mapper = new JsonRpcModelMapper();

            EthModule module = new EthModule(_jsonSerializer, _configProvider, mapper, _logManager, blockchainBridge);

            _rpcModuleProvider.Register <IEthModule>(module);

            DebugModule debugModule = new DebugModule(_configProvider, _logManager, debugBridge, mapper, _jsonSerializer);

            _rpcModuleProvider.Register <IDebugModule>(debugModule);

            if (_sealEngine is CliqueSealEngine)
            {
                CliqueModule cliqueModule = new CliqueModule(_configProvider, _logManager, _jsonSerializer, new CliqueBridge(_blockProducer as CliqueBlockProducer, _blockTree));
                _rpcModuleProvider.Register <ICliqueModule>(cliqueModule);
            }

            AdminModule adminModule = new AdminModule(_configProvider, _logManager, _jsonSerializer);

            _rpcModuleProvider.Register <IAdminModule>(adminModule);

            TxPoolModule txPoolModule = new TxPoolModule(_configProvider, _logManager, _jsonSerializer, blockchainBridge, mapper);

            _rpcModuleProvider.Register <ITxPoolModule>(txPoolModule);

            if (_initConfig.NetworkEnabled && _initConfig.SynchronizationEnabled)
            {
                NetModule netModule = new NetModule(_configProvider, _logManager, _jsonSerializer, new NetBridge(_syncManager));
                _rpcModuleProvider.Register <INetModule>(netModule);
            }

            TraceModule traceModule = new TraceModule(_configProvider, _logManager, _jsonSerializer, tracer);

            _rpcModuleProvider.Register <ITraceModule>(traceModule);

            _rpcModuleProvider.Register <INethmModule>(new NethmModule(_configProvider, _logManager, _jsonSerializer, _enode));
        }
Exemplo n.º 7
0
        public virtual Task Execute(CancellationToken cancellationToken)
        {
            if (_context.RpcModuleProvider == null)
            {
                throw new StepDependencyException(nameof(_context.RpcModuleProvider));
            }
            if (_context.TxPool == null)
            {
                throw new StepDependencyException(nameof(_context.TxPool));
            }
            if (_context.BlockTree == null)
            {
                throw new StepDependencyException(nameof(_context.BlockTree));
            }
            if (_context.Wallet == null)
            {
                throw new StepDependencyException(nameof(_context.Wallet));
            }
            if (_context.SpecProvider == null)
            {
                throw new StepDependencyException(nameof(_context.SpecProvider));
            }

            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>();
            IBaselineConfig baselineConfig = _context.Config <IBaselineConfig>();
            INetworkConfig  networkConfig  = _context.Config <INetworkConfig>();

            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, rpcConfig, _context.BlockTree,
                                                                         _context.EthereumEcdsa, _context.MainBlockProcessor, _context.ReceiptFinder, _context.SpecProvider, rpcConfig, _context.BloomStorage, _context.LogManager, initConfig.IsMining);
                _context.RpcModuleProvider.Register(new BoundedModulePool <IEthModule>(8, ethModuleFactory));
            }

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

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

            DebugModuleFactory debugModuleFactory = new DebugModuleFactory(_context.DbProvider, _context.BlockTree, rpcConfig, _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, rpcConfig, _context.RecoveryStep, _context.RewardCalculatorSource, _context.ReceiptStorage, _context.SpecProvider, _context.LogManager);

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

            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.BlockTree, networkConfig, _context.PeerManager, _context.StaticNodesManager, _context.Enode, initConfig.BaseDbPath);

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

            LogFinder logFinder = new LogFinder(
                _context.BlockTree,
                _context.ReceiptFinder,
                _context.BloomStorage,
                _context.LogManager,
                new ReceiptsRecovery(), 1024);

            if (baselineConfig.Enabled)
            {
                BaselineModuleFactory baselineModuleFactory = new BaselineModuleFactory(
                    _context.TxPool,
                    logFinder,
                    _context.BlockTree,
                    _context.AbiEncoder,
                    _context.Wallet,
                    _context.SpecProvider,
                    _context.FileSystem,
                    _context.LogManager);

                _context.RpcModuleProvider.Register(new SingletonModulePool <IBaselineModule>(baselineModuleFactory, true));
                if (logger?.IsInfo ?? false)
                {
                    logger !.Info($"Baseline RPC Module has been enabled");
                }
            }

            // commented out because of temporary strange build issues on the build server
            // IDepositConfig depositConfig = _context.Config<IDepositConfig>();
            // if (depositConfig.DepositContractAddress != null)
            // {
            //     TxPoolBridge txPoolBridge = new TxPoolBridge(
            //         _context.TxPool, new WalletTxSigner(_context.Wallet, _context.SpecProvider.ChainId), _context.Timestamper);
            //     DepositModule depositModule = new DepositModule(txPoolBridge, logFinder, depositConfig, _context.LogManager);
            //     _context.RpcModuleProvider.Register(new SingletonModulePool<IDepositModule>(depositModule, true));
            // }

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

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

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

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

            ParityModule parityModule = new ParityModule(
                _context.EthereumEcdsa,
                _context.TxPool,
                _context.BlockTree,
                _context.ReceiptFinder,
                _context.Enode,
                _context.Signer,
                _context.KeyStore,
                _context.LogManager);

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

            return(Task.CompletedTask);
        }
Exemplo n.º 8
0
        public virtual async Task Execute(CancellationToken cancellationToken)
        {
            if (_api.BlockTree == null)
            {
                throw new StepDependencyException(nameof(_api.BlockTree));
            }
            if (_api.ReceiptFinder == null)
            {
                throw new StepDependencyException(nameof(_api.ReceiptFinder));
            }
            if (_api.BloomStorage == null)
            {
                throw new StepDependencyException(nameof(_api.BloomStorage));
            }
            if (_api.LogManager == null)
            {
                throw new StepDependencyException(nameof(_api.LogManager));
            }

            IJsonRpcConfig jsonRpcConfig = _api.Config <IJsonRpcConfig>();

            if (!jsonRpcConfig.Enabled)
            {
                return;
            }

            if (_api.RpcModuleProvider == null)
            {
                throw new StepDependencyException(nameof(_api.RpcModuleProvider));
            }
            if (_api.FileSystem == null)
            {
                throw new StepDependencyException(nameof(_api.FileSystem));
            }
            if (_api.TxPool == null)
            {
                throw new StepDependencyException(nameof(_api.TxPool));
            }
            if (_api.Wallet == null)
            {
                throw new StepDependencyException(nameof(_api.Wallet));
            }
            if (_api.SpecProvider == null)
            {
                throw new StepDependencyException(nameof(_api.SpecProvider));
            }
            if (_api.TxSender == null)
            {
                throw new StepDependencyException(nameof(_api.TxSender));
            }
            if (_api.StateReader == null)
            {
                throw new StepDependencyException(nameof(_api.StateReader));
            }

            if (jsonRpcConfig.Enabled)
            {
                _api.RpcModuleProvider = new RpcModuleProvider(_api.FileSystem, jsonRpcConfig, _api.LogManager);
            }
            else
            {
                _api.RpcModuleProvider ??= NullModuleProvider.Instance;
            }

            // the following line needs to be called in order to make sure that the CLI library is referenced from runner and built alongside
            ILogger logger = _api.LogManager.GetClassLogger();

            IInitConfig    initConfig    = _api.Config <IInitConfig>();
            IJsonRpcConfig rpcConfig     = _api.Config <IJsonRpcConfig>();
            INetworkConfig networkConfig = _api.Config <INetworkConfig>();

            // lets add threads to support parallel eth_getLogs
            ThreadPool.GetMinThreads(out var workerThreads, out var completionPortThreads);
            ThreadPool.SetMinThreads(workerThreads + Environment.ProcessorCount, completionPortThreads + Environment.ProcessorCount);

            EthModuleFactory ethModuleFactory = new EthModuleFactory(
                _api.TxPool,
                _api.TxSender,
                _api.Wallet,
                _api.BlockTree,
                _api.Config <IJsonRpcConfig>(),
                _api.LogManager,
                _api.StateReader,
                _api);

            _api.RpcModuleProvider.Register(new BoundedModulePool <IEthModule>(ethModuleFactory, _cpuCount, rpcConfig.Timeout));

            if (_api.DbProvider == null)
            {
                throw new StepDependencyException(nameof(_api.DbProvider));
            }
            if (_api.BlockPreprocessor == null)
            {
                throw new StepDependencyException(nameof(_api.BlockPreprocessor));
            }
            if (_api.BlockValidator == null)
            {
                throw new StepDependencyException(nameof(_api.BlockValidator));
            }
            if (_api.RewardCalculatorSource == null)
            {
                throw new StepDependencyException(nameof(_api.RewardCalculatorSource));
            }

            ProofModuleFactory proofModuleFactory = new ProofModuleFactory(_api.DbProvider, _api.BlockTree, _api.BlockPreprocessor, _api.ReceiptFinder, _api.SpecProvider, _api.LogManager);

            _api.RpcModuleProvider.Register(new BoundedModulePool <IProofModule>(proofModuleFactory, 2, rpcConfig.Timeout));

            DebugModuleFactory debugModuleFactory = new DebugModuleFactory(
                _api.DbProvider,
                _api.BlockTree,
                rpcConfig,
                _api.BlockValidator,
                _api.BlockPreprocessor,
                _api.RewardCalculatorSource,
                _api.ReceiptStorage,
                new ReceiptMigration(_api),
                _api.ConfigProvider,
                _api.SpecProvider,
                _api.LogManager);

            _api.RpcModuleProvider.Register(new BoundedModulePool <IDebugModule>(debugModuleFactory, _cpuCount, rpcConfig.Timeout));

            TraceModuleFactory traceModuleFactory = new TraceModuleFactory(
                _api.DbProvider,
                _api.BlockTree,
                rpcConfig,
                _api.BlockPreprocessor,
                _api.RewardCalculatorSource,
                _api.ReceiptStorage,
                _api.SpecProvider,
                _api.LogManager);

            _api.RpcModuleProvider.Register(new BoundedModulePool <ITraceModule>(traceModuleFactory, _cpuCount, rpcConfig.Timeout));

            if (_api.EthereumEcdsa == null)
            {
                throw new StepDependencyException(nameof(_api.EthereumEcdsa));
            }
            if (_api.Wallet == null)
            {
                throw new StepDependencyException(nameof(_api.Wallet));
            }

            PersonalModule personalModule = new PersonalModule(
                _api.EthereumEcdsa,
                _api.Wallet,
                _api.LogManager);

            _api.RpcModuleProvider.Register(new SingletonModulePool <IPersonalModule>(personalModule, true));

            if (_api.PeerManager == null)
            {
                throw new StepDependencyException(nameof(_api.PeerManager));
            }
            if (_api.StaticNodesManager == null)
            {
                throw new StepDependencyException(nameof(_api.StaticNodesManager));
            }
            if (_api.Enode == null)
            {
                throw new StepDependencyException(nameof(_api.Enode));
            }

            AdminModule adminModule = new AdminModule(
                _api.BlockTree,
                networkConfig,
                _api.PeerManager,
                _api.StaticNodesManager,
                _api.Enode,
                initConfig.BaseDbPath);

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

            if (_api.TxPoolInfoProvider == null)
            {
                throw new StepDependencyException(nameof(_api.TxPoolInfoProvider));
            }

            TxPoolModule txPoolModule = new TxPoolModule(_api.BlockTree, _api.TxPoolInfoProvider, _api.LogManager);

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

            if (_api.SyncServer == null)
            {
                throw new StepDependencyException(nameof(_api.SyncServer));
            }
            if (_api.EngineSignerStore == null)
            {
                throw new StepDependencyException(nameof(_api.EngineSignerStore));
            }

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

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

            ParityModule parityModule = new ParityModule(
                _api.EthereumEcdsa,
                _api.TxPool,
                _api.BlockTree,
                _api.ReceiptFinder,
                _api.Enode,
                _api.EngineSignerStore,
                _api.KeyStore,
                _api.LogManager);

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

            Web3Module web3Module = new Web3Module(_api.LogManager);

            _api.RpcModuleProvider.Register(new SingletonModulePool <IWeb3Module>(web3Module, true));

            foreach (INethermindPlugin plugin in _api.Plugins)
            {
                await plugin.InitRpcModules();
            }

            if (logger.IsDebug)
            {
                logger.Debug($"RPC modules  : {string.Join(", ", _api.RpcModuleProvider.Enabled.OrderBy(x => x))}");
            }
            ThisNodeInfo.AddInfo("RPC modules  :", $"{string.Join(", ", _api.RpcModuleProvider.Enabled.OrderBy(x => x))}");
        }