Ejemplo n.º 1
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void TestDBreezeInsertOrder()
        {
            using (NodeContext ctx = NodeContext.Create())
            {
                using (var engine = new DBreeze.DBreezeEngine(ctx.FolderName + "/2"))
                {
                    var data = new[]
                    {
                        new uint256(3),
                        new uint256(2),
                        new uint256(2439425),
                        new uint256(5),
                        new uint256(243945),
                        new uint256(10),
                        new uint256(Hashes.Hash256(new byte[0])),
                        new uint256(Hashes.Hash256(new byte[] { 1 })),
                        new uint256(Hashes.Hash256(new byte[] { 2 })),
                    };
                    Array.Sort(data, new UInt256Comparer());

                    using (var tx = engine.GetTransaction())
                    {
                        foreach (var d in data)
                        {
                            tx.Insert("Table", d.ToBytes(false), d.ToBytes());
                        }
                        tx.Commit();
                    }
                    var data2 = new uint256[data.Length];
                    using (var tx = engine.GetTransaction())
                    {
                        int i = 0;
                        foreach (var row in tx.SelectForward <byte[], byte[]>("Table"))
                        {
                            data2[i++] = new uint256(row.Key, false);
                        }
                    }
                    Assert.True(data.SequenceEqual(data2));
                }
            }
        }
Ejemplo n.º 3
0
        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 UnspentOutputs[] { new UnspentOutputs(genesis.Transactions[0].GetHash(), new Coins(genesis.Transactions[0], 0)) });
                Assert.NotNull(ctx.PersistentCoinView.FetchCoins(new[] { genesis.Transactions[0].GetHash() })[0]);
                Assert.Null(ctx.PersistentCoinView.FetchCoins(new[] { new uint256() })[0]);

                var chained = MakeNext(MakeNext(genesisChainedBlock));
                chained = MakeNext(MakeNext(genesisChainedBlock));
                ctx.PersistentCoinView.SaveChanges(chained, new UnspentOutputs[0]);
                Assert.Equal(chained.HashBlock, ctx.PersistentCoinView.Tip.HashBlock);
                ctx.ReloadPersistentCoinView();
                Assert.Equal(chained.HashBlock, ctx.PersistentCoinView.Tip.HashBlock);
                Assert.NotNull(ctx.PersistentCoinView.FetchCoins(new[] { genesis.Transactions[0].GetHash() })[0]);
                Assert.Null(ctx.PersistentCoinView.FetchCoins(new[] { new uint256() })[0]);
            }
        }
Ejemplo n.º 4
0
        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;
                        }
                    }
                }
            }
        }