sc_cli/params/
import_params.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19use 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;
27use std::path::PathBuf;
28
29/// Parameters for block import.
30#[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	/// Method for executing Wasm runtime code.
41	#[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	/// The WASM instantiation method to use.
51	///
52	/// Only has an effect when `wasm-execution` is set to `compiled`.
53	/// The copy-on-write strategies are only supported on Linux.
54	/// If the copy-on-write variant of a strategy is unsupported
55	/// the executor will fall back to the non-CoW equivalent.
56	/// The fastest (and the default) strategy available is `pooling-copy-on-write`.
57	/// The `legacy-instance-reuse` strategy is deprecated and will
58	/// be removed in the future. It should only be used in case of
59	/// issues with the default instantiation strategy.
60	#[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	/// Specify the path where local WASM runtimes are stored.
69	///
70	/// These runtimes will override on-chain runtimes when the version matches.
71	#[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	/// Specify the state cache size.
79	///
80	/// Providing `0` will disable the cache.
81	#[arg(long, value_name = "Bytes", default_value_t = 1024 * 1024 * 1024)]
82	pub trie_cache_size: usize,
83}
84
85impl ImportParams {
86	/// Specify the trie cache maximum size.
87	pub fn trie_cache_maximum_size(&self) -> Option<usize> {
88		if self.trie_cache_size == 0 {
89			None
90		} else {
91			Some(self.trie_cache_size)
92		}
93	}
94
95	/// Get the WASM execution method from the parameters
96	pub fn wasm_method(&self) -> sc_service::config::WasmExecutionMethod {
97		self.execution_strategies.check_usage_and_print_deprecation_warning();
98
99		crate::execution_method_from_cli(self.wasm_method, self.wasmtime_instantiation_strategy)
100	}
101
102	/// Enable overriding on-chain WASM with locally-stored WASM
103	/// by specifying the path where local WASM is stored.
104	pub fn wasm_runtime_overrides(&self) -> Option<PathBuf> {
105		self.wasm_runtime_overrides.clone()
106	}
107}
108
109/// Execution strategies parameters.
110#[derive(Debug, Clone, Args)]
111pub struct ExecutionStrategiesParams {
112	/// Runtime execution strategy for importing blocks during initial sync.
113	#[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
114	pub execution_syncing: Option<ExecutionStrategy>,
115
116	/// Runtime execution strategy for general block import (including locally authored blocks).
117	#[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
118	pub execution_import_block: Option<ExecutionStrategy>,
119
120	/// Runtime execution strategy for constructing blocks.
121	#[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
122	pub execution_block_construction: Option<ExecutionStrategy>,
123
124	/// Runtime execution strategy for offchain workers.
125	#[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
126	pub execution_offchain_worker: Option<ExecutionStrategy>,
127
128	/// Runtime execution strategy when not syncing, importing or constructing blocks.
129	#[arg(long, value_name = "STRATEGY", value_enum, ignore_case = true)]
130	pub execution_other: Option<ExecutionStrategy>,
131
132	/// The execution strategy that should be used by all execution contexts.
133	#[arg(
134		long,
135		value_name = "STRATEGY",
136		value_enum,
137		ignore_case = true,
138		conflicts_with_all = &[
139			"execution_other",
140			"execution_offchain_worker",
141			"execution_block_construction",
142			"execution_import_block",
143			"execution_syncing",
144		]
145	)]
146	pub execution: Option<ExecutionStrategy>,
147}
148
149impl ExecutionStrategiesParams {
150	/// Check if one of the parameters is still passed and print a warning if so.
151	fn check_usage_and_print_deprecation_warning(&self) {
152		for (param, name) in [
153			(&self.execution_syncing, "execution-syncing"),
154			(&self.execution_import_block, "execution-import-block"),
155			(&self.execution_block_construction, "execution-block-construction"),
156			(&self.execution_offchain_worker, "execution-offchain-worker"),
157			(&self.execution_other, "execution-other"),
158			(&self.execution, "execution"),
159		] {
160			if param.is_some() {
161				eprintln!(
162					"CLI parameter `--{name}` has no effect anymore and will be removed in the future!"
163				);
164			}
165		}
166	}
167}