Esempio n. 1
0
        public void CanSaveChain()
        {
            var             stream = new StreamObjectStream <ChainChange>();
            PersistantChain chain  = new PersistantChain(Network.Main, stream);

            AppendBlock(chain);
            AppendBlock(chain);
            var fork = AppendBlock(chain);

            AppendBlock(chain);


            stream.Rewind();

            var chain2 = new PersistantChain(stream);

            Assert.True(chain.SameTip(chain2));

            stream.WriteNext(new ChainChange()
            {
                ChangeType       = ChainChangeType.BackStep,
                HeightOrBackstep = 1
            });
            stream.Rewind();

            var chain3 = new PersistantChain(stream);

            AssertHeight(stream, 3);
            var actualFork = chain3.FindFork(chain);

            Assert.Equal(fork.HashBlock, actualFork.HashBlock);
        }
Esempio n. 2
0
        public void BenchmarkCreateChainFromBlocks()
        {
            BlockStore store     = new BlockStore(@"E:\Bitcoin\blocks\", Network.Main);
            Chain      chain     = null;
            var        fullBuild = Bench(() =>
            {
                chain = store.BuildChain();
            });

            chain.Changes.Rewind();
            var rebuildFromMemory = Bench(() =>
            {
                var chain2 = new Chain(chain.Changes);
            });

            chain.Changes.Rewind();
            var halfChain = new StreamObjectStream <ChainChange>();

            for (int i = 0; i < 300000; i++)
            {
                halfChain.WriteNext(chain.Changes.ReadNext());
            }

            var halfBuild = Bench(() =>
            {
                var fullChain = store.BuildChain(halfChain);
            });
        }
Esempio n. 3
0
        public void CanSaveChain()
        {
            var stream = new StreamObjectStream<ChainChange>();
            Chain chain = new Chain(Network.Main, stream);
            AppendBlock(chain);
            AppendBlock(chain);
            var fork = AppendBlock(chain);
            AppendBlock(chain);

            stream.Rewind();

            var chain2 = new Chain(stream);
            Assert.True(chain.SameTip(chain2));

            stream.WriteNext(new ChainChange()
            {
                Add = false,
                HeightOrBackstep = 1
            });
            stream.Rewind();

            var chain3 = new Chain(stream);
            AssertHeight(stream, 3);
            var actualFork = chain3.FindFork(chain);
            Assert.Equal(fork.HashBlock, actualFork.HashBlock);
        }