Skip to content

Commit b50a0d9

Browse files
starknet_patricia_storage: non mut get in storage trait
1 parent df1d000 commit b50a0d9

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
@@ -117,7 +117,7 @@ impl Storage for AerospikeStorage {
117117
type Stats = NoStats;
118118
type Config = EmptyStorageConfig;
119119

120-
async fn get(&mut self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
120+
async fn get(&self, key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
121121
let record = self
122122
.client
123123
.get(&self.config.read_policy, &self.get_key(key.clone())?, Bins::All)
@@ -136,7 +136,7 @@ impl Storage for AerospikeStorage {
136136
.await?)
137137
}
138138

139-
async fn mget(&mut self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
139+
async fn mget(&self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
140140
let mut ops = Vec::new();
141141
for key in keys.iter() {
142142
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
@@ -51,11 +51,11 @@ impl Storage for MapStorage {
5151
Ok(())
5252
}
5353

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

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

@@ -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.get(key) {
227227
return Ok(cached_value);
228228
}
@@ -239,7 +239,7 @@ impl<S: Storage> Storage for CachedStorage<S> {
239239
Ok(())
240240
}
241241

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

@@ -194,15 +194,15 @@ impl Storage for NullStorage {
194194
type Stats = NoStats;
195195
type Config = EmptyStorageConfig;
196196

197-
async fn get(&mut self, _key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
197+
async fn get(&self, _key: &DbKey) -> PatriciaStorageResult<Option<DbValue>> {
198198
Ok(None)
199199
}
200200

201201
async fn set(&mut self, _key: DbKey, _value: DbValue) -> PatriciaStorageResult<()> {
202202
Ok(())
203203
}
204204

205-
async fn mget(&mut self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
205+
async fn mget(&self, keys: &[&DbKey]) -> PatriciaStorageResult<Vec<Option<DbValue>>> {
206206
Ok(vec![None; keys.len()])
207207
}
208208

0 commit comments

Comments
 (0)