Ejemplo n.º 1
0
        public LiteDBRichStore(
            BaseBlockStatesStore store,
            string path,
            bool journal       = true,
            int indexCacheSize = 50000,
            bool flush         = true,
            bool readOnly      = false)
        {
            _store = store;

            if (path is null)
            {
                _memoryStream = new MemoryStream();
                _db           = new LiteDatabase(_memoryStream);
            }
            else
            {
                var connectionString = new ConnectionString
                {
                    Filename  = Path.Combine(path, "ext.ldb"),
                    Journal   = journal,
                    CacheSize = indexCacheSize,
                    Flush     = flush,
                };

                if (readOnly)
                {
                    connectionString.Mode = FileMode.ReadOnly;
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) &&
                         Type.GetType("Mono.Runtime") is null)
                {
                    // macOS + .NETCore doesn't support shared lock.
                    connectionString.Mode = FileMode.Exclusive;
                }

                _db = new LiteDatabase(connectionString);

                lock (_db.Mapper)
                {
                    _db.Mapper.RegisterType(
                        hash => hash.ToByteArray(),
                        b => new HashDigest <SHA256>(b));
                    _db.Mapper.RegisterType(
                        txid => txid.ToByteArray(),
                        b => new TxId(b));
                    _db.Mapper.RegisterType(
                        address => address.ToByteArray(),
                        b => new Address(b.AsBinary));
                }

                _blockCache = new LruCache <HashDigest <SHA256>, BlockDigest>(capacity: 512);
            }
        }
Ejemplo n.º 2
0
        public MySQLRichStore(BaseBlockStatesStore store, MySQLRichStoreOptions options)
        {
            _store = store;

            var builder = new MySqlConnectionStringBuilder
            {
                Database = options.Database,
                UserID   = options.Username,
                Password = options.Password,
                Server   = options.Server,
                Port     = options.Port,
            };

            _connectionString = builder.ConnectionString;
            _compiler         = new MySqlCompiler();

            _blockCache = new LruCache <HashDigest <SHA256>, BlockDigest>(capacity: 512);
        }
        protected (BaseBlockStatesStore, IStateStore) LoadStore(string path, string type, int statesCacheSize)
        {
            BaseBlockStatesStore store      = null;
            IStateStore          stateStore = null;

            if (type == "rocksdb")
            {
                try
                {
                    store = new RocksDBStore.RocksDBStore(
                        path,
                        statesCacheSize: statesCacheSize,
                        maxTotalWalSize: 16 * 1024 * 1024,
                        keepLogFileNum: 1);
                    Log.Debug("RocksDB is initialized.");
                }
                catch (TypeInitializationException e)
                {
                    Log.Error("RocksDB is not available. DefaultStore will be used. {0}", e);
                }
            }
            else
            {
                var message = type is null
                    ? "Storage Type is not specified"
                    : $"Storage Type {type} is not supported";
                Log.Debug($"{message}. DefaultStore will be used.");
            }

            store ??= new DefaultStore(
                path, flush: false, compress: true, statesCacheSize: statesCacheSize);

            IKeyValueStore stateKeyValueStore     = new RocksDBKeyValueStore(Path.Combine(path, "states")),
                           stateHashKeyValueStore = new RocksDBKeyValueStore(Path.Combine(path, "state_hashes"));

            stateStore = new TrieStateStore(stateKeyValueStore, stateHashKeyValueStore);

            return(store, stateStore);
        }