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 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);
                }