Skip to content

Commit db97ed3

Browse files
starknet_committer_cli: use Box<dyn Storage> for storage init
1 parent a01772e commit db97ed3

File tree

2 files changed

+27
-40
lines changed

2 files changed

+27
-40
lines changed

crates/starknet_committer_cli/src/commands.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ pub type InputImpl = Input<ConfigImpl>;
1313
/// Runs the committer on n_iterations random generated blocks.
1414
/// Prints the time measurement to the console and saves statistics to a CSV file in the given
1515
/// output directory.
16-
pub async fn run_storage_benchmark<S: Storage>(
16+
pub async fn run_storage_benchmark<S: Storage + ?Sized>(
1717
seed: u64,
1818
n_iterations: usize,
1919
n_storage_updates_per_iteration: usize,
2020
output_dir: &str,
2121
checkpoint_dir: Option<&str>,
22-
mut storage: S,
22+
storage: &mut S,
2323
checkpoint_interval: usize,
2424
) {
2525
let mut time_measurement = TimeMeasurement::new(checkpoint_interval);
@@ -45,11 +45,11 @@ pub async fn run_storage_benchmark<S: Storage>(
4545
};
4646

4747
time_measurement.start_measurement(Action::EndToEnd);
48-
let filled_forest = commit_block(input, &mut storage, Some(&mut time_measurement))
48+
let filled_forest = commit_block(input, storage, Some(&mut time_measurement))
4949
.await
5050
.expect("Failed to commit the given block.");
5151
time_measurement.start_measurement(Action::Write);
52-
let n_new_facts = filled_forest.write_to_storage(&mut storage);
52+
let n_new_facts = filled_forest.write_to_storage(storage);
5353
info!("Written {n_new_facts} new facts to storage");
5454
time_measurement.stop_measurement(None, Action::Write);
5555

crates/starknet_committer_cli/src/main.rs

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use clap::{Args, Parser, Subcommand};
77
use starknet_committer_cli::commands::run_storage_benchmark;
88
use starknet_patricia_storage::map_storage::{CachedStorage, MapStorage};
99
use starknet_patricia_storage::mdbx_storage::MdbxStorage;
10+
use starknet_patricia_storage::storage_trait::Storage;
1011
use tracing::info;
1112
use tracing::level_filters::LevelFilter;
1213
use tracing_subscriber::reload::Handle;
@@ -99,56 +100,42 @@ pub async fn run_committer_cli(
99100
format!("{data_path}/{storage_type:?}/checkpoints/{n_iterations}")
100101
});
101102

102-
match storage_type {
103-
StorageType::MapStorage => {
104-
let storage = MapStorage::default();
105-
run_storage_benchmark(
106-
seed,
107-
n_iterations,
108-
n_diffs,
109-
&output_dir,
110-
None,
111-
storage,
112-
checkpoint_interval,
113-
)
114-
.await;
115-
}
103+
let (mut storage, checkpoint_dir): (Box<dyn Storage>, Option<&str>) = match storage_type
104+
{
105+
StorageType::MapStorage => (Box::new(MapStorage::default()), None),
116106
StorageType::Mdbx => {
117107
let storage_path = storage_path
118108
.unwrap_or_else(|| format!("{data_path}/storage/{storage_type:?}"));
119109
fs::create_dir_all(&storage_path).expect("Failed to create storage directory.");
120-
let storage = MdbxStorage::open(Path::new(&storage_path)).unwrap();
121-
run_storage_benchmark(
122-
seed,
123-
n_iterations,
124-
n_diffs,
125-
&output_dir,
110+
(
111+
Box::new(MdbxStorage::open(Path::new(&storage_path)).unwrap()),
126112
Some(&checkpoint_dir),
127-
storage,
128-
checkpoint_interval,
129113
)
130-
.await;
131114
}
132115
StorageType::CachedMdbx => {
133116
let storage_path = storage_path
134117
.unwrap_or_else(|| format!("{data_path}/storage/{storage_type:?}"));
135118
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,
119+
(
120+
Box::new(CachedStorage::new(
121+
MdbxStorage::open(Path::new(&storage_path)).unwrap(),
122+
NonZeroUsize::new(cache_size).unwrap(),
123+
)),
145124
Some(&checkpoint_dir),
146-
storage,
147-
checkpoint_interval,
148125
)
149-
.await;
150126
}
151-
}
127+
};
128+
129+
run_storage_benchmark(
130+
seed,
131+
n_iterations,
132+
n_diffs,
133+
&output_dir,
134+
checkpoint_dir,
135+
&mut *storage,
136+
checkpoint_interval,
137+
)
138+
.await;
152139
}
153140
}
154141
}

0 commit comments

Comments
 (0)