Skip to content

Commit 3a7cf7e

Browse files
starknet_committer_cli: add option for key size
1 parent 8fd1036 commit 3a7cf7e

File tree

1 file changed

+74
-4
lines changed
  • crates/starknet_committer_cli/src

1 file changed

+74
-4
lines changed

crates/starknet_committer_cli/src/main.rs

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ struct StorageArgs {
4343
/// checkpointing is ignored.
4444
#[clap(long, default_value = "cached-mdbx")]
4545
storage_type: StorageType,
46+
/// If not none, wraps the storage in a key-shrinking storage.
47+
/// See `short_key_storage.rs` for more details and allowed values.
48+
#[clap(long, default_value = None)]
49+
key_size: Option<u8>,
4650
/// If using cached storage, the size of the cache.
4751
#[clap(long, default_value = "1000000")]
4852
cache_size: usize,
@@ -74,6 +78,54 @@ enum Command {
7478
StorageBenchmark(StorageArgs),
7579
}
7680

81+
/// Multiplexer to avoid dynamic dispatch.
82+
/// If the key_size is not None, wraps the storage in a key-shrinking storage before running the
83+
/// benchmark.
84+
macro_rules! generate_short_key_benchmark {
85+
(
86+
$key_size:expr,
87+
$seed:expr,
88+
$n_iterations:expr,
89+
$n_diffs:expr,
90+
$output_dir:expr,
91+
$checkpoint_dir_arg:expr,
92+
$storage:expr,
93+
$checkpoint_interval:expr,
94+
$( ($size:expr, $name:ident) ),+ $(,)?
95+
) => {
96+
match $key_size {
97+
None => {
98+
run_storage_benchmark(
99+
$seed,
100+
$n_iterations,
101+
$n_diffs,
102+
&$output_dir,
103+
$checkpoint_dir_arg,
104+
$storage,
105+
$checkpoint_interval,
106+
)
107+
.await
108+
}
109+
$(
110+
Some(size) if size == $size => {
111+
let storage = starknet_patricia_storage::short_key_storage::$name::new($storage);
112+
run_storage_benchmark(
113+
$seed,
114+
$n_iterations,
115+
$n_diffs,
116+
&$output_dir,
117+
$checkpoint_dir_arg,
118+
storage,
119+
$checkpoint_interval,
120+
)
121+
.await
122+
}
123+
)+
124+
Some(other_size) => panic!("Invalid key size: {other_size}"),
125+
}
126+
}
127+
}
128+
77129
/// Wrapper to reduce boilerplate and avoid having to use `Box<dyn Storage>`.
78130
/// Different invocations of this function are used with different concrete storage types.
79131
async fn run_storage_benchmark_wrapper<S: Storage>(
@@ -86,6 +138,7 @@ async fn run_storage_benchmark_wrapper<S: Storage>(
86138
data_path,
87139
output_dir,
88140
checkpoint_dir,
141+
key_size,
89142
..
90143
}: StorageArgs,
91144
storage: S,
@@ -102,16 +155,33 @@ async fn run_storage_benchmark_wrapper<S: Storage>(
102155
StorageType::MapStorage => None,
103156
};
104157

105-
run_storage_benchmark(
158+
generate_short_key_benchmark!(
159+
key_size,
106160
seed,
107161
n_iterations,
108162
n_diffs,
109-
&output_dir,
163+
output_dir,
110164
checkpoint_dir_arg,
111165
storage,
112166
checkpoint_interval,
113-
)
114-
.await;
167+
(16, ShortKeyStorage16),
168+
(17, ShortKeyStorage17),
169+
(18, ShortKeyStorage18),
170+
(19, ShortKeyStorage19),
171+
(20, ShortKeyStorage20),
172+
(21, ShortKeyStorage21),
173+
(22, ShortKeyStorage22),
174+
(23, ShortKeyStorage23),
175+
(24, ShortKeyStorage24),
176+
(25, ShortKeyStorage25),
177+
(26, ShortKeyStorage26),
178+
(27, ShortKeyStorage27),
179+
(28, ShortKeyStorage28),
180+
(29, ShortKeyStorage29),
181+
(30, ShortKeyStorage30),
182+
(31, ShortKeyStorage31),
183+
(32, ShortKeyStorage32)
184+
);
115185
}
116186

117187
pub async fn run_committer_cli(

0 commit comments

Comments
 (0)