try_runtime_core/common/
shared_parameters.rs

1// This file is part of try-runtime-cli.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18use std::{path::PathBuf, str::FromStr};
19
20use sc_cli::{
21    WasmExecutionMethod, WasmtimeInstantiationStrategy, DEFAULT_WASMTIME_INSTANTIATION_STRATEGY,
22    DEFAULT_WASM_EXECUTION_METHOD,
23};
24use sp_runtime::StateVersion;
25
26use crate::common::parse;
27
28/// Shared parameters of the `try-runtime` commands
29#[derive(Debug, Clone, clap::Parser)]
30#[group(skip)]
31pub struct SharedParams {
32    /// The runtime to use.
33    ///
34    /// Must be a path to a wasm blob, compiled with `try-runtime` feature flag.
35    ///
36    /// Or, `existing`, indicating that you don't want to overwrite the runtime. This will use
37    /// whatever comes from the remote node, or the snapshot file. This will most likely not work
38    /// against a remote node, as no (sane) blockchain should compile its onchain wasm with
39    /// `try-runtime` feature.
40    #[arg(long, default_value = "existing")]
41    pub runtime: Runtime,
42
43    /// Whether to disable enforcing the new runtime `spec_name` matches the existing `spec_name`.
44    #[clap(long, default_value = "false", default_missing_value = "true")]
45    pub disable_spec_name_check: bool,
46
47    /// Type of wasm execution used.
48    #[arg(
49		long = "wasm-execution",
50		value_name = "METHOD",
51		value_enum,
52		ignore_case = true,
53		default_value_t = DEFAULT_WASM_EXECUTION_METHOD,
54	)]
55    pub wasm_method: WasmExecutionMethod,
56
57    /// The WASM instantiation method to use.
58    ///
59    /// Only has an effect when `wasm-execution` is set to `compiled`.
60    #[arg(
61		long = "wasm-instantiation-strategy",
62		value_name = "STRATEGY",
63		default_value_t = DEFAULT_WASMTIME_INSTANTIATION_STRATEGY,
64		value_enum,
65	)]
66    pub wasmtime_instantiation_strategy: WasmtimeInstantiationStrategy,
67
68    /// The number of 64KB pages to allocate for Wasm execution.
69    ///
70    /// Defaults to `sc_service::Configuration::default_heap_pages`.
71    #[arg(long)]
72    pub heap_pages: Option<u64>,
73
74    /// Path to a file to export the storage proof into (as a JSON).
75    /// If several blocks are executed, the path is interpreted as a folder
76    /// where one file per block will be written (named `{block_number}-{block_hash}`).
77    #[clap(long)]
78    pub export_proof: Option<PathBuf>,
79
80    /// Overwrite the `state_version`.
81    ///
82    /// Otherwise `remote-externalities` will automatically set the correct state version.
83    #[arg(long, value_parser = parse::state_version)]
84    pub overwrite_state_version: Option<StateVersion>,
85}
86
87#[derive(Debug, Clone)]
88pub enum Runtime {
89    /// Use the given path to the wasm binary file.
90    ///
91    /// It must have been compiled with `try-runtime`.
92    Path(PathBuf),
93
94    /// Use the code of the remote node, or the snapshot.
95    ///
96    /// In almost all cases, this is not what you want, because the code in the remote node does
97    /// not have any of the try-runtime custom runtime APIs.
98    Existing,
99}
100
101impl FromStr for Runtime {
102    type Err = String;
103
104    fn from_str(s: &str) -> Result<Self, Self::Err> {
105        Ok(match s.to_lowercase().as_ref() {
106            "existing" => Runtime::Existing,
107            x => Runtime::Path(x.into()),
108        })
109    }
110}