Exemplo n.º 1
0
        public NodeDataFeed(ISnapshotableDb codeDb, ISnapshotableDb stateDb, ILogManager logManager)
        {
            _codeDb  = codeDb ?? throw new ArgumentNullException(nameof(codeDb));
            _stateDb = stateDb ?? throw new ArgumentNullException(nameof(stateDb));
            _logger  = logManager.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));

            byte[] progress = _codeDb.Get(_fastSyncProgressKey);
            if (progress != null)
            {
                Rlp.DecoderContext context = new Rlp.DecoderContext(progress);
                context.ReadSequenceLength();
                _consumedNodesCount  = context.DecodeLong();
                _savedStorageCount   = context.DecodeLong();
                _savedStateCount     = context.DecodeLong();
                _savedNodesCount     = context.DecodeLong();
                _savedAccounts       = context.DecodeLong();
                _savedCode           = context.DecodeLong();
                _requestedNodesCount = context.DecodeLong();
                _dbChecks            = context.DecodeLong();
                _stateWasThere       = context.DecodeLong();
                _stateWasNotThere    = context.DecodeLong();
                if (context.Position != context.Length)
                {
                    _dataSize = context.DecodeLong();
                }
            }
        }
Exemplo n.º 2
0
        public SyncServer(
            ISnapshotableDb stateDb,
            ISnapshotableDb codeDb,
            IBlockTree blockTree,
            IReceiptFinder receiptFinder,
            IBlockValidator blockValidator,
            ISealValidator sealValidator,
            ISyncPeerPool pool,
            ISyncModeSelector syncModeSelector,
            ISyncConfig syncConfig,
            ILogManager logManager,
            CanonicalHashTrie cht = null)
        {
            _syncConfig       = syncConfig ?? throw new ArgumentNullException(nameof(syncConfig));
            _pool             = pool ?? throw new ArgumentNullException(nameof(pool));
            _syncModeSelector = syncModeSelector ?? throw new ArgumentNullException(nameof(syncModeSelector));
            _sealValidator    = sealValidator ?? throw new ArgumentNullException(nameof(sealValidator));
            _stateDb          = stateDb ?? throw new ArgumentNullException(nameof(stateDb));
            _codeDb           = codeDb ?? throw new ArgumentNullException(nameof(codeDb));
            _blockTree        = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
            _receiptFinder    = receiptFinder ?? throw new ArgumentNullException(nameof(receiptFinder));
            _blockValidator   = blockValidator ?? throw new ArgumentNullException(nameof(blockValidator));
            _logger           = logManager.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
            _cht         = cht;
            _pivotNumber = _syncConfig.PivotNumberParsed;

            _blockTree.NewHeadBlock += OnNewHeadBlock;
            _pivotHash = new Keccak(_syncConfig.PivotHash ?? Keccak.Zero.ToString());
        }
Exemplo n.º 3
0
        public Ledger(IDeltaExecutor deltaExecutor,
                      IStateProvider stateProvider,
                      IStorageProvider storageProvider,
                      ISnapshotableDb stateDb,
                      ISnapshotableDb codeDb,
                      IAccountRepository accounts,
                      IDeltaHashProvider deltaHashProvider,
                      ILedgerSynchroniser synchroniser,
                      IMempool <PublicEntryDao> mempool,
                      IMapperProvider mapperProvider,
                      ILogger logger)
        {
            Accounts         = accounts;
            _deltaExecutor   = deltaExecutor;
            _stateProvider   = stateProvider;
            _storageProvider = storageProvider;
            _stateDb         = stateDb;
            _codeDb          = codeDb;
            _synchroniser    = synchroniser;
            _mempool         = mempool;
            _mapperProvider  = mapperProvider;
            _logger          = logger;

            _deltaUpdatesSubscription = deltaHashProvider.DeltaHashUpdates.Subscribe(Update);
            LatestKnownDelta          = _synchroniser.DeltaCache.GenesisHash;
        }
Exemplo n.º 4
0
        public RocksDbProvider(string dbBasePath, ILogManager logManager, IDbConfig dbConfig)
        {
            _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));

            _stateDb = new SnapshotableDb(new DbOnTheRocks(Path.Combine(dbBasePath, DbOnTheRocks.StateDbPath), dbConfig));
            _codeDb  = new SnapshotableDb(new DbOnTheRocks(Path.Combine(dbBasePath, DbOnTheRocks.CodeDbPath), dbConfig));
        }
Exemplo n.º 5
0
 public BlockProcessor(ISpecProvider specProvider,
                       IBlockValidator blockValidator,
                       IRewardCalculator rewardCalculator,
                       ITransactionProcessor transactionProcessor,
                       ISnapshotableDb stateDb,
                       ISnapshotableDb codeDb,
                       IStateProvider stateProvider,
                       IStorageProvider storageProvider,
                       ITxPool txPool,
                       IReceiptStorage receiptStorage,
                       ILogManager logManager)
 {
     _logger               = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
     _specProvider         = specProvider ?? throw new ArgumentNullException(nameof(specProvider));
     _blockValidator       = blockValidator ?? throw new ArgumentNullException(nameof(blockValidator));
     _stateProvider        = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider));
     _storageProvider      = storageProvider ?? throw new ArgumentNullException(nameof(storageProvider));
     _txPool               = txPool ?? throw new ArgumentNullException(nameof(txPool));
     _receiptStorage       = receiptStorage ?? throw new ArgumentNullException(nameof(receiptStorage));
     _rewardCalculator     = rewardCalculator ?? throw new ArgumentNullException(nameof(rewardCalculator));
     _transactionProcessor = transactionProcessor ?? throw new ArgumentNullException(nameof(transactionProcessor));
     _stateDb              = stateDb ?? throw new ArgumentNullException(nameof(stateDb));
     _codeDb               = codeDb ?? throw new ArgumentNullException(nameof(codeDb));
     _receiptsTracer       = new BlockReceiptsTracer();
 }
Exemplo n.º 6
0
 public void Setup()
 {
     _stateDb           = new StateDb();
     _codeDb            = new StateDb();
     _blockhashProvider = new TestBlockhashProvider();
     _stateProvider     = new StateProvider(_stateDb, _codeDb, _logManager);
     _storageProvider   = new StorageProvider(_stateDb, _stateProvider, _logManager);
 }
Exemplo n.º 7
0
 public void Setup()
 {
     _stateDb           = new StateDb();
     _codeDb            = new StateDb();
     _blockhashProvider = new TestBlockhashProvider();
     _specProvider      = OlympicSpecProvider.Instance;;
     _stateProvider     = new StateProvider(_stateDb, _codeDb, _logManager);
     _storageProvider   = new StorageProvider(_stateDb, _stateProvider, _logManager);
 }
Exemplo n.º 8
0
 public StateReader(ISnapshotableDb stateDb, IDb codeDb, ILogManager logManager)
 {
     if (stateDb == null)
     {
         throw new ArgumentNullException(nameof(stateDb));
     }
     _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
     _codeDb = codeDb ?? throw new ArgumentNullException(nameof(codeDb));
     _state  = new StateTree(stateDb);
 }
Exemplo n.º 9
0
        public SyncServer(ISnapshotableDb stateDb, ISnapshotableDb codeDb, IBlockTree blockTree, IReceiptStorage receiptStorage, ISealValidator sealValidator, IEthSyncPeerPool pool, ISynchronizer synchronizer, ILogManager logManager)
        {
            _synchronizer   = synchronizer ?? throw new ArgumentNullException(nameof(synchronizer));
            _pool           = pool ?? throw new ArgumentNullException(nameof(pool));
            _sealValidator  = sealValidator ?? throw new ArgumentNullException(nameof(sealValidator));
            _stateDb        = stateDb ?? throw new ArgumentNullException(nameof(stateDb));
            _codeDb         = codeDb ?? throw new ArgumentNullException(nameof(codeDb));
            _blockTree      = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
            _receiptStorage = receiptStorage ?? throw new ArgumentNullException(nameof(receiptStorage));
            _logger         = logManager.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));

            _blockTree.NewHeadBlock += OnNewHeadBlock;
        }
Exemplo n.º 10
0
 public HiveRunner(IJsonSerializer jsonSerializer, IBlockchainProcessor blockchainProcessor,
                   IBlockTree blockTree, IStateProvider stateProvider, ISnapshotableDb stateDb, ILogger logger,
                   IConfigProvider configurationProvider, ISpecProvider specProvider, HiveWallet wallet)
 {
     _jsonSerializer      = jsonSerializer;
     _blockchainProcessor = blockchainProcessor;
     _blockTree           = blockTree;
     _stateProvider       = stateProvider;
     _stateDb             = stateDb;
     _logger = logger;
     _configurationProvider = configurationProvider;
     _specProvider          = specProvider;
     _wallet = wallet;
 }
Exemplo n.º 11
0
        public virtual void Setup()
        {
            ILogManager logger = LimboLogs.Instance;;
            IDb         codeDb = new StateDb();

            _stateDb       = new StateDb();
            TestState      = new StateProvider(_stateDb, codeDb, logger);
            Storage        = new StorageProvider(_stateDb, TestState, logger);
            _ethereumEcdsa = new EthereumEcdsa(SpecProvider, logger);
            IBlockhashProvider blockhashProvider = new TestBlockhashProvider();

            Machine    = new VirtualMachine(TestState, Storage, blockhashProvider, SpecProvider, logger);
            _processor = new TransactionProcessor(SpecProvider, TestState, Storage, Machine, logger);
        }
Exemplo n.º 12
0
        public RpcState(IBlockTree blockTree, ISpecProvider specProvider, IReadOnlyDbProvider readOnlyDbProvider, ILogManager logManager)
        {
            ISnapshotableDb stateDb = readOnlyDbProvider.StateDb;
            IDb             codeDb  = readOnlyDbProvider.CodeDb;

            StateReader     = new StateReader(stateDb, codeDb, logManager);
            StateProvider   = new StateProvider(stateDb, codeDb, logManager);
            StorageProvider = new StorageProvider(stateDb, StateProvider, logManager);

            BlockTree         = new ReadOnlyBlockTree(blockTree);
            BlockhashProvider = new BlockhashProvider(BlockTree, logManager);

            VirtualMachine       = new VirtualMachine(StateProvider, StorageProvider, BlockhashProvider, logManager);
            TransactionProcessor = new TransactionProcessor(specProvider, StateProvider, StorageProvider, VirtualMachine, logManager);
        }
Exemplo n.º 13
0
        public StateSyncFeed(ISnapshotableDb codeDb, ISnapshotableDb stateDb, IDb tempDb, ISyncModeSelector syncModeSelector, IBlockTree blockTree, ILogManager logManager)
            : base(logManager)
        {
            _codeDb                    = codeDb?.Innermost ?? throw new ArgumentNullException(nameof(codeDb));
            _stateDb                   = stateDb?.Innermost ?? throw new ArgumentNullException(nameof(stateDb));
            _tempDb                    = tempDb ?? throw new ArgumentNullException(nameof(tempDb));
            _blockTree                 = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
            _syncModeSelector          = syncModeSelector ?? throw new ArgumentNullException(nameof(syncModeSelector));
            _syncModeSelector.Changed += SyncModeSelectorOnChanged;

            _logger = logManager.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));

            byte[] progress = _codeDb.Get(_fastSyncProgressKey);
            _data         = new DetailedProgress(_blockTree.ChainId, progress);
            _pendingItems = new PendingSyncItems();
        }
Exemplo n.º 14
0
        public VirtualMachineTestsBase()
        {
            ILogManager logger = LimboLogs.Instance;;
            IDb         codeDb = new StateDb();

            _stateDb = new StateDb();
            StateTree stateTree = new StateTree(_stateDb);

            TestState       = new StateProvider(stateTree, codeDb, logger);
            Storage         = new StorageProvider(_stateDb, TestState, logger);
            _ethereumSigner = new EthereumSigner(SpecProvider, logger);
            IBlockhashProvider blockhashProvider = new TestBlockhashProvider();
            IVirtualMachine    virtualMachine    = new VirtualMachine(TestState, Storage, blockhashProvider, logger);

            _processor = new TransactionProcessor(SpecProvider, TestState, Storage, virtualMachine, logger);
        }
Exemplo n.º 15
0
        public virtual void Setup()
        {
            ILogManager logger = LimboLogs.Instance;

            ISnapshotableDb beamSyncDb     = new StateDb(new BeamSyncDb(new MemDb(), LimboLogs.Instance));
            IDb             beamSyncCodeDb = new BeamSyncDb(new MemDb(), LimboLogs.Instance);
            IDb             codeDb         = UseBeamSync ? beamSyncCodeDb : new StateDb();

            _stateDb       = UseBeamSync ? beamSyncDb : new StateDb();
            TestState      = new StateProvider(_stateDb, codeDb, logger);
            Storage        = new StorageProvider(_stateDb, TestState, logger);
            _ethereumEcdsa = new EthereumEcdsa(SpecProvider, logger);
            IBlockhashProvider blockhashProvider = TestBlockhashProvider.Instance;

            Machine    = new VirtualMachine(TestState, Storage, blockhashProvider, SpecProvider, logger);
            _processor = new TransactionProcessor(SpecProvider, TestState, Storage, Machine, logger);
        }
Exemplo n.º 16
0
 public AuRaBlockProcessor(
     ISpecProvider specProvider,
     IBlockValidator blockValidator,
     IRewardCalculator rewardCalculator,
     ITransactionProcessor transactionProcessor,
     ISnapshotableDb stateDb,
     ISnapshotableDb codeDb,
     IStateProvider stateProvider,
     IStorageProvider storageProvider,
     ITxPool txPool,
     IReceiptStorage receiptStorage,
     ILogManager logManager,
     IAuRaBlockProcessorExtension auRaBlockProcessorExtension)
     : base(specProvider, blockValidator, rewardCalculator, transactionProcessor, stateDb, codeDb, stateProvider, storageProvider, txPool, receiptStorage, logManager)
 {
     _auRaBlockProcessorExtension = auRaBlockProcessorExtension ?? throw new ArgumentNullException(nameof(auRaBlockProcessorExtension));
 }
Exemplo n.º 17
0
        public Ledger(IDeltaExecutor deltaExecutor,
                      IStateProvider stateProvider,
                      IStorageProvider storageProvider,
                      ISnapshotableDb stateDb,
                      IDb codeDb,
                      IAccountRepository accounts,
                      IDeltaIndexService deltaIndexService,
                      ITransactionRepository receipts,
                      IDeltaHashProvider deltaHashProvider,
                      ISynchroniser synchroniser,
                      IMempool <PublicEntryDao> mempool,
                      IMapperProvider mapperProvider,
                      IHashProvider hashProvider,
                      ILogger logger)
        {
            Accounts         = accounts;
            _deltaExecutor   = deltaExecutor;
            _stateProvider   = stateProvider;
            _storageProvider = storageProvider;

            _stateDb        = stateDb;
            _codeDb         = codeDb;
            _mempool        = mempool;
            _mapperProvider = mapperProvider;
            _hashProvider   = hashProvider;
            _logger         = logger;
            _receipts       = receipts;
            _synchroniser   = synchroniser;

            _deltaUpdatesSubscription = deltaHashProvider.DeltaHashUpdates.Subscribe(Update);

            _deltaIndexService = deltaIndexService;

            var latestDeltaIndex = _deltaIndexService.LatestDeltaIndex();

            if (latestDeltaIndex != null)
            {
                _latestKnownDelta       = latestDeltaIndex.Cid;
                _latestKnownDeltaNumber = (long)latestDeltaIndex.Height;
                return;
            }

            _latestKnownDelta = _synchroniser.DeltaCache.GenesisHash;
            WriteLatestKnownDelta(_latestKnownDelta);
        }
Exemplo n.º 18
0
        public VirtualMachineTestsBase()
        {
            SpecProvider = RopstenSpecProvider.Instance;
            ILogManager logger = NullLogManager.Instance;
            IDb         codeDb = new MemDb();

            _stateDb = new SnapshotableDb(new MemDb());
            StateTree stateTree = new StateTree(_stateDb);

            TestState          = new StateProvider(stateTree, codeDb, logger);
            _storageDbProvider = new MemDbProvider(logger);
            Storage            = new StorageProvider(_storageDbProvider, TestState, logger);
            _ethereumSigner    = new EthereumSigner(SpecProvider, logger);
            IBlockhashProvider blockhashProvider = new TestBlockhashProvider();
            IVirtualMachine    virtualMachine    = new VirtualMachine(TestState, Storage, blockhashProvider, logger);

            _processor = new TransactionProcessor(SpecProvider, TestState, Storage, virtualMachine, this, logger);
        }
Exemplo n.º 19
0
        public ReadOnlyTxProcessingEnv(
            IReadOnlyDbProvider readOnlyDbProvider,
            ReadOnlyBlockTree readOnlyBlockTree,
            ISpecProvider specProvider,
            ILogManager logManager)
        {
            DbProvider = readOnlyDbProvider;
            ISnapshotableDb stateDb = readOnlyDbProvider.StateDb;
            IDb             codeDb  = readOnlyDbProvider.CodeDb;

            StateReader     = new StateReader(stateDb, codeDb, logManager);
            StateProvider   = new StateProvider(stateDb, codeDb, logManager);
            StorageProvider = new StorageProvider(stateDb, StateProvider, logManager);

            BlockTree         = readOnlyBlockTree;
            BlockhashProvider = new BlockhashProvider(BlockTree, logManager);

            VirtualMachine       = new VirtualMachine(StateProvider, StorageProvider, BlockhashProvider, specProvider, logManager);
            TransactionProcessor = new TransactionProcessor(specProvider, StateProvider, StorageProvider, VirtualMachine, logManager);
        }
Exemplo n.º 20
0
        public DeltaCache(IHashProvider hashProvider,
                          IMemoryCache memoryCache,
                          IDeltaDfsReader dfsReader,
                          IDeltaCacheChangeTokenProvider changeTokenProvider,
                          IStorageProvider storageProvider,
                          IStateProvider stateProvider,
                          ISnapshotableDb stateDb,
                          IDeltaIndexService deltaIndexService,
                          ILogger logger)
        {
            _deltaIndexService = deltaIndexService;

            stateProvider.CreateAccount(TruffleTestAccount, 1_000_000_000.Kat());
            stateProvider.CreateAccount(CatalystTruffleTestAccount, 1_000_000_000.Kat());

            storageProvider.Commit();
            stateProvider.Commit(CatalystGenesisSpec.Instance);

            storageProvider.CommitTrees();
            stateProvider.CommitTree();

            stateDb.Commit();

            var genesisDelta = new Delta
            {
                TimeStamp = Timestamp.FromDateTime(DateTime.UnixEpoch),
                StateRoot = ByteString.CopyFrom(stateProvider.StateRoot.Bytes),
            };


            GenesisHash = hashProvider.ComputeMultiHash(genesisDelta).ToCid();

            _dfsReader    = dfsReader;
            _logger       = logger;
            _entryOptions = () => new MemoryCacheEntryOptions()
                            .AddExpirationToken(changeTokenProvider.GetChangeToken())
                            .RegisterPostEvictionCallback(EvictionCallback);

            _memoryCache = memoryCache;
            _memoryCache.Set(GenesisHash, genesisDelta);
        }
Exemplo n.º 21
0
 public AuRaBlockProcessor(
     ISpecProvider specProvider,
     IBlockValidator blockValidator,
     IRewardCalculator rewardCalculator,
     ITransactionProcessor transactionProcessor,
     ISnapshotableDb stateDb,
     ISnapshotableDb codeDb,
     IStateProvider stateProvider,
     IStorageProvider storageProvider,
     ITxPool txPool,
     IReceiptStorage receiptStorage,
     ILogManager logManager,
     IBlockTree blockTree,
     ITxPermissionFilter txFilter       = null,
     IGasLimitOverride gasLimitOverride = null)
     : base(specProvider, blockValidator, rewardCalculator, transactionProcessor, stateDb, codeDb, stateProvider, storageProvider, txPool, receiptStorage, logManager)
 {
     _blockTree        = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
     _logger           = logManager?.GetClassLogger <AuRaBlockProcessor>() ?? throw new ArgumentNullException(nameof(logManager));
     _txFilter         = txFilter ?? NullTxPermissionFilter.Instance;
     _gasLimitOverride = gasLimitOverride;
 }
Exemplo n.º 22
0
        public BlockProcessor(ISpecProvider specProvider,
                              IBlockValidator blockValidator,
                              IRewardCalculator rewardCalculator,
                              ITransactionProcessor transactionProcessor,
                              ISnapshotableDb stateDb,
                              ISnapshotableDb codeDb,
                              IDb traceDb,
                              IStateProvider stateProvider,
                              IStorageProvider storageProvider,
                              ITxPool txPool,
                              IReceiptStorage receiptStorage,
                              ILogManager logManager,
                              IEnumerable <IAdditionalBlockProcessor> additionalBlockProcessors = null)
        {
            _logger               = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
            _specProvider         = specProvider ?? throw new ArgumentNullException(nameof(specProvider));
            _blockValidator       = blockValidator ?? throw new ArgumentNullException(nameof(blockValidator));
            _stateProvider        = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider));
            _storageProvider      = storageProvider ?? throw new ArgumentNullException(nameof(storageProvider));
            _txPool               = txPool ?? throw new ArgumentNullException(nameof(txPool));
            _receiptStorage       = receiptStorage ?? throw new ArgumentNullException(nameof(receiptStorage));
            _rewardCalculator     = rewardCalculator ?? throw new ArgumentNullException(nameof(rewardCalculator));
            _transactionProcessor = transactionProcessor ?? throw new ArgumentNullException(nameof(transactionProcessor));
            _stateDb              = stateDb ?? throw new ArgumentNullException(nameof(stateDb));
            _codeDb               = codeDb ?? throw new ArgumentNullException(nameof(codeDb));
            _traceDb              = traceDb ?? throw new ArgumentNullException(nameof(traceDb));
            _receiptsTracer       = new BlockReceiptsTracer(_specProvider, _stateProvider);

            if (additionalBlockProcessors != null)
            {
                var additionalBlockProcessorsArray = additionalBlockProcessors.ToArray();
                if (additionalBlockProcessorsArray.Length > 0)
                {
                    _additionalBlockProcessor = additionalBlockProcessorsArray.Length == 1
                        ? additionalBlockProcessorsArray[0]
                        : new CompositeAdditionalBlockProcessor(additionalBlockProcessorsArray);
                }
            }
        }
Exemplo n.º 23
0
            public SyncingContext(SynchronizerType synchronizerType)
            {
                _logger = _logManager.GetClassLogger();
                ISyncConfig     syncConfig  = synchronizerType == SynchronizerType.Fast ? SyncConfig.WithFastSync : SyncConfig.WithFullSyncOnly;
                MemDbProvider   dbProvider  = new MemDbProvider();
                ISnapshotableDb stateDb     = dbProvider.StateDb;
                ISnapshotableDb codeDb      = dbProvider.CodeDb;
                MemDb           blockInfoDb = new MemDb();

                BlockTree = new BlockTree(new MemDb(), new MemDb(), blockInfoDb, new ChainLevelInfoRepository(blockInfoDb), new SingleReleaseSpecProvider(Constantinople.Instance, 1), NullBloomStorage.Instance, _logManager);
                NodeStatsManager stats = new NodeStatsManager(_logManager);

                SyncPeerPool = new SyncPeerPool(BlockTree, stats, 25, _logManager);

                SyncProgressResolver  syncProgressResolver = new SyncProgressResolver(BlockTree, NullReceiptStorage.Instance, stateDb, new MemDb(), syncConfig, _logManager);
                MultiSyncModeSelector syncModeSelector     = new MultiSyncModeSelector(syncProgressResolver, SyncPeerPool, syncConfig, _logManager);

                Synchronizer = new Synchronizer(
                    dbProvider,
                    MainnetSpecProvider.Instance,
                    BlockTree,
                    NullReceiptStorage.Instance,
                    Always.Valid,
                    Always.Valid,
                    SyncPeerPool,
                    stats,
                    syncModeSelector,
                    syncConfig,
                    _logManager);

                SyncServer = new SyncServer(stateDb, codeDb, BlockTree, NullReceiptStorage.Instance, Always.Valid, Always.Valid, SyncPeerPool, syncModeSelector, syncConfig, _logManager);
                SyncPeerPool.Start();

                Synchronizer.Start();
                Synchronizer.SyncEvent += SynchronizerOnSyncEvent;

                AllInstances.Add(this);
            }
Exemplo n.º 24
0
        private SyncTestContext CreateSyncManager(int index)
        {
            var logManager            = NoErrorLimboLogs.Instance;
            ConsoleAsyncLogger logger = new ConsoleAsyncLogger(LogLevel.Debug, "PEER " + index + " ");
//            var logManager = new OneLoggerLogManager(logger);
            var specProvider = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, MainnetSpecProvider.Instance.ChainId);

            var             dbProvider  = TestMemDbProvider.Init();
            IDb             blockDb     = dbProvider.BlocksDb;
            IDb             headerDb    = dbProvider.HeadersDb;
            IDb             blockInfoDb = dbProvider.BlockInfosDb;
            ISnapshotableDb codeDb      = dbProvider.CodeDb;
            ISnapshotableDb stateDb     = dbProvider.StateDb;

            var stateReader   = new StateReader(stateDb, codeDb, logManager);
            var stateProvider = new StateProvider(stateDb, codeDb, logManager);

            stateProvider.CreateAccount(TestItem.AddressA, 10000.Ether());
            stateProvider.Commit(specProvider.GenesisSpec);
            stateProvider.CommitTree();
            stateProvider.RecalculateStateRoot();
            stateDb.Commit();

            var storageProvider = new StorageProvider(stateDb, stateProvider, logManager);
            var receiptStorage  = new InMemoryReceiptStorage();

            var ecdsa             = new EthereumEcdsa(specProvider.ChainId, logManager);
            var txPool            = new TxPool.TxPool(new InMemoryTxStorage(), ecdsa, specProvider, new TxPoolConfig(), stateProvider, logManager);
            var tree              = new BlockTree(blockDb, headerDb, blockInfoDb, new ChainLevelInfoRepository(blockInfoDb), specProvider, NullBloomStorage.Instance, logManager);
            var blockhashProvider = new BlockhashProvider(tree, LimboLogs.Instance);
            var virtualMachine    = new VirtualMachine(stateProvider, storageProvider, blockhashProvider, specProvider, logManager);

            var sealValidator   = Always.Valid;
            var headerValidator = new HeaderValidator(tree, sealValidator, specProvider, logManager);
            var txValidator     = Always.Valid;
            var ommersValidator = new OmmersValidator(tree, headerValidator, logManager);
            var blockValidator  = new BlockValidator(txValidator, headerValidator, ommersValidator, specProvider, logManager);

            ISyncConfig syncConfig = _synchronizerType == SynchronizerType.Fast ? SyncConfig.WithFastSync : SyncConfig.WithFullSyncOnly;

            var rewardCalculator = new RewardCalculator(specProvider);
            var txProcessor      = new TransactionProcessor(specProvider, stateProvider, storageProvider, virtualMachine, logManager);
            var blockProcessor   = new BlockProcessor(specProvider, blockValidator, rewardCalculator, txProcessor, stateDb, codeDb, stateProvider, storageProvider, txPool, receiptStorage, logManager);

            var step      = new RecoverSignatures(ecdsa, txPool, specProvider, logManager);
            var processor = new BlockchainProcessor(tree, blockProcessor, step, logManager, BlockchainProcessor.Options.Default);

            var nodeStatsManager = new NodeStatsManager(logManager);
            var syncPeerPool     = new SyncPeerPool(tree, nodeStatsManager, 25, logManager);

            StateProvider   devState            = new StateProvider(stateDb, codeDb, logManager);
            StorageProvider devStorage          = new StorageProvider(stateDb, devState, logManager);
            var             devEvm              = new VirtualMachine(devState, devStorage, blockhashProvider, specProvider, logManager);
            var             devTxProcessor      = new TransactionProcessor(specProvider, devState, devStorage, devEvm, logManager);
            var             devBlockProcessor   = new BlockProcessor(specProvider, blockValidator, rewardCalculator, devTxProcessor, stateDb, codeDb, devState, devStorage, txPool, receiptStorage, logManager);
            var             devChainProcessor   = new BlockchainProcessor(tree, devBlockProcessor, step, logManager, BlockchainProcessor.Options.NoReceipts);
            var             transactionSelector = new TxPoolTxSource(txPool, stateReader, logManager);
            var             producer            = new DevBlockProducer(
                transactionSelector,
                devChainProcessor,
                stateProvider, tree,
                processor,
                txPool,
                Timestamper.Default,
                logManager);

            SyncProgressResolver  resolver     = new SyncProgressResolver(tree, receiptStorage, stateDb, new MemDb(), syncConfig, logManager);
            MultiSyncModeSelector selector     = new MultiSyncModeSelector(resolver, syncPeerPool, syncConfig, logManager);
            Synchronizer          synchronizer = new Synchronizer(
                dbProvider,
                MainnetSpecProvider.Instance,
                tree,
                NullReceiptStorage.Instance,
                blockValidator,
                sealValidator,
                syncPeerPool,
                nodeStatsManager,
                StaticSelector.Full,
                syncConfig,
                logManager);
            var syncServer = new SyncServer(stateDb, codeDb, tree, receiptStorage, Always.Valid, Always.Valid, syncPeerPool, selector, syncConfig, logManager);

            ManualResetEventSlim waitEvent = new ManualResetEventSlim();

            tree.NewHeadBlock += (s, e) => waitEvent.Set();

            if (index == 0)
            {
                _genesis = Build.A.Block.Genesis.WithStateRoot(stateProvider.StateRoot).TestObject;
                producer.Start();
            }

            syncPeerPool.Start();
            synchronizer.Start();
            processor.Start();
            tree.SuggestBlock(_genesis);

            if (!waitEvent.Wait(1000))
            {
                throw new Exception("No genesis");
            }

            SyncTestContext context = new SyncTestContext();

            context.Ecdsa = ecdsa;
            context.BlockchainProcessor = processor;
            context.PeerPool            = syncPeerPool;
            context.StateProvider       = stateProvider;
            context.Synchronizer        = synchronizer;
            context.SyncServer          = syncServer;
            context.Tree          = tree;
            context.BlockProducer = producer;
            context.TxPool        = txPool;
            context.Logger        = logger;
            return(context);
        }
Exemplo n.º 25
0
        public void GlobalSetup()
        {
            var             dbProvider  = new MemDbProvider();
            ISnapshotableDb codeDb      = dbProvider.CodeDb;
            ISnapshotableDb stateDb     = dbProvider.StateDb;
            IDb             blockInfoDb = new MemDb(10, 5);

            ISpecProvider specProvider = MainnetSpecProvider.Instance;
            IReleaseSpec  spec         = MainnetSpecProvider.Instance.GenesisSpec;

            StateProvider stateProvider = new StateProvider(stateDb, codeDb, LimboLogs.Instance);

            stateProvider.CreateAccount(Address.Zero, 1000.Ether());
            stateProvider.Commit(spec);

            StorageProvider storageProvider = new StorageProvider(stateDb, stateProvider, LimboLogs.Instance);
            StateReader     stateReader     = new StateReader(stateDb, codeDb, LimboLogs.Instance);

            ChainLevelInfoRepository chainLevelInfoRepository = new ChainLevelInfoRepository(blockInfoDb);
            BlockTree blockTree = new BlockTree(dbProvider, chainLevelInfoRepository, specProvider, NullTxPool.Instance, NullBloomStorage.Instance, LimboLogs.Instance);

            _blockhashProvider = new BlockhashProvider(blockTree, LimboLogs.Instance);
            _virtualMachine    = new VirtualMachine(stateProvider, storageProvider, _blockhashProvider, specProvider, LimboLogs.Instance);

            Block genesisBlock = Build.A.Block.Genesis.TestObject;

            blockTree.SuggestBlock(genesisBlock);

            Block block1 = Build.A.Block.WithParent(genesisBlock).WithNumber(1).TestObject;

            blockTree.SuggestBlock(block1);

            TransactionProcessor transactionProcessor
                = new TransactionProcessor(MainnetSpecProvider.Instance, stateProvider, storageProvider, _virtualMachine, LimboLogs.Instance);

            BlockProcessor blockProcessor = new BlockProcessor(specProvider, Always.Valid, new RewardCalculator(specProvider), transactionProcessor,
                                                               stateDb, codeDb, stateProvider, storageProvider, NullTxPool.Instance, NullReceiptStorage.Instance, LimboLogs.Instance);

            EthereumEcdsa       ecdsa = new EthereumEcdsa(specProvider.ChainId, LimboLogs.Instance);
            BlockchainProcessor blockchainProcessor = new BlockchainProcessor(
                blockTree,
                blockProcessor,
                new TxSignaturesRecoveryStep(
                    ecdsa,
                    NullTxPool.Instance,
                    specProvider,
                    LimboLogs.Instance),
                LimboLogs.Instance,
                BlockchainProcessor.Options.NoReceipts);

            blockchainProcessor.Process(genesisBlock, ProcessingOptions.None, NullBlockTracer.Instance);
            blockchainProcessor.Process(block1, ProcessingOptions.None, NullBlockTracer.Instance);

            IBloomStorage bloomStorage = new BloomStorage(new BloomConfig(), new MemDb(), new InMemoryDictionaryFileStoreFactory());

            LogFinder logFinder = new LogFinder(
                blockTree,
                new InMemoryReceiptStorage(),
                bloomStorage,
                LimboLogs.Instance,
                new ReceiptsRecovery(ecdsa, specProvider));

            BlockchainBridge bridge = new BlockchainBridge(
                new ReadOnlyTxProcessingEnv(
                    new ReadOnlyDbProvider(dbProvider, false),
                    new ReadOnlyBlockTree(blockTree),
                    specProvider,
                    LimboLogs.Instance),
                NullTxPool.Instance,
                NullReceiptStorage.Instance,
                NullFilterStore.Instance,
                NullFilterManager.Instance,
                ecdsa,
                Timestamper.Default,
                logFinder,
                false,
                false);

            _ethModule = new EthModule(
                new JsonRpcConfig(),
                bridge,
                blockTree,
                stateReader,
                NullTxPool.Instance,
                NullTxSender.Instance,
                NullWallet.Instance,
                LimboLogs.Instance);
        }
Exemplo n.º 26
0
 public StorageProvider(ISnapshotableDb stateDb, IStateProvider stateProvider, ILogManager logManager)
 {
     _logger        = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
     _stateDb       = stateDb ?? throw new ArgumentNullException(nameof(stateDb));
     _stateProvider = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider));
 }
Exemplo n.º 27
0
        private AddNodeResult AddNode(StateSyncItem syncItem, DependentItem dependentItem, string reason, bool missing = false)
        {
            if (!missing)
            {
                if (_alreadySaved.Get(syncItem.Hash) != null)
                {
                    Interlocked.Increment(ref _checkWasCached);
                    if (_logger.IsTrace)
                    {
                        _logger.Trace($"Node already in the DB - skipping {syncItem.Hash}");
                    }
                    return(AddNodeResult.AlreadySaved);
                }

                object lockToTake = syncItem.NodeDataType == NodeDataType.Code ? _codeDbLock : _stateDbLock;
                lock (lockToTake)
                {
                    ISnapshotableDb dbToCheck = syncItem.NodeDataType == NodeDataType.Code ? _codeDb : _stateDb;
                    Interlocked.Increment(ref _dbChecks);
                    bool keyExists = dbToCheck.KeyExists(syncItem.Hash);
                    if (keyExists)
                    {
                        if (_logger.IsTrace)
                        {
                            _logger.Trace($"Node already in the DB - skipping {syncItem.Hash}");
                        }
                        _alreadySaved.Set(syncItem.Hash, _nullObject);
                        Interlocked.Increment(ref _stateWasThere);
                        return(AddNodeResult.AlreadySaved);
                    }

                    Interlocked.Increment(ref _stateWasNotThere);
                }

                bool isAlreadyRequested;
                lock (_dependencies)
                {
                    isAlreadyRequested = _dependencies.ContainsKey(syncItem.Hash);
                    if (dependentItem != null)
                    {
                        if (_logger.IsTrace)
                        {
                            _logger.Trace($"Adding dependency {syncItem.Hash} -> {dependentItem.SyncItem.Hash}");
                        }
                        AddDependency(syncItem.Hash, dependentItem);
                    }
                }

                /* same items can have same hashes and we only need them once
                 * there is an issue when we have an item, we add it to dependencies, then we request it and the request times out
                 * and we never request it again because it was already on the dependencies list */
                if (isAlreadyRequested)
                {
                    Interlocked.Increment(ref _checkWasInDependencies);
                    if (_logger.IsTrace)
                    {
                        _logger.Trace($"Node already requested - skipping {syncItem.Hash}");
                    }
                    return(AddNodeResult.AlreadyRequested);
                }
            }

            PushToSelectedStream(syncItem);
            if (_logger.IsTrace)
            {
                _logger.Trace($"Added a node {syncItem.Hash} - {reason}");
            }
            return(AddNodeResult.Added);
        }
Exemplo n.º 28
0
 public StateProvider(ISnapshotableDb stateDb, IDb codeDb, ILogManager logManager)
     : this(new StateTree(stateDb), codeDb, logManager)
 {
 }