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 sc_service::config::TrieCacheWarmUpStrategy {
107 fn from(strategy: TrieCacheWarmUpStrategy) -> Self {
108 match strategy {
109 TrieCacheWarmUpStrategy::NonBlocking =>
110 sc_service::config::TrieCacheWarmUpStrategy::NonBlocking,
111 TrieCacheWarmUpStrategy::Blocking =>
112 sc_service::config::TrieCacheWarmUpStrategy::Blocking,
113 }
114 }
115}
116
117impl ImportParams {
118 pub fn trie_cache_maximum_size(&self) -> Option<usize> {
120 if self.trie_cache_size == 0 {
121 None
122 } else {
123 Some(self.trie_cache_size)
124 }
125 }
126
127 pub fn warm_up_trie_cache(&self) -> Option<TrieCacheWarmUpStrategy> {
129 self.warm_up_trie_cache
130 }
131
132 pub fn wasm_method(&self) -> sc_service::config::WasmExecutionMethod {
134 self.execution_strategies.check_usage_and_print_deprecation_warning();
135
136 crate::execution_method_from_cli(self.wasm_method, self.wasmtime_instantiation_strategy)
137 }
138
139 pub fn wasm_runtime_overrides(&self) -> Option<PathBuf> {
142 self.wasm_runtime_overrides.clone()
143 }
144}
145
146#[derive(Debug, Clone, Args)]
148pub struct ExecutionStrategiesParams {
149 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
151 pub execution_syncing: Option<ExecutionStrategy>,
152
153 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
155 pub execution_import_block: Option<ExecutionStrategy>,
156
157 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
159 pub execution_block_construction: Option<ExecutionStrategy>,
160
161 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
163 pub execution_offchain_worker: Option<ExecutionStrategy>,
164
165 #[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
167 pub execution_other: Option<ExecutionStrategy>,
168
169 #[arg(
171 long,
172 value_name = "STRATEGY",
173 value_enum,
174 ignore_case = true,
175 conflicts_with_all = &[
176 "execution_other",
177 "execution_offchain_worker",
178 "execution_block_construction",
179 "execution_import_block",
180 "execution_syncing",
181 ]
182 )]
183 pub execution: Option<ExecutionStrategy>,
184}
185
186impl ExecutionStrategiesParams {
187 fn check_usage_and_print_deprecation_warning(&self) {
189 for (param, name) in [
190 (&self.execution_syncing, "execution-syncing"),
191 (&self.execution_import_block, "execution-import-block"),
192 (&self.execution_block_construction, "execution-block-construction"),
193 (&self.execution_offchain_worker, "execution-offchain-worker"),
194 (&self.execution_other, "execution-other"),
195 (&self.execution, "execution"),
196 ] {
197 if param.is_some() {
198 eprintln!(
199 "CLI parameter `--{name}` has no effect anymore and will be removed in the future!"
200 );
201 }
202 }
203 }
204}