public async Task Can_prepare_3_requests_in_a_row()
        {
            MemDbProvider       memDbProvider = new MemDbProvider();
            BlockTree           blockTree     = new BlockTree(memDbProvider.BlocksDb, memDbProvider.HeadersDb, memDbProvider.BlockInfosDb, new ChainLevelInfoRepository(memDbProvider.BlockInfosDb), MainnetSpecProvider.Instance, NullTxPool.Instance, NullBloomStorage.Instance, LimboLogs.Instance);
            FastHeadersSyncFeed feed          = new FastHeadersSyncFeed(blockTree, Substitute.For <ISyncPeerPool>(), new SyncConfig {
                FastSync = true, FastBlocks = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000"
            }, Substitute.For <ISyncReport>(), LimboLogs.Instance);
            HeadersSyncBatch batch1 = await feed.PrepareRequest();

            HeadersSyncBatch batch2 = await feed.PrepareRequest();

            HeadersSyncBatch batch3 = await feed.PrepareRequest();
        }
        public async Task Can_keep_returning_nulls_after_all_batches_were_prepared()
        {
            MemDbProvider       memDbProvider = new MemDbProvider();
            BlockTree           blockTree     = new BlockTree(memDbProvider.BlocksDb, memDbProvider.HeadersDb, memDbProvider.BlockInfosDb, new ChainLevelInfoRepository(memDbProvider.BlockInfosDb), MainnetSpecProvider.Instance, NullTxPool.Instance, NullBloomStorage.Instance, LimboLogs.Instance);
            FastHeadersSyncFeed feed          = new FastHeadersSyncFeed(blockTree, Substitute.For <ISyncPeerPool>(), new SyncConfig {
                FastSync = true, FastBlocks = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000"
            }, Substitute.For <ISyncReport>(), LimboLogs.Instance);

            for (int i = 0; i < 10; i++)
            {
                await feed.PrepareRequest();
            }

            var result = await feed.PrepareRequest();

            result.Should().BeNull();
        }
        public async Task Finishes_when_all_downloaded()
        {
            IBlockTree blockTree = Substitute.For <IBlockTree>();

            blockTree.LowestInsertedHeader.Returns(Build.A.BlockHeader.WithNumber(1000).TestObject);
            ISyncReport report = Substitute.For <ISyncReport>();

            report.HeadersInQueue.Returns(new MeasuredProgress());
            MeasuredProgress measuredProgress = new MeasuredProgress();

            report.FastBlocksHeaders.Returns(measuredProgress);
            FastHeadersSyncFeed feed = new FastHeadersSyncFeed(blockTree, Substitute.For <ISyncPeerPool>(), new SyncConfig {
                FastSync = true, FastBlocks = true, PivotNumber = "1000", PivotHash = Keccak.Zero.ToString(), PivotTotalDifficulty = "1000"
            }, report, LimboLogs.Instance);
            await feed.PrepareRequest();

            blockTree.LowestInsertedHeader.Returns(Build.A.BlockHeader.WithNumber(1).TestObject);
            var result = await feed.PrepareRequest();

            result.Should().BeNull();
            feed.CurrentState.Should().Be(SyncFeedState.Finished);
            measuredProgress.HasEnded.Should().BeTrue();
        }
Example #4
0
        private void StartFastBlocksComponents()
        {
            FastBlocksPeerAllocationStrategyFactory fastFactory = new FastBlocksPeerAllocationStrategyFactory();

            _headersFeed = new FastHeadersSyncFeed(_blockTree, _syncPeerPool, _syncConfig, _syncReport, _logManager);
            HeadersSyncDispatcher headersDispatcher = new HeadersSyncDispatcher(_headersFeed, _syncPeerPool, fastFactory, _logManager);
            Task headersTask = headersDispatcher.Start(_syncCancellation.Token).ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    if (_logger.IsError)
                    {
                        _logger.Error("Fast blocks headers downloader failed", t.Exception);
                    }
                }
                else
                {
                    if (_logger.IsInfo)
                    {
                        _logger.Info("Fast blocks headers task completed.");
                    }
                }
            });

            if (_syncConfig.DownloadHeadersInFastSync)
            {
                if (_syncConfig.DownloadBodiesInFastSync)
                {
                    _bodiesFeed = new FastBodiesSyncFeed(_blockTree, _syncPeerPool, _syncConfig, _syncReport, _logManager);
                    BodiesSyncDispatcher bodiesDispatcher = new BodiesSyncDispatcher(_bodiesFeed, _syncPeerPool, fastFactory, _logManager);
                    Task bodiesTask = bodiesDispatcher.Start(_syncCancellation.Token).ContinueWith(t =>
                    {
                        if (t.IsFaulted)
                        {
                            if (_logger.IsError)
                            {
                                _logger.Error("Fast bodies sync failed", t.Exception);
                            }
                        }
                        else
                        {
                            if (_logger.IsInfo)
                            {
                                _logger.Info("Fast blocks bodies task completed.");
                            }
                        }
                    });
                }

                if (_syncConfig.DownloadReceiptsInFastSync)
                {
                    FastReceiptsSyncFeed   receiptsFeed       = new FastReceiptsSyncFeed(_specProvider, _blockTree, _receiptStorage, _syncPeerPool, _syncConfig, _syncReport, _logManager);
                    ReceiptsSyncDispatcher receiptsDispatcher = new ReceiptsSyncDispatcher(receiptsFeed, _syncPeerPool, fastFactory, _logManager);
                    Task receiptsTask = receiptsDispatcher.Start(_syncCancellation.Token).ContinueWith(t =>
                    {
                        if (t.IsFaulted)
                        {
                            if (_logger.IsError)
                            {
                                _logger.Error("Fast receipts sync failed", t.Exception);
                            }
                        }
                        else
                        {
                            if (_logger.IsInfo)
                            {
                                _logger.Info("Fast blocks receipts task completed.");
                            }
                        }
                    });
                }
            }
        }