public ReadOnlyTxProcessingEnv( IReadOnlyDbProvider?readOnlyDbProvider, IReadOnlyTrieStore?readOnlyTrieStore, IReadOnlyBlockTree?readOnlyBlockTree, ISpecProvider?specProvider, ILogManager?logManager) { if (specProvider == null) { throw new ArgumentNullException(nameof(specProvider)); } DbProvider = readOnlyDbProvider ?? throw new ArgumentNullException(nameof(readOnlyDbProvider)); _codeDb = readOnlyDbProvider.CodeDb.AsReadOnly(true); StateReader = new StateReader(readOnlyTrieStore, _codeDb, logManager); StateProvider = new StateProvider(readOnlyTrieStore, _codeDb, logManager); StorageProvider = new StorageProvider(readOnlyTrieStore, StateProvider, logManager); IWorldState worldState = new WorldState(StateProvider, StorageProvider); BlockTree = readOnlyBlockTree ?? throw new ArgumentNullException(nameof(readOnlyBlockTree)); BlockhashProvider = new BlockhashProvider(BlockTree, logManager); Machine = new VirtualMachine(BlockhashProvider, specProvider, logManager); TransactionProcessor = new TransactionProcessor(specProvider, worldState, Machine, logManager); }
public async Task Init(string basePath, IDbConfig dbConfig, bool useReceiptsDb) { _dbConfig = dbConfig; _basePath = basePath; HashSet <Task> allInitializers = new HashSet <Task>(); allInitializers.Add(Task.Run(() => BlocksDb = new BlocksRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => HeadersDb = new HeadersRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => BlockInfosDb = new BlockInfosRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => StateDb = new StateDb(new StateRocksDb(basePath, dbConfig, _logManager)))); allInitializers.Add(Task.Run(() => CodeDb = new StateDb(new CodeRocksDb(basePath, dbConfig, _logManager)))); allInitializers.Add(Task.Run(() => PendingTxsDb = new PendingTxsRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => BloomDb = new BloomRocksDb(basePath, dbConfig, _logManager))); allInitializers.Add(Task.Run(() => { if (useReceiptsDb) { ReceiptsDb = new ReceiptsRocksDb(basePath, dbConfig, _logManager); } else { ReceiptsDb = new ReadOnlyDb(new MemDb(), false); } })); await Task.WhenAll(allInitializers); }
public BaselineTree CreateHistoricalTree(Address address, long blockNumber) { if (_logger.IsWarn) { _logger.Warn($"Building historical tree at {address} for block {blockNumber}"); } var readOnlyMain = new ReadOnlyDb(_mainDb, true); var readOnlyMetadata = new ReadOnlyDb(_metadataBaselineDb, true); var historicalTree = new ShaBaselineTree(readOnlyMain, readOnlyMetadata, address.Bytes, BaselineModule.TruncationLength, _logger); var endIndex = historicalTree.Count; var historicalCount = historicalTree.GetBlockCount(blockNumber); if (_logger.IsWarn) { _logger.Warn($"Historical count of {historicalTree} for block {blockNumber} is {historicalCount}"); } if (endIndex - historicalCount > 0) { if (_logger.IsWarn) { _logger.Warn($"Deleting {endIndex - historicalCount} from {historicalTree}"); } historicalTree.Delete(endIndex - historicalCount, false); historicalTree.CalculateHashes(historicalCount, endIndex); if (_logger.IsWarn) { _logger.Warn($"After deleting from {historicalTree} root is {historicalTree.Root}"); } } return(historicalTree); }
public ReadOnlyTransactionProcessor(ITransactionProcessor transactionProcessor, IStateProvider stateProvider, IStorageProvider storageProvider, ReadOnlyDb codeDb, Keccak startState) { _transactionProcessor = transactionProcessor ?? throw new ArgumentNullException(nameof(transactionProcessor)); _stateProvider = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider)); _storageProvider = storageProvider ?? throw new ArgumentNullException(nameof(storageProvider)); _codeDb = codeDb ?? throw new ArgumentNullException(nameof(codeDb)); _stateBefore = _stateProvider.StateRoot; _stateProvider.StateRoot = startState ?? throw new ArgumentNullException(nameof(startState)); }
public RpcDbProvider(IJsonSerializer serializer, IJsonRpcClient client, ILogManager logManager, IDbProvider recordDbProvider) { _recordDbProvider = recordDbProvider; StateDb = new StateDb(new ReadOnlyDb(new RpcDb(DbNames.State, serializer, client, logManager, recordDbProvider?.StateDb), true)); CodeDb = new StateDb(new ReadOnlyDb(new RpcDb(DbNames.Code, serializer, client, logManager, recordDbProvider?.CodeDb), true)); ReceiptsDb = new ReadOnlyDb(new RpcDb(DbNames.Receipts, serializer, client, logManager, recordDbProvider?.ReceiptsDb), true); BlocksDb = new ReadOnlyDb(new RpcDb(DbNames.Blocks, serializer, client, logManager, recordDbProvider?.BlocksDb), true); BlockInfosDb = new ReadOnlyDb(new RpcDb(DbNames.BlockInfos, serializer, client, logManager, recordDbProvider?.BlockInfosDb), true); PendingTxsDb = new ReadOnlyDb(new RpcDb(DbNames.PendingTxs, serializer, client, logManager, recordDbProvider?.ReceiptsDb), true); TraceDb = new ReadOnlyDb(new RpcDb(DbNames.Trace, serializer, client, logManager, recordDbProvider?.ReceiptsDb), true); }
public RpcDbProvider(IJsonSerializer serializer, IJsonRpcClient client, ILogManager logManager, IDbProvider recordDbProvider) { _recordDbProvider = recordDbProvider; StateDb = new StateDb(new ReadOnlyDb(new RpcDb(DbNames.State, serializer, client, logManager, recordDbProvider?.StateDb), true)); CodeDb = new StateDb(new ReadOnlyDb(new RpcDb(DbNames.Code, serializer, client, logManager, recordDbProvider?.CodeDb), true)); ReceiptsDb = new ReadOnlyColumnsDb <ReceiptsColumns>(new RpcColumnsDb <ReceiptsColumns>(DbNames.Receipts, serializer, client, logManager, recordDbProvider?.ReceiptsDb), true); BlocksDb = new ReadOnlyDb(new RpcDb(DbNames.Blocks, serializer, client, logManager, recordDbProvider?.BlocksDb), true); HeadersDb = new ReadOnlyDb(new RpcDb(DbNames.Headers, serializer, client, logManager, recordDbProvider?.HeadersDb), true); BlockInfosDb = new ReadOnlyDb(new RpcDb(DbNames.BlockInfos, serializer, client, logManager, recordDbProvider?.BlockInfosDb), true); PendingTxsDb = new ReadOnlyDb(new RpcDb(DbNames.PendingTxs, serializer, client, logManager, recordDbProvider?.ReceiptsDb), true); ConfigsDb = new ReadOnlyDb(new RpcDb(DbNames.Configs, serializer, client, logManager, recordDbProvider?.ConfigsDb), true); EthRequestsDb = new ReadOnlyDb(new RpcDb(DbNames.EthRequests, serializer, client, logManager, recordDbProvider?.EthRequestsDb), true); BloomDb = new ReadOnlyDb(new RpcDb(DbNames.EthRequests, serializer, client, logManager, recordDbProvider?.BloomDb), true); }
public ReadOnlyTxProcessingEnv( IReadOnlyDbProvider readOnlyDbProvider, ReadOnlyTrieStore readOnlyTrieStore, ReadOnlyBlockTree readOnlyBlockTree, ISpecProvider specProvider, ILogManager logManager) { DbProvider = readOnlyDbProvider; _codeDb = readOnlyDbProvider.CodeDb.AsReadOnly(true); StateReader = new StateReader(readOnlyTrieStore, _codeDb, logManager); StateProvider = new StateProvider(readOnlyTrieStore, _codeDb, logManager); StorageProvider = new StorageProvider(readOnlyTrieStore, StateProvider, logManager); BlockTree = readOnlyBlockTree; BlockhashProvider = new BlockhashProvider(BlockTree, logManager); Machine = new VirtualMachine(StateProvider, StorageProvider, BlockhashProvider, specProvider, logManager); TransactionProcessor = new TransactionProcessor(specProvider, StateProvider, StorageProvider, Machine, logManager); }