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); }
/// <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(); }
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; }
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; }
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)); } }
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)); } }
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); } }
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); }