Skip to content

Commit 1a35b95

Browse files
committed
Fix build break
1 parent eaca740 commit 1a35b95

28 files changed

Lines changed: 156 additions & 157 deletions

File tree

src/Blockcore.Features.BlockStore.Tests/BlockRepositoryTests.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void InitializesGenesisBlockAndTxIndexOnFirstLoad()
2626
byte[] blockRow = engine.Get(DBH.Key(BlockRepository.CommonTableName, new byte[0]));
2727
bool txIndexRow = BitConverter.ToBoolean(engine.Get(DBH.Key(BlockRepository.CommonTableName, new byte[1])));
2828

29-
Assert.Equal(this.Network.GetGenesis().GetHash(), this.DBreezeSerializer.Deserialize<HashHeightPair>(blockRow).Hash);
29+
Assert.Equal(this.Network.GetGenesis().GetHash(), this.DataStoreSerializer.Deserialize<HashHeightPair>(blockRow).Hash);
3030
Assert.False(txIndexRow);
3131
}
3232
}
@@ -38,7 +38,7 @@ public void DoesNotOverwriteExistingBlockAndTxIndexOnFirstLoad()
3838

3939
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
4040
{
41-
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DBreezeSerializer.Serialize(new HashHeightPair(new uint256(56), 1)));
41+
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(new uint256(56), 1)));
4242
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
4343
}
4444

@@ -51,7 +51,7 @@ public void DoesNotOverwriteExistingBlockAndTxIndexOnFirstLoad()
5151
byte[] blockRow = engine.Get(DBH.Key(BlockRepository.CommonTableName, new byte[0]));
5252
bool txIndexRow = BitConverter.ToBoolean(engine.Get(DBH.Key(BlockRepository.CommonTableName, new byte[1])));
5353

54-
Assert.Equal(new HashHeightPair(new uint256(56), 1), this.DBreezeSerializer.Deserialize<HashHeightPair>(blockRow));
54+
Assert.Equal(new HashHeightPair(new uint256(56), 1), this.DataStoreSerializer.Deserialize<HashHeightPair>(blockRow));
5555
Assert.True(txIndexRow);
5656
}
5757
}
@@ -63,7 +63,7 @@ public void GetTrxAsyncWithoutTransactionIndexReturnsNewTransaction()
6363

6464
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
6565
{
66-
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DBreezeSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
66+
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
6767
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(false));
6868
}
6969

@@ -81,7 +81,7 @@ public void GetTrxAsyncWithoutTransactionInIndexReturnsNull()
8181
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
8282
{
8383
var blockId = new uint256(8920);
84-
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DBreezeSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
84+
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
8585
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
8686
}
8787

@@ -106,7 +106,7 @@ public void GetTrxAsyncWithTransactionReturnsExistingTransaction()
106106

107107
engine.Put(DBH.Key(BlockRepository.BlockTableName, block.Header.GetHash().ToBytes()), block.ToBytes());
108108
engine.Put(DBH.Key(BlockRepository.TransactionTableName, trans.GetHash().ToBytes()), block.Header.GetHash().ToBytes());
109-
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DBreezeSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
109+
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
110110
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
111111
}
112112

@@ -123,7 +123,7 @@ public void GetTrxBlockIdAsyncWithoutTxIndexReturnsDefaultId()
123123

124124
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
125125
{
126-
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DBreezeSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
126+
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
127127
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(false));
128128
}
129129

@@ -140,7 +140,7 @@ public void GetTrxBlockIdAsyncWithoutExistingTransactionReturnsNull()
140140

141141
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
142142
{
143-
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DBreezeSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
143+
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
144144
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
145145
}
146146

@@ -158,7 +158,7 @@ public void GetTrxBlockIdAsyncWithTransactionReturnsBlockId()
158158
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
159159
{
160160
engine.Put(DBH.Key(BlockRepository.TransactionTableName, new uint256(26).ToBytes()), new uint256(42).ToBytes());
161-
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DBreezeSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
161+
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
162162
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
163163
}
164164

@@ -195,7 +195,7 @@ public void PutAsyncWritesBlocksAndTransactionsToDbAndSavesNextBlockHash()
195195

196196
using (var engine = new DB(new Options() { CreateIfMissing = true }, dir))
197197
{
198-
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DBreezeSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
198+
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[0]), this.DataStoreSerializer.Serialize(new HashHeightPair(uint256.Zero, 1)));
199199
engine.Put(DBH.Key(BlockRepository.CommonTableName, new byte[1]), BitConverter.GetBytes(true));
200200
}
201201

@@ -211,7 +211,7 @@ public void PutAsyncWritesBlocksAndTransactionsToDbAndSavesNextBlockHash()
211211
Dictionary<byte[], byte[]> blockDict = engine.SelectDictionary(BlockRepository.BlockTableName);
212212
Dictionary<byte[], byte[]> transDict = engine.SelectDictionary(BlockRepository.TransactionTableName);
213213

214-
Assert.Equal(new HashHeightPair(nextBlockHash, 100), this.DBreezeSerializer.Deserialize<HashHeightPair>(blockHashKeyRow));
214+
Assert.Equal(new HashHeightPair(nextBlockHash, 100), this.DataStoreSerializer.Deserialize<HashHeightPair>(blockHashKeyRow));
215215
Assert.Equal(2, blockDict.Count);
216216
Assert.Equal(3, transDict.Count);
217217

@@ -362,7 +362,7 @@ public void DeleteAsyncRemovesBlocksAndTransactions()
362362
Dictionary<byte[], byte[]> blockDict = engine.SelectDictionary(BlockRepository.BlockTableName);
363363
Dictionary<byte[], byte[]> transDict = engine.SelectDictionary(BlockRepository.TransactionTableName);
364364

365-
Assert.Equal(tip, this.DBreezeSerializer.Deserialize<HashHeightPair>(blockHashKeyRow));
365+
Assert.Equal(tip, this.DataStoreSerializer.Deserialize<HashHeightPair>(blockHashKeyRow));
366366
Assert.Empty(blockDict);
367367
Assert.Empty(transDict);
368368
}
@@ -397,7 +397,7 @@ public void ReIndexAsync_TxIndex_OffToOn()
397397

398398
// Block stored as expected.
399399
Assert.Single(blockDict);
400-
Assert.Equal(block.GetHash(), this.DBreezeSerializer.Deserialize<Block>(blockDict.FirstOrDefault().Value).GetHash());
400+
Assert.Equal(block.GetHash(), this.DataStoreSerializer.Deserialize<Block>(blockDict.FirstOrDefault().Value).GetHash());
401401

402402
// Transaction row in database stored as expected.
403403
Assert.Single(transDict);
@@ -437,7 +437,7 @@ public void ReIndexAsync_TxIndex_OnToOff()
437437

438438
// Block still stored as expected.
439439
Assert.Single(blockDict);
440-
Assert.Equal(block.GetHash(), this.DBreezeSerializer.Deserialize<Block>(blockDict.FirstOrDefault().Value).GetHash());
440+
Assert.Equal(block.GetHash(), this.DataStoreSerializer.Deserialize<Block>(blockDict.FirstOrDefault().Value).GetHash());
441441

442442
// No transactions indexed.
443443
Assert.Empty(transDict);
@@ -536,7 +536,7 @@ public void GetBlockIdByTransactionIdForGenesisBlock()
536536

537537
private IBlockRepository SetupRepository(Network main, string dir)
538538
{
539-
var dBreezeSerializer = new DBreezeSerializer(main.Consensus.ConsensusFactory);
539+
var dBreezeSerializer = new DataStoreSerializer(main.Consensus.ConsensusFactory);
540540

541541
var repository = new BlockRepository(main, dir, this.LoggerFactory.Object, dBreezeSerializer);
542542
repository.Initialize();

src/Blockcore.Features.BlockStore.Tests/PruneBlockRepositoryTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void PruneRepository_PruneAndCompact_FromGenesis_OnStartUp()
2424
var dataFolderPath = CreateTestDir(this);
2525
var dataFolder = new DataFolder(dataFolderPath);
2626

27-
var dBreezeSerializer = new DBreezeSerializer(this.Network.Consensus.ConsensusFactory);
27+
var dBreezeSerializer = new DataStoreSerializer(this.Network.Consensus.ConsensusFactory);
2828

2929
var blockRepository = new BlockRepository(this.Network, dataFolder, this.LoggerFactory.Object, dBreezeSerializer);
3030
blockRepository.PutBlocks(new HashHeightPair(posBlocks.Last().GetHash(), 50), posBlocks);
@@ -54,7 +54,7 @@ public void PruneRepository_PruneAndCompact_MidChain_OnStartUp()
5454
var dataFolderPath = CreateTestDir(this);
5555
var dataFolder = new DataFolder(dataFolderPath);
5656

57-
var dBreezeSerializer = new DBreezeSerializer(this.Network.Consensus.ConsensusFactory);
57+
var dBreezeSerializer = new DataStoreSerializer(this.Network.Consensus.ConsensusFactory);
5858

5959
var blockRepository = new BlockRepository(this.Network, dataFolder, this.LoggerFactory.Object, dBreezeSerializer);
6060
blockRepository.PutBlocks(new HashHeightPair(posBlocks.Take(100).Last().GetHash(), 100), posBlocks.Take(100).ToList());
@@ -93,7 +93,7 @@ public void PruneRepository_PruneAndCompact_OnShutDown()
9393
var dataFolderPath = CreateTestDir(this);
9494
var dataFolder = new DataFolder(dataFolderPath);
9595

96-
var dBreezeSerializer = new DBreezeSerializer(this.Network.Consensus.ConsensusFactory);
96+
var dBreezeSerializer = new DataStoreSerializer(this.Network.Consensus.ConsensusFactory);
9797

9898
var blockRepository = new BlockRepository(this.Network, dataFolder, this.LoggerFactory.Object, dBreezeSerializer);
9999
blockRepository.PutBlocks(new HashHeightPair(posBlocks.Last().GetHash(), 50), posBlocks);

src/Blockcore.Features.BlockStore/BlockRepository.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ public class BlockRepository : IBlockRepository
100100

101101
public DB Leveldb => this.leveldb;
102102

103-
private readonly DBreezeSerializer dBreezeSerializer;
103+
private readonly DataStoreSerializer dataStoreSerializer;
104104
private readonly IReadOnlyDictionary<uint256, Transaction> genesisTransactions;
105105

106106
public BlockRepository(Network network, DataFolder dataFolder,
107-
ILoggerFactory loggerFactory, DBreezeSerializer dBreezeSerializer)
108-
: this(network, dataFolder.BlockPath, loggerFactory, dBreezeSerializer)
107+
ILoggerFactory loggerFactory, DataStoreSerializer dataStoreSerializer)
108+
: this(network, dataFolder.BlockPath, loggerFactory, dataStoreSerializer)
109109
{
110110
}
111111

112-
public BlockRepository(Network network, string folder, ILoggerFactory loggerFactory, DBreezeSerializer dBreezeSerializer)
112+
public BlockRepository(Network network, string folder, ILoggerFactory loggerFactory, DataStoreSerializer dataStoreSerializer)
113113
{
114114
Guard.NotNull(network, nameof(network));
115115
Guard.NotEmpty(folder, nameof(folder));
@@ -121,7 +121,7 @@ public BlockRepository(Network network, string folder, ILoggerFactory loggerFact
121121

122122
this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
123123
this.network = network;
124-
this.dBreezeSerializer = dBreezeSerializer;
124+
this.dataStoreSerializer = dataStoreSerializer;
125125
this.genesisTransactions = network.GetGenesis().Transactions.ToDictionary(k => k.GetHash());
126126
}
127127

@@ -175,7 +175,7 @@ public Transaction GetTransactionById(uint256 trxid)
175175

176176
if (blockRow != null)
177177
{
178-
var block = this.dBreezeSerializer.Deserialize<Block>(blockRow);
178+
var block = this.dataStoreSerializer.Deserialize<Block>(blockRow);
179179
res = block.Transactions.FirstOrDefault(t => t.GetHash() == trxid);
180180
}
181181
}
@@ -231,7 +231,7 @@ public Transaction GetTransactionById(uint256 trxid)
231231
return null;
232232
}
233233

234-
var block = this.dBreezeSerializer.Deserialize<Block>(blockRow);
234+
var block = this.dataStoreSerializer.Deserialize<Block>(blockRow);
235235
Transaction tx = block.Transactions.FirstOrDefault(t => t.GetHash() == trxids[i]);
236236

237237
txes[i] = tx;
@@ -297,7 +297,7 @@ protected virtual void OnInsertBlocks(List<Block> blocks)
297297
byte[] blockRow = this.leveldb.Get(DBH.Key(BlockTableName, blockId.ToBytes()));
298298
if (blockRow == null)
299299
{
300-
batch.Put(DBH.Key(BlockTableName, blockId.ToBytes()), this.dBreezeSerializer.Serialize(block));
300+
batch.Put(DBH.Key(BlockTableName, blockId.ToBytes()), this.dataStoreSerializer.Serialize(block));
301301

302302
if (this.TxIndex)
303303
{
@@ -336,7 +336,7 @@ public IEnumerable<Block> EnumeratehBatch(List<ChainedHeader> headers)
336336
foreach (ChainedHeader chainedHeader in headers)
337337
{
338338
byte[] blockRow = this.leveldb.Get(DBH.Key(BlockTableName, chainedHeader.HashBlock.ToBytes()));
339-
Block block = blockRow != null ? this.dBreezeSerializer.Deserialize<Block>(blockRow) : null;
339+
Block block = blockRow != null ? this.dataStoreSerializer.Deserialize<Block>(blockRow) : null;
340340
yield return block;
341341
}
342342
}
@@ -371,7 +371,7 @@ public void ReIndex()
371371
{
372372
if (enumerator.Current.Key[0] == BlockTableName)
373373
{
374-
var block = this.dBreezeSerializer.Deserialize<Block>(enumerator.Current.Value);
374+
var block = this.dataStoreSerializer.Deserialize<Block>(enumerator.Current.Value);
375375
foreach (Transaction transaction in block.Transactions)
376376
{
377377
batch.Put(DBH.Key(TransactionTableName, transaction.GetHash().ToBytes()), block.GetHash().ToBytes());
@@ -454,7 +454,7 @@ private HashHeightPair LoadTipHashAndHeight()
454454
{
455455
byte[] row = this.leveldb.Get(DBH.Key(CommonTableName, RepositoryTipKey));
456456
if (row != null)
457-
this.TipHashAndHeight = this.dBreezeSerializer.Deserialize<HashHeightPair>(row);
457+
this.TipHashAndHeight = this.dataStoreSerializer.Deserialize<HashHeightPair>(row);
458458
}
459459

460460
return this.TipHashAndHeight;
@@ -463,7 +463,7 @@ private HashHeightPair LoadTipHashAndHeight()
463463
private void SaveTipHashAndHeight(HashHeightPair newTip)
464464
{
465465
this.TipHashAndHeight = newTip;
466-
this.leveldb.Put(DBH.Key(CommonTableName, RepositoryTipKey), this.dBreezeSerializer.Serialize(newTip));
466+
this.leveldb.Put(DBH.Key(CommonTableName, RepositoryTipKey), this.dataStoreSerializer.Serialize(newTip));
467467
}
468468

469469
/// <inheritdoc />
@@ -561,7 +561,7 @@ public List<Block> GetBlocksFromHashes(List<uint256> hashes)
561561
byte[] blockRow = this.leveldb.Get(DBH.Key(BlockTableName, key.Item2));
562562
if (blockRow != null)
563563
{
564-
results[key.Item1] = this.dBreezeSerializer.Deserialize<Block>(blockRow);
564+
results[key.Item1] = this.dataStoreSerializer.Deserialize<Block>(blockRow);
565565

566566
this.logger.LogDebug("Block hash '{0}' loaded from the store.", key.Item1);
567567
}

src/Blockcore.Features.BlockStore/Pruning/PrunedBlockRepository.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ namespace Blockcore.Features.BlockStore.Pruning
1313
public class PrunedBlockRepository : IPrunedBlockRepository
1414
{
1515
private readonly IBlockRepository blockRepository;
16-
private readonly DBreezeSerializer dBreezeSerializer;
16+
private readonly DataStoreSerializer dataStoreSerializer;
1717
private readonly ILogger logger;
1818
private static readonly byte[] prunedTipKey = new byte[2];
1919
private readonly StoreSettings storeSettings;
2020

2121
/// <inheritdoc />
2222
public HashHeightPair PrunedTip { get; private set; }
2323

24-
public PrunedBlockRepository(IBlockRepository blockRepository, DBreezeSerializer dBreezeSerializer, ILoggerFactory loggerFactory, StoreSettings storeSettings)
24+
public PrunedBlockRepository(IBlockRepository blockRepository, DataStoreSerializer dataStoreSerializer, ILoggerFactory loggerFactory, StoreSettings storeSettings)
2525
{
2626
this.blockRepository = blockRepository;
27-
this.dBreezeSerializer = dBreezeSerializer;
27+
this.dataStoreSerializer = dataStoreSerializer;
2828
this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
2929
this.storeSettings = storeSettings;
3030
}
@@ -46,7 +46,7 @@ public void PruneAndCompactDatabase(ChainedHeader blockRepositoryTip, Network ne
4646

4747
this.PrunedTip = new HashHeightPair(genesis.GetHash(), 0);
4848

49-
this.blockRepository.Leveldb.Put(DBH.Key(BlockRepository.CommonTableName, prunedTipKey), this.dBreezeSerializer.Serialize(this.PrunedTip));
49+
this.blockRepository.Leveldb.Put(DBH.Key(BlockRepository.CommonTableName, prunedTipKey), this.dataStoreSerializer.Serialize(this.PrunedTip));
5050
}
5151

5252
if (nodeInitializing)
@@ -110,7 +110,7 @@ private void LoadPrunedTip(DB leveldb)
110110
{
111111
byte[] row = leveldb.Get(DBH.Key(BlockRepository.CommonTableName, prunedTipKey));
112112
if (row != null)
113-
this.PrunedTip = this.dBreezeSerializer.Deserialize<HashHeightPair>(row);
113+
this.PrunedTip = this.dataStoreSerializer.Deserialize<HashHeightPair>(row);
114114
}
115115
}
116116

0 commit comments

Comments
 (0)