1use crate::{
20 arg_enums::{
21 ExecutionStrategy, WasmExecutionMethod, WasmtimeInstantiationStrategy,
22 DEFAULT_WASMTIME_INSTANTIATION_STRATEGY, DEFAULT_WASM_EXECUTION_METHOD,
23 },
24 params::{DatabaseParams, PruningParams},
25};
26use clap::{Args, ValueEnum};
27use std::path::PathBuf;
28
29#[derive(Debug, Clone, Args)]
31pub struct ImportParams {
32 #[allow(missing_docs)]
33 #[clap(flatten)]
34 pub pruning_params: PruningParams,
35
36 #[allow(missing_docs)]
37 #[clap(flatten)]
38 pub database_params: DatabaseParams,
39
40 #[arg(
42 long = "wasm-execution",
43 value_name = "METHOD",
44 value_enum,
45 ignore_case = true,
46 default_value_t = DEFAULT_WASM_EXECUTION_METHOD,
47 )]
48 pub wasm_method: WasmExecutionMethod,
49
50 #[arg(
61 long,
62 value_name = "STRATEGY",
63 default_value_t = DEFAULT_WASMTIME_INSTANTIATION_STRATEGY,
64 value_enum,
65 )]
66 pub wasmtime_instantiation_strategy: WasmtimeInstantiationStrategy,
67
68 #[arg(long, value_name = "PATH")]
72 pub wasm_runtime_overrides: Option<PathBuf>,
73
74 #[allow(missing_docs)]
75 #[clap(flatten)]
76 pub execution_strategies: ExecutionStrategiesParams,
77
78 #[arg(long, value_name = "Bytes", default_value_t = 1024 * 1024 * 1024)]
82 pub trie_cache_size: usize,
83
84 #[arg(long, value_name = "STRATEGY", value_enum, num_args = 0..=1, default_missing_value = "non-blocking")]
88 pub warm_up_trie_cache: Option<TrieCacheWarmUpStrategy>,
89}
90
91#[derive(Debug, Clone, Copy, ValueEnum)]
93pub enum TrieCacheWarmUpStrategy {
94 #[clap(name = "non-blocking")]
96 NonBlocking,
97 #[clap(name = "blocking")]
103 Blocking,
104}
105
106impl From<TrieCacheWarmUpStrategy> for pezsc_service::config::TrieCacheWarmUpStrategy {
107 fn from(strategy: TrieCacheWarmUpStrategy) -> Self {
108 match strategy {
109 TrieCacheWarmUpStrategy::NonBlocking => {
110 pezsc_service::config::TrieCacheWarmUpStrategy::NonBlocking
111 },
112 TrieCacheWarmUpStrategy::Blocking => {
113 pezsc_service::config::TrieCacheWarmUpStrategy::Blocking
114 },
115 }
116 }
117}
118
119impl ImportParams {
120 pub fn trie_cache_maximum_size(&self) -> Option<usize> {
122 if self.trie_cache_size == 0 {
123 None
124 } else {
125 Some(self.trie_cache_size)
126 }
127 }
128
129 pub fn warm_up_trie_cache(&self) -> Option<TrieCacheWarmUpStrategy> {
131 self.warm_up_trie_cache
132 }
133
134 pub fn wasm_method(&self) -> pezsc_service::config::WasmExecutionMethod {
136 self.execution_strategies.check_usage_and_print_deprecation_warning();
137
138 crate::execution_method_from_cli(self.wasm_method, self.wasmtime_instantiation_strategy)
139 }
140
141 pub fn wasm_runtime_overrides(&self) -> Option<PathBuf> {
144 self.wasm_runtime_overrides.clone()
145 }
146}
147
148#[derive(Debug, Clone, Args)]
150pub struct ExecutionStrategiesParams {
151 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
153 pub execution_syncing: Option<ExecutionStrategy>,
154
155 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
157 pub execution_import_block: Option<ExecutionStrategy>,
158
159 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
161 pub execution_block_construction: Option<ExecutionStrategy>,
162
163 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
165 pub execution_offchain_worker: Option<ExecutionStrategy>,
166
167 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
169 pub execution_other: Option<ExecutionStrategy>,
170
171 #[arg(
173 long,
174 value_name = "STRATEGY",
175 value_enum,
176 ignore_case = true,
177 conflicts_with_all = &[
178 "execution_other",
179 "execution_offchain_worker",
180 "execution_block_construction",
181 "execution_import_block",
182 "execution_syncing",
183 ]
184 )]
185 pub execution: Option<ExecutionStrategy>,
186}
187
188impl ExecutionStrategiesParams {
189 fn check_usage_and_print_deprecation_warning(&self) {
191 for (param, name) in [
192 (&self.execution_syncing, "execution-syncing"),
193 (&self.execution_import_block, "execution-import-block"),
194 (&self.execution_block_construction, "execution-block-construction"),
195 (&self.execution_offchain_worker, "execution-offchain-worker"),
196 (&self.execution_other, "execution-other"),
197 (&self.execution, "execution"),
198 ] {
199 if param.is_some() {
200 eprintln!(
201 "CLI parameter `--{name}` has no effect anymore and will be removed in the future!"
202 );
203 }
204 }
205 }
206}