//[Fact] public void BlockRepositoryBench() { using (var dir = TestDirectory.Create()) { using (var blockRepo = new BlockStore.BlockRepository(Network.Main, dir.FolderName)) { var lst = new List <Block>(); for (int i = 0; i < 30; i++) { // roughly 1mb blocks var block = new Block(); for (int j = 0; j < 3000; j++) { var trx = new Transaction(); block.AddTransaction(new Transaction()); trx.AddInput(new TxIn(Script.Empty)); trx.AddOutput(Money.COIN + j + i, new Script(Guid.NewGuid().ToByteArray() .Concat(Guid.NewGuid().ToByteArray()) .Concat(Guid.NewGuid().ToByteArray()) .Concat(Guid.NewGuid().ToByteArray()) .Concat(Guid.NewGuid().ToByteArray()) .Concat(Guid.NewGuid().ToByteArray()))); trx.AddInput(new TxIn(Script.Empty)); trx.AddOutput(Money.COIN + j + i + 1, new Script(Guid.NewGuid().ToByteArray() .Concat(Guid.NewGuid().ToByteArray()) .Concat(Guid.NewGuid().ToByteArray()) .Concat(Guid.NewGuid().ToByteArray()) .Concat(Guid.NewGuid().ToByteArray()) .Concat(Guid.NewGuid().ToByteArray()))); block.AddTransaction(trx); } block.UpdateMerkleRoot(); block.Header.HashPrevBlock = lst.Any() ? lst.Last().GetHash() : Network.Main.GenesisHash; lst.Add(block); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); blockRepo.PutAsync(lst.Last().GetHash(), lst).GetAwaiter().GetResult(); var first = stopwatch.ElapsedMilliseconds; blockRepo.PutAsync(lst.Last().GetHash(), lst).GetAwaiter().GetResult(); var second = stopwatch.ElapsedMilliseconds; } } }
public void BlockRepositoryPutBatch() { using (var dir = TestDirectory.Create()) { using (var blockRepo = new BlockStore.BlockRepository(Network.Main, dir.FolderName)) { blockRepo.SetTxIndex(true).Wait(); var lst = new List <Block>(); for (int i = 0; i < 5; i++) { // put var block = new Block(); block.AddTransaction(new Transaction()); block.AddTransaction(new Transaction()); block.Transactions[0].AddInput(new TxIn(Script.Empty)); block.Transactions[0].AddOutput(Money.COIN + i * 2, Script.Empty); block.Transactions[1].AddInput(new TxIn(Script.Empty)); block.Transactions[1].AddOutput(Money.COIN + i * 2 + 1, Script.Empty); block.UpdateMerkleRoot(); block.Header.HashPrevBlock = lst.Any() ? lst.Last().GetHash() : Network.Main.GenesisHash; lst.Add(block); } blockRepo.PutAsync(lst.Last().GetHash(), lst).GetAwaiter().GetResult(); // check each block foreach (var block in lst) { var received = blockRepo.GetAsync(block.GetHash()).GetAwaiter().GetResult(); Assert.True(block.ToBytes().SequenceEqual(received.ToBytes())); foreach (var transaction in block.Transactions) { var trx = blockRepo.GetTrxAsync(transaction.GetHash()).GetAwaiter().GetResult(); Assert.True(trx.ToBytes().SequenceEqual(transaction.ToBytes())); } } // delete blockRepo.DeleteAsync(lst.ElementAt(2).GetHash(), new[] { lst.ElementAt(2).GetHash() }.ToList()); var deleted = blockRepo.GetAsync(lst.ElementAt(2).GetHash()).GetAwaiter().GetResult(); Assert.Null(deleted); } } }