public LevelDbStorageManager(string baseDirectory,
                                     ulong?blocksCacheSize              = null, ulong?blocksWriteCacheSize     = null,
                                     ulong?blockTxesCacheSize           = null, ulong?blockTxesWriteCacheSize  = null,
                                     ulong?chainStateCacheSize          = null, ulong?chainStateWriteCacheSize = null,
                                     string[] blockTxesStorageLocations = null)
        {
            this.baseDirectory             = baseDirectory;
            this.blockTxesStorageLocations = blockTxesStorageLocations;

            blockStorage = new Lazy <LevelDb.LevelDbBlockStorage>(() => new LevelDbBlockStorage(this.baseDirectory, blocksCacheSize, blocksWriteCacheSize));

            blockTxesStorage = new Lazy <IBlockTxesStorage>(() =>
            {
                if (blockTxesStorageLocations == null)
                {
                    return(new LevelDbBlockTxesStorage(this.baseDirectory, blockTxesCacheSize, blockTxesWriteCacheSize));
                }
                else
                {
                    return(new SplitBlockTxesStorage(blockTxesStorageLocations, path => new LevelDbBlockTxesStorage(path, blockTxesCacheSize, blockTxesWriteCacheSize)));
                }
            });

            chainStateManager         = new Lazy <LevelDbChainStateManager>(() => new LevelDbChainStateManager(this.baseDirectory, chainStateCacheSize, chainStateWriteCacheSize));
            this.memoryStorageManager = new Lazy <MemoryStorageManager>(() =>
            {
                // create memory storage with the unconfirmed txes chain tip already in sync with chain state
                ChainedHeader chainTip;
                using (var handle = OpenChainStateCursor())
                {
                    handle.Item.BeginTransaction(readOnly: true);
                    chainTip = handle.Item.ChainTip;
                }

                var memoryStorageManager = new MemoryStorageManager();
                using (var handle = memoryStorageManager.OpenUnconfirmedTxesCursor())
                {
                    handle.Item.BeginTransaction();
                    handle.Item.ChainTip = chainTip;
                    handle.Item.CommitTransaction();
                }

                return(memoryStorageManager);
            });
        }
Esempio n. 2
0
        public EsentStorageManager(string baseDirectory, string[] blockTxesStorageLocations = null)
        {
            this.baseDirectory             = baseDirectory;
            this.blockTxesStorageLocations = blockTxesStorageLocations;

            this.blockStorage = new Lazy <Esent.EsentBlockStorage>(() => new EsentBlockStorage(this.baseDirectory));

            this.blockTxesStorage = new Lazy <IBlockTxesStorage>(() =>
            {
                if (blockTxesStorageLocations == null)
                {
                    return(new EsentBlockTxesStorage(this.baseDirectory));
                }
                else
                {
                    return(new SplitBlockTxesStorage(blockTxesStorageLocations, path => new EsentBlockTxesStorage(path)));
                }
            });

            this.chainStateManager    = new Lazy <EsentChainStateManager>(() => new EsentChainStateManager(this.baseDirectory));
            this.memoryStorageManager = new Lazy <MemoryStorageManager>(() =>
            {
                // create memory storage with the unconfirmed txes chain tip already in sync with chain state
                ChainedHeader chainTip;
                using (var handle = OpenChainStateCursor())
                {
                    handle.Item.BeginTransaction(readOnly: true);
                    chainTip = handle.Item.ChainTip;
                }

                var memoryStorageManager = new MemoryStorageManager();
                using (var handle = memoryStorageManager.OpenUnconfirmedTxesCursor())
                {
                    handle.Item.BeginTransaction();
                    handle.Item.ChainTip = chainTip;
                    handle.Item.CommitTransaction();
                }

                return(memoryStorageManager);
            });
        }