private void SetDefaults()
                {
                    SyncPeerPool = Substitute.For <ISyncPeerPool>();
                    var peerInfos = _peers.Select(p => new PeerInfo(p));

                    SyncPeerPool.InitializedPeers.Returns(peerInfos);
                    SyncPeerPool.AllPeers.Returns(peerInfos);

                    SyncProgressResolver = Substitute.For <ISyncProgressResolver>();
                    SyncProgressResolver.ChainDifficulty.Returns(ValidGenesis.TotalDifficulty ?? 0);
                    SyncProgressResolver.FindBestHeader().Returns(0);
                    SyncProgressResolver.FindBestFullBlock().Returns(0);
                    SyncProgressResolver.FindBestFullState().Returns(0);
                    SyncProgressResolver.IsLoadingBlocksFromDb().Returns(false);
                    SyncProgressResolver.IsFastBlocksFinished().Returns(false);

                    SyncConfig.FastSync                   = false;
                    SyncConfig.FastBlocks                 = false;
                    SyncConfig.BeamSync                   = false;
                    SyncConfig.PivotNumber                = Pivot.Number.ToString();
                    SyncConfig.PivotHash                  = Keccak.Zero.ToString();
                    SyncConfig.SynchronizationEnabled     = true;
                    SyncConfig.DownloadBodiesInFastSync   = true;
                    SyncConfig.DownloadReceiptsInFastSync = true;
                    SyncConfig.FastSyncCatchUpHeightDelta = FastSyncCatchUpHeightDelta;
                }
示例#2
0
        public void Receipts_finish_properly_when_the_last_batch_has_no_receipts()
        {
            _syncConfig                            = new SyncConfig();
            _syncConfig.PivotHash                  = _validTree2048NoTransactions.Head.Hash.ToString();
            _syncConfig.PivotNumber                = _validTree2048NoTransactions.Head.Number.ToString();
            _syncConfig.PivotTotalDifficulty       = _validTree2048NoTransactions.Head.TotalDifficulty.ToString();
            _syncConfig.UseGethLimitsInFastBlocks  = false;
            _syncConfig.DownloadBodiesInFastSync   = true;
            _syncConfig.DownloadReceiptsInFastSync = true;
            _syncConfig.FastBlocks                 = true;

            _feed = new FastBlocksFeed(_specProvider, _localBlockTree, _localReceiptStorage, _syncPeerPool, _syncConfig, NullSyncReport.Instance, LimboLogs.Instance);

            LatencySyncPeerMock syncPeer1 = new LatencySyncPeerMock(_validTree2048NoTransactions);

            SetupSyncPeers(syncPeer1);

            RunFeed(10000);

            SyncProgressResolver resolver = new SyncProgressResolver(
                _localBlockTree,
                _localReceiptStorage,
                Substitute.For <INodeDataDownloader>(),
                _syncConfig,
                LimboLogs.Instance);

            Assert.True(resolver.IsFastBlocksFinished(), "is fast blocks finished");

            AssertTreeSynced(_validTree2048NoTransactions, true, true);
        }
示例#3
0
        public void Is_fast_block_finished_returns_true_when_no_fast_block_sync_is_used()
        {
            IBlockTree          blockTree          = Substitute.For <IBlockTree>();
            IReceiptStorage     receiptStorage     = Substitute.For <IReceiptStorage>();
            INodeDataDownloader nodeDataDownloader = Substitute.For <INodeDataDownloader>();
            SyncConfig          syncConfig         = new SyncConfig();

            syncConfig.FastBlocks = false;

            SyncProgressResolver syncProgressResolver = new SyncProgressResolver(blockTree, receiptStorage, nodeDataDownloader, syncConfig, LimboLogs.Instance);

            Assert.True(syncProgressResolver.IsFastBlocksFinished());
        }
示例#4
0
        public void Is_fast_block_finished_returns_true_when_no_fast_block_sync_is_used()
        {
            IBlockTree      blockTree      = Substitute.For <IBlockTree>();
            IReceiptStorage receiptStorage = Substitute.For <IReceiptStorage>();
            IDb             stateDb        = new MemDb();
            SyncConfig      syncConfig     = new SyncConfig();

            syncConfig.FastBlocks  = false;
            syncConfig.PivotNumber = "1";

            SyncProgressResolver syncProgressResolver = new SyncProgressResolver(blockTree, receiptStorage, stateDb, new MemDb(), syncConfig, LimboLogs.Instance);

            Assert.True(syncProgressResolver.IsFastBlocksFinished());
        }
 public ScenarioBuilder IfThisNodeFinishedFastBlocksButNotFastSync()
 {
     _syncProgressSetups.Add(
         () =>
     {
         SyncProgressResolver.FindBestHeader().Returns(Pivot.Number + 16);
         SyncProgressResolver.FindBestFullBlock().Returns(0);
         SyncProgressResolver.FindBestFullState().Returns(0);
         SyncProgressResolver.FindBestProcessedBlock().Returns(0);
         SyncProgressResolver.IsFastBlocksFinished().Returns(true);
         SyncProgressResolver.ChainDifficulty.Returns(UInt256.Zero);
         return("mid fast sync");
     }
         );
     return(this);
 }
 public ScenarioBuilder IfThisNodeJustFinishedStateSyncButNeedsToCatchUpToHeaders()
 {
     _syncProgressSetups.Add(
         () =>
     {
         SyncProgressResolver.FindBestHeader().Returns(ChainHead.Number - MultiSyncModeSelector.FastSyncLag);
         SyncProgressResolver.FindBestFullBlock().Returns(0);
         SyncProgressResolver.FindBestFullState().Returns(ChainHead.Number - MultiSyncModeSelector.FastSyncLag - 7);
         SyncProgressResolver.FindBestProcessedBlock().Returns(0);
         SyncProgressResolver.IsFastBlocksFinished().Returns(true);
         SyncProgressResolver.ChainDifficulty.Returns(UInt256.Zero);
         return("just finished state sync and needs to catch up");
     }
         );
     return(this);
 }
 public ScenarioBuilder IfThisNodeJustFinishedFastBlocksAndFastSync()
 {
     _syncProgressSetups.Add(
         () =>
     {
         SyncProgressResolver.FindBestHeader().Returns(ChainHead.Number - MultiSyncModeSelector.FastSyncLag);
         SyncProgressResolver.FindBestFullBlock().Returns(0);
         SyncProgressResolver.FindBestFullState().Returns(0);
         SyncProgressResolver.FindBestProcessedBlock().Returns(0);
         SyncProgressResolver.IsFastBlocksFinished().Returns(true);
         SyncProgressResolver.ChainDifficulty.Returns(UInt256.Zero);
         return("just after fast blocks and fast sync");
     }
         );
     return(this);
 }
 public ScenarioBuilder IfThisNodeJustCameBackFromBeingOfflineForLongTimeAndFinishedFastSyncCatchUp()
 {
     _syncProgressSetups.Add(
         () =>
     {
         SyncProgressResolver.FindBestHeader().Returns(ChainHead.Number);
         SyncProgressResolver.FindBestFullBlock().Returns(ChainHead.Number);
         SyncProgressResolver.FindBestFullState().Returns(ChainHead.Number - FastSyncCatchUpHeightDelta - 1);
         SyncProgressResolver.FindBestProcessedBlock().Returns(ChainHead.Number - FastSyncCatchUpHeightDelta - 1);
         SyncProgressResolver.IsFastBlocksFinished().Returns(true);
         SyncProgressResolver.ChainDifficulty.Returns(UInt256.Zero);
         return("mid fast sync");
     }
         );
     return(this);
 }
 public ScenarioBuilder IfThisNodeFinishedStateSyncButNotFastBlocks()
 {
     _syncProgressSetups.Add(
         () =>
     {
         SyncProgressResolver.FindBestHeader().Returns(ChainHead.Number - MultiSyncModeSelector.FastSyncLag);
         SyncProgressResolver.FindBestFullBlock().Returns(0);
         SyncProgressResolver.FindBestFullState().Returns(ChainHead.Number - MultiSyncModeSelector.FastSyncLag);
         SyncProgressResolver.FindBestProcessedBlock().Returns(0);
         SyncProgressResolver.IsFastBlocksFinished().Returns(false);
         SyncProgressResolver.ChainDifficulty.Returns(UInt256.Zero);
         return("just finished state sync but not fast blocks");
     }
         );
     return(this);
 }
 public ScenarioBuilder IfThisNodeIsInTheMiddleOfFastSyncAndFastBlocks()
 {
     _syncProgressSetups.Add(
         () =>
     {
         SyncProgressResolver.FindBestHeader().Returns(Pivot.Number + 16);
         SyncProgressResolver.FindBestFullBlock().Returns(0);
         SyncProgressResolver.FindBestFullState().Returns(0);
         SyncProgressResolver.FindBestProcessedBlock().Returns(0);
         SyncProgressResolver.IsFastBlocksFinished().Returns(false);
         SyncProgressResolver.ChainDifficulty.Returns(UInt256.Zero);
         return("mid fast sync and fast blocks");
     }
         );
     return(this);
 }
 public ScenarioBuilder IfThisNodeIsProcessingAlreadyDownloadedBlocksInFullSync()
 {
     _syncProgressSetups.Add(
         () =>
     {
         SyncProgressResolver.FindBestHeader().Returns(ChainHead.Number);
         SyncProgressResolver.FindBestFullBlock().Returns(ChainHead.Number);
         SyncProgressResolver.FindBestFullState().Returns(ChainHead.Number - FastSyncCatchUpHeightDelta + 1);
         SyncProgressResolver.FindBestProcessedBlock().Returns(ChainHead.Number - FastSyncCatchUpHeightDelta + 1);
         SyncProgressResolver.IsFastBlocksFinished().Returns(true);
         SyncProgressResolver.ChainDifficulty.Returns(ChainHead.TotalDifficulty ?? 0);
         return("fully syncing");
     }
         );
     return(this);
 }
 public ScenarioBuilder IfThisNodeIsFullySynced()
 {
     _syncProgressSetups.Add(
         () =>
     {
         SyncProgressResolver.FindBestHeader().Returns(ChainHead.Number);
         SyncProgressResolver.FindBestFullBlock().Returns(ChainHead.Number);
         SyncProgressResolver.FindBestFullState().Returns(ChainHead.Number);
         SyncProgressResolver.FindBestProcessedBlock().Returns(ChainHead.Number);
         SyncProgressResolver.IsFastBlocksFinished().Returns(true);
         SyncProgressResolver.ChainDifficulty.Returns(ChainHead.TotalDifficulty ?? 0);
         return("fully synced node");
     }
         );
     return(this);
 }
 /// <summary>
 /// Empty clique chains do not update state root on empty blocks (no block reward)
 /// </summary>
 /// <returns></returns>
 public ScenarioBuilder IfThisNodeRecentlyStartedFullSyncProcessingOnEmptyCliqueChain()
 {
     // so the state root check can think that state root is after processed
     _syncProgressSetups.Add(
         () =>
     {
         SyncProgressResolver.FindBestHeader().Returns(ChainHead.Number);
         SyncProgressResolver.FindBestFullBlock().Returns(ChainHead.Number);
         SyncProgressResolver.FindBestFullState().Returns(ChainHead.Number - MultiSyncModeSelector.FastSyncLag + 1);
         SyncProgressResolver.FindBestProcessedBlock().Returns(ChainHead.Number - MultiSyncModeSelector.FastSyncLag);
         SyncProgressResolver.IsFastBlocksFinished().Returns(true);
         SyncProgressResolver.ChainDifficulty.Returns((UInt256)ChainHead.Number - MultiSyncModeSelector.FastSyncLag);
         return("recently started full sync on empty clique chain");
     }
         );
     return(this);
 }
示例#14
0
        public void Is_fast_block_finished_returns_false_when_headers_not_downloaded()
        {
            IBlockTree          blockTree          = Substitute.For <IBlockTree>();
            IReceiptStorage     receiptStorage     = Substitute.For <IReceiptStorage>();
            INodeDataDownloader nodeDataDownloader = Substitute.For <INodeDataDownloader>();
            SyncConfig          syncConfig         = new SyncConfig();

            syncConfig.FastBlocks = true;
            syncConfig.DownloadBodiesInFastSync   = true;
            syncConfig.DownloadReceiptsInFastSync = true;

            blockTree.LowestInsertedHeader.Returns(Build.A.BlockHeader.WithNumber(2).TestObject);

            SyncProgressResolver syncProgressResolver = new SyncProgressResolver(blockTree, receiptStorage, nodeDataDownloader, syncConfig, LimboLogs.Instance);

            Assert.False(syncProgressResolver.IsFastBlocksFinished());
        }
                public ScenarioBuilder IfTheSyncProgressIsCorrupted()
                {
                    _syncProgressSetups.Add(
                        () =>
                    {
                        SyncProgressResolver.FindBestHeader().Returns(ChainHead.Number);
                        SyncProgressResolver.FindBestFullBlock().Returns(ChainHead.Number);

                        SyncProgressResolver.FindBestFullState().Returns(ChainHead.Number - 1);
                        SyncProgressResolver.FindBestProcessedBlock().Returns(ChainHead.Number);
                        SyncProgressResolver.IsFastBlocksFinished().Returns(true);
                        SyncProgressResolver.ChainDifficulty.Returns((UInt256)ChainHead.Number);
                        return("corrupted progress");
                    }
                        );

                    return(this);
                }
                public ScenarioBuilder IfThisNodeNearlyNeedsAFastSyncCatchUp()
                {
                    long currentBlock = ChainHead.Number - FastSyncCatchUpHeightDelta + 1;

                    _syncProgressSetups.Add(
                        () =>
                    {
                        SyncProgressResolver.FindBestHeader().Returns(currentBlock);
                        SyncProgressResolver.FindBestFullBlock().Returns(currentBlock);
                        SyncProgressResolver.FindBestFullState().Returns(currentBlock);
                        SyncProgressResolver.FindBestProcessedBlock().Returns(currentBlock);
                        SyncProgressResolver.IsFastBlocksFinished().Returns(true);
                        SyncProgressResolver.ChainDifficulty.Returns((UInt256)currentBlock);
                        return("fast sync catch up");
                    }
                        );
                    return(this);
                }
                public ScenarioBuilder IfThisNodeRecentlyStartedFullSyncProcessing()
                {
                    long currentBlock = ChainHead.Number - MultiSyncModeSelector.FastSyncLag / 2;

                    _syncProgressSetups.Add(
                        () =>
                    {
                        SyncProgressResolver.FindBestHeader().Returns(ChainHead.Number);
                        SyncProgressResolver.FindBestFullBlock().Returns(ChainHead.Number);
                        SyncProgressResolver.FindBestFullState().Returns(currentBlock);
                        SyncProgressResolver.FindBestProcessedBlock().Returns(currentBlock);
                        SyncProgressResolver.IsFastBlocksFinished().Returns(true);
                        SyncProgressResolver.ChainDifficulty.Returns((UInt256)currentBlock);
                        return("recently started full sync");
                    }
                        );
                    return(this);
                }
示例#18
0
        public void Is_fast_block_finished_returns_false_when_headers_not_downloaded()
        {
            IBlockTree      blockTree      = Substitute.For <IBlockTree>();
            IReceiptStorage receiptStorage = Substitute.For <IReceiptStorage>();
            IDb             stateDb        = new MemDb();
            SyncConfig      syncConfig     = new SyncConfig();

            syncConfig.FastBlocks = true;
            syncConfig.DownloadBodiesInFastSync   = true;
            syncConfig.DownloadReceiptsInFastSync = true;
            syncConfig.PivotNumber = "1";

            blockTree.LowestInsertedHeader.Returns(Build.A.BlockHeader.WithNumber(2).WithStateRoot(TestItem.KeccakA).TestObject);

            SyncProgressResolver syncProgressResolver = new SyncProgressResolver(blockTree, receiptStorage, stateDb, new MemDb(), syncConfig, LimboLogs.Instance);

            Assert.False(syncProgressResolver.IsFastBlocksFinished());
        }
                public ScenarioBuilder IfThisNodeHasStateThatIsFarInThePast()
                {
                    // this is a scenario when we actually have state but the lookup depth is limiting
                    // our ability to find out at what level the state is
                    long currentBlock = ChainHead.Number - FastSyncCatchUpHeightDelta - 16;

                    _syncProgressSetups.Add(
                        () =>
                    {
                        SyncProgressResolver.FindBestHeader().Returns(ChainHead.Number);
                        SyncProgressResolver.FindBestFullBlock().Returns(ChainHead.Number);
                        SyncProgressResolver.FindBestFullState().Returns(0);
                        SyncProgressResolver.FindBestProcessedBlock().Returns(currentBlock);
                        SyncProgressResolver.IsFastBlocksFinished().Returns(true);
                        SyncProgressResolver.ChainDifficulty.Returns((UInt256)currentBlock);
                        return("fast sync catch up");
                    }
                        );
                    return(this);
                }