public void ValidSomeBlocks() { using (NodeContext ctx = NodeContext.Create(network: Network.Main)) { var network = ctx.Network; var chain = new ConcurrentChain(network.GetGenesis().Header); if (network == NBitcoin.Network.Main) { chain.Load(GetFile("main.data", "https://aois.blob.core.windows.net/public/main.data")); } else { chain.Load(GetFile("test.data", "https://aois.blob.core.windows.net/public/test.data")); } var stack = new CoinViewStack( new CacheCoinView( new PrefetcherCoinView( new BackgroundCommiterCoinView( ctx.PersistentCoinView)))); var cache = stack.Find <CacheCoinView>(); var backgroundCommiter = stack.Find <BackgroundCommiterCoinView>(); ConsensusValidator valid = new ConsensusValidator(network.Consensus); valid.UseConsensusLib = false; Node node = Node.Connect(network, "yournode"); node.VersionHandshake(); var puller = new CustomNodeBlockPuller(chain, node); var lastSnapshot = valid.PerformanceCounter.Snapshot(); var lastSnapshot2 = ctx.PersistentCoinView.PerformanceCounter.Snapshot(); var lastSnapshot3 = cache.PerformanceCounter.Snapshot(); foreach (var block in valid.Run(stack, puller)) { if ((DateTimeOffset.UtcNow - lastSnapshot.Taken) > TimeSpan.FromSeconds(5.0)) { Console.WriteLine(); Console.WriteLine("ActualLookahead :\t" + puller.ActualLookahead + " blocks"); Console.WriteLine("Downloaded Count :\t" + puller.RollingAverageDownloadedCount + " blocks"); Console.WriteLine("CoinViewTip :\t" + backgroundCommiter.Tip.Height); Console.WriteLine("CommitingTip :\t" + backgroundCommiter.CommitingTip.Height); Console.WriteLine("InnerTip :\t" + backgroundCommiter.InnerTip.Height); Console.WriteLine("Cache entries :\t" + cache.CacheEntryCount); var snapshot = valid.PerformanceCounter.Snapshot(); Console.Write(snapshot - lastSnapshot); lastSnapshot = snapshot; var snapshot2 = ctx.PersistentCoinView.PerformanceCounter.Snapshot(); Console.Write(snapshot2 - lastSnapshot2); lastSnapshot2 = snapshot2; var snapshot3 = cache.PerformanceCounter.Snapshot(); Console.Write(snapshot3 - lastSnapshot3); lastSnapshot3 = snapshot3; } } } }
public void ValidSomeBlocks() { using (NodeContext ctx = NodeContext.Create(network: Network.Main, clean: false)) { var network = ctx.Network; var chain = new ConcurrentChain(network.GetGenesis().Header); if (network == NBitcoin.Network.Main) { chain.Load(GetFile("main.data", "https://aois.blob.core.windows.net/public/main.data")); } else { chain.Load(GetFile("test.data", "https://aois.blob.core.windows.net/public/test.data")); } //var threads = new CustomThreadPoolTaskScheduler(10, 100, "Parallel Coin Fetcher"); var stack = new CoinViewStack( new CacheCoinView( // PrefetcherCoinView( //new ParallelCoinView(threads, new BackgroundCommiterCoinView( ctx.PersistentCoinView))); //); //new InMemoryCoinView(chain.Genesis)); var bottom = stack.Bottom; var cache = stack.Find <CacheCoinView>(); var backgroundCommiter = stack.Find <BackgroundCommiterCoinView>(); ConsensusValidator valid = new ConsensusValidator(network.Consensus); valid.UseConsensusLib = false; Node node = Node.Connect(network, "yournode"); node.VersionHandshake(); var puller = new CustomNodeBlockPuller(chain, node); var lastSnapshot = valid.PerformanceCounter.Snapshot(); var lastSnapshot2 = ctx.PersistentCoinView.PerformanceCounter.Snapshot(); var lastSnapshot3 = cache == null ? null : cache.PerformanceCounter.Snapshot(); foreach (var block in valid.Run(stack, puller)) { if ((DateTimeOffset.UtcNow - lastSnapshot.Taken) > TimeSpan.FromSeconds(5.0)) { Console.WriteLine(); Console.WriteLine("ActualLookahead :\t" + puller.ActualLookahead + " blocks"); Console.WriteLine("Median Downloaded :\t" + puller.MedianDownloadCount + " blocks"); if (backgroundCommiter != null) { Console.WriteLine("CoinViewTip :\t" + backgroundCommiter.Tip.Height); Console.WriteLine("CommitingTip :\t" + backgroundCommiter.CommitingTip.Height); } Console.WriteLine("Bottom Tip :\t" + bottom.Tip.Height); if (cache != null) { Console.WriteLine("Cache entries :\t" + cache.CacheEntryCount); } var snapshot = valid.PerformanceCounter.Snapshot(); Console.Write(snapshot - lastSnapshot); lastSnapshot = snapshot; var snapshot2 = ctx.PersistentCoinView.PerformanceCounter.Snapshot(); Console.Write(snapshot2 - lastSnapshot2); lastSnapshot2 = snapshot2; if (cache != null) { var snapshot3 = cache.PerformanceCounter.Snapshot(); Console.Write(snapshot3 - lastSnapshot3); lastSnapshot3 = snapshot3; } } } } }