/// <inheritdoc/> public override BlockDigest?GetBlockDigest(HashDigest <SHA256> blockHash) { if (_blockCache.TryGetValue(blockHash, out BlockDigest cachedDigest)) { return(cachedDigest); } byte[] key = BlockKey(blockHash); if (!(_blockIndexDb.Get(key) is byte[] blockDbNameBytes)) { return(null); } _rwBlockLock.EnterReadLock(); try { string blockDbName = RocksDBStoreBitConverter.GetString(blockDbNameBytes); if (!_blockDbCache.TryGetValue(blockDbName, out RocksDb blockDb)) { blockDb = RocksDBUtils.OpenRocksDb(_options, BlockDbPath(blockDbName)); _blockDbCache.AddOrUpdate(blockDbName, blockDb); } byte[] blockBytes = blockDb.Get(key); BlockDigest blockDigest = BlockDigest.Deserialize(blockBytes); _blockCache.AddOrUpdate(blockHash, blockDigest); return(blockDigest); } finally { _rwBlockLock.ExitReadLock(); } }
/// <inheritdoc/> public override BlockDigest?GetBlockDigest(HashDigest <SHA256> blockHash) { if (_blockCache.TryGetValue(blockHash, out BlockDigest cachedDigest)) { return(cachedDigest); } byte[] key = BlockKey(blockHash); byte[] bytes = _blockDb.Get(key); if (bytes is null) { return(null); } BlockDigest blockDigest = BlockDigest.Deserialize(bytes); _blockCache.AddOrUpdate(blockHash, blockDigest); return(blockDigest); }