diff --git a/substrate/primitives/blockchain/src/header_metadata.rs b/substrate/primitives/blockchain/src/header_metadata.rs index 30024765add3..b2910a32e995 100644 --- a/substrate/primitives/blockchain/src/header_metadata.rs +++ b/substrate/primitives/blockchain/src/header_metadata.rs @@ -18,7 +18,7 @@ //! Implements tree backend, cached header metadata and algorithms //! to compute routes efficiently over the tree of headers. -use parking_lot::RwLock; +use parking_lot::Mutex; use schnellru::{ByLength, LruMap}; use sp_core::U256; use sp_runtime::{ @@ -248,33 +248,33 @@ pub trait HeaderMetadata { /// Caches header metadata in an in-memory LRU cache. pub struct HeaderMetadataCache { - cache: RwLock>>, + cache: Mutex>>, } impl HeaderMetadataCache { /// Creates a new LRU header metadata cache with `capacity`. pub fn new(capacity: u32) -> Self { - HeaderMetadataCache { cache: RwLock::new(LruMap::new(ByLength::new(capacity))) } + HeaderMetadataCache { cache: Mutex::new(LruMap::new(ByLength::new(capacity))) } } } impl Default for HeaderMetadataCache { fn default() -> Self { - HeaderMetadataCache { cache: RwLock::new(LruMap::new(ByLength::new(LRU_CACHE_SIZE))) } + Self::new(LRU_CACHE_SIZE) } } impl HeaderMetadataCache { pub fn header_metadata(&self, hash: Block::Hash) -> Option> { - self.cache.write().get(&hash).cloned() + self.cache.lock().get(&hash).cloned() } pub fn insert_header_metadata(&self, hash: Block::Hash, metadata: CachedHeaderMetadata) { - self.cache.write().insert(hash, metadata); + self.cache.lock().insert(hash, metadata); } pub fn remove_header_metadata(&self, hash: Block::Hash) { - self.cache.write().remove(&hash); + self.cache.lock().remove(&hash); } }