Skip to content

Commit b32f6a9

Browse files
starknet_patricia_storage: change cache size to u64
1 parent 4231b13 commit b32f6a9

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

crates/apollo_committer_config/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use starknet_patricia_storage::storage_trait::{Storage, StorageConfigTrait};
1111
use validator::Validate;
1212

1313
// 1M size cache.
14-
pub const DEFAULT_CACHE_MAX_ENTRIES: usize = 1000000;
14+
pub const DEFAULT_CACHE_MAX_ENTRIES: u64 = 1000000;
1515

1616
pub type ApolloStorage = CachedStorage<RocksDbStorage>;
1717

crates/starknet_committer_cli/src/args.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::fs;
2-
use std::num::NonZeroUsize;
32
use std::path::Path;
43
use std::sync::LazyLock;
54

@@ -219,7 +218,7 @@ pub struct CachedStorageArgs<InnerStorageArgs: StorageFromArgs> {
219218

220219
/// The size of the cache.
221220
#[clap(long, default_value = "1000000")]
222-
pub cache_size: usize,
221+
pub cache_size: u64,
223222
}
224223

225224
#[async_trait]

crates/starknet_patricia_storage/src/map_storage.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::collections::BTreeMap;
22
use std::fmt::Display;
3-
use std::num::NonZeroUsize;
43

54
use apollo_config::dumping::{prepend_sub_config_name, ser_param, SerializeConfig};
65
use apollo_config::{ParamPath, ParamPrivacyInput, SerializedParam};
@@ -23,7 +22,7 @@ use crate::storage_trait::{
2322
};
2423

2524
// 1M entries.
26-
const DEFAULT_CACHE_SIZE: usize = 1000000;
25+
const DEFAULT_CACHE_SIZE: u64 = 1000000;
2726

2827
#[derive(Debug, Default, PartialEq, Serialize)]
2928
pub struct MapStorage(pub DbHashMap);
@@ -85,7 +84,7 @@ pub struct CachedStorage<S: Storage> {
8584
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
8685
pub struct CachedStorageConfig<InnerStorageConfig: StorageConfigTrait> {
8786
// Max number of entries in the cache.
88-
pub cache_size: NonZeroUsize, // TODO(Nimrod): Change type to `u64`.
87+
pub cache_size: u64,
8988

9089
// If true, the cache is updated on write operations even if the value is not in the cache.
9190
pub cache_on_write: bool,
@@ -100,7 +99,7 @@ pub struct CachedStorageConfig<InnerStorageConfig: StorageConfigTrait> {
10099
impl<InnerStorageConfig: StorageConfigTrait> Default for CachedStorageConfig<InnerStorageConfig> {
101100
fn default() -> Self {
102101
Self {
103-
cache_size: NonZeroUsize::new(DEFAULT_CACHE_SIZE).unwrap(),
102+
cache_size: DEFAULT_CACHE_SIZE,
104103
cache_on_write: true,
105104
include_inner_stats: true,
106105
inner_storage_config: InnerStorageConfig::default(),
@@ -203,9 +202,7 @@ impl<S: Storage> CachedStorage<S> {
203202
// TODO(Nimrod): Consider defining custom eviction policies.
204203
Self {
205204
storage,
206-
cache: Cache::builder()
207-
.max_capacity(config.cache_size.get().try_into().unwrap())
208-
.build(),
205+
cache: Cache::builder().max_capacity(config.cache_size).build(),
209206
cache_on_write: config.cache_on_write,
210207
reads: 0,
211208
cached_reads: 0,

crates/starknet_patricia_storage/src/map_storage_test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::collections::HashMap;
2-
use std::num::NonZeroUsize;
32

43
use rstest::rstest;
54

@@ -10,7 +9,7 @@ use crate::storage_trait::{DbKey, DbValue, EmptyStorageConfig, Storage};
109
#[case::map_storage(MapStorage::default())]
1110
#[case::cached_storage(
1211
CachedStorage::new(MapStorage::default(), CachedStorageConfig {
13-
cache_size: NonZeroUsize::new(2).unwrap(),
12+
cache_size: 2,
1413
cache_on_write: true,
1514
include_inner_stats: false,
1615
inner_storage_config: EmptyStorageConfig::default(),

0 commit comments

Comments
 (0)