Skip to content

Commit a861514

Browse files
starknet_patricia_storage: always cache writes in cached storage
1 parent f073c3d commit a861514

File tree

6 files changed

+2
-31
lines changed

6 files changed

+2
-31
lines changed

crates/apollo_deployments/resources/app_configs/committer_config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"committer_config.db_path": "/data/committer",
33
"committer_config.reader_config.warn_on_trivial_modifications": false,
44
"committer_config.reader_config.build_storage_tries_concurrently": false,
5-
"committer_config.storage_config.cache_on_write": true,
65
"committer_config.storage_config.cache_size": 1000000,
76
"committer_config.storage_config.include_inner_stats": true,
87
"committer_config.storage_config.inner_storage_config.bloom_filter_bits": 10,

crates/apollo_deployments/resources/app_configs/replacer_committer_config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"committer_config.db_path": "/data/committer",
33
"committer_config.reader_config.warn_on_trivial_modifications": false,
44
"committer_config.reader_config.build_storage_tries_concurrently": false,
5-
"committer_config.storage_config.cache_on_write": true,
65
"committer_config.storage_config.cache_size": "$$$_COMMITTER_CONFIG-STORAGE_CONFIG-CACHE_SIZE_$$$",
76
"committer_config.storage_config.include_inner_stats": true,
87
"committer_config.storage_config.inner_storage_config.bloom_filter_bits": 10,

crates/apollo_node/resources/config_schema.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,6 @@
514514
"privacy": "Public",
515515
"value": false
516516
},
517-
"committer_config.storage_config.cache_on_write": {
518-
"description": "If true, the cache is updated on write operations",
519-
"privacy": "Public",
520-
"value": true
521-
},
522517
"committer_config.storage_config.cache_size": {
523518
"description": "Max number of entries in the cache",
524519
"privacy": "Public",

crates/starknet_committer_cli/src/args.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ impl<InnerStorageArgs: StorageFromArgs + Sync> StorageFromArgs
231231
fn storage_config(&self) -> <Self::Storage as Storage>::Config {
232232
CachedStorageConfig {
233233
cache_size: NonZeroUsize::new(self.cache_size).unwrap(),
234-
cache_on_write: true,
235234
include_inner_stats: self.include_inner_stats,
236235
inner_storage_config: self.storage_args.storage_config(),
237236
}

crates/starknet_patricia_storage/src/map_storage.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ impl Storage for MapStorage {
7676
pub struct CachedStorage<S: Storage> {
7777
pub storage: S,
7878
pub cache: LruCache<DbKey, Option<DbValue>>,
79-
pub cache_on_write: bool,
8079
reads: AtomicU64,
8180
cached_reads: AtomicU64,
8281
writes: u128,
@@ -88,9 +87,6 @@ pub struct CachedStorageConfig<InnerStorageConfig: StorageConfigTrait> {
8887
// Max number of entries in the cache.
8988
pub cache_size: NonZeroUsize,
9089

91-
// If true, the cache is updated on write operations even if the value is not in the cache.
92-
pub cache_on_write: bool,
93-
9490
// If true, the inner stats are included when collecting statistics.
9591
pub include_inner_stats: bool,
9692

@@ -102,7 +98,6 @@ impl<InnerStorageConfig: StorageConfigTrait> Default for CachedStorageConfig<Inn
10298
fn default() -> Self {
10399
Self {
104100
cache_size: NonZeroUsize::new(DEFAULT_CACHE_SIZE).unwrap(),
105-
cache_on_write: true,
106101
include_inner_stats: true,
107102
inner_storage_config: InnerStorageConfig::default(),
108103
}
@@ -126,12 +121,6 @@ impl<InnerStorageConfig: StorageConfigTrait> SerializeConfig
126121
"Max number of entries in the cache",
127122
ParamPrivacyInput::Public,
128123
),
129-
ser_param(
130-
"cache_on_write",
131-
&self.cache_on_write,
132-
"If true, the cache is updated on write operations",
133-
ParamPrivacyInput::Public,
134-
),
135124
ser_param(
136125
"include_inner_stats",
137126
&self.include_inner_stats,
@@ -204,20 +193,13 @@ impl<S: Storage> CachedStorage<S> {
204193
Self {
205194
storage,
206195
cache: LruCache::new(config.cache_size),
207-
cache_on_write: config.cache_on_write,
208196
reads: AtomicU64::new(0),
209197
cached_reads: AtomicU64::new(0),
210198
writes: 0,
211199
include_inner_stats: config.include_inner_stats,
212200
}
213201
}
214202

215-
fn update_cached_value(&mut self, key: &DbKey, value: &DbValue) {
216-
if self.cache_on_write || self.cache.contains(key) {
217-
self.cache.put(key.clone(), Some(value.clone()));
218-
}
219-
}
220-
221203
pub fn total_writes(&self) -> u128 {
222204
self.writes
223205
}
@@ -247,7 +229,7 @@ impl<S: Storage> Storage for CachedStorage<S> {
247229
async fn set(&mut self, key: DbKey, value: DbValue) -> PatriciaStorageResult<()> {
248230
self.writes += 1;
249231
self.storage.set(key.clone(), value.clone()).await?;
250-
self.update_cached_value(&key, &value);
232+
self.cache.put(key, Some(value));
251233
Ok(())
252234
}
253235

@@ -282,9 +264,7 @@ impl<S: Storage> Storage for CachedStorage<S> {
282264
async fn mset(&mut self, key_to_value: DbHashMap) -> PatriciaStorageResult<()> {
283265
self.writes += u128::try_from(key_to_value.len()).expect("usize should fit in u128");
284266
self.storage.mset(key_to_value.clone()).await?;
285-
key_to_value.iter().for_each(|(key, value)| {
286-
self.update_cached_value(key, value);
287-
});
267+
self.flush_to_cache(key_to_value);
288268
Ok(())
289269
}
290270

crates/starknet_patricia_storage/src/map_storage_test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::storage_trait::{DbKey, DbValue, EmptyStorageConfig, Storage};
1111
#[case::cached_storage(
1212
CachedStorage::new(MapStorage::default(), CachedStorageConfig {
1313
cache_size: NonZeroUsize::new(2).unwrap(),
14-
cache_on_write: true,
1514
include_inner_stats: false,
1615
inner_storage_config: EmptyStorageConfig::default(),
1716
})

0 commit comments

Comments
 (0)