11use std:: fs;
2+ use std:: num:: NonZeroUsize ;
23use std:: path:: Path ;
34
45use apollo_infra_utils:: tracing_utils:: { configure_tracing, modify_log_level} ;
56use clap:: { Args , Parser , Subcommand } ;
67use starknet_committer_cli:: commands:: run_storage_benchmark;
7- use starknet_patricia_storage:: map_storage:: MapStorage ;
8+ use starknet_patricia_storage:: map_storage:: { CachedStorage , MapStorage } ;
89use starknet_patricia_storage:: mdbx_storage:: MdbxStorage ;
910use tracing:: info;
1011use tracing:: level_filters:: LevelFilter ;
@@ -21,6 +22,7 @@ pub struct CommitterCliCommand {
2122pub enum StorageType {
2223 MapStorage ,
2324 Mdbx ,
25+ CachedMdbx ,
2426}
2527
2628const DEFAULT_DATA_PATH : & str = "/tmp/committer_storage_benchmark" ;
@@ -38,8 +40,11 @@ struct StorageArgs {
3840 n_diffs : usize ,
3941 /// Storage impl to use. Note that MapStorage isn't persisted in the file system, so
4042 /// checkpointing is ignored.
41- #[ clap( long, default_value = "mdbx" ) ]
43+ #[ clap( long, default_value = "cached- mdbx" ) ]
4244 storage_type : StorageType ,
45+ /// If using cached storage, the size of the cache.
46+ #[ clap( long, default_value = "1000000" ) ]
47+ cache_size : usize ,
4348 #[ clap( long, default_value = "1000" ) ]
4449 checkpoint_interval : usize ,
4550 #[ clap( long, default_value = "warn" ) ]
@@ -79,6 +84,7 @@ pub async fn run_committer_cli(
7984 n_iterations,
8085 n_diffs,
8186 storage_type,
87+ cache_size,
8288 checkpoint_interval,
8389 log_level,
8490 data_path,
@@ -123,6 +129,25 @@ pub async fn run_committer_cli(
123129 )
124130 . await ;
125131 }
132+ StorageType :: CachedMdbx => {
133+ let storage_path = storage_path
134+ . unwrap_or_else ( || format ! ( "{data_path}/storage/{storage_type:?}" ) ) ;
135+ fs:: create_dir_all ( & storage_path) . expect ( "Failed to create storage directory." ) ;
136+ let storage = CachedStorage :: new (
137+ MdbxStorage :: open ( Path :: new ( & storage_path) ) . unwrap ( ) ,
138+ NonZeroUsize :: new ( cache_size) . unwrap ( ) ,
139+ ) ;
140+ run_storage_benchmark (
141+ seed,
142+ n_iterations,
143+ n_diffs,
144+ & output_dir,
145+ Some ( & checkpoint_dir) ,
146+ storage,
147+ checkpoint_interval,
148+ )
149+ . await ;
150+ }
126151 }
127152 }
128153 }
0 commit comments