public void TestCacheCoinView() { using (NodeContext ctx = NodeContext.Create(this)) { Block genesis = ctx.Network.GetGenesis(); var genesisChainedHeader = new ChainedHeader(genesis.Header, ctx.Network.GenesisHash, 0); ChainedHeader chained = this.MakeNext(genesisChainedHeader, ctx.Network); var cacheCoinView = new CachedCoinView(ctx.PersistentCoinView, DateTimeProvider.Default, this.loggerFactory); cacheCoinView.SaveChangesAsync(new UnspentOutputs[] { new UnspentOutputs(genesis.Transactions[0].GetHash(), new Coins(genesis.Transactions[0], 0)) }, null, genesisChainedHeader.HashBlock, chained.HashBlock).Wait(); Assert.NotNull(cacheCoinView.FetchCoinsAsync(new[] { genesis.Transactions[0].GetHash() }).Result.UnspentOutputs[0]); Assert.Null(cacheCoinView.FetchCoinsAsync(new[] { new uint256() }).Result.UnspentOutputs[0]); Assert.Equal(chained.HashBlock, cacheCoinView.GetBlockHashAsync().Result); Assert.Null(ctx.PersistentCoinView.FetchCoinsAsync(new[] { genesis.Transactions[0].GetHash() }).Result.UnspentOutputs[0]); Assert.Equal(chained.Previous.HashBlock, ctx.PersistentCoinView.GetBlockHashAsync().Result); cacheCoinView.FlushAsync().GetAwaiter().GetResult(); Assert.NotNull(ctx.PersistentCoinView.FetchCoinsAsync(new[] { genesis.Transactions[0].GetHash() }).Result.UnspentOutputs[0]); Assert.Equal(chained.HashBlock, ctx.PersistentCoinView.GetBlockHashAsync().Result); //Assert.Null(ctx.PersistentCoinView.FetchCoinsAsync(new[] { new uint256() }).Result.UnspentOutputs[0]); //var previous = chained; //chained = MakeNext(MakeNext(genesisChainedBlock)); //chained = MakeNext(MakeNext(genesisChainedBlock)); //ctx.PersistentCoinView.SaveChangesAsync(new UnspentOutputs[0], previous.HashBlock, chained.HashBlock).Wait(); //Assert.Equal(chained.HashBlock, ctx.PersistentCoinView.GetBlockHashAsync().GetAwaiter().GetResult()); //ctx.ReloadPersistentCoinView(); //Assert.Equal(chained.HashBlock, ctx.PersistentCoinView.GetBlockHashAsync().GetAwaiter().GetResult()); //Assert.NotNull(ctx.PersistentCoinView.FetchCoinsAsync(new[] { genesis.Transactions[0].GetHash() }).Result.UnspentOutputs[0]); //Assert.Null(ctx.PersistentCoinView.FetchCoinsAsync(new[] { new uint256() }).Result.UnspentOutputs[0]); } }
public void Log() { StringBuilder benchLogs = new StringBuilder(); if (lookaheadPuller != null) { benchLogs.AppendLine("======Block Puller======"); benchLogs.AppendLine("Lookahead:".PadRight(Logs.ColumnLength) + lookaheadPuller.ActualLookahead + " blocks"); benchLogs.AppendLine("Downloaded:".PadRight(Logs.ColumnLength) + lookaheadPuller.MedianDownloadCount + " blocks"); benchLogs.AppendLine("=========================="); } benchLogs.AppendLine("Persistent Tip:".PadRight(Logs.ColumnLength) + this.fullNode.Chain.GetBlock(bottom.GetBlockHashAsync().Result).Height); if (cache != null) { benchLogs.AppendLine("Cache Tip".PadRight(Logs.ColumnLength) + this.fullNode.Chain.GetBlock(cache.GetBlockHashAsync().Result).Height); benchLogs.AppendLine("Cache entries".PadRight(Logs.ColumnLength) + cache.CacheEntryCount); } var snapshot = this.fullNode.ConsensusLoop.Validator.PerformanceCounter.Snapshot(); benchLogs.AppendLine((snapshot - lastSnapshot).ToString()); lastSnapshot = snapshot; if (dbreeze != null) { var snapshot2 = dbreeze.PerformanceCounter.Snapshot(); benchLogs.AppendLine((snapshot2 - lastSnapshot2).ToString()); lastSnapshot2 = snapshot2; } if (cache != null) { var snapshot3 = cache.PerformanceCounter.Snapshot(); benchLogs.AppendLine((snapshot3 - lastSnapshot3).ToString()); lastSnapshot3 = snapshot3; } benchLogs.AppendLine(this.fullNode.ConnectionManager.GetStats()); Logs.Bench.LogInformation(benchLogs.ToString()); }