Exemplo n.º 1
0
        public void CanReIndex()
        {
            var source = new BlockStore(@"data\blocks", Network.Main);
            var store  = CreateBlockStore("CanReIndexFolder");

            store.AppendAll(source.Enumerate(false).Take(100).Select(b => b.Item));


            var test      = new IndexedBlockStore(new InMemoryNoSqlRepository(), store);
            var reIndexed = test.ReIndex();

            Assert.Equal(100, reIndexed);
            int i = 0;

            foreach (var b in store.Enumerate(true))
            {
                var result = test.Get(b.Item.GetHash());
                Assert.Equal(result.GetHash(), b.Item.GetHash());
                i++;
            }
            Assert.Equal(100, i);

            var last = source.Enumerate(false).Skip(100).FirstOrDefault();

            store.Append(last.Item);

            reIndexed = test.ReIndex();
            Assert.Equal(1, reIndexed);

            reIndexed = test.ReIndex();
            Assert.Equal(0, reIndexed);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method populates index for faster block access.
        /// </summary>
        public void PrepareIndex(string datapath)
        {
            BlockStore store = new BlockStore(datapath, Network.Main);

            index = new IndexedBlockStore(new InMemoryNoSqlRepository(), store);
            index.ReIndex();
        }
Exemplo n.º 3
0
        public void BenchmarkBlockIndexing()
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            BlockStore        store   = new BlockStore(@"E:\Bitcoin\blocks\", Network.Main);
            IndexedBlockStore indexed = new IndexedBlockStore(new InMemoryNoSqlRepository(), store);

            indexed.ReIndex();
            watch.Stop();
            var time = watch.Elapsed;
        }
Exemplo n.º 4
0
        public void BenchmarkBlockIndexing()
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            BlockStore        store   = new BlockStore(this.BlockStoreFolder, Network.PurpleMain);
            IndexedBlockStore indexed = new IndexedBlockStore(new InMemoryNoSqlRepository(), store);

            indexed.ReIndex();
            watch.Stop();
            var time = watch.Elapsed;
        }
Exemplo n.º 5
0
        public void IndexTheFullChain()
        {
            var store      = new BlockStore(TestDataLocations.BlockFolderLocation, Network.StratisMain);
            var indexStore = new IndexedBlockStore(new InMemoryNoSqlRepository(), store);
            var reindexed  = indexStore.ReIndex();

            Assert.Equal(103952, reindexed);

            ConcurrentChain chain = store.GetChain();

            foreach (ChainedBlock item in chain.ToEnumerable(false))
            {
                Block block = indexStore.Get(item.HashBlock);
                Assert.True(BlockValidator.CheckBlock(block));
            }
        }
Exemplo n.º 6
0
        public static void CanCalculatePowPosCorrectly()
        {
            var store      = new BlockStore(TestDataLocations.BlockFolderLocation, Network.Main);
            var chain      = store.GetChain();
            var stakeChain = new MemoryStakeChain(Network.Main);
            var indexStore = new IndexedBlockStore(new InMemoryNoSqlRepository(), store);
            var reindexed  = indexStore.ReIndex();

            Assert.Equal(reindexed, 103952);

            foreach (var chainedBlock in chain.EnumerateAfter(chain.Genesis))
            {
                var block      = indexStore.Get(chainedBlock.HashBlock);
                var blockstake = new BlockStake(block);
                stakeChain.Set(chainedBlock.HashBlock, blockstake);

                Assert.True(stakeChain.CheckPowPosAndTarget(chainedBlock, blockstake, Network.Main));
            }
        }
Exemplo n.º 7
0
        public void CanCalculateDifficulty()
        {
            var histories = File.ReadAllLines(TestDataLocations.DataFolder(@"targethistory.csv"));

            var store = new BlockStore(TestDataLocations.BlockFolderLocation, Network.Main);
            // todo: load the chain with a header only file
            ConcurrentChain chain = store.GetChain();

            var stakeChain = new MemoryStakeChain(Network.Main);
            var indexStore = new IndexedBlockStore(new InMemoryNoSqlRepository(), store);
            var reindexed  = indexStore.ReIndex();

            Assert.Equal(reindexed, 103952);

            var lastIndex = 0;

            foreach (var history in histories)
            {
                var height         = int.Parse(history.Split(',')[0]);
                var expectedTarget = new Target(new BigInteger(history.Split(',')[1].Trim(), 10));

                var chainedBlock = chain.GetBlock(height);
                for (int i = height; i > lastIndex; i--)
                {
                    var g     = chain.GetBlock(i);
                    var block = indexStore.Get(g.HashBlock);
                    stakeChain.Set(g.HashBlock, new BlockStake(block));
                }
                lastIndex = height;

                Assert.Equal(expectedTarget, chainedBlock.Header.Bits);
                var target = stakeChain.GetWorkRequired(chainedBlock, stakeChain.Get(chainedBlock.HashBlock), Network.Main.Consensus);
                //var target = chain.GetWorkRequired(Network.Main, height);
                Assert.Equal(expectedTarget, target);
            }
        }
Exemplo n.º 8
0
        public void CanReIndex()
        {
            var source = new BlockStore(@"data\blocks", Network.Main);
            var store = CreateBlockStore("CanReIndexFolder");
            store.AppendAll(source.Enumerate(false).Take(100).Select(b => b.Item));

            var test = new IndexedBlockStore(new SQLiteNoSqlRepository("CanReIndex", true), store);
            var reIndexed = test.ReIndex();
            Assert.Equal(100, reIndexed);
            int i = 0;
            foreach(var b in store.Enumerate(true))
            {
                var result = test.Get(b.Item.GetHash());
                Assert.Equal(result.GetHash(), b.Item.GetHash());
                i++;
            }
            Assert.Equal(100, i);

            var last = source.Enumerate(false).Skip(100).FirstOrDefault();
            store.Append(last.Item);

            reIndexed = test.ReIndex();
            Assert.Equal(1, reIndexed);

            reIndexed = test.ReIndex();
            Assert.Equal(0, reIndexed);
        }
Exemplo n.º 9
0
		public void BenchmarkBlockIndexing()
		{
			Stopwatch watch = new Stopwatch();
			watch.Start();
			BlockStore store = new BlockStore(@"E:\Bitcoin\blocks\", Network.Main);
			IndexedBlockStore indexed = new IndexedBlockStore(new InMemoryNoSqlRepository(), store);
			indexed.ReIndex();
			watch.Stop();
			var time = watch.Elapsed;
		}