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

Remove wasmi backend from sc-executor #13800

Merged
merged 45 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0edd825
refactor: use builder api for all executors
yjhmelody Mar 28, 2023
9750b54
improve a lot
yjhmelody Mar 28, 2023
de50bf8
remove unused args
yjhmelody Mar 28, 2023
fb0539d
cleanup deps
yjhmelody Mar 28, 2023
b60bbd8
fix inconsistency about heap alloc
yjhmelody Mar 28, 2023
4eb0dc2
add `heap_pages` back to try-runtime
yjhmelody Mar 28, 2023
f449134
fix
yjhmelody Mar 28, 2023
c4175b2
chore: reduce duplicated code for sc-service-test
yjhmelody Mar 28, 2023
86172e6
cleanup code
yjhmelody Mar 28, 2023
f2c2e54
fmt
yjhmelody Mar 28, 2023
ce6dfb6
improve test executor
yjhmelody Mar 28, 2023
95dca94
improve
yjhmelody Mar 29, 2023
cd3bacb
Merge branch 'master' into refactor-use-executor-builder
yjhmelody Mar 29, 2023
c22e1bf
Merge branch 'master' into refactor-use-executor-builder
yjhmelody Mar 29, 2023
7147033
use #[deprecated]
yjhmelody Mar 29, 2023
157646e
set runtime_cache_size: 4
yjhmelody Mar 29, 2023
3f43381
wip
yjhmelody Mar 30, 2023
2dfbe0e
fix and improve
yjhmelody Mar 30, 2023
48161e5
Merge branch 'refactor-use-executor-builder' into refactor-remove-wasmi
yjhmelody Mar 30, 2023
3659412
remove sc-executor-wasmi deps
yjhmelody Mar 30, 2023
9e068da
clean up bench and tests
yjhmelody Mar 30, 2023
16d2e5a
delete "client/executor/wasmi"
yjhmelody Mar 30, 2023
18bbf96
cleanup
yjhmelody Mar 30, 2023
31ac181
refactor builder
yjhmelody Mar 30, 2023
d4cacc0
fix
yjhmelody Mar 30, 2023
7054f42
fix bench
yjhmelody Mar 30, 2023
fd173f6
fix tests
yjhmelody Mar 30, 2023
c523c6e
fix warnings
yjhmelody Mar 30, 2023
68661c0
fix warnings
yjhmelody Mar 30, 2023
00bc047
fix
yjhmelody Mar 30, 2023
35701eb
fix
yjhmelody Mar 30, 2023
3ab11e4
Merge branch 'master' into refactor-use-executor-builder
yjhmelody Mar 31, 2023
149939d
Merge branch 'refactor-use-executor-builder' into refactor-remove-wasmi
yjhmelody Apr 2, 2023
075cf2b
Merge branch 'master' into refactor-remove-wasmi
yjhmelody Apr 2, 2023
3571d48
remove wasmi and fix tests
yjhmelody Apr 2, 2023
a41f6e7
Merge branch 'master' into refactor-remove-wasmi
yjhmelody Apr 10, 2023
51b6bc3
unused imports
yjhmelody Apr 11, 2023
e2d1812
Merge branch 'master' into refactor-remove-wasmi
yjhmelody Apr 23, 2023
5dfe57d
erge branch 'master' into refactor-remove-wasmi
yjhmelody Apr 26, 2023
dfe0e80
improve by suggestions
yjhmelody May 13, 2023
0ee08dc
Merge branch 'master' into refactor-remove-wasmi
yjhmelody May 13, 2023
1b7375a
Update client/cli/src/arg_enums.rs
bkchr May 15, 2023
e24a1e3
Merge remote-tracking branch 'origin/master' into refactor-remove-wasmi
May 21, 2023
d4ccbcd
Merge branch 'master' into refactor-remove-wasmi
yjhmelody May 23, 2023
bbad9f1
Merge remote-tracking branch 'my/refactor-remove-wasmi' into refactor…
yjhmelody May 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 0 additions & 28 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: 1 addition & 0 deletions bin/node/cli/benches/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use kitchensink_runtime::{constants::currency::*, BalancesCall, SudoCall};
use node_cli::service::{create_extrinsic, fetch_nonce, FullClient, TransactionPool};
use node_primitives::AccountId;
use sc_client_api::execution_extensions::ExecutionStrategies;
use sc_executor::WasmtimeInstantiationStrategy;
yjhmelody marked this conversation as resolved.
Show resolved Hide resolved
use sc_service::{
config::{
BlocksPruning, DatabaseSource, KeystoreConfig, NetworkConfiguration, OffchainWorkerConfig,
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
5 changes: 0 additions & 5 deletions client/cli/src/arg_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,13 @@ pub const DEFAULT_WASMTIME_INSTANTIATION_STRATEGY: WasmtimeInstantiationStrategy
#[derive(Debug, Clone, Copy, ValueEnum)]
#[value(rename_all = "kebab-case")]
pub enum WasmExecutionMethod {
/// Uses an interpreter.
#[clap(name = "interpreted-i-know-what-i-do")]
Interpreted,
yjhmelody marked this conversation as resolved.
Show resolved Hide resolved
/// 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"),
}
}
Expand All @@ -77,7 +73,6 @@ pub fn execution_method_from_cli(
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 =>
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 @@ -208,7 +200,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
57 changes: 5 additions & 52 deletions client/executor/src/integration_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use codec::{Decode, Encode};
use sc_executor_common::{
error::Error,
runtime_blob::RuntimeBlob,
wasm_runtime::{HeapAllocStrategy, WasmModule, DEFAULT_HEAP_ALLOC_STRATEGY},
wasm_runtime::{HeapAllocStrategy, WasmModule},
};
use sc_runtime_test::wasm_binary_unwrap;
use sp_core::{
Expand All @@ -50,12 +50,6 @@ type HostFunctions = sp_io::SubstrateHostFunctions;
macro_rules! test_wasm_execution {
($method_name:ident) => {
paste::item! {
#[test]
fn [<$method_name _interpreted>]() {
let _ = sp_tracing::try_init_simple();
$method_name(WasmExecutionMethod::Interpreted);
}

#[test]
fn [<$method_name _compiled_recreate_instance_cow>]() {
let _ = sp_tracing::try_init_simple();
Expand Down Expand Up @@ -97,15 +91,6 @@ macro_rules! test_wasm_execution {
}
}
};

(interpreted_only $method_name:ident) => {
paste::item! {
#[test]
fn [<$method_name _interpreted>]() {
$method_name(WasmExecutionMethod::Interpreted);
}
}
};
}

fn call_in_wasm<E: Externalities>(
Expand Down Expand Up @@ -144,8 +129,8 @@ fn call_not_existing_function(wasm_method: WasmExecutionMethod) {
match call_in_wasm("test_calling_missing_external", &[], wasm_method, &mut ext).unwrap_err() {
Error::AbortedDueToTrap(error) => {
let expected = match wasm_method {
WasmExecutionMethod::Interpreted => "Other: Function `missing_external` is only a stub. Calling a stub is not allowed.",
WasmExecutionMethod::Compiled { .. } => "call to a missing function env:missing_external"
WasmExecutionMethod::Compiled { .. } =>
"call to a missing function env:missing_external",
};
assert_eq!(error.message, expected);
},
Expand All @@ -163,8 +148,8 @@ fn call_yet_another_not_existing_function(wasm_method: WasmExecutionMethod) {
{
Error::AbortedDueToTrap(error) => {
let expected = match wasm_method {
WasmExecutionMethod::Interpreted => "Other: Function `yet_another_missing_external` is only a stub. Calling a stub is not allowed.",
WasmExecutionMethod::Compiled { .. } => "call to a missing function env:yet_another_missing_external"
WasmExecutionMethod::Compiled { .. } =>
"call to a missing function env:yet_another_missing_external",
};
assert_eq!(error.message, expected);
},
Expand Down Expand Up @@ -473,9 +458,6 @@ fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) {
r#"host code panicked while being called by the runtime: Failed to allocate memory: "Allocator ran out of space""#
);
},
Error::RuntimePanicked(error) if wasm_method == WasmExecutionMethod::Interpreted => {
assert_eq!(error, r#"Failed to allocate memory: "Allocator ran out of space""#);
},
error => panic!("unexpected error: {:?}", error),
}
}
Expand Down Expand Up @@ -558,25 +540,6 @@ fn restoration_of_globals(wasm_method: WasmExecutionMethod) {
assert!(res.is_ok());
}

test_wasm_execution!(interpreted_only heap_is_reset_between_calls);
fn heap_is_reset_between_calls(wasm_method: WasmExecutionMethod) {
let runtime = mk_test_runtime(wasm_method, DEFAULT_HEAP_ALLOC_STRATEGY);
let mut instance = runtime.new_instance().unwrap();

let heap_base = instance
.get_global_const("__heap_base")
.expect("`__heap_base` is valid")
.expect("`__heap_base` exists")
.as_i32()
.expect("`__heap_base` is an `i32`");

let params = (heap_base as u32, 512u32 * 64 * 1024).encode();
instance.call_export("check_and_set_in_heap", &params).unwrap();

// Cal it a second time to check that the heap was freed.
instance.call_export("check_and_set_in_heap", &params).unwrap();
}

test_wasm_execution!(parallel_execution);
fn parallel_execution(wasm_method: WasmExecutionMethod) {
let executor = Arc::new(
Expand Down Expand Up @@ -787,7 +750,6 @@ fn unreachable_intrinsic(wasm_method: WasmExecutionMethod) {
match call_in_wasm("test_unreachable_intrinsic", &[], wasm_method, &mut ext).unwrap_err() {
Error::AbortedDueToTrap(error) => {
let expected = match wasm_method {
WasmExecutionMethod::Interpreted => "unreachable",
WasmExecutionMethod::Compiled { .. } =>
"wasm trap: wasm `unreachable` instruction executed",
};
Expand All @@ -814,9 +776,6 @@ fn return_huge_len(wasm_method: WasmExecutionMethod) {
let mut ext = ext.ext();

match call_in_wasm("test_return_huge_len", &[], wasm_method, &mut ext).unwrap_err() {
Error::Runtime => {
assert_matches!(wasm_method, WasmExecutionMethod::Interpreted);
},
Error::OutputExceedsBounds => {
assert_matches!(wasm_method, WasmExecutionMethod::Compiled { .. });
},
Expand All @@ -843,9 +802,6 @@ fn return_max_memory_offset_plus_one(wasm_method: WasmExecutionMethod) {
match call_in_wasm("test_return_max_memory_offset_plus_one", &[], wasm_method, &mut ext)
.unwrap_err()
{
Error::Runtime => {
assert_matches!(wasm_method, WasmExecutionMethod::Interpreted);
},
Error::OutputExceedsBounds => {
assert_matches!(wasm_method, WasmExecutionMethod::Compiled { .. });
},
Expand All @@ -859,9 +815,6 @@ fn return_overflow(wasm_method: WasmExecutionMethod) {
let mut ext = ext.ext();

match call_in_wasm("test_return_overflow", &[], wasm_method, &mut ext).unwrap_err() {
Error::Runtime => {
assert_matches!(wasm_method, WasmExecutionMethod::Interpreted);
},
Error::OutputExceedsBounds => {
assert_matches!(wasm_method, WasmExecutionMethod::Compiled { .. });
},
Expand Down