use crate::arg_enums::{
ExecutionStrategy, WasmExecutionMethod, DEFAULT_EXECUTION_BLOCK_CONSTRUCTION,
DEFAULT_EXECUTION_IMPORT_BLOCK, DEFAULT_EXECUTION_IMPORT_BLOCK_VALIDATOR,
DEFAULT_EXECUTION_OFFCHAIN_WORKER, DEFAULT_EXECUTION_OTHER, DEFAULT_EXECUTION_SYNCING,
};
use crate::params::DatabaseParams;
use crate::params::PruningParams;
use tc_client_api::execution_extensions::ExecutionStrategies;
use structopt::StructOpt;
use std::path::PathBuf;
#[derive(Debug, StructOpt)]
pub struct ImportParams {
#[allow(missing_docs)]
#[structopt(flatten)]
pub pruning_params: PruningParams,
#[allow(missing_docs)]
#[structopt(flatten)]
pub database_params: DatabaseParams,
#[structopt(long = "unsafe-pruning")]
pub unsafe_pruning: bool,
#[structopt(
long = "wasm-execution",
value_name = "METHOD",
possible_values = &WasmExecutionMethod::enabled_variants(),
case_insensitive = true,
default_value = "Interpreted"
)]
pub wasm_method: WasmExecutionMethod,
#[structopt(long, value_name = "PATH", parse(from_os_str))]
pub wasm_runtime_overrides: Option<PathBuf>,
#[allow(missing_docs)]
#[structopt(flatten)]
pub execution_strategies: ExecutionStrategiesParams,
#[structopt(
long = "state-cache-size",
value_name = "Bytes",
default_value = "67108864"
)]
pub state_cache_size: usize,
}
impl ImportParams {
pub fn state_cache_size(&self) -> usize {
self.state_cache_size
}
pub fn wasm_method(&self) -> tc_service::config::WasmExecutionMethod {
self.wasm_method.into()
}
pub fn wasm_runtime_overrides(&self) -> Option<PathBuf> {
self.wasm_runtime_overrides.clone()
}
pub fn execution_strategies(&self, is_dev: bool, is_validator: bool) -> ExecutionStrategies {
let exec = &self.execution_strategies;
let exec_all_or = |strat: Option<ExecutionStrategy>, default: ExecutionStrategy| {
let default = if is_dev {
ExecutionStrategy::Native
} else {
default
};
exec.execution.unwrap_or_else(|| strat.unwrap_or(default)).into()
};
let default_execution_import_block = if is_validator {
DEFAULT_EXECUTION_IMPORT_BLOCK_VALIDATOR
} else {
DEFAULT_EXECUTION_IMPORT_BLOCK
};
ExecutionStrategies {
syncing: exec_all_or(exec.execution_syncing, DEFAULT_EXECUTION_SYNCING),
importing: exec_all_or(exec.execution_import_block, default_execution_import_block),
block_construction:
exec_all_or(exec.execution_block_construction, DEFAULT_EXECUTION_BLOCK_CONSTRUCTION),
offchain_worker:
exec_all_or(exec.execution_offchain_worker, DEFAULT_EXECUTION_OFFCHAIN_WORKER),
other: exec_all_or(exec.execution_other, DEFAULT_EXECUTION_OTHER),
}
}
}
#[derive(Debug, StructOpt)]
pub struct ExecutionStrategiesParams {
#[structopt(
long = "execution-syncing",
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
)]
pub execution_syncing: Option<ExecutionStrategy>,
#[structopt(
long = "execution-import-block",
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
)]
pub execution_import_block: Option<ExecutionStrategy>,
#[structopt(
long = "execution-block-construction",
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
)]
pub execution_block_construction: Option<ExecutionStrategy>,
#[structopt(
long = "execution-offchain-worker",
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
)]
pub execution_offchain_worker: Option<ExecutionStrategy>,
#[structopt(
long = "execution-other",
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
)]
pub execution_other: Option<ExecutionStrategy>,
#[structopt(
long = "execution",
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
conflicts_with_all = &[
"execution-other",
"execution-offchain-worker",
"execution-block-construction",
"execution-import-block",
"execution-syncing",
]
)]
pub execution: Option<ExecutionStrategy>,
}