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 Header_block_is_0_when_no_header_was_suggested() { 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); blockTree.BestSuggestedHeader.Returns((BlockHeader)null); Assert.AreEqual(0, syncProgressResolver.FindBestHeader()); }
public void Header_block_is_0_when_no_header_was_suggested() { IBlockTree blockTree = Substitute.For <IBlockTree>(); IReceiptStorage receiptStorage = Substitute.For <IReceiptStorage>(); IDb stateDb = new MemDb(); SyncConfig syncConfig = new SyncConfig(); syncConfig.PivotNumber = "1"; SyncProgressResolver syncProgressResolver = new SyncProgressResolver(blockTree, receiptStorage, stateDb, new MemDb(), syncConfig, LimboLogs.Instance); blockTree.BestSuggestedHeader.Returns((BlockHeader)null); Assert.AreEqual(0, syncProgressResolver.FindBestHeader()); }
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 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 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 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 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 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); }