public void TestDBreezeSerialization() { using (NodeContext ctx = NodeContext.Create()) { var genesis = ctx.Network.GetGenesis(); var genesisChainedBlock = new ChainedBlock(genesis.Header, 0); ctx.PersistentCoinView.SaveChanges(genesisChainedBlock, new uint256[] { genesis.Transactions[0].GetHash() }, new Coins[] { new Coins(genesis.Transactions[0], 0) }); Assert.NotNull(ctx.PersistentCoinView.AccessCoins(genesis.Transactions[0].GetHash())); Assert.Null(ctx.PersistentCoinView.AccessCoins(new uint256())); var chained = MakeNext(MakeNext(genesisChainedBlock)); chained = MakeNext(MakeNext(genesisChainedBlock)); ctx.PersistentCoinView.SaveChanges(chained, new uint256[0], new Coins[0]); Assert.Equal(chained.HashBlock, ctx.PersistentCoinView.Tip.HashBlock); ctx.ReloadPersistentCoinView(); Assert.Equal(chained.HashBlock, ctx.PersistentCoinView.Tip.HashBlock); Assert.NotNull(ctx.PersistentCoinView.AccessCoins(genesis.Transactions[0].GetHash())); Assert.Null(ctx.PersistentCoinView.AccessCoins(new uint256())); } }
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; } } } } }