Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/starknet_committer_cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub struct CachedStorageArgs<InnerStorageArgs: StorageFromArgs> {
impl<InnerStorageArgs: StorageFromArgs + Sync> StorageFromArgs
for CachedStorageArgs<InnerStorageArgs>
where
InnerStorageArgs::Storage: ImmutableReadOnlyStorage,
InnerStorageArgs::Storage: ImmutableReadOnlyStorage + 'static,
{
type Storage = CachedStorage<InnerStorageArgs::Storage>;

Expand Down
7 changes: 7 additions & 0 deletions crates/starknet_patricia_storage/src/aerospike_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::storage_trait::{
DbOperationMap,
DbValue,
EmptyStorageConfig,
GatherableStorage,
ImmutableReadOnlyStorage,
NoStats,
PatriciaStorageResult,
Expand Down Expand Up @@ -255,4 +256,10 @@ impl Storage for AerospikeStorage {
fn get_async_self(&self) -> Option<impl AsyncStorage> {
Some(self.clone())
}

fn as_gatherable_storage(&mut self) -> Option<&mut impl GatherableStorage> {
Some(self)
}
}

impl GatherableStorage for AerospikeStorage {}
11 changes: 10 additions & 1 deletion crates/starknet_patricia_storage/src/map_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ impl Storage for MapStorage {
// Need a concrete Option type.
None::<NullStorage>
}

fn as_gatherable_storage(&mut self) -> Option<&mut impl GatherableStorage> {
// Return None to avoid using the MapStorage concurrently; the reads are fast anyway.
None::<&mut NullStorage>
}
Comment thread
cursor[bot] marked this conversation as resolved.
}

/// A storage wrapper that adds an LRU cache to an underlying storage.
Expand Down Expand Up @@ -342,7 +347,7 @@ impl<S: Storage> ReadOnlyStorage for CachedStorage<S> {
}
}

impl<S: Storage> Storage for CachedStorage<S> {
impl<S: Storage + ImmutableReadOnlyStorage + 'static> Storage for CachedStorage<S> {
type Stats = CachedStorageStats<S::Stats>;
type Config = CachedStorageConfig<S::Config>;

Expand Down Expand Up @@ -414,4 +419,8 @@ impl<S: Storage> Storage for CachedStorage<S> {
// Need a concrete Option type.
None::<NullStorage>
}

fn as_gatherable_storage(&mut self) -> Option<&mut impl GatherableStorage> {
Some(self)
}
}
7 changes: 7 additions & 0 deletions crates/starknet_patricia_storage/src/mdbx_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::storage_trait::{
DbOperationMap,
DbValue,
EmptyStorageConfig,
GatherableStorage,
ImmutableReadOnlyStorage,
PatriciaStorageResult,
ReadOnlyStorage,
Expand Down Expand Up @@ -190,4 +191,10 @@ impl Storage for MdbxStorage {
fn get_async_self(&self) -> Option<impl AsyncStorage> {
Some(self.clone())
}

fn as_gatherable_storage(&mut self) -> Option<&mut impl GatherableStorage> {
Some(self)
}
}

impl GatherableStorage for MdbxStorage {}
7 changes: 7 additions & 0 deletions crates/starknet_patricia_storage/src/rocksdb_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::storage_trait::{
DbOperation,
DbOperationMap,
DbValue,
GatherableStorage,
ImmutableReadOnlyStorage,
PatriciaStorageError,
PatriciaStorageResult,
Expand Down Expand Up @@ -375,4 +376,10 @@ impl Storage for RocksDbStorage {
fn get_async_self(&self) -> Option<impl AsyncStorage> {
Some(self.clone())
}

fn as_gatherable_storage(&mut self) -> Option<&mut impl GatherableStorage> {
Some(self)
}
}

impl GatherableStorage for RocksDbStorage {}
6 changes: 6 additions & 0 deletions crates/starknet_patricia_storage/src/short_key_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use crate::storage_trait::{
DbOperationMap,
DbValue,
EmptyStorageConfig,
GatherableStorage,
ImmutableReadOnlyStorage,
NullStorage,
PatriciaStorageResult,
ReadOnlyStorage,
Storage,
Expand Down Expand Up @@ -121,6 +123,10 @@ macro_rules! define_short_key_storage {
fn get_async_self(&self) -> Option<impl AsyncStorage> {
Some($name::new(self.storage.get_async_self()?))
}

fn as_gatherable_storage(&mut self) -> Option<&mut impl GatherableStorage> {
None::<&mut NullStorage>
}
}

impl<S: AsyncStorage> Clone for $name<S> {
Expand Down
10 changes: 10 additions & 0 deletions crates/starknet_patricia_storage/src/storage_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ pub trait Storage: ReadOnlyStorage {

/// If the storage is async, returns an instance of the async storage.
fn get_async_self(&self) -> Option<impl AsyncStorage>;

/// If the storage supports concurrent task execution via [GatherableStorage::gather], returns
/// a mutable reference to it. Returns `None` otherwise.
fn as_gatherable_storage(&mut self) -> Option<&mut impl GatherableStorage>;
}

/// A trait wrapper for [Storage] that supports concurrency.
Expand Down Expand Up @@ -327,8 +331,14 @@ impl Storage for NullStorage {
fn get_async_self(&self) -> Option<impl AsyncStorage> {
Some(self.clone())
}

fn as_gatherable_storage(&mut self) -> Option<&mut impl GatherableStorage> {
Some(self)
}
}

impl GatherableStorage for NullStorage {}

#[derive(Debug)]
pub struct DbKeyPrefix(Cow<'static, [u8]>);

Expand Down
Loading