Beispiel #1
0
        public DepositModule(ITxPoolBridge txPoolBridge, ILogFinder logFinder, IDepositConfig depositConfig, ILogManager logManager)
        {
            _logger        = logManager?.GetClassLogger <DepositModule>() ?? throw new ArgumentNullException(nameof(logManager));
            _txPoolBridge  = txPoolBridge ?? throw new ArgumentNullException(nameof(txPoolBridge));
            _logFinder     = logFinder ?? throw new ArgumentNullException(nameof(logFinder));
            _depositConfig = depositConfig ?? throw new ArgumentNullException(nameof(depositConfig));

            if (!string.IsNullOrEmpty(depositConfig.DepositContractAddress))
            {
                var address = new Address(depositConfig.DepositContractAddress);
                _depositContract = new DepositContract(new AbiEncoder(), address);
            }
        }
        public DepositModule(ITxPoolBridge txPoolBridge, ILogFinder logFinder, IDepositConfig depositConfig, ILogManager logManager)
        {
            _logger        = logManager?.GetClassLogger <DepositModule>() ?? throw new ArgumentNullException(nameof(logManager));
            _txPoolBridge  = txPoolBridge ?? throw new ArgumentNullException(nameof(txPoolBridge));
            _logFinder     = logFinder ?? throw new ArgumentNullException(nameof(logFinder));
            _depositConfig = depositConfig ?? throw new ArgumentNullException(nameof(depositConfig));
            _abiDefinition = _parser.Parse(File.ReadAllText("contracts/validator_registration.json"));

            if (depositConfig.DepositContractAddress != null)
            {
                var address = new Address(depositConfig.DepositContractAddress);
                _depositContract = new DepositContract(_abiDefinition, new AbiEncoder(), address);
            }
        }
Beispiel #3
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, _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, _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.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");
                }
            }

            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.LogManager);

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

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