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; }
public void Best_state_is_head_when_there_are_no_suggested_blocks() { IBlockTree blockTree = Substitute.For <IBlockTree>(); IReceiptStorage receiptStorage = Substitute.For <IReceiptStorage>(); INodeDataDownloader nodeDataDownloader = Substitute.For <INodeDataDownloader>(); SyncConfig syncConfig = new SyncConfig(); SyncProgressResolver syncProgressResolver = new SyncProgressResolver(blockTree, receiptStorage, nodeDataDownloader, syncConfig, LimboLogs.Instance); var head = Build.A.BlockHeader.WithNumber(5).TestObject; blockTree.Head.Returns(head); nodeDataDownloader.IsFullySynced(head).Returns(true); Assert.AreEqual(head.Number, syncProgressResolver.FindBestFullState()); }
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 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 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 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 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 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); }
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); }
public void Best_state_is_head_if_there_is_suggested_block_without_state() { IBlockTree blockTree = Substitute.For <IBlockTree>(); IReceiptStorage receiptStorage = Substitute.For <IReceiptStorage>(); INodeDataDownloader nodeDataDownloader = Substitute.For <INodeDataDownloader>(); SyncConfig syncConfig = new SyncConfig(); SyncProgressResolver syncProgressResolver = new SyncProgressResolver(blockTree, receiptStorage, nodeDataDownloader, syncConfig, LimboLogs.Instance); var head = Build.A.BlockHeader.WithNumber(5).TestObject; var suggested = Build.A.BlockHeader.WithNumber(6).TestObject; blockTree.Head.Returns(head); blockTree.BestSuggestedHeader.Returns(suggested); blockTree.FindHeader(Arg.Any <Keccak>(), BlockTreeLookupOptions.TotalDifficultyNotNeeded).Returns(head); nodeDataDownloader.IsFullySynced(head).Returns(true); nodeDataDownloader.IsFullySynced(suggested).Returns(false); Assert.AreEqual(head.Number, syncProgressResolver.FindBestFullState()); }
public void Best_state_is_head_when_there_are_no_suggested_blocks() { IBlockTree blockTree = Substitute.For <IBlockTree>(); IReceiptStorage receiptStorage = Substitute.For <IReceiptStorage>(); IDb stateDb = Substitute.For <IDb>(); SyncConfig syncConfig = new SyncConfig(); syncConfig.PivotNumber = "1"; SyncProgressResolver syncProgressResolver = new SyncProgressResolver(blockTree, receiptStorage, stateDb, new MemDb(), syncConfig, LimboLogs.Instance); var head = Build.A.Block.WithHeader(Build.A.BlockHeader.WithNumber(5).WithStateRoot(TestItem.KeccakA).TestObject).TestObject; blockTree.Head.Returns(head); blockTree.BestSuggestedHeader.Returns(head.Header); stateDb.Get(head.StateRoot).Returns(new byte[] { 1 }); stateDb.Innermost.Returns(stateDb); Assert.AreEqual(head.Number, syncProgressResolver.FindBestFullState()); }
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); }
public void Best_state_is_suggested_if_there_is_suggested_block_with_state() { IBlockTree blockTree = Substitute.For <IBlockTree>(); IReceiptStorage receiptStorage = Substitute.For <IReceiptStorage>(); IDb stateDb = Substitute.For <IDb>(); SyncConfig syncConfig = new SyncConfig(); syncConfig.PivotNumber = "1"; SyncProgressResolver syncProgressResolver = new SyncProgressResolver(blockTree, receiptStorage, stateDb, new MemDb(), syncConfig, LimboLogs.Instance); var head = Build.A.Block.WithHeader(Build.A.BlockHeader.WithNumber(5).WithStateRoot(TestItem.KeccakA).TestObject).TestObject; var suggested = Build.A.BlockHeader.WithNumber(6).WithStateRoot(TestItem.KeccakB).TestObject; blockTree.Head.Returns(head); blockTree.BestSuggestedHeader.Returns(suggested); blockTree.FindHeader(Arg.Any <Keccak>(), BlockTreeLookupOptions.TotalDifficultyNotNeeded).Returns(head.Header); stateDb.Get(head.StateRoot).Returns(new byte[] { 1 }); stateDb.Get(suggested.StateRoot).Returns(new byte[] { 1 }); Assert.AreEqual(suggested.Number, syncProgressResolver.FindBestFullState()); }