Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Remove wasmi backend from sc-executor (#13800)
Browse files Browse the repository at this point in the history
* refactor: use builder api for all executors

* improve a lot

* remove unused args

* cleanup deps

* fix inconsistency about heap alloc

* add `heap_pages` back to try-runtime

* fix

* chore: reduce duplicated code for sc-service-test

* cleanup code

* fmt

* improve test executor

* improve

* use #[deprecated]

* set runtime_cache_size: 4

* wip

* fix and improve

* remove sc-executor-wasmi deps

* clean up bench and tests

* delete "client/executor/wasmi"

* cleanup

* refactor builder

* fix

* fix bench

* fix tests

* fix warnings

* fix warnings

* fix

* fix

* remove wasmi and fix tests

* unused imports

* improve by suggestions

* Update client/cli/src/arg_enums.rs

---------

Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: parity-processbot <>
  • Loading branch information
2 people authored and gpestana committed May 27, 2023
1 parent 685bfde commit 0ed6d19
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 795 deletions.
34 changes: 3 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ members = [
"client/executor",
"client/executor/common",
"client/executor/runtime-test",
"client/executor/wasmi",
"client/executor/wasmtime",
"client/informant",
"client/keystore",
Expand Down
1 change: 0 additions & 1 deletion bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ pub fn new_partial(
.transpose()?;

let executor = sc_service::new_native_or_wasm_executor(&config);

let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, _>(
config,
Expand Down
1 change: 0 additions & 1 deletion bin/node/executor/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ fn bench_execute_block(c: &mut Criterion) {
let mut group = c.benchmark_group("execute blocks");
let execution_methods = vec![
ExecutionMethod::Native,
ExecutionMethod::Wasm(WasmExecutionMethod::Interpreted),
ExecutionMethod::Wasm(WasmExecutionMethod::Compiled {
instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
}),
Expand Down
35 changes: 19 additions & 16 deletions client/cli/src/arg_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub const DEFAULT_WASMTIME_INSTANTIATION_STRATEGY: WasmtimeInstantiationStrategy
#[derive(Debug, Clone, Copy, ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum WasmExecutionMethod {
/// Uses an interpreter.
/// Uses an interpreter which now is deprecated.
#[clap(name = "interpreted-i-know-what-i-do")]
Interpreted,
/// Uses a compiled runtime.
Expand All @@ -76,21 +76,24 @@ pub fn execution_method_from_cli(
execution_method: WasmExecutionMethod,
instantiation_strategy: WasmtimeInstantiationStrategy,
) -> sc_service::config::WasmExecutionMethod {
match execution_method {
WasmExecutionMethod::Interpreted => sc_service::config::WasmExecutionMethod::Interpreted,
WasmExecutionMethod::Compiled => sc_service::config::WasmExecutionMethod::Compiled {
instantiation_strategy: match instantiation_strategy {
WasmtimeInstantiationStrategy::PoolingCopyOnWrite =>
sc_service::config::WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
WasmtimeInstantiationStrategy::RecreateInstanceCopyOnWrite =>
sc_service::config::WasmtimeInstantiationStrategy::RecreateInstanceCopyOnWrite,
WasmtimeInstantiationStrategy::Pooling =>
sc_service::config::WasmtimeInstantiationStrategy::Pooling,
WasmtimeInstantiationStrategy::RecreateInstance =>
sc_service::config::WasmtimeInstantiationStrategy::RecreateInstance,
WasmtimeInstantiationStrategy::LegacyInstanceReuse =>
sc_service::config::WasmtimeInstantiationStrategy::LegacyInstanceReuse,
},
if let WasmExecutionMethod::Interpreted = execution_method {
log::warn!(
"`interpreted-i-know-what-i-do` is deprecated and will be removed in the future. Defaults to `compiled` execution mode."
);
}

sc_service::config::WasmExecutionMethod::Compiled {
instantiation_strategy: match instantiation_strategy {
WasmtimeInstantiationStrategy::PoolingCopyOnWrite =>
sc_service::config::WasmtimeInstantiationStrategy::PoolingCopyOnWrite,
WasmtimeInstantiationStrategy::RecreateInstanceCopyOnWrite =>
sc_service::config::WasmtimeInstantiationStrategy::RecreateInstanceCopyOnWrite,
WasmtimeInstantiationStrategy::Pooling =>
sc_service::config::WasmtimeInstantiationStrategy::Pooling,
WasmtimeInstantiationStrategy::RecreateInstance =>
sc_service::config::WasmtimeInstantiationStrategy::RecreateInstance,
WasmtimeInstantiationStrategy::LegacyInstanceReuse =>
sc_service::config::WasmtimeInstantiationStrategy::LegacyInstanceReuse,
},
}
}
Expand Down
2 changes: 0 additions & 2 deletions client/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ targets = ["x86_64-unknown-linux-gnu"]
lru = "0.8.1"
parking_lot = "0.12.1"
tracing = "0.1.29"
wasmi = "0.13.2"

codec = { package = "parity-scale-codec", version = "3.2.2" }
sc-executor-common = { version = "0.10.0-dev", path = "common" }
sc-executor-wasmi = { version = "0.10.0-dev", path = "wasmi" }
sc-executor-wasmtime = { version = "0.10.0-dev", path = "wasmtime" }
sp-api = { version = "4.0.0-dev", path = "../../primitives/api" }
sp-core = { version = "7.0.0", path = "../../primitives/core" }
Expand Down
11 changes: 1 addition & 10 deletions client/executor/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use std::sync::{

#[derive(Clone)]
enum Method {
Interpreted,
Compiled { instantiation_strategy: InstantiationStrategy, precompile: bool },
}

Expand All @@ -50,17 +49,10 @@ fn initialize(
method: Method,
) -> Box<dyn WasmModule> {
let blob = RuntimeBlob::uncompress_if_needed(runtime).unwrap();
let host_functions = sp_io::SubstrateHostFunctions::host_functions();

let allow_missing_func_imports = true;

match method {
Method::Interpreted => sc_executor_wasmi::create_runtime(
blob,
DEFAULT_HEAP_ALLOC_STRATEGY,
host_functions,
allow_missing_func_imports,
)
.map(|runtime| -> Box<dyn WasmModule> { Box::new(runtime) }),
Method::Compiled { instantiation_strategy, precompile } => {
let config = sc_executor_wasmtime::Config {
allow_missing_func_imports,
Expand Down Expand Up @@ -215,7 +207,6 @@ fn bench_call_instance(c: &mut Criterion) {
precompile: true,
},
),
("interpreted", Method::Interpreted),
];

let runtimes = [("kusama_runtime", kusama_runtime()), ("test_runtime", test_runtime())];
Expand Down
1 change: 0 additions & 1 deletion client/executor/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
thiserror = "1.0.30"
wasm-instrument = "0.3"
wasmi = "0.13.2"
sc-allocator = { version = "4.1.0-dev", path = "../../allocator" }
sp-maybe-compressed-blob = { version = "4.1.0-dev", path = "../../../primitives/maybe-compressed-blob" }
sp-wasm-interface = { version = "7.0.0", path = "../../../primitives/wasm-interface" }
Expand Down
10 changes: 0 additions & 10 deletions client/executor/common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@

//! Rust executor possible errors.

use wasmi;

/// Result type alias.
pub type Result<T> = std::result::Result<T, Error>;

/// Error type.
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error(transparent)]
Wasmi(#[from] wasmi::Error),

#[error("Error calling api function: {0}")]
ApiError(Box<dyn std::error::Error + Send + Sync>),

Expand All @@ -48,9 +43,6 @@ pub enum Error {
#[error("Invalid type returned (should be u64)")]
InvalidReturn,

#[error("Runtime error")]
Runtime,

#[error("Runtime panicked: {0}")]
RuntimePanicked(String),

Expand Down Expand Up @@ -109,8 +101,6 @@ pub enum Error {
OutputExceedsBounds,
}

impl wasmi::HostError for Error {}

impl From<&'static str> for Error {
fn from(err: &'static str) -> Error {
Error::Other(err.into())
Expand Down
3 changes: 0 additions & 3 deletions client/executor/common/src/runtime_blob/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
//!
//! To give you some examples:
//!
//! - wasmi allows reaching to non-exported mutable globals so that we could reset them. Wasmtime
//! doesn’t support that.
//!
//! We need to reset the globals because when we
//! execute the Substrate Runtime, we do not drop and create the instance anew, instead
//! we restore some selected parts of the state.
Expand Down
23 changes: 2 additions & 21 deletions client/executor/src/integration_tests/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,15 @@

//! Tests that are only relevant for Linux.

mod smaps;

use super::mk_test_runtime;
use crate::WasmExecutionMethod;
use codec::Encode as _;
use sc_executor_common::wasm_runtime::DEFAULT_HEAP_ALLOC_STRATEGY;

mod smaps;

use self::smaps::Smaps;

#[test]
fn memory_consumption_interpreted() {
let _ = sp_tracing::try_init_simple();

if std::env::var("RUN_TEST").is_ok() {
memory_consumption(WasmExecutionMethod::Interpreted);
} else {
// We need to run the test in isolation, to not getting interfered by the other tests.
let executable = std::env::current_exe().unwrap();
let output = std::process::Command::new(executable)
.env("RUN_TEST", "1")
.args(&["--nocapture", "memory_consumption_interpreted"])
.output()
.unwrap();

assert!(output.status.success());
}
}

#[test]
fn memory_consumption_compiled() {
let _ = sp_tracing::try_init_simple();
Expand Down
Loading

0 comments on commit 0ed6d19

Please sign in to comment.