Esempio n. 1
0
        private void InitDbApi(IInitConfig initConfig, IDbConfig dbConfig, bool storeReceipts)
        {
            switch (initConfig.DiagnosticMode)
            {
            case DiagnosticMode.RpcDb:
                _api.DbProvider = new DbProvider(DbModeHint.Persisted);
                var rocksDbFactory = new RocksDbFactory(dbConfig, _api.LogManager, Path.Combine(initConfig.BaseDbPath, "debug"));
                var rpcDbFactory   = new RpcDbFactory(new MemDbFactory(), rocksDbFactory, _api.EthereumJsonSerializer, new BasicJsonRpcClient(new Uri(initConfig.RpcDbUrl), _api.EthereumJsonSerializer, _api.LogManager), _api.LogManager);
                _api.RocksDbFactory = rpcDbFactory;
                _api.MemDbFactory   = rpcDbFactory;
                break;

            case DiagnosticMode.ReadOnlyDb:
                var rocksDbProvider = new DbProvider(DbModeHint.Persisted);
                _api.DbProvider = new ReadOnlyDbProvider(rocksDbProvider, storeReceipts);     // ToDo storeReceipts as createInMemoryWriteStore - bug?
                _api.DisposeStack.Push(rocksDbProvider);
                _api.RocksDbFactory = new RocksDbFactory(dbConfig, _api.LogManager, Path.Combine(initConfig.BaseDbPath, "debug"));
                _api.MemDbFactory   = new MemDbFactory();
                break;

            case DiagnosticMode.MemDb:
                _api.DbProvider     = new DbProvider(DbModeHint.Mem);
                _api.RocksDbFactory = new RocksDbFactory(dbConfig, _api.LogManager, Path.Combine(initConfig.BaseDbPath, "debug"));
                _api.MemDbFactory   = new MemDbFactory();
                break;

            default:
                _api.DbProvider     = new DbProvider(DbModeHint.Persisted);
                _api.RocksDbFactory = new RocksDbFactory(dbConfig, _api.LogManager, initConfig.BaseDbPath);
                _api.MemDbFactory   = new MemDbFactory();
                break;
            }
        }
Esempio n. 2
0
        public void ValidateDbs()
        {
            void ValidateDb <T>(params IDb[] dbs) where T : IDb
            {
                foreach (IDb db in dbs)
                {
                    db.Should().BeAssignableTo <T>(db.Name);
                    db.Innermost.Should().BeAssignableTo <RpcDb>(db.Name);
                }
            }

            IJsonSerializer jsonSerializer = Substitute.For <IJsonSerializer>();
            IJsonRpcClient  jsonRpcClient  = Substitute.For <IJsonRpcClient>();
            IMemDbFactory   rpcDbFactory   = new RpcDbFactory(new MemDbFactory(), null, jsonSerializer, jsonRpcClient, LimboLogs.Instance);

            IDbProvider           memDbProvider         = new DbProvider(DbModeHint.Mem);
            StandardDbInitializer standardDbInitializer = new(memDbProvider, null, rpcDbFactory);

            standardDbInitializer.InitStandardDbs(true);

            ValidateDb <ReadOnlyDb>(
                memDbProvider.BlocksDb,
                memDbProvider.BloomDb,
                memDbProvider.HeadersDb,
                memDbProvider.ReceiptsDb,
                memDbProvider.BlockInfosDb,
                memDbProvider.PendingTxsDb);

            ValidateDb <ReadOnlyDb>(
                memDbProvider.StateDb,
                memDbProvider.CodeDb);
        }
Esempio n. 3
0
        public async Task ProviderInitTests_RpcDbProvider()
        {
            var dbProvider     = new DbProvider(DbModeHint.Persisted);
            var rocksDbFactory = new RocksDbFactory(new DbConfig(), LimboLogs.Instance, Path.Combine(_folderWithDbs, "rpc"));
            var serializer     = Substitute.For <IJsonSerializer>();
            var client         = Substitute.For <IJsonRpcClient>();
            var rpcDbFactory   = new RpcDbFactory(new MemDbFactory(), rocksDbFactory, serializer, client, LimboLogs.Instance);
            var initializer    = new NdmDbInitializer(new NdmConfig(), dbProvider, rpcDbFactory, rpcDbFactory);
            await initializer.Init();

            dbProvider.RegisterDb("test", new MemDb());
            Assert.NotNull(dbProvider.GetDb <IDb>(NdmDbNames.Configs));
            Assert.NotNull(dbProvider.GetDb <IDb>(NdmDbNames.EthRequests));
            Assert.AreEqual(3, dbProvider.RegisteredDbs.Count());
            Assert.IsTrue(dbProvider.GetDb <IDb>(NdmDbNames.Configs) is ReadOnlyDb);
            Assert.IsTrue(dbProvider.GetDb <IDb>(NdmDbNames.EthRequests) is ReadOnlyDb);
        }