Skip to content

Commit aa7cced

Browse files
starknet_patricia_storage: non mut get in storage trait
1 parent 43eaaff commit aa7cced

File tree

8 files changed

+18
-18
lines changed

8 files changed

+18
-18
lines changed

crates/starknet_committer_cli/src/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ fn apply_interference<S: AsyncStorage>(
376376
n_updates_arg: usize,
377377
block_number: usize,
378378
task_set: &mut JoinSet<()>,
379-
mut storage: S,
379+
storage: S,
380380
rng: &mut SmallRng,
381381
) {
382382
match interference_type {

crates/starknet_patricia_storage/src/aerospike_storage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl Storage for AerospikeStorage {
124124
type Stats = NoStats;
125125
type Config = EmptyStorageConfig;
126126

127-
async fn get(&mut self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
127+
async fn get(&self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
128128
let record = self
129129
.client
130130
.get(&self.config.read_policy, &self.get_key(key.clone())?, Bins::All)
@@ -143,7 +143,7 @@ impl Storage for AerospikeStorage {
143143
.await?)
144144
}
145145

146-
async fn mget(&mut self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
146+
async fn mget(&self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
147147
let mut ops = Vec::new();
148148
for key in keys.iter() {
149149
ops.push(BatchOperation::read(

crates/starknet_patricia_storage/src/map_storage.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ impl Storage for MapStorage {
5252
Ok(())
5353
}
5454

55-
async fn get(&mut self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
55+
async fn get(&self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
5656
Ok(self.0.get(key).cloned())
5757
}
5858

59-
async fn mget(&mut self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
59+
async fn mget(&self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
6060
Ok(keys.iter().map(|key| self.0.get(key).cloned()).collect())
6161
}
6262

@@ -222,7 +222,7 @@ impl<S: Storage> Storage for CachedStorage<S> {
222222
type Stats = CachedStorageStats<S::Stats>;
223223
type Config = CachedStorageConfig<S::Config>;
224224

225-
async fn get(&mut self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
225+
async fn get(&self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
226226
if let Some(cached_value) = self.cache.peek(key) {
227227
return Ok(cached_value.clone());
228228
}
@@ -238,7 +238,7 @@ impl<S: Storage> Storage for CachedStorage<S> {
238238
Ok(())
239239
}
240240

241-
async fn mget(&mut self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
241+
async fn mget(&self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
242242
let mut values = vec![None; keys.len()]; // The None values are placeholders.
243243
let mut keys_to_fetch = Vec::new();
244244
let mut indices_to_fetch = Vec::new();

crates/starknet_patricia_storage/src/mdbx_storage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl Storage for MdbxStorage {
103103
type Stats = MdbxStorageStats;
104104
type Config = EmptyStorageConfig;
105105

106-
async fn get(&mut self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
106+
async fn get(&self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
107107
let txn = self.db.begin_ro_txn()?;
108108
let table = txn.open_table(None)?;
109109
Ok(txn.get(&table, &key.0)?.map(DbValue))
@@ -117,7 +117,7 @@ impl Storage for MdbxStorage {
117117
Ok(())
118118
}
119119

120-
async fn mget(&mut self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
120+
async fn mget(&self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
121121
let txn = self.db.begin_ro_txn()?;
122122
let table = txn.open_table(None)?;
123123
let mut res = Vec::with_capacity(keys.len());

crates/starknet_patricia_storage/src/rocksdb_storage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,15 @@ impl Storage for RocksDbStorage {
277277
type Stats = RocksDbStats;
278278
type Config = RocksDbStorageConfig;
279279

280-
async fn get(&mut self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
280+
async fn get(&self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
281281
Ok(self.db.get(&key.0)?.map(DbValue))
282282
}
283283

284284
async fn set(&mut self, key: DbKey, value: DbValue) -> PatriciaStorageResult<()> {
285285
Ok(self.db.put_opt(&key.0, &value.0, &self.options.write_options)?)
286286
}
287287

288-
async fn mget(&mut self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
288+
async fn mget(&self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
289289
let raw_keys = keys.iter().map(|k| &k.0);
290290
let res = self
291291
.db

crates/starknet_patricia_storage/src/short_key_storage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ macro_rules! define_short_key_storage {
5050
type Stats = S::Stats;
5151
type Config = EmptyStorageConfig;
5252

53-
async fn get(&mut self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
53+
async fn get(&self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
5454
self.storage.get(&Self::small_key(key)).await
5555
}
5656

5757
async fn set(&mut self, key: DbKey, value: DbValue) -> PatriciaStorageResult<()> {
5858
self.storage.set(Self::small_key(&key), value).await
5959
}
6060

61-
async fn mget(&mut self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
61+
async fn mget(&self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
6262
let small_keys = keys
6363
.iter()
6464
.map(|key| Self::small_key(key))

crates/starknet_patricia_storage/src/storage_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async fn test_storage_concurrent_access(#[case] mut storage: impl AsyncStorage)
3737
// Parallel reads from the storage while some writes are happening.
3838
let mut tasks = JoinSet::new();
3939
for i in 0..10u8 {
40-
let mut cloned_storage = storage.clone();
40+
let cloned_storage = storage.clone();
4141
tasks.spawn(async move {
4242
let result = cloned_storage.get(&DbKey(vec![i])).await.unwrap().unwrap().0[0];
4343
// The result is either the original value or the new value.

crates/starknet_patricia_storage/src/storage_trait.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub trait Storage: Send + Sync {
103103
// https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html#async-fn-in-public-traits
104104
// for details.
105105
fn get(
106-
&mut self,
106+
&self,
107107
key: &DbKey,
108108
) -> impl Future<Output = PatriciaStorageResult<Option<DbValue>>> + Send;
109109

@@ -123,7 +123,7 @@ pub trait Storage: Send + Sync {
123123
// https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html#async-fn-in-public-traits
124124
// for details.
125125
fn mget(
126-
&mut self,
126+
&self,
127127
keys: &[&DbKey],
128128
) -> impl Future<Output = PatriciaStorageResult<Vec<Option<DbValue>>>> + Send;
129129

@@ -185,15 +185,15 @@ impl Storage for NullStorage {
185185
type Stats = NoStats;
186186
type Config = EmptyStorageConfig;
187187

188-
async fn get(&mut self, _key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
188+
async fn get(&self, _key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
189189
Ok(None)
190190
}
191191

192192
async fn set(&mut self, _key: DbKey, _value: DbValue) -> PatriciaStorageResult<()> {
193193
Ok(())
194194
}
195195

196-
async fn mget(&mut self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
196+
async fn mget(&self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
197197
Ok(vec![None; keys.len()])
198198
}
199199

0 commit comments

Comments
 (0)