Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Make wasmtime the default when the feature is enabled (paritytech#8855)
Browse files Browse the repository at this point in the history
* Make wasmtime the default when the feature is enabled

* Update client/cli/src/arg_enums.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
  • Loading branch information
2 people authored and nazar-pc committed Aug 8, 2021
1 parent 7b08886 commit 3cce9e2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
62 changes: 45 additions & 17 deletions client/cli/src/arg_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,54 @@

use structopt::clap::arg_enum;

arg_enum! {
/// How to execute Wasm runtime code
#[allow(missing_docs)]
#[derive(Debug, Clone, Copy)]
pub enum WasmExecutionMethod {
// Uses an interpreter.
Interpreted,
// Uses a compiled runtime.
Compiled,
/// How to execute Wasm runtime code.
#[derive(Debug, Clone, Copy)]
pub enum WasmExecutionMethod {
/// Uses an interpreter.
Interpreted,
/// Uses a compiled runtime.
Compiled,
}

impl std::fmt::Display for WasmExecutionMethod {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Interpreted => write!(f, "Interpreted"),
Self::Compiled => write!(f, "Compiled"),
}
}
}

impl std::str::FromStr for WasmExecutionMethod {
type Err = String;

fn from_str(s: &str) -> Result<Self, String> {
if s.eq_ignore_ascii_case("interpreted-i-know-what-i-do") {
Ok(Self::Interpreted)
} else if s.eq_ignore_ascii_case("compiled") {
#[cfg(feature = "wasmtime")]
{
Ok(Self::Compiled)
}
#[cfg(not(feature = "wasmtime"))]
{
Err(format!("`Compiled` variant requires the `wasmtime` feature to be enabled"))
}
} else {
Err(format!("Unknown variant `{}`, known variants: {:?}", s, Self::variants()))
}
}
}

impl WasmExecutionMethod {
/// Returns list of variants that are not disabled by feature flags.
pub fn enabled_variants() -> Vec<&'static str> {
Self::variants()
.iter()
.cloned()
.filter(|&name| cfg!(feature = "wasmtime") || name != "Compiled")
.collect()
/// Returns all the variants of this enum to be shown in the cli.
pub fn variants() -> &'static [&'static str] {
let variants = &["interpreted-i-know-what-i-do", "compiled"];
if cfg!(feature = "wasmtime") {
variants
} else {
&variants[..1]
}
}
}

Expand Down Expand Up @@ -181,7 +209,7 @@ impl std::str::FromStr for Database {
} else if s.eq_ignore_ascii_case("paritydb-experimental") {
Ok(Self::ParityDb)
} else {
Err(format!("Unknwon variant `{}`, known variants: {:?}", s, Self::variants()))
Err(format!("Unknown variant `{}`, known variants: {:?}", s, Self::variants()))
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions client/cli/src/params/import_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ use sc_client_api::execution_extensions::ExecutionStrategies;
use structopt::StructOpt;
use std::path::PathBuf;

#[cfg(feature = "wasmtime")]
const WASM_METHOD_DEFAULT: &str = "Compiled";

#[cfg(not(feature = "wasmtime"))]
const WASM_METHOD_DEFAULT: &str = "interpreted-i-know-what-i-do";

/// Parameters for block import.
#[derive(Debug, StructOpt, Clone)]
pub struct ImportParams {
Expand All @@ -50,9 +56,9 @@ pub struct ImportParams {
#[structopt(
long = "wasm-execution",
value_name = "METHOD",
possible_values = &WasmExecutionMethod::enabled_variants(),
possible_values = &WasmExecutionMethod::variants(),
case_insensitive = true,
default_value = "Interpreted"
default_value = WASM_METHOD_DEFAULT
)]
pub wasm_method: WasmExecutionMethod,

Expand All @@ -76,7 +82,6 @@ pub struct ImportParams {
}

impl ImportParams {

/// Specify the state cache size.
pub fn state_cache_size(&self) -> usize {
self.state_cache_size
Expand Down
2 changes: 1 addition & 1 deletion utils/frame/benchmarking-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub struct BenchmarkCmd {
#[structopt(
long = "wasm-execution",
value_name = "METHOD",
possible_values = &WasmExecutionMethod::enabled_variants(),
possible_values = &WasmExecutionMethod::variants(),
case_insensitive = true,
default_value = "Interpreted"
)]
Expand Down
2 changes: 1 addition & 1 deletion utils/frame/try-runtime/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct TryRuntimeCmd {
#[structopt(
long = "wasm-execution",
value_name = "METHOD",
possible_values = &WasmExecutionMethod::enabled_variants(),
possible_values = &WasmExecutionMethod::variants(),
case_insensitive = true,
default_value = "Interpreted"
)]
Expand Down

0 comments on commit 3cce9e2

Please sign in to comment.