Skip to content

Commit 79b85ab

Browse files
starknet_particia_storage: extend the storage trait to optionally flush to cache
1 parent 7a53b42 commit 79b85ab

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

crates/starknet_patricia_storage/src/map_storage.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,8 @@ impl<S: Storage> CachedStorage<S> {
223223
}
224224

225225
pub fn flush_to_cache(&mut self, map: DbHashMap) {
226-
let cache =
227-
Arc::get_mut(&mut self.cache).expect("Failed to get mutable reference to cache.");
228226
map.into_iter().for_each(|(key, value)| {
229-
cache.put(key, Some(value));
227+
self.cache.put(key, Some(value));
230228
});
231229
}
232230
}
@@ -321,4 +319,8 @@ impl<S: Storage> Storage for CachedStorage<S> {
321319
// Need a concrete Option type.
322320
None::<NullStorage>
323321
}
322+
fn flush_to_cache(&mut self, map: DbHashMap) -> PatriciaStorageResult<()> {
323+
Self::flush_to_cache(self, map);
324+
Ok(())
325+
}
324326
}

crates/starknet_patricia_storage/src/storage_trait.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ pub trait Storage: Send + Sync {
155155

156156
/// If the storage is async, returns an instance of the async storage.
157157
fn get_async_self(&self) -> Option<impl AsyncStorage>;
158+
159+
/// If uses a cache, flushes the given map into the cache.
160+
fn flush_to_cache(&mut self, _map: DbHashMap) -> PatriciaStorageResult<()> {
161+
Ok(())
162+
}
158163
}
159164

160165
/// A trait wrapper for [Storage] that supports concurrency.

0 commit comments

Comments
 (0)