public EsentBlockStorage(string baseDirectory) { this.jetDirectory = Path.Combine(baseDirectory, "Blocks"); this.jetDatabase = Path.Combine(this.jetDirectory, "Blocks.edb"); this.cursorCache = new DisposableCache <EsentBlockCursor>(1024, createFunc: () => new EsentBlockCursor(this.jetDatabase, this.jetInstance)); this.jetInstance = new Instance(Guid.NewGuid().ToString()); var success = false; try { EsentStorageManager.InitInstanceParameters(jetInstance, jetDirectory); this.jetInstance.Init(); this.CreateOrOpenDatabase(); success = true; } finally { if (!success) { this.jetInstance.Dispose(); } } }
public override void Load() { EsentStorageManager.InitSystemParameters(cacheSizeMinBytes, cacheSizeMaxBytes); // bind concrete storage providers this.Bind <EsentStorageManager>().ToSelf().InSingletonScope() .WithConstructorArgument("baseDirectory", this.dataDirectory) .WithConstructorArgument("blockTxesStorageLocations", this.blockTxesStorageLocations); this.Bind <NetworkPeerStorage>().ToSelf().InSingletonScope() .WithConstructorArgument("baseDirectory", this.peersDirectory) .WithConstructorArgument("chainType", this.chainType); // bind storage providers interfaces this.Bind <IStorageManager>().ToMethod(x => this.Kernel.Get <EsentStorageManager>()).InSingletonScope(); this.Bind <INetworkPeerStorage>().ToMethod(x => this.Kernel.Get <NetworkPeerStorage>()).InSingletonScope(); }
public EsentChainStateManager(string baseDirectory) { this.baseDirectory = baseDirectory; this.jetDirectory = Path.Combine(baseDirectory, "ChainState"); this.jetDatabase = Path.Combine(this.jetDirectory, "ChainState.edb"); this.jetInstance = new Instance(Guid.NewGuid().ToString()); var success = false; try { EsentStorageManager.InitInstanceParameters(jetInstance, jetDirectory); this.jetInstance.Init(); this.CreateOrOpenDatabase(); this.cursorCache = new DisposableCache <IChainStateCursor>(1024, createFunc: () => new EsentChainStateCursor(this.jetDatabase, this.jetInstance), prepareAction: cursor => { // rollback any open transaction before returning the cursor to the cache if (cursor.InTransaction) { cursor.RollbackTransaction(); } }); success = true; } finally { if (!success) { this.cursorCache?.Dispose(); this.jetInstance.Dispose(); } } }