referrerpolicy=no-referrer-when-downgrade

sc_cli/params/
runtime_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 clap::Args;
20use std::str::FromStr;
21
22/// Parameters used to config runtime.
23#[derive(Debug, Clone, Args)]
24pub struct RuntimeParams {
25	/// The size of the instances cache for each runtime [max: 32].
26	///
27	/// Values higher than 32 are illegal.
28	#[arg(long, default_value_t = 8, value_parser = parse_max_runtime_instances)]
29	pub max_runtime_instances: usize,
30
31	/// Maximum number of different runtimes that can be cached.
32	#[arg(long, default_value_t = 2)]
33	pub runtime_cache_size: u8,
34}
35
36fn parse_max_runtime_instances(s: &str) -> Result<usize, String> {
37	let max_runtime_instances = usize::from_str(s)
38		.map_err(|_err| format!("Illegal `--max-runtime-instances` value: {s}"))?;
39
40	if max_runtime_instances > 32 {
41		Err(format!("Illegal `--max-runtime-instances` value: {max_runtime_instances} is more than the allowed maximum of `32` "))
42	} else {
43		Ok(max_runtime_instances)
44	}
45}