Skip to content

Commit

Permalink
Merge pull request stratisproject#8 from quantumagi/kvstore
Browse files Browse the repository at this point in the history
Add a LevelDB Key-Value Store and upgrade the Block Repository
  • Loading branch information
quantumagi authored Dec 11, 2019
2 parents 596b4c4 + 156db6b commit 7d1e56c
Show file tree
Hide file tree
Showing 28 changed files with 1,637 additions and 433 deletions.
292 changes: 154 additions & 138 deletions src/Stratis.Bitcoin.Features.BlockStore.Tests/BlockRepositoryTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public PruneBlockRepositoryTests() : base(new StratisMain())
}

[Fact]
public void PruneRepository_PruneAndCompact_FromGenesis_OnStartUp()
public void PruneRepositoryPruneAndCompactFromGenesisOnStartUp()
{
var posBlocks = CreatePosBlocks(50);
var chainedHeaderTip = BuildProvenHeaderChainFromBlocks(posBlocks);
Expand All @@ -24,8 +24,10 @@ public void PruneRepository_PruneAndCompact_FromGenesis_OnStartUp()
var dataFolder = new DataFolder(dataFolderPath);

var dBreezeSerializer = new DBreezeSerializer(this.Network.Consensus.ConsensusFactory);
var keyValueStore = new BlockKeyValueStore(this.Network, dataFolder, this.LoggerFactory.Object, DateTimeProvider.Default);

var blockRepository = new BlockRepository(this.Network, this.LoggerFactory.Object, keyValueStore);

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

var storeSettings = new StoreSettings(NodeSettings.Default(this.Network))
Expand All @@ -45,7 +47,7 @@ public void PruneRepository_PruneAndCompact_FromGenesis_OnStartUp()
}

[Fact]
public void PruneRepository_PruneAndCompact_MidChain_OnStartUp()
public void PruneRepositoryPruneAndCompactMidChainOnStartUp()
{
var posBlocks = CreatePosBlocks(200);
var chainedHeaderTip = BuildProvenHeaderChainFromBlocks(posBlocks);
Expand All @@ -54,8 +56,10 @@ public void PruneRepository_PruneAndCompact_MidChain_OnStartUp()
var dataFolder = new DataFolder(dataFolderPath);

var dBreezeSerializer = new DBreezeSerializer(this.Network.Consensus.ConsensusFactory);
var keyValueStore = new BlockKeyValueStore(this.Network, dataFolder, this.LoggerFactory.Object, DateTimeProvider.Default);

var blockRepository = new BlockRepository(this.Network, this.LoggerFactory.Object, keyValueStore);

var blockRepository = new BlockRepository(this.Network, dataFolder, this.LoggerFactory.Object, dBreezeSerializer);
blockRepository.PutBlocks(new HashHeightPair(posBlocks.Take(100).Last().GetHash(), 100), posBlocks.Take(100).ToList());

var storeSettings = new StoreSettings(NodeSettings.Default(this.Network))
Expand Down Expand Up @@ -84,7 +88,7 @@ public void PruneRepository_PruneAndCompact_MidChain_OnStartUp()
}

[Fact]
public void PruneRepository_PruneAndCompact_OnShutDown()
public void PruneRepositoryPruneAndCompactOnShutDown()
{
var posBlocks = CreatePosBlocks(50);
var chainedHeaderTip = BuildProvenHeaderChainFromBlocks(posBlocks);
Expand All @@ -93,8 +97,10 @@ public void PruneRepository_PruneAndCompact_OnShutDown()
var dataFolder = new DataFolder(dataFolderPath);

var dBreezeSerializer = new DBreezeSerializer(this.Network.Consensus.ConsensusFactory);
var keyValueStore = new BlockKeyValueStore(this.Network, dataFolder, this.LoggerFactory.Object, DateTimeProvider.Default);

var blockRepository = new BlockRepository(this.Network, this.LoggerFactory.Object, keyValueStore);

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

var storeSettings = new StoreSettings(NodeSettings.Default(this.Network))
Expand Down
22 changes: 22 additions & 0 deletions src/Stratis.Bitcoin.Features.BlockStore/BlockKeyValueStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.Extensions.Logging;
using NBitcoin;
using Stratis.Bitcoin.Configuration;
using Stratis.Bitcoin.Utilities;
using Stratis.Features.NodeStorage.Interfaces;
using Stratis.Features.NodeStorage.KeyValueStore;
using Stratis.Features.NodeStorage.KeyValueStoreLevelDB;

namespace Stratis.Bitcoin.Features.BlockStore
{
public interface IBlockKeyValueStore : IKeyValueStore
{
}

public class BlockKeyValueStore : KeyValueStore<KeyValueStoreLevelDB>, IBlockKeyValueStore
{
public BlockKeyValueStore(Network network, DataFolder dataFolder, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider)
:base(dataFolder.BlockPath, loggerFactory, dateTimeProvider, new DBreezeSerializer(network.Consensus.ConsensusFactory))
{
}
}
}
Loading

0 comments on commit 7d1e56c

Please sign in to comment.