Skip to content

Commit

Permalink
Move init logic to initialize method (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
fassadlr committed May 19, 2021
1 parent 736bb27 commit f4588f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class LevelDbCoindb : ICoindb, IStakedb, IDisposable
private static readonly byte rewindTable = 3;
private static readonly byte stakeTable = 4;

private readonly string dataFolder;

/// <summary>Instance logger.</summary>
private readonly ILogger logger;

Expand All @@ -38,7 +40,7 @@ public class LevelDbCoindb : ICoindb, IStakedb, IDisposable
private BackendPerformanceSnapshot latestPerformanceSnapShot;

/// <summary>Access to dBreeze database.</summary>
private readonly DB leveldb;
private DB leveldb;

private readonly DBreezeSerializer dBreezeSerializer;

Expand All @@ -48,20 +50,15 @@ public LevelDbCoindb(Network network, DataFolder dataFolder, IDateTimeProvider d
{
}

public LevelDbCoindb(Network network, string folder, IDateTimeProvider dateTimeProvider,
public LevelDbCoindb(Network network, string dataFolder, IDateTimeProvider dateTimeProvider,
ILoggerFactory loggerFactory, INodeStats nodeStats, DBreezeSerializer dBreezeSerializer)
{
Guard.NotNull(network, nameof(network));
Guard.NotEmpty(folder, nameof(folder));
Guard.NotEmpty(dataFolder, nameof(dataFolder));

this.dataFolder = dataFolder;
this.dBreezeSerializer = dBreezeSerializer;

this.logger = loggerFactory.CreateLogger(this.GetType().FullName);

// Open a connection to a new DB and create if not found
var options = new Options { CreateIfMissing = true };
this.leveldb = new DB(options, folder);

this.network = network;
this.performanceCounter = new BackendPerformanceCounter(dateTimeProvider);

Expand All @@ -71,6 +68,10 @@ public LevelDbCoindb(Network network, string folder, IDateTimeProvider dateTimeP

public void Initialize()
{
// Open a connection to a new DB and create if not found
var options = new Options { CreateIfMissing = true };
this.leveldb = new DB(options, this.dataFolder);

Block genesis = this.network.GetGenesis();

if (this.GetTipHash() == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ public class RocksDbCoindb : ICoindb, IStakedb, IDisposable
private static readonly byte rewindTable = 3;
private static readonly byte stakeTable = 4;

private readonly string dataFolder;

/// <summary>Hash of the block which is currently the tip of the coinview.</summary>
private HashHeightPair persistedCoinviewTip;
private readonly DBreezeSerializer dBreezeSerializer;
private readonly DbOptions dbOptions;
private readonly RocksDb rocksDb;
private DbOptions dbOptions;
private RocksDb rocksDb;
private BackendPerformanceSnapshot latestPerformanceSnapShot;
private readonly ILogger logger;
private readonly Network network;
Expand All @@ -40,8 +42,7 @@ public RocksDbCoindb(
INodeStats nodeStats,
DBreezeSerializer dBreezeSerializer)
{
this.dbOptions = new DbOptions().SetCreateIfMissing(true);
this.rocksDb = RocksDb.Open(this.dbOptions, dataFolder.CoindbPath);
this.dataFolder = dataFolder.CoindbPath;
this.dBreezeSerializer = dBreezeSerializer;
this.logger = LogManager.GetCurrentClassLogger();
this.network = network;
Expand All @@ -53,6 +54,9 @@ public RocksDbCoindb(

public void Initialize()
{
this.dbOptions = new DbOptions().SetCreateIfMissing(true);
this.rocksDb = RocksDb.Open(this.dbOptions, this.dataFolder);

Block genesis = this.network.GetGenesis();

if (this.GetTipHash() == null)
Expand Down

0 comments on commit f4588f4

Please sign in to comment.