1use crate::{
8 arg_enums::{
9 ExecutionStrategy, WasmExecutionMethod, WasmtimeInstantiationStrategy,
10 DEFAULT_WASMTIME_INSTANTIATION_STRATEGY, DEFAULT_WASM_EXECUTION_METHOD,
11 },
12 params::{DatabaseParams, PruningParams},
13};
14use clap::{Args, ValueEnum};
15use std::path::PathBuf;
16
17#[derive(Debug, Clone, Args)]
19pub struct ImportParams {
20 #[allow(missing_docs)]
21 #[clap(flatten)]
22 pub pruning_params: PruningParams,
23
24 #[allow(missing_docs)]
25 #[clap(flatten)]
26 pub database_params: DatabaseParams,
27
28 #[arg(
30 long = "wasm-execution",
31 value_name = "METHOD",
32 value_enum,
33 ignore_case = true,
34 default_value_t = DEFAULT_WASM_EXECUTION_METHOD,
35 )]
36 pub wasm_method: WasmExecutionMethod,
37
38 #[arg(
49 long,
50 value_name = "STRATEGY",
51 default_value_t = DEFAULT_WASMTIME_INSTANTIATION_STRATEGY,
52 value_enum,
53 )]
54 pub wasmtime_instantiation_strategy: WasmtimeInstantiationStrategy,
55
56 #[arg(long, value_name = "PATH")]
60 pub wasm_runtime_overrides: Option<PathBuf>,
61
62 #[allow(missing_docs)]
63 #[clap(flatten)]
64 pub execution_strategies: ExecutionStrategiesParams,
65
66 #[arg(long, value_name = "Bytes", default_value_t = 1024 * 1024 * 1024)]
70 pub trie_cache_size: usize,
71
72 #[arg(long, value_name = "STRATEGY", value_enum, num_args = 0..=1, default_missing_value = "non-blocking")]
76 pub warm_up_trie_cache: Option<TrieCacheWarmUpStrategy>,
77}
78
79#[derive(Debug, Clone, Copy, ValueEnum)]
81pub enum TrieCacheWarmUpStrategy {
82 #[clap(name = "non-blocking")]
84 NonBlocking,
85 #[clap(name = "blocking")]
91 Blocking,
92}
93
94impl From<TrieCacheWarmUpStrategy> for soil_service::config::TrieCacheWarmUpStrategy {
95 fn from(strategy: TrieCacheWarmUpStrategy) -> Self {
96 match strategy {
97 TrieCacheWarmUpStrategy::NonBlocking => {
98 soil_service::config::TrieCacheWarmUpStrategy::NonBlocking
99 },
100 TrieCacheWarmUpStrategy::Blocking => {
101 soil_service::config::TrieCacheWarmUpStrategy::Blocking
102 },
103 }
104 }
105}
106
107impl ImportParams {
108 pub fn trie_cache_maximum_size(&self) -> Option<usize> {
110 if self.trie_cache_size == 0 {
111 None
112 } else {
113 Some(self.trie_cache_size)
114 }
115 }
116
117 pub fn warm_up_trie_cache(&self) -> Option<TrieCacheWarmUpStrategy> {
119 self.warm_up_trie_cache
120 }
121
122 pub fn wasm_method(&self) -> soil_service::config::WasmExecutionMethod {
124 self.execution_strategies.check_usage_and_print_deprecation_warning();
125
126 crate::execution_method_from_cli(self.wasm_method, self.wasmtime_instantiation_strategy)
127 }
128
129 pub fn wasm_runtime_overrides(&self) -> Option<PathBuf> {
132 self.wasm_runtime_overrides.clone()
133 }
134}
135
136#[derive(Debug, Clone, Args)]
138pub struct ExecutionStrategiesParams {
139 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
141 pub execution_syncing: Option<ExecutionStrategy>,
142
143 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
145 pub execution_import_block: Option<ExecutionStrategy>,
146
147 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
149 pub execution_block_construction: Option<ExecutionStrategy>,
150
151 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
153 pub execution_offchain_worker: Option<ExecutionStrategy>,
154
155 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
157 pub execution_other: Option<ExecutionStrategy>,
158
159 #[arg(
161 long,
162 value_name = "STRATEGY",
163 value_enum,
164 ignore_case = true,
165 conflicts_with_all = &[
166 "execution_other",
167 "execution_offchain_worker",
168 "execution_block_construction",
169 "execution_import_block",
170 "execution_syncing",
171 ]
172 )]
173 pub execution: Option<ExecutionStrategy>,
174}
175
176impl ExecutionStrategiesParams {
177 fn check_usage_and_print_deprecation_warning(&self) {
179 for (param, name) in [
180 (&self.execution_syncing, "execution-syncing"),
181 (&self.execution_import_block, "execution-import-block"),
182 (&self.execution_block_construction, "execution-block-construction"),
183 (&self.execution_offchain_worker, "execution-offchain-worker"),
184 (&self.execution_other, "execution-other"),
185 (&self.execution, "execution"),
186 ] {
187 if param.is_some() {
188 eprintln!(
189 "CLI parameter `--{name}` has no effect anymore and will be removed in the future!"
190 );
191 }
192 }
193 }
194}