use crate::{
arg_enums::{
ExecutionStrategy, WasmExecutionMethod, WasmtimeInstantiationStrategy,
DEFAULT_WASMTIME_INSTANTIATION_STRATEGY, DEFAULT_WASM_EXECUTION_METHOD,
},
params::{DatabaseParams, PruningParams},
};
use clap::{Args, ValueEnum};
use std::path::PathBuf;
#[derive(Debug, Clone, Args)]
pub struct ImportParams {
#[allow(missing_docs)]
#[clap(flatten)]
pub pruning_params: PruningParams,
#[allow(missing_docs)]
#[clap(flatten)]
pub database_params: DatabaseParams,
#[arg(
long = "wasm-execution",
value_name = "METHOD",
value_enum,
ignore_case = true,
default_value_t = DEFAULT_WASM_EXECUTION_METHOD,
)]
pub wasm_method: WasmExecutionMethod,
#[arg(
long,
value_name = "STRATEGY",
default_value_t = DEFAULT_WASMTIME_INSTANTIATION_STRATEGY,
value_enum,
)]
pub wasmtime_instantiation_strategy: WasmtimeInstantiationStrategy,
#[arg(long, value_name = "PATH")]
pub wasm_runtime_overrides: Option<PathBuf>,
#[allow(missing_docs)]
#[clap(flatten)]
pub execution_strategies: ExecutionStrategiesParams,
#[arg(long, value_name = "Bytes", default_value_t = 1024 * 1024 * 1024)]
pub trie_cache_size: usize,
#[arg(long, value_name = "STRATEGY", value_enum, num_args = 0..=1, default_missing_value = "non-blocking")]
pub warm_up_trie_cache: Option<TrieCacheWarmUpStrategy>,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum TrieCacheWarmUpStrategy {
#[clap(name = "non-blocking")]
NonBlocking,
#[clap(name = "blocking")]
Blocking,
}
impl From<TrieCacheWarmUpStrategy> for pezsc_service::config::TrieCacheWarmUpStrategy {
fn from(strategy: TrieCacheWarmUpStrategy) -> Self {
match strategy {
TrieCacheWarmUpStrategy::NonBlocking => {
pezsc_service::config::TrieCacheWarmUpStrategy::NonBlocking
},
TrieCacheWarmUpStrategy::Blocking => {
pezsc_service::config::TrieCacheWarmUpStrategy::Blocking
},
}
}
}
impl ImportParams {
pub fn trie_cache_maximum_size(&self) -> Option<usize> {
if self.trie_cache_size == 0 {
None
} else {
Some(self.trie_cache_size)
}
}
pub fn warm_up_trie_cache(&self) -> Option<TrieCacheWarmUpStrategy> {
self.warm_up_trie_cache
}
pub fn wasm_method(&self) -> pezsc_service::config::WasmExecutionMethod {
self.execution_strategies.check_usage_and_print_deprecation_warning();
crate::execution_method_from_cli(self.wasm_method, self.wasmtime_instantiation_strategy)
}
pub fn wasm_runtime_overrides(&self) -> Option<PathBuf> {
self.wasm_runtime_overrides.clone()
}
}
#[derive(Debug, Clone, Args)]
pub struct ExecutionStrategiesParams {
#[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
pub execution_syncing: Option<ExecutionStrategy>,
#[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
pub execution_import_block: Option<ExecutionStrategy>,
#[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
pub execution_block_construction: Option<ExecutionStrategy>,
#[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
pub execution_offchain_worker: Option<ExecutionStrategy>,
#[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
pub execution_other: Option<ExecutionStrategy>,
#[arg(
long,
value_name = "STRATEGY",
value_enum,
ignore_case = true,
conflicts_with_all = &[
"execution_other",
"execution_offchain_worker",
"execution_block_construction",
"execution_import_block",
"execution_syncing",
]
)]
pub execution: Option<ExecutionStrategy>,
}
impl ExecutionStrategiesParams {
fn check_usage_and_print_deprecation_warning(&self) {
for (param, name) in [
(&self.execution_syncing, "execution-syncing"),
(&self.execution_import_block, "execution-import-block"),
(&self.execution_block_construction, "execution-block-construction"),
(&self.execution_offchain_worker, "execution-offchain-worker"),
(&self.execution_other, "execution-other"),
(&self.execution, "execution"),
] {
if param.is_some() {
eprintln!(
"CLI parameter `--{name}` has no effect anymore and will be removed in the future!"
);
}
}
}
}