public void Run() { _receiptStorage = _context.ReceiptStorage ?? throw new StepDependencyException(nameof(_context.ReceiptStorage)); _dbProvider = _context.DbProvider ?? throw new StepDependencyException(nameof(_context.DbProvider)); _disposeStack = _context.DisposeStack ?? throw new StepDependencyException(nameof(_context.DisposeStack)); _blockTree = _context.BlockTree ?? throw new StepDependencyException(nameof(_context.BlockTree)); _syncModeSelector = _context.SyncModeSelector ?? throw new StepDependencyException(nameof(_context.SyncModeSelector)); _chainLevelInfoRepository = _context.ChainLevelInfoRepository ?? throw new StepDependencyException(nameof(_context.ChainLevelInfoRepository)); var initConfig = _context.Config <IInitConfig>(); if (initConfig.StoreReceipts) { if (initConfig.ReceiptsMigration) { if (CanMigrate(_syncModeSelector.Current)) { RunMigration(); } else { _syncModeSelector.Changed += OnSyncModeChanged; } } else { if (_logger.IsInfo) { _logger.Info($"ReceiptsDb migration disabled. Finding logs when multiple blocks receipts need to be scanned might be slow."); } } } }
public StandardDbInitializer( IDbProvider?dbProvider, IRocksDbFactory?rocksDbFactory, IMemDbFactory?memDbFactory) : base(dbProvider, rocksDbFactory, memDbFactory) { }
public ReadOnlyTxProcessingEnv( IDbProvider?dbProvider, IReadOnlyTrieStore?trieStore, IBlockTree?blockTree, ISpecProvider?specProvider, ILogManager?logManager) : this(dbProvider?.AsReadOnly(false), trieStore, blockTree?.AsReadOnly(), specProvider, logManager) { }
public StandardDbInitializer( IDbProvider?dbProvider, IRocksDbFactory?rocksDbFactory, IMemDbFactory?memDbFactory, IFileSystem?fileSystem = null, bool fullPruning = false) : base(dbProvider, rocksDbFactory, memDbFactory) { _fileSystem = fileSystem ?? new FileSystem(); _fullPruning = fullPruning; }
public ReceiptMigration(IApiWithNetwork api) { _logger = api.LogManager.GetClassLogger <ReceiptMigration>(); _receiptStorage = api.ReceiptStorage ?? throw new StepDependencyException(nameof(api.ReceiptStorage)); _dbProvider = api.DbProvider ?? throw new StepDependencyException(nameof(api.DbProvider)); _disposeStack = api.DisposeStack ?? throw new StepDependencyException(nameof(api.DisposeStack)); _blockTree = api.BlockTree ?? throw new StepDependencyException(nameof(api.BlockTree)); _syncModeSelector = api.SyncModeSelector ?? throw new StepDependencyException(nameof(api.SyncModeSelector)); _chainLevelInfoRepository = api.ChainLevelInfoRepository ?? throw new StepDependencyException(nameof(api.ChainLevelInfoRepository)); _initConfig = api.Config <IInitConfig>() ?? throw new StepDependencyException("initConfig"); }
public ReceiptMigration(NethermindApi context) { _logger = context.LogManager.GetClassLogger <ReceiptMigration>(); _receiptStorage = context.ReceiptStorage ?? throw new StepDependencyException(nameof(context.ReceiptStorage)); _dbProvider = context.DbProvider ?? throw new StepDependencyException(nameof(context.DbProvider)); _disposeStack = context.DisposeStack ?? throw new StepDependencyException(nameof(context.DisposeStack)); _blockTree = context.BlockTree ?? throw new StepDependencyException(nameof(context.BlockTree)); _syncModeSelector = context.SyncModeSelector ?? throw new StepDependencyException(nameof(context.SyncModeSelector)); _chainLevelInfoRepository = context.ChainLevelInfoRepository ?? throw new StepDependencyException(nameof(context.ChainLevelInfoRepository)); _initConfig = context.Config <IInitConfig>() ?? throw new StepDependencyException("initConfig"); }
public ReadOnlyDbProvider(IDbProvider?wrappedProvider, bool createInMemoryWriteStore) { _wrappedProvider = wrappedProvider ?? throw new ArgumentNullException(nameof(wrappedProvider)); _createInMemoryWriteStore = createInMemoryWriteStore; if (wrappedProvider == null) { throw new ArgumentNullException(nameof(wrappedProvider)); } foreach ((string key, IDb value) in _wrappedProvider.RegisteredDbs) { RegisterReadOnlyDb(key, value); } }
protected async Task PreInitAsync(INdmApi ndmApi) { if (ndmApi == null) { throw new ArgumentNullException(nameof(ndmApi)); } IDbProvider?dbProvider = ndmApi.DbProvider; if (dbProvider == null) { throw new ArgumentNullException(nameof(dbProvider)); } IConfigProvider configProvider = ndmApi.ConfigProvider; ILogManager logManager = ndmApi.LogManager; if (!(configProvider.GetConfig <INdmConfig>() is NdmConfig defaultConfig)) { return; } if (!defaultConfig.Enabled) { return; } if (defaultConfig.StoreConfigInDatabase && string.IsNullOrWhiteSpace(defaultConfig.Id)) { throw new ArgumentException("NDM config stored in database requires an id.", nameof(defaultConfig.Id)); } IConfigRepository configRepository; IEthRequestRepository ethRequestRepository; switch (defaultConfig.Persistence?.ToLowerInvariant()) { case "mongo": ndmApi.MongoProvider = new MongoProvider(configProvider.GetConfig <INdmMongoConfig>(), logManager); IMongoDatabase?database = ndmApi.MongoProvider.GetDatabase(); if (database == null) { throw new ApplicationException("Failed to initialize Mongo database"); } configRepository = new ConfigMongoRepository(database); ethRequestRepository = new EthRequestMongoRepository(database); break; default: ndmApi.MongoProvider = NullMongoProvider.Instance; var ndmDbProvider = new NdmDbInitializer(defaultConfig, ndmApi.DbProvider, ndmApi.RocksDbFactory, ndmApi.MemDbFactory); await ndmDbProvider.Init(); configRepository = new ConfigRocksRepository(ndmApi.DbProvider.GetDb <IDb>(NdmDbNames.Configs), new NdmConfigDecoder()); ethRequestRepository = new EthRequestRocksRepository(ndmApi.DbProvider.GetDb <IDb>(NdmDbNames.EthRequests), new EthRequestDecoder()); break; } ndmApi.ConfigManager = new ConfigManager(defaultConfig, configRepository); ndmApi.NdmConfig = await ndmApi.ConfigManager.GetAsync(defaultConfig.Id); if (ndmApi.NdmConfig is null) { ndmApi.NdmConfig = defaultConfig; if (defaultConfig.StoreConfigInDatabase) { await ndmApi.ConfigManager.UpdateAsync((NdmConfig)ndmApi.NdmConfig); } } IWebSocketsModule webSocketsModule = ndmApi.WebSocketsManager !.GetModule("ndm"); ndmApi.NdmNotifier = new NdmNotifier(webSocketsModule); ndmApi.EthRequestService = new EthRequestService(ndmApi.NdmConfig.FaucetHost, logManager); string baseDbPath = configProvider.GetConfig <IInitConfig>().BaseDbPath; ndmApi.BaseDbPath = DbPath = Path.Combine(baseDbPath, ndmApi.NdmConfig.DatabasePath); await _ndmModule.InitAsync(); if (ndmApi.NdmConfig.FaucetEnabled) { // faucet should be separate from NDM? but it uses MongoDB? // so maybe we could extract Mongo DB beyond NDM? why would it be related? if (string.IsNullOrWhiteSpace(ndmApi.NdmConfig.FaucetAddress)) { ndmApi.NdmFaucet = EmptyFaucet.Instance; _logger.Warn("Faucet cannot be started due to missing faucet address configuration."); } else { Address faucetAddress = new(ndmApi.NdmConfig.FaucetAddress); ndmApi.NdmFaucet = new NdmFaucet( ndmApi.BlockchainBridge, ethRequestRepository, faucetAddress, ndmApi.NdmConfig.FaucetWeiRequestMaxValue, ndmApi.NdmConfig.FaucetEthDailyRequestsTotalValue, ndmApi.NdmConfig.FaucetEnabled, ndmApi.Timestamper, ndmApi.Wallet, logManager); } } else { ndmApi.NdmFaucet = EmptyFaucet.Instance; } ndmApi.ConsumerAddress = string.IsNullOrWhiteSpace(ndmApi.NdmConfig.ConsumerAddress) ? Address.Zero : new Address(ndmApi.NdmConfig.ConsumerAddress); ndmApi.ProviderAddress = string.IsNullOrWhiteSpace(ndmApi.NdmConfig.ProviderAddress) ? Address.Zero : new Address(ndmApi.NdmConfig.ProviderAddress); await _ndmConsumersModule.Init(); }