mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 09:57:56 +00:00
Remove wasmi backend from sc-executor (#13800)
* 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 <git@kchr.de> Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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::{
|
||||
@@ -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();
|
||||
@@ -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>(
|
||||
@@ -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);
|
||||
},
|
||||
@@ -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);
|
||||
},
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
@@ -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", ¶ms).unwrap();
|
||||
|
||||
// Cal it a second time to check that the heap was freed.
|
||||
instance.call_export("check_and_set_in_heap", ¶ms).unwrap();
|
||||
}
|
||||
|
||||
test_wasm_execution!(parallel_execution);
|
||||
fn parallel_execution(wasm_method: WasmExecutionMethod) {
|
||||
let executor = Arc::new(
|
||||
@@ -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",
|
||||
};
|
||||
@@ -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 { .. });
|
||||
},
|
||||
@@ -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 { .. });
|
||||
},
|
||||
@@ -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 { .. });
|
||||
},
|
||||
|
||||
@@ -49,7 +49,6 @@ pub use sp_core::traits::Externalities;
|
||||
pub use sp_version::{NativeVersion, RuntimeVersion};
|
||||
#[doc(hidden)]
|
||||
pub use sp_wasm_interface;
|
||||
pub use wasmi;
|
||||
|
||||
pub use sc_executor_common::{
|
||||
error,
|
||||
|
||||
@@ -43,8 +43,6 @@ use sp_wasm_interface::HostFunctions;
|
||||
/// Specification of different methods of executing the runtime Wasm code.
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)]
|
||||
pub enum WasmExecutionMethod {
|
||||
/// Uses the Wasmi interpreter.
|
||||
Interpreted,
|
||||
/// Uses the Wasmtime compiled runtime.
|
||||
Compiled {
|
||||
/// The instantiation strategy to use.
|
||||
@@ -53,8 +51,10 @@ pub enum WasmExecutionMethod {
|
||||
}
|
||||
|
||||
impl Default for WasmExecutionMethod {
|
||||
fn default() -> WasmExecutionMethod {
|
||||
WasmExecutionMethod::Interpreted
|
||||
fn default() -> Self {
|
||||
Self::Compiled {
|
||||
instantiation_strategy: sc_executor_wasmtime::InstantiationStrategy::PoolingCopyOnWrite,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,21 +299,6 @@ where
|
||||
H: HostFunctions,
|
||||
{
|
||||
match wasm_method {
|
||||
WasmExecutionMethod::Interpreted => {
|
||||
// Wasmi doesn't have any need in a cache directory.
|
||||
//
|
||||
// We drop the cache_path here to silence warnings that cache_path is not used if
|
||||
// compiling without the `wasmtime` flag.
|
||||
let _ = cache_path;
|
||||
|
||||
sc_executor_wasmi::create_runtime(
|
||||
blob,
|
||||
heap_alloc_strategy,
|
||||
H::host_functions(),
|
||||
allow_missing_func_imports,
|
||||
)
|
||||
.map(|runtime| -> Box<dyn WasmModule> { Box::new(runtime) })
|
||||
},
|
||||
WasmExecutionMethod::Compiled { instantiation_strategy } =>
|
||||
sc_executor_wasmtime::create_runtime::<H>(
|
||||
blob,
|
||||
|
||||
Reference in New Issue
Block a user