From 0edd82506da3e60d7f281985f0055c88c65b761b Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 29 Mar 2023 00:31:11 +0800 Subject: [PATCH 01/32] refactor: use builder api for all executors --- Cargo.lock | 1 + bin/node/executor/benches/bench.rs | 6 +++-- bin/node/executor/tests/common.rs | 6 +++-- bin/node/testing/src/bench.rs | 11 ++++---- client/executor/src/integration_tests/mod.rs | 23 +++++----------- client/executor/src/lib.rs | 9 +++---- client/executor/src/native_executor.rs | 17 +++++++----- client/service/src/client/call_executor.rs | 25 +++++++++-------- client/service/src/client/wasm_override.rs | 27 +++++++++---------- client/service/test/src/client/mod.rs | 2 +- primitives/api/test/tests/runtime_calls.rs | 8 +++--- primitives/runtime-interface/test/src/lib.rs | 3 ++- test-utils/runtime/client/src/lib.rs | 5 +++- test-utils/runtime/src/system.rs | 6 +++-- .../benchmarking-cli/src/pallet/command.rs | 16 ++++++----- utils/frame/try-runtime/cli/Cargo.toml | 1 + utils/frame/try-runtime/cli/src/lib.rs | 21 +++++++++------ 17 files changed, 97 insertions(+), 90 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 33bca4005483c..807aaff525c07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11920,6 +11920,7 @@ dependencies = [ "parity-scale-codec", "sc-cli", "sc-executor", + "sc-executor-common", "sc-service", "serde", "serde_json", diff --git a/bin/node/executor/benches/bench.rs b/bin/node/executor/benches/bench.rs index a8c31068e853b..05c406bb5274f 100644 --- a/bin/node/executor/benches/bench.rs +++ b/bin/node/executor/benches/bench.rs @@ -26,7 +26,7 @@ use node_executor::ExecutorDispatch; use node_primitives::{BlockNumber, Hash}; use node_testing::keyring::*; use sc_executor::{ - Externalities, NativeElseWasmExecutor, RuntimeVersionOf, WasmExecutionMethod, + Externalities, NativeElseWasmExecutor, RuntimeVersionOf, WasmExecutionMethod, WasmExecutor, WasmtimeInstantiationStrategy, }; use sp_core::{ @@ -196,7 +196,9 @@ fn bench_execute_block(c: &mut Criterion) { ExecutionMethod::Wasm(wasm_method) => (false, wasm_method), }; - let executor = NativeElseWasmExecutor::new(wasm_method, None, 8, 2); + let executor = NativeElseWasmExecutor::new_with_wasm_executor( + WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), + ); let runtime_code = RuntimeCode { code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()), hash: vec![1, 2, 3], diff --git a/bin/node/executor/tests/common.rs b/bin/node/executor/tests/common.rs index 2f92423ffb508..d8699b9555d42 100644 --- a/bin/node/executor/tests/common.rs +++ b/bin/node/executor/tests/common.rs @@ -18,7 +18,7 @@ use codec::{Decode, Encode}; use frame_support::Hashable; use frame_system::offchain::AppCrypto; -use sc_executor::{error::Result, NativeElseWasmExecutor, WasmExecutionMethod}; +use sc_executor::{error::Result, NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor}; use sp_consensus_babe::{ digests::{PreDigest, SecondaryPlainPreDigest}, Slot, BABE_ENGINE_ID, @@ -98,7 +98,9 @@ pub fn from_block_number(n: u32) -> Header { } pub fn executor() -> NativeElseWasmExecutor { - NativeElseWasmExecutor::new(WasmExecutionMethod::Interpreted, None, 8, 2) + NativeElseWasmExecutor::new_with_wasm_executor( + WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), + ) } pub fn executor_call( diff --git a/bin/node/testing/src/bench.rs b/bin/node/testing/src/bench.rs index d6bcf6e252fe0..af95a4d4d5f8d 100644 --- a/bin/node/testing/src/bench.rs +++ b/bin/node/testing/src/bench.rs @@ -392,14 +392,13 @@ impl BenchDb { let task_executor = TaskExecutor::new(); let backend = sc_service::new_db_backend(db_config).expect("Should not fail"); - let executor = NativeElseWasmExecutor::new( - WasmExecutionMethod::Compiled { + let executor = NativeElseWasmExecutor::new_with_wasm_executor( + sc_executor::WasmExecutor::builder(WasmExecutionMethod::Compiled { instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite, - }, - None, - 8, - 2, + }) + .build(), ); + let client_config = sc_service::ClientConfig::default(); let genesis_block_builder = sc_service::GenesisBlockBuilder::new( &keyring.generate_genesis(), diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index 066b1497fb6ec..8259f90ab29e6 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -114,8 +114,8 @@ fn call_in_wasm( execution_method: WasmExecutionMethod, ext: &mut E, ) -> Result, Error> { - let executor = - crate::WasmExecutor::::new(execution_method, Some(1024), 8, None, 2); + let executor = crate::WasmExecutor::::builder(execution_method).build(); + executor.uncached_call( RuntimeBlob::uncompress_if_needed(wasm_binary_unwrap()).unwrap(), ext, @@ -446,13 +446,10 @@ test_wasm_execution!(should_trap_when_heap_exhausted); fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) { let mut ext = TestExternalities::default(); - let executor = crate::WasmExecutor::::new( - wasm_method, - Some(17), // `17` is the initial number of pages compiled into the binary. - 8, - None, - 2, - ); + let executor = crate::WasmExecutor::::builder(wasm_method) + // `17` is the initial number of pages compiled into the binary. + .with_onchain_heap_alloc_strategy(HeapAllocStrategy::Static { extra_pages: 17 }) + .build(); let err = executor .uncached_call( @@ -579,13 +576,7 @@ fn heap_is_reset_between_calls(wasm_method: WasmExecutionMethod) { test_wasm_execution!(parallel_execution); fn parallel_execution(wasm_method: WasmExecutionMethod) { - let executor = std::sync::Arc::new(crate::WasmExecutor::::new( - wasm_method, - Some(1024), - 8, - None, - 2, - )); + let executor = Arc::new(crate::WasmExecutor::::builder(wasm_method).build()); let threads: Vec<_> = (0..8) .map(|_| { let executor = executor.clone(); diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index e5bae474e9e25..3e4b47d158f97 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -74,13 +74,10 @@ mod tests { let mut ext = TestExternalities::default(); let mut ext = ext.ext(); - let executor = WasmExecutor::::new( + let executor = WasmExecutor::::builder( WasmExecutionMethod::Interpreted, - Some(8), - 8, - None, - 2, - ); + ) + .build(); let res = executor .uncached_call( RuntimeBlob::uncompress_if_needed(wasm_binary_unwrap()).unwrap(), diff --git a/client/executor/src/native_executor.rs b/client/executor/src/native_executor.rs index c72cf3c9c91df..ebccea7810448 100644 --- a/client/executor/src/native_executor.rs +++ b/client/executor/src/native_executor.rs @@ -107,7 +107,7 @@ impl WasmExecutorBuilder { onchain_heap_alloc_strategy: None, offchain_heap_alloc_strategy: None, max_runtime_instances: 2, - runtime_cache_size: 4, + runtime_cache_size: 8, allow_missing_host_functions: false, cache_path: None, } @@ -173,7 +173,7 @@ impl WasmExecutorBuilder { /// Defines the number of different runtimes/instantiated wasm blobs the cache stores. /// Runtimes/wasm blobs are differentiated based on the hash and the number of heap pages. /// - /// By default this value is set to `4`. + /// By default this value is set to `8`. pub fn with_runtime_cache_size(mut self, runtime_cache_size: u8) -> Self { self.runtime_cache_size = runtime_cache_size; self @@ -238,6 +238,8 @@ impl WasmExecutor where H: HostFunctions, { + /// *To be deprecated*: use [`Self::builder`] method instead of it. + /// /// Create new instance. /// /// # Parameters @@ -539,6 +541,8 @@ pub struct NativeElseWasmExecutor { } impl NativeElseWasmExecutor { + /// *To be deprecated*: use [`Self::new_with_wasm_executor`] method instead of it. + /// /// Create new instance. /// /// # Parameters @@ -579,6 +583,8 @@ impl NativeElseWasmExecutor { Self { native_version: D::native_version(), wasm: executor } } + /// *To be deprecated*: use [`Self::new_with_wasm_executor`] method to configure it. + /// /// Ignore missing function imports if set true. pub fn allow_missing_host_functions(&mut self, allow_missing_host_functions: bool) { self.wasm.allow_missing_host_functions = allow_missing_host_functions @@ -714,11 +720,8 @@ mod tests { #[test] fn native_executor_registers_custom_interface() { - let executor = NativeElseWasmExecutor::::new( - WasmExecutionMethod::Interpreted, - None, - 8, - 2, + let executor = NativeElseWasmExecutor::::new_with_wasm_executor( + WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), ); fn extract_host_functions( diff --git a/client/service/src/client/call_executor.rs b/client/service/src/client/call_executor.rs index 82d3e36ac80ea..9134f9fb2f286 100644 --- a/client/service/src/client/call_executor.rs +++ b/client/service/src/client/call_executor.rs @@ -368,7 +368,7 @@ mod tests { use super::*; use backend::Backend; use sc_client_api::in_mem; - use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod}; + use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor}; use sp_core::{ testing::TaskExecutor, traits::{FetchRuntimeCode, WrappedRuntimeCode}, @@ -376,14 +376,18 @@ mod tests { use std::collections::HashMap; use substrate_test_runtime_client::{runtime, GenesisInit, LocalExecutorDispatch}; + fn executor() -> NativeElseWasmExecutor { + NativeElseWasmExecutor::new_with_wasm_executor( + WasmExecutor::builder(WasmExecutionMethod::Interpreted) + .with_max_runtime_instances(1) + .with_runtime_cache_size(2) + .build(), + ) + } + #[test] fn should_get_override_if_exists() { - let executor = NativeElseWasmExecutor::::new( - WasmExecutionMethod::Interpreted, - Some(128), - 1, - 2, - ); + let executor = executor(); let overrides = crate::client::wasm_override::dummy_overrides(); let onchain_code = WrappedRuntimeCode(substrate_test_runtime::wasm_binary_unwrap().into()); @@ -451,12 +455,7 @@ mod tests { fn returns_runtime_version_from_substitute() { const SUBSTITUTE_SPEC_NAME: &str = "substitute-spec-name-cool"; - let executor = NativeElseWasmExecutor::::new( - WasmExecutionMethod::Interpreted, - Some(128), - 1, - 2, - ); + let executor = executor(); let backend = Arc::new(in_mem::Backend::::new()); diff --git a/client/service/src/client/wasm_override.rs b/client/service/src/client/wasm_override.rs index 3a56e5c595829..6a9428ce36991 100644 --- a/client/service/src/client/wasm_override.rs +++ b/client/service/src/client/wasm_override.rs @@ -264,21 +264,25 @@ pub fn dummy_overrides() -> WasmOverride { #[cfg(test)] mod tests { use super::*; - use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod}; + use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor}; use std::fs::{self, File}; use substrate_test_runtime_client::LocalExecutorDispatch; + fn executor() -> NativeElseWasmExecutor { + NativeElseWasmExecutor::::new_with_wasm_executor( + WasmExecutor::builder(WasmExecutionMethod::Interpreted) + // .with_onchain_heap_alloc_strategy(128) + .with_max_runtime_instances(1) + .with_runtime_cache_size(2) + .build() + ) + } + fn wasm_test(fun: F) where F: Fn(&Path, &[u8], &NativeElseWasmExecutor), { - let exec = - NativeElseWasmExecutor::::new( - WasmExecutionMethod::Interpreted, - Some(128), - 1, - 2, - ); + let exec = executor(); let bytes = substrate_test_runtime::wasm_binary_unwrap(); let dir = tempfile::tempdir().expect("Create a temporary directory"); fun(dir.path(), bytes, &exec); @@ -287,12 +291,7 @@ mod tests { #[test] fn should_get_runtime_version() { - let executor = NativeElseWasmExecutor::::new( - WasmExecutionMethod::Interpreted, - Some(128), - 1, - 2, - ); + let executor = executor(); let version = WasmOverride::runtime_version( &executor, diff --git a/client/service/test/src/client/mod.rs b/client/service/test/src/client/mod.rs index 96a0a8fe2a023..ad7db0da7811b 100644 --- a/client/service/test/src/client/mod.rs +++ b/client/service/test/src/client/mod.rs @@ -72,7 +72,7 @@ impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { } } -fn executor() -> sc_executor::NativeElseWasmExecutor { +fn executor() -> NativeElseWasmExecutor { sc_executor::NativeElseWasmExecutor::new( sc_executor::WasmExecutionMethod::Interpreted, None, diff --git a/primitives/api/test/tests/runtime_calls.rs b/primitives/api/test/tests/runtime_calls.rs index 69f9a88ffadb3..5c3310dce7298 100644 --- a/primitives/api/test/tests/runtime_calls.rs +++ b/primitives/api/test/tests/runtime_calls.rs @@ -29,6 +29,7 @@ use substrate_test_runtime_client::{ use codec::Encode; use sc_block_builder::BlockBuilderProvider; use sp_consensus::SelectChain; +use substrate_test_runtime_client::sc_executor::WasmExecutor; fn calling_function_with_strat(strat: ExecutionStrategy) { let client = TestClientBuilder::new().set_execution_strategy(strat).build(); @@ -178,11 +179,8 @@ fn record_proof_works() { // Use the proof backend to execute `execute_block`. let mut overlay = Default::default(); - let executor = NativeElseWasmExecutor::::new( - WasmExecutionMethod::Interpreted, - None, - 8, - 2, + let executor = NativeElseWasmExecutor::::new_with_wasm_executor( + WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), ); execution_proof_check_on_trie_backend( &backend, diff --git a/primitives/runtime-interface/test/src/lib.rs b/primitives/runtime-interface/test/src/lib.rs index d691d4846c330..032224e97eeaf 100644 --- a/primitives/runtime-interface/test/src/lib.rs +++ b/primitives/runtime-interface/test/src/lib.rs @@ -42,7 +42,8 @@ fn call_wasm_method_with_result( let executor = sc_executor::WasmExecutor::< ExtendedHostFunctions, - >::new(sc_executor::WasmExecutionMethod::Interpreted, Some(8), 8, None, 2); + >::builder(sc_executor::WasmExecutionMethod::Interpreted) + .build(); let (result, allocation_stats) = executor.uncached_call_with_allocation_stats( RuntimeBlob::uncompress_if_needed(binary).expect("Failed to parse binary"), diff --git a/test-utils/runtime/client/src/lib.rs b/test-utils/runtime/client/src/lib.rs index 099aeab11f768..35aab025d3360 100644 --- a/test-utils/runtime/client/src/lib.rs +++ b/test-utils/runtime/client/src/lib.rs @@ -38,6 +38,7 @@ use sp_core::{ Pair, }; use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT}; +use substrate_test_client::sc_executor::WasmExecutor; use substrate_test_runtime::genesismap::{additional_storage_with_genesis, GenesisConfig}; /// A prelude to import in tests. @@ -291,5 +292,7 @@ pub fn new() -> Client { /// Create a new native executor. pub fn new_native_executor() -> NativeElseWasmExecutor { - NativeElseWasmExecutor::new(sc_executor::WasmExecutionMethod::Interpreted, None, 8, 2) + NativeElseWasmExecutor::new_with_wasm_executor( + WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), + ) } diff --git a/test-utils/runtime/src/system.rs b/test-utils/runtime/src/system.rs index 12ebf486bb1b9..0265b0a03295c 100644 --- a/test-utils/runtime/src/system.rs +++ b/test-utils/runtime/src/system.rs @@ -350,7 +350,7 @@ mod tests { use super::*; use crate::{wasm_binary_unwrap, Header, Transfer}; - use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod}; + use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor}; use sp_core::{ map, traits::{CallContext, CodeExecutor, RuntimeCode}, @@ -374,7 +374,9 @@ mod tests { } fn executor() -> NativeElseWasmExecutor { - NativeElseWasmExecutor::new(WasmExecutionMethod::Interpreted, None, 8, 2) + NativeElseWasmExecutor::new_with_wasm_executor( + WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), + ) } fn new_test_ext() -> TestExternalities { diff --git a/utils/frame/benchmarking-cli/src/pallet/command.rs b/utils/frame/benchmarking-cli/src/pallet/command.rs index 15ebc668ff4fb..45e31575510ca 100644 --- a/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -27,7 +27,7 @@ use sc_cli::{ execution_method_from_cli, CliConfiguration, ExecutionStrategy, Result, SharedParams, }; use sc_client_db::BenchmarkingState; -use sc_executor::NativeElseWasmExecutor; +use sc_executor::{NativeElseWasmExecutor, WasmExecutor}; use sc_service::{Configuration, NativeExecutionDispatch}; use serde::Serialize; use sp_core::{ @@ -209,11 +209,15 @@ impl PalletCmd { // Do not enable storage tracking false, )?; - let executor = NativeElseWasmExecutor::::new( - execution_method_from_cli(self.wasm_method, self.wasmtime_instantiation_strategy), - self.heap_pages, - 2, // The runtime instances cache size. - 2, // The runtime cache size + + let method = + execution_method_from_cli(self.wasm_method, self.wasmtime_instantiation_strategy); + + let executor = NativeElseWasmExecutor::::new_with_wasm_executor( + WasmExecutor::builder(method) + .with_max_runtime_instances(2) + .with_runtime_cache_size(2) + .build(), ); let extensions = || -> Extensions { diff --git a/utils/frame/try-runtime/cli/Cargo.toml b/utils/frame/try-runtime/cli/Cargo.toml index a220289542464..e553e4e062b2f 100644 --- a/utils/frame/try-runtime/cli/Cargo.toml +++ b/utils/frame/try-runtime/cli/Cargo.toml @@ -14,6 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] remote-externalities = { version = "0.10.0-dev", path = "../../remote-externalities", package = "frame-remote-externalities" } sc-cli = { version = "0.10.0-dev", path = "../../../../client/cli" } +sc-executor-common = { version = "0.10.0-dev", path = "../../../../client/executor/common" } sc-executor = { version = "0.10.0-dev", path = "../../../../client/executor" } sc-service = { version = "0.10.0-dev", default-features = false, path = "../../../../client/service" } sp-consensus-aura = { path = "../../../../primitives/consensus/aura" } diff --git a/utils/frame/try-runtime/cli/src/lib.rs b/utils/frame/try-runtime/cli/src/lib.rs index e1873f6a04abd..73d3cd114cb8d 100644 --- a/utils/frame/try-runtime/cli/src/lib.rs +++ b/utils/frame/try-runtime/cli/src/lib.rs @@ -369,6 +369,7 @@ use sc_cli::{ DEFAULT_WASM_EXECUTION_METHOD, }; use sc_executor::{sp_wasm_interface::HostFunctions, WasmExecutor}; +use sc_executor_common::wasm_runtime::HeapAllocStrategy; use sp_api::HashT; use sp_core::{ hexdisplay::HexDisplay, @@ -826,17 +827,21 @@ pub(crate) fn full_extensions() -> Extensions { } pub(crate) fn build_executor(shared: &SharedParams) -> WasmExecutor { - let heap_pages = shared.heap_pages.or(Some(2048)); + let heap_pages = shared.heap_pages.unwrap_or(2048); let max_runtime_instances = 8; let runtime_cache_size = 2; - WasmExecutor::new( - execution_method_from_cli(shared.wasm_method, shared.wasmtime_instantiation_strategy), - heap_pages, - max_runtime_instances, - None, - runtime_cache_size, - ) + sc_executor_common::wasm_runtime::HeapAllocStrategy; + let method = + execution_method_from_cli(shared.wasm_method, shared.wasmtime_instantiation_strategy); + + WasmExecutor::builder(method) + .with_offchain_heap_alloc_strategy(HeapAllocStrategy::Static { + extra_pages: heap_pages as _, + }) + .with_max_runtime_instances(max_runtime_instances) + .with_runtime_cache_size(runtime_cache_size) + .build() } /// Ensure that the given `ext` is compiled with `try-runtime` From 9750b54a645101aec99b8fa5eb60890720e13200 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 29 Mar 2023 00:48:43 +0800 Subject: [PATCH 02/32] improve a lot --- bin/node-template/node/src/service.rs | 7 +----- bin/node/cli/src/service.rs | 7 +----- bin/node/inspect/src/command.rs | 25 +++++++------------ .../src/{native_executor.rs => executor.rs} | 0 client/executor/src/lib.rs | 12 +++++---- client/executor/src/wasm_runtime.rs | 2 +- client/service/src/builder.rs | 13 +++++++++- client/service/src/lib.rs | 2 +- 8 files changed, 32 insertions(+), 36 deletions(-) rename client/executor/src/{native_executor.rs => executor.rs} (100%) diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index dfbb5e96354e4..0cd6267d21ab5 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -68,12 +68,7 @@ pub fn new_partial( }) .transpose()?; - let executor = NativeElseWasmExecutor::::new( - config.wasm_method, - config.default_heap_pages, - config.max_runtime_instances, - config.runtime_cache_size, - ); + let executor = sc_service::new_native_executor(&config); let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::( diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index ca6830085b055..510210ba8c042 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -163,12 +163,7 @@ pub fn new_partial( }) .transpose()?; - let executor = NativeElseWasmExecutor::::new( - config.wasm_method, - config.default_heap_pages, - config.max_runtime_instances, - config.runtime_cache_size, - ); + let executor = sc_service::new_native_executor(&config); let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::( diff --git a/bin/node/inspect/src/command.rs b/bin/node/inspect/src/command.rs index 3dca979eb9e4a..6fca6de30f93d 100644 --- a/bin/node/inspect/src/command.rs +++ b/bin/node/inspect/src/command.rs @@ -23,41 +23,34 @@ use crate::{ Inspector, }; use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams}; -use sc_executor::NativeElseWasmExecutor; -use sc_service::{new_full_client, Configuration, NativeExecutionDispatch}; +use sc_service::{Configuration, NativeExecutionDispatch}; use sp_runtime::traits::Block; use std::str::FromStr; impl InspectCmd { /// Run the inspect command, passing the inspector. - pub fn run(&self, config: Configuration) -> Result<()> + pub fn run(&self, config: Configuration) -> Result<()> where B: Block, B::Hash: FromStr, RA: Send + Sync + 'static, - EX: NativeExecutionDispatch + 'static, + D: NativeExecutionDispatch + 'static, { - let executor = NativeElseWasmExecutor::::new( - config.wasm_method, - config.default_heap_pages, - config.max_runtime_instances, - config.runtime_cache_size, - ); - - let client = new_full_client::(&config, None, executor)?; + let executor = sc_service::new_native_executor::(&config); + let client = sc_service::new_full_client::(&config, None, executor)?; let inspect = Inspector::::new(client); match &self.command { InspectSubCmd::Block { input } => { let input = input.parse()?; - let res = inspect.block(input).map_err(|e| format!("{}", e))?; - println!("{}", res); + let res = inspect.block(input).map_err(|e| e.to_string())?; + println!("{res}"); Ok(()) }, InspectSubCmd::Extrinsic { input } => { let input = input.parse()?; - let res = inspect.extrinsic(input).map_err(|e| format!("{}", e))?; - println!("{}", res); + let res = inspect.extrinsic(input).map_err(|e| e.to_string())?; + println!("{res}"); Ok(()) }, } diff --git a/client/executor/src/native_executor.rs b/client/executor/src/executor.rs similarity index 100% rename from client/executor/src/native_executor.rs rename to client/executor/src/executor.rs diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index 3e4b47d158f97..b44c67a6e6168 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -32,21 +32,23 @@ #![recursion_limit = "128"] #[macro_use] -mod native_executor; +mod executor; #[cfg(test)] mod integration_tests; mod wasm_runtime; -pub use codec::Codec; -pub use native_executor::{ - with_externalities_safe, NativeElseWasmExecutor, NativeExecutionDispatch, WasmExecutor, +pub use self::{ + executor::{ + with_externalities_safe, NativeElseWasmExecutor, NativeExecutionDispatch, WasmExecutor, + }, + wasm_runtime::{read_embedded_version, WasmExecutionMethod}, }; +pub use codec::Codec; #[doc(hidden)] pub use sp_core::traits::Externalities; pub use sp_version::{NativeVersion, RuntimeVersion}; #[doc(hidden)] pub use sp_wasm_interface; -pub use wasm_runtime::{read_embedded_version, WasmExecutionMethod}; pub use wasmi; pub use sc_executor_common::error; diff --git a/client/executor/src/wasm_runtime.rs b/client/executor/src/wasm_runtime.rs index 254380dbb3693..fb42c1eca3dc8 100644 --- a/client/executor/src/wasm_runtime.rs +++ b/client/executor/src/wasm_runtime.rs @@ -430,7 +430,7 @@ where // The following unwind safety assertion is OK because if the method call panics, the // runtime will be dropped. let runtime = AssertUnwindSafe(runtime.as_ref()); - crate::native_executor::with_externalities_safe(&mut **ext, move || { + crate::executor::with_externalities_safe(&mut **ext, move || { runtime.new_instance()?.call("Core_version".into(), &[]) }) .map_err(|_| WasmError::Instantiation("panic in call to get runtime version".into()))? diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 7cbbf2a4dda0f..0857186902f8d 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -36,7 +36,7 @@ use sc_client_api::{ }; use sc_client_db::{Backend, DatabaseSettings}; use sc_consensus::import_queue::ImportQueue; -use sc_executor::RuntimeVersionOf; +use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch, RuntimeVersionOf}; use sc_keystore::LocalKeystore; use sc_network::{ config::SyncMode, NetworkEventStream, NetworkService, NetworkStateInfo, NetworkStatusProvider, @@ -230,6 +230,17 @@ where Ok((client, backend, keystore_container, task_manager)) } + +/// Creates a [`NativeElseWasmExecutor`] according to [`Configuration`]. +pub fn new_native_executor(config: &Configuration) -> NativeElseWasmExecutor { + NativeElseWasmExecutor::::new( + config.wasm_method, + config.default_heap_pages, + config.max_runtime_instances, + config.runtime_cache_size, + ) +} + /// Create an instance of default DB-backend backend. pub fn new_db_backend( settings: DatabaseSettings, diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 54f11ec25a02a..7b5ad5aa3bdf8 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -58,7 +58,7 @@ pub use self::{ build_network, build_offchain_workers, new_client, new_db_backend, new_full_client, new_full_parts, new_full_parts_with_genesis_builder, spawn_tasks, BuildNetworkParams, KeystoreContainer, NetworkStarter, SpawnTasksParams, TFullBackend, TFullCallExecutor, - TFullClient, + TFullClient, new_native_executor, }, client::{ClientConfig, LocalCallExecutor}, error::Error, From de50bf8f678d43dfb99fb98567d40edb96f7b61f Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 29 Mar 2023 00:56:44 +0800 Subject: [PATCH 03/32] remove unused args --- client/service/src/builder.rs | 5 +++-- client/service/src/lib.rs | 6 +++--- utils/frame/try-runtime/cli/src/lib.rs | 26 ++++++-------------------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 0857186902f8d..80d6ab5003af8 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -230,9 +230,10 @@ where Ok((client, backend, keystore_container, task_manager)) } - /// Creates a [`NativeElseWasmExecutor`] according to [`Configuration`]. -pub fn new_native_executor(config: &Configuration) -> NativeElseWasmExecutor { +pub fn new_native_executor( + config: &Configuration, +) -> NativeElseWasmExecutor { NativeElseWasmExecutor::::new( config.wasm_method, config.default_heap_pages, diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index 7b5ad5aa3bdf8..17d21b485bd59 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -56,9 +56,9 @@ use sp_runtime::{ pub use self::{ builder::{ build_network, build_offchain_workers, new_client, new_db_backend, new_full_client, - new_full_parts, new_full_parts_with_genesis_builder, spawn_tasks, BuildNetworkParams, - KeystoreContainer, NetworkStarter, SpawnTasksParams, TFullBackend, TFullCallExecutor, - TFullClient, new_native_executor, + new_full_parts, new_full_parts_with_genesis_builder, new_native_executor, spawn_tasks, + BuildNetworkParams, KeystoreContainer, NetworkStarter, SpawnTasksParams, TFullBackend, + TFullCallExecutor, TFullClient, }, client::{ClientConfig, LocalCallExecutor}, error::Error, diff --git a/utils/frame/try-runtime/cli/src/lib.rs b/utils/frame/try-runtime/cli/src/lib.rs index 73d3cd114cb8d..0070392b263a1 100644 --- a/utils/frame/try-runtime/cli/src/lib.rs +++ b/utils/frame/try-runtime/cli/src/lib.rs @@ -531,11 +531,6 @@ pub struct SharedParams { )] pub wasmtime_instantiation_strategy: WasmtimeInstantiationStrategy, - /// The number of 64KB pages to allocate for Wasm execution. Defaults to - /// [`sc_service::Configuration.default_heap_pages`]. - #[arg(long)] - pub heap_pages: Option, - /// Path to a file to export the storage proof into (as a JSON). /// If several blocks are executed, the path is interpreted as a folder /// where one file per block will be written (named `{block_number}-{block_hash}`). @@ -826,22 +821,13 @@ pub(crate) fn full_extensions() -> Extensions { extensions } +/// Build wasm executor by default config. pub(crate) fn build_executor(shared: &SharedParams) -> WasmExecutor { - let heap_pages = shared.heap_pages.unwrap_or(2048); - let max_runtime_instances = 8; - let runtime_cache_size = 2; - - sc_executor_common::wasm_runtime::HeapAllocStrategy; - let method = - execution_method_from_cli(shared.wasm_method, shared.wasmtime_instantiation_strategy); - - WasmExecutor::builder(method) - .with_offchain_heap_alloc_strategy(HeapAllocStrategy::Static { - extra_pages: heap_pages as _, - }) - .with_max_runtime_instances(max_runtime_instances) - .with_runtime_cache_size(runtime_cache_size) - .build() + WasmExecutor::builder(execution_method_from_cli( + shared.wasm_method, + shared.wasmtime_instantiation_strategy, + )) + .build() } /// Ensure that the given `ext` is compiled with `try-runtime` From fb0539d165b43d85ae79794c33f8456026a2dea4 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 29 Mar 2023 01:00:08 +0800 Subject: [PATCH 04/32] cleanup deps --- Cargo.lock | 1 - utils/frame/try-runtime/cli/Cargo.toml | 1 - utils/frame/try-runtime/cli/src/lib.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 807aaff525c07..33bca4005483c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11920,7 +11920,6 @@ dependencies = [ "parity-scale-codec", "sc-cli", "sc-executor", - "sc-executor-common", "sc-service", "serde", "serde_json", diff --git a/utils/frame/try-runtime/cli/Cargo.toml b/utils/frame/try-runtime/cli/Cargo.toml index e553e4e062b2f..a220289542464 100644 --- a/utils/frame/try-runtime/cli/Cargo.toml +++ b/utils/frame/try-runtime/cli/Cargo.toml @@ -14,7 +14,6 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] remote-externalities = { version = "0.10.0-dev", path = "../../remote-externalities", package = "frame-remote-externalities" } sc-cli = { version = "0.10.0-dev", path = "../../../../client/cli" } -sc-executor-common = { version = "0.10.0-dev", path = "../../../../client/executor/common" } sc-executor = { version = "0.10.0-dev", path = "../../../../client/executor" } sc-service = { version = "0.10.0-dev", default-features = false, path = "../../../../client/service" } sp-consensus-aura = { path = "../../../../primitives/consensus/aura" } diff --git a/utils/frame/try-runtime/cli/src/lib.rs b/utils/frame/try-runtime/cli/src/lib.rs index 0070392b263a1..31a6968bc1364 100644 --- a/utils/frame/try-runtime/cli/src/lib.rs +++ b/utils/frame/try-runtime/cli/src/lib.rs @@ -369,7 +369,6 @@ use sc_cli::{ DEFAULT_WASM_EXECUTION_METHOD, }; use sc_executor::{sp_wasm_interface::HostFunctions, WasmExecutor}; -use sc_executor_common::wasm_runtime::HeapAllocStrategy; use sp_api::HashT; use sp_core::{ hexdisplay::HexDisplay, From b60bbd852ac6813bf1f417f546d5b15460d0659a Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 29 Mar 2023 01:25:33 +0800 Subject: [PATCH 05/32] fix inconsistency about heap alloc --- client/executor/benches/bench.rs | 7 +++---- client/executor/common/src/wasm_runtime.rs | 4 ++++ client/executor/src/executor.rs | 8 +++----- client/executor/src/lib.rs | 2 +- client/executor/wasmtime/src/tests.rs | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/client/executor/benches/bench.rs b/client/executor/benches/bench.rs index 10425ea461c21..0194160e6dd51 100644 --- a/client/executor/benches/bench.rs +++ b/client/executor/benches/bench.rs @@ -21,7 +21,7 @@ use codec::Encode; use sc_executor_common::{ runtime_blob::RuntimeBlob, - wasm_runtime::{HeapAllocStrategy, WasmInstance, WasmModule}, + wasm_runtime::{HeapAllocStrategy, WasmInstance, WasmModule, DEFAULT_HEAP_ALLOC_STRATEGY}, }; use sc_executor_wasmtime::InstantiationStrategy; use sc_runtime_test::wasm_binary_unwrap as test_runtime; @@ -51,13 +51,12 @@ fn initialize( ) -> Arc { let blob = RuntimeBlob::uncompress_if_needed(runtime).unwrap(); let host_functions = sp_io::SubstrateHostFunctions::host_functions(); - let extra_pages = 2048; let allow_missing_func_imports = true; match method { Method::Interpreted => sc_executor_wasmi::create_runtime( blob, - HeapAllocStrategy::Static { extra_pages }, + DEFAULT_HEAP_ALLOC_STRATEGY, host_functions, allow_missing_func_imports, ) @@ -67,7 +66,7 @@ fn initialize( allow_missing_func_imports, cache_path: None, semantics: sc_executor_wasmtime::Semantics { - heap_alloc_strategy: HeapAllocStrategy::Static { extra_pages }, + heap_alloc_strategy: DEFAULT_HEAP_ALLOC_STRATEGY, instantiation_strategy, deterministic_stack_limit: None, canonicalize_nans: false, diff --git a/client/executor/common/src/wasm_runtime.rs b/client/executor/common/src/wasm_runtime.rs index e3db7e52fc7e7..f25bfe0925989 100644 --- a/client/executor/common/src/wasm_runtime.rs +++ b/client/executor/common/src/wasm_runtime.rs @@ -23,6 +23,10 @@ use sp_wasm_interface::Value; pub use sc_allocator::AllocationStats; +/// Default heap allocation strategy. +pub const DEFAULT_HEAP_ALLOC_STRATEGY: HeapAllocStrategy = + HeapAllocStrategy::Static { extra_pages: 2048 }; + /// A method to be used to find the entrypoint when calling into the runtime /// /// Contains variants on how to resolve wasm function that will be invoked. diff --git a/client/executor/src/executor.rs b/client/executor/src/executor.rs index ebccea7810448..34ffbeab96748 100644 --- a/client/executor/src/executor.rs +++ b/client/executor/src/executor.rs @@ -32,16 +32,14 @@ use std::{ use codec::Encode; use sc_executor_common::{ runtime_blob::RuntimeBlob, - wasm_runtime::{AllocationStats, HeapAllocStrategy, WasmInstance, WasmModule}, + wasm_runtime::{ + AllocationStats, HeapAllocStrategy, WasmInstance, WasmModule, DEFAULT_HEAP_ALLOC_STRATEGY, + }, }; use sp_core::traits::{CallContext, CodeExecutor, Externalities, RuntimeCode}; use sp_version::{GetNativeVersion, NativeVersion, RuntimeVersion}; use sp_wasm_interface::{ExtendedHostFunctions, HostFunctions}; -/// Default heap allocation strategy. -const DEFAULT_HEAP_ALLOC_STRATEGY: HeapAllocStrategy = - HeapAllocStrategy::Static { extra_pages: 2048 }; - /// Set up the externalities and safe calling environment to execute runtime calls. /// /// If the inner closure panics, it will be caught and return an error. diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index b44c67a6e6168..4547fd689b05e 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -51,7 +51,7 @@ pub use sp_version::{NativeVersion, RuntimeVersion}; pub use sp_wasm_interface; pub use wasmi; -pub use sc_executor_common::error; +pub use sc_executor_common::{error, wasm_runtime::HeapAllocStrategy}; pub use sc_executor_wasmtime::InstantiationStrategy as WasmtimeInstantiationStrategy; /// Extracts the runtime version of a given runtime code. diff --git a/client/executor/wasmtime/src/tests.rs b/client/executor/wasmtime/src/tests.rs index 7f222b6cf7c05..493c96e5517a6 100644 --- a/client/executor/wasmtime/src/tests.rs +++ b/client/executor/wasmtime/src/tests.rs @@ -20,7 +20,7 @@ use codec::{Decode as _, Encode as _}; use sc_executor_common::{ error::Error, runtime_blob::RuntimeBlob, - wasm_runtime::{HeapAllocStrategy, WasmModule}, + wasm_runtime::{HeapAllocStrategy, WasmModule, DEFAULT_HEAP_ALLOC_STRATEGY}, }; use sc_runtime_test::wasm_binary_unwrap; @@ -473,7 +473,7 @@ fn test_instances_without_reuse_are_not_leaked() { deterministic_stack_limit: None, canonicalize_nans: false, parallel_compilation: true, - heap_alloc_strategy: HeapAllocStrategy::Static { extra_pages: 2048 }, + heap_alloc_strategy: DEFAULT_HEAP_ALLOC_STRATEGY, }, }, ) From 4eb0dc2ff4f970e0ab547f2b5fde7fb920271766 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 29 Mar 2023 01:42:07 +0800 Subject: [PATCH 06/32] add `heap_pages` back to try-runtime --- utils/frame/try-runtime/cli/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/utils/frame/try-runtime/cli/src/lib.rs b/utils/frame/try-runtime/cli/src/lib.rs index 31a6968bc1364..a45e73a37c75d 100644 --- a/utils/frame/try-runtime/cli/src/lib.rs +++ b/utils/frame/try-runtime/cli/src/lib.rs @@ -369,6 +369,7 @@ use sc_cli::{ DEFAULT_WASM_EXECUTION_METHOD, }; use sc_executor::{sp_wasm_interface::HostFunctions, WasmExecutor}; +use sc_executor_common::wasm_runtime::HeapAllocStrategy; use sp_api::HashT; use sp_core::{ hexdisplay::HexDisplay, @@ -530,6 +531,11 @@ pub struct SharedParams { )] pub wasmtime_instantiation_strategy: WasmtimeInstantiationStrategy, + /// The number of 64KB pages to allocate for Wasm execution. Defaults to + /// [`sc_service::Configuration.default_heap_pages`]. + #[arg(long)] + pub heap_pages: Option, + /// Path to a file to export the storage proof into (as a JSON). /// If several blocks are executed, the path is interpreted as a folder /// where one file per block will be written (named `{block_number}-{block_hash}`). @@ -822,10 +828,15 @@ pub(crate) fn full_extensions() -> Extensions { /// Build wasm executor by default config. pub(crate) fn build_executor(shared: &SharedParams) -> WasmExecutor { + let heap_pages = + HeapAllocStrategy::Static { extra_pages: shared.heap_pages.unwrap_or(2048) as _ }; + WasmExecutor::builder(execution_method_from_cli( shared.wasm_method, shared.wasmtime_instantiation_strategy, )) + .with_onchain_heap_alloc_strategy(heap_pages) + .with_offchain_heap_alloc_strategy(heap_pages) .build() } From f4491343558f0ae27c5b5105d0a3c21655fdecbf Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 29 Mar 2023 04:46:16 +0800 Subject: [PATCH 07/32] fix --- utils/frame/try-runtime/cli/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/frame/try-runtime/cli/src/lib.rs b/utils/frame/try-runtime/cli/src/lib.rs index a45e73a37c75d..15a6f0f83384b 100644 --- a/utils/frame/try-runtime/cli/src/lib.rs +++ b/utils/frame/try-runtime/cli/src/lib.rs @@ -368,8 +368,7 @@ use sc_cli::{ WasmtimeInstantiationStrategy, DEFAULT_WASMTIME_INSTANTIATION_STRATEGY, DEFAULT_WASM_EXECUTION_METHOD, }; -use sc_executor::{sp_wasm_interface::HostFunctions, WasmExecutor}; -use sc_executor_common::wasm_runtime::HeapAllocStrategy; +use sc_executor::{sp_wasm_interface::HostFunctions, HeapAllocStrategy, WasmExecutor}; use sp_api::HashT; use sp_core::{ hexdisplay::HexDisplay, From c4175b22c7efddffa0e25e02f5def20d937d814b Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 29 Mar 2023 05:08:42 +0800 Subject: [PATCH 08/32] chore: reduce duplicated code for sc-service-test --- client/service/test/src/client/mod.rs | 38 ++++++--------------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/client/service/test/src/client/mod.rs b/client/service/test/src/client/mod.rs index ad7db0da7811b..fa523141ec712 100644 --- a/client/service/test/src/client/mod.rs +++ b/client/service/test/src/client/mod.rs @@ -45,6 +45,7 @@ use sp_trie::{LayoutV0, TrieConfiguration}; use std::{collections::HashSet, sync::Arc}; use substrate_test_runtime::TestAPI; use substrate_test_runtime_client::{ + new_native_executor, prelude::*, runtime::{ genesismap::{insert_genesis_block, GenesisConfig}, @@ -58,29 +59,6 @@ mod db; const TEST_ENGINE_ID: ConsensusEngineId = *b"TEST"; -pub struct ExecutorDispatch; - -impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { - type ExtendHostFunctions = (); - - fn dispatch(method: &str, data: &[u8]) -> Option> { - substrate_test_runtime_client::runtime::api::dispatch(method, data) - } - - fn native_version() -> sc_executor::NativeVersion { - substrate_test_runtime_client::runtime::native_version() - } -} - -fn executor() -> NativeElseWasmExecutor { - sc_executor::NativeElseWasmExecutor::new( - sc_executor::WasmExecutionMethod::Interpreted, - None, - 8, - 2, - ) -} - fn construct_block( backend: &InMemoryBackend, number: BlockNumber, @@ -109,7 +87,7 @@ fn construct_block( StateMachine::new( backend, &mut overlay, - &executor(), + &new_native_executor(), "Core_initialize_block", &header.encode(), Default::default(), @@ -124,7 +102,7 @@ fn construct_block( StateMachine::new( backend, &mut overlay, - &executor(), + &new_native_executor(), "BlockBuilder_apply_extrinsic", &tx.encode(), Default::default(), @@ -139,7 +117,7 @@ fn construct_block( let ret_data = StateMachine::new( backend, &mut overlay, - &executor(), + &new_native_executor(), "BlockBuilder_finalize_block", &[], Default::default(), @@ -212,7 +190,7 @@ fn construct_genesis_should_work_with_native() { let _ = StateMachine::new( &backend, &mut overlay, - &executor(), + &new_native_executor(), "Core_execute_block", &b1data, Default::default(), @@ -246,7 +224,7 @@ fn construct_genesis_should_work_with_wasm() { let _ = StateMachine::new( &backend, &mut overlay, - &executor(), + &new_native_executor(), "Core_execute_block", &b1data, Default::default(), @@ -280,7 +258,7 @@ fn construct_genesis_with_bad_transaction_should_panic() { let r = StateMachine::new( &backend, &mut overlay, - &executor(), + &new_native_executor(), "Core_execute_block", &b1data, Default::default(), @@ -1917,7 +1895,7 @@ fn cleans_up_closed_notification_sinks_on_block_import() { use substrate_test_runtime_client::GenesisInit; let backend = Arc::new(sc_client_api::in_mem::Backend::new()); - let executor = substrate_test_runtime_client::new_native_executor(); + let executor = new_native_executor(); let client_config = sc_service::ClientConfig::default(); let genesis_block_builder = sc_service::GenesisBlockBuilder::new( From 86172e61db071115fefcba67bf88613db1c67496 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 29 Mar 2023 05:12:13 +0800 Subject: [PATCH 09/32] cleanup code --- client/service/src/builder.rs | 8 ++++---- client/service/test/src/lib.rs | 4 ++-- test-utils/runtime/client/src/lib.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 80d6ab5003af8..56c1585436148 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -76,11 +76,11 @@ pub type TFullClient = Client, TFullCallExecutor, TBl, TRtApi>; /// Full client backend type. -pub type TFullBackend = sc_client_db::Backend; +pub type TFullBackend = Backend; /// Full client call executor type. pub type TFullCallExecutor = - crate::client::LocalCallExecutor, TExec>; + crate::client::LocalCallExecutor, TExec>; type TFullParts = (TFullClient, Arc>, KeystoreContainer, TaskManager); @@ -267,7 +267,7 @@ pub fn new_client( telemetry: Option, config: ClientConfig, ) -> Result< - crate::client::Client< + Client< Backend, crate::client::LocalCallExecutor, E>, Block, @@ -291,7 +291,7 @@ where execution_extensions, )?; - crate::client::Client::new( + Client::new( backend, executor, spawn_handle, diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index 8a2e5050bd5d3..b45b88ddf11a9 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -66,7 +66,7 @@ impl Drop for TestNet { } pub trait TestNetNode: - Clone + Future> + Send + 'static + Clone + Future> + Send + 'static { type Block: BlockT; type Backend: Backend; @@ -128,7 +128,7 @@ impl Clone impl Future for TestNetComponents { - type Output = Result<(), sc_service::Error>; + type Output = Result<(), Error>; fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll { Pin::new(&mut self.task_manager.lock().future()).poll(cx) diff --git a/test-utils/runtime/client/src/lib.rs b/test-utils/runtime/client/src/lib.rs index 35aab025d3360..20c76bd994978 100644 --- a/test-utils/runtime/client/src/lib.rs +++ b/test-utils/runtime/client/src/lib.rs @@ -172,7 +172,7 @@ pub type Client = client::Client< client::LocalCallExecutor< substrate_test_runtime::Block, B, - sc_executor::NativeElseWasmExecutor, + NativeElseWasmExecutor, >, substrate_test_runtime::Block, substrate_test_runtime::RuntimeApi, From f2c2e54180de0450bbb37be5c284d9a5fa044b7c Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 29 Mar 2023 05:56:12 +0800 Subject: [PATCH 10/32] fmt --- client/service/src/builder.rs | 3 +-- client/service/test/src/lib.rs | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 56c1585436148..f159ce663da58 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -79,8 +79,7 @@ pub type TFullClient = pub type TFullBackend = Backend; /// Full client call executor type. -pub type TFullCallExecutor = - crate::client::LocalCallExecutor, TExec>; +pub type TFullCallExecutor = crate::client::LocalCallExecutor, TExec>; type TFullParts = (TFullClient, Arc>, KeystoreContainer, TaskManager); diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index b45b88ddf11a9..966ea238ef233 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -65,9 +65,7 @@ impl Drop for TestNet { } } -pub trait TestNetNode: - Clone + Future> + Send + 'static -{ +pub trait TestNetNode: Clone + Future> + Send + 'static { type Block: BlockT; type Backend: Backend; type Executor: CallExecutor + Send + Sync; From ce6dfb6b8ea62fbc50c9ea8440f354e0b0bc7bf0 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 29 Mar 2023 06:01:20 +0800 Subject: [PATCH 11/32] improve test executor --- client/service/src/client/wasm_override.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/service/src/client/wasm_override.rs b/client/service/src/client/wasm_override.rs index 6a9428ce36991..868c719ab962a 100644 --- a/client/service/src/client/wasm_override.rs +++ b/client/service/src/client/wasm_override.rs @@ -264,14 +264,17 @@ pub fn dummy_overrides() -> WasmOverride { #[cfg(test)] mod tests { use super::*; - use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor}; + use sc_executor::{ + HeapAllocStrategy, NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor, + }; use std::fs::{self, File}; use substrate_test_runtime_client::LocalExecutorDispatch; fn executor() -> NativeElseWasmExecutor { NativeElseWasmExecutor::::new_with_wasm_executor( WasmExecutor::builder(WasmExecutionMethod::Interpreted) - // .with_onchain_heap_alloc_strategy(128) + .with_onchain_heap_alloc_strategy(HeapAllocStrategy::Static {extra_pages: 128}) + .with_offchain_heap_alloc_strategy(HeapAllocStrategy::Static {extra_pages: 128}) .with_max_runtime_instances(1) .with_runtime_cache_size(2) .build() From 95dca94048c789c9d6f6c5eef0913a66b3b73e76 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 29 Mar 2023 15:46:29 +0800 Subject: [PATCH 12/32] improve --- client/executor/common/src/wasm_runtime.rs | 5 ++++- client/executor/src/lib.rs | 5 ++++- client/service/src/builder.rs | 25 ++++++++++++++++------ test-utils/client/src/lib.rs | 6 ++++-- utils/frame/try-runtime/cli/src/lib.rs | 6 ++++-- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/client/executor/common/src/wasm_runtime.rs b/client/executor/common/src/wasm_runtime.rs index f25bfe0925989..5dac77e59fa74 100644 --- a/client/executor/common/src/wasm_runtime.rs +++ b/client/executor/common/src/wasm_runtime.rs @@ -25,7 +25,10 @@ pub use sc_allocator::AllocationStats; /// Default heap allocation strategy. pub const DEFAULT_HEAP_ALLOC_STRATEGY: HeapAllocStrategy = - HeapAllocStrategy::Static { extra_pages: 2048 }; + HeapAllocStrategy::Static { extra_pages: DEFAULT_HEAP_ALLOC_PAGES }; + +/// Default heap allocation pages. +pub const DEFAULT_HEAP_ALLOC_PAGES: u32 = 2048; /// A method to be used to find the entrypoint when calling into the runtime /// diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index 4547fd689b05e..16ad0c6616f21 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -51,7 +51,10 @@ pub use sp_version::{NativeVersion, RuntimeVersion}; pub use sp_wasm_interface; pub use wasmi; -pub use sc_executor_common::{error, wasm_runtime::HeapAllocStrategy}; +pub use sc_executor_common::{ + error, + wasm_runtime::{HeapAllocStrategy, DEFAULT_HEAP_ALLOC_PAGES, DEFAULT_HEAP_ALLOC_STRATEGY}, +}; pub use sc_executor_wasmtime::InstantiationStrategy as WasmtimeInstantiationStrategy; /// Extracts the runtime version of a given runtime code. diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index f159ce663da58..18b1e58f1b5b2 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -36,7 +36,10 @@ use sc_client_api::{ }; use sc_client_db::{Backend, DatabaseSettings}; use sc_consensus::import_queue::ImportQueue; -use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch, RuntimeVersionOf}; +use sc_executor::{ + sp_wasm_interface::HostFunctions, HeapAllocStrategy, NativeElseWasmExecutor, + NativeExecutionDispatch, RuntimeVersionOf, WasmExecutor, DEFAULT_HEAP_ALLOC_PAGES, +}; use sc_keystore::LocalKeystore; use sc_network::{ config::SyncMode, NetworkEventStream, NetworkService, NetworkStateInfo, NetworkStatusProvider, @@ -233,12 +236,20 @@ where pub fn new_native_executor( config: &Configuration, ) -> NativeElseWasmExecutor { - NativeElseWasmExecutor::::new( - config.wasm_method, - config.default_heap_pages, - config.max_runtime_instances, - config.runtime_cache_size, - ) + NativeElseWasmExecutor::new_with_wasm_executor(new_wasm_executor(config)) +} + +/// Creates a [`WasmExecutor`] according to [`Configuration`]. +pub fn new_wasm_executor(config: &Configuration) -> WasmExecutor { + let extra_pages = + config.default_heap_pages.map(|p| p as u32).unwrap_or(DEFAULT_HEAP_ALLOC_PAGES); + let strategy = HeapAllocStrategy::Static { extra_pages }; + WasmExecutor::::builder(config.wasm_method) + .with_onchain_heap_alloc_strategy(strategy) + .with_onchain_heap_alloc_strategy(strategy) + .with_max_runtime_instances(config.max_runtime_instances) + .with_runtime_cache_size(config.runtime_cache_size) + .build() } /// Create an instance of default DB-backend backend. diff --git a/test-utils/client/src/lib.rs b/test-utils/client/src/lib.rs index a91aa99929e2f..fc44168ab3175 100644 --- a/test-utils/client/src/lib.rs +++ b/test-utils/client/src/lib.rs @@ -27,7 +27,7 @@ pub use sc_client_api::{ BadBlocks, ForkBlocks, }; pub use sc_client_db::{self, Backend, BlocksPruning}; -pub use sc_executor::{self, NativeElseWasmExecutor, WasmExecutionMethod}; +pub use sc_executor::{self, NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor}; pub use sc_service::{client, RpcHandlers}; pub use sp_consensus; pub use sp_keyring::{ @@ -286,7 +286,9 @@ impl Backend: sc_client_api::backend::Backend + 'static, { let executor = executor.into().unwrap_or_else(|| { - NativeElseWasmExecutor::new(WasmExecutionMethod::Interpreted, None, 8, 2) + NativeElseWasmExecutor::new_with_wasm_executor( + WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), + ) }); let executor = LocalCallExecutor::new( self.backend.clone(), diff --git a/utils/frame/try-runtime/cli/src/lib.rs b/utils/frame/try-runtime/cli/src/lib.rs index 15a6f0f83384b..0bce93ae8b950 100644 --- a/utils/frame/try-runtime/cli/src/lib.rs +++ b/utils/frame/try-runtime/cli/src/lib.rs @@ -369,6 +369,7 @@ use sc_cli::{ DEFAULT_WASM_EXECUTION_METHOD, }; use sc_executor::{sp_wasm_interface::HostFunctions, HeapAllocStrategy, WasmExecutor}; +use sc_executor_common::wasm_runtime::DEFAULT_HEAP_ALLOC_PAGES; use sp_api::HashT; use sp_core::{ hexdisplay::HexDisplay, @@ -827,8 +828,9 @@ pub(crate) fn full_extensions() -> Extensions { /// Build wasm executor by default config. pub(crate) fn build_executor(shared: &SharedParams) -> WasmExecutor { - let heap_pages = - HeapAllocStrategy::Static { extra_pages: shared.heap_pages.unwrap_or(2048) as _ }; + let heap_pages = HeapAllocStrategy::Static { + extra_pages: shared.heap_pages.map(|p| p as u32).unwrap_or(DEFAULT_HEAP_ALLOC_PAGES), + }; WasmExecutor::builder(execution_method_from_cli( shared.wasm_method, From 714703398bdfe92354c102b1f3e70fa963839a05 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 29 Mar 2023 23:33:08 +0800 Subject: [PATCH 13/32] use #[deprecated] --- client/executor/src/executor.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/client/executor/src/executor.rs b/client/executor/src/executor.rs index 34ffbeab96748..ffcdac6342268 100644 --- a/client/executor/src/executor.rs +++ b/client/executor/src/executor.rs @@ -236,8 +236,6 @@ impl WasmExecutor where H: HostFunctions, { - /// *To be deprecated*: use [`Self::builder`] method instead of it. - /// /// Create new instance. /// /// # Parameters @@ -256,6 +254,7 @@ where /// compiled execution method is used. /// /// `runtime_cache_size` - The capacity of runtime cache. + #[deprecated(note = "use `Self::builder` method instead of it")] pub fn new( method: WasmExecutionMethod, default_heap_pages: Option, @@ -288,6 +287,7 @@ where } /// Ignore missing function imports if set true. + #[deprecated(note = "use `Self::builder` method instead of it")] pub fn allow_missing_host_functions(&mut self, allow_missing_host_functions: bool) { self.allow_missing_host_functions = allow_missing_host_functions } @@ -539,7 +539,6 @@ pub struct NativeElseWasmExecutor { } impl NativeElseWasmExecutor { - /// *To be deprecated*: use [`Self::new_with_wasm_executor`] method instead of it. /// /// Create new instance. /// @@ -555,6 +554,7 @@ impl NativeElseWasmExecutor { /// `max_runtime_instances` - The number of runtime instances to keep in memory ready for reuse. /// /// `runtime_cache_size` - The capacity of runtime cache. + #[deprecated(note = "use `Self::new_with_wasm_executor` method instead of it")] pub fn new( fallback_method: WasmExecutionMethod, default_heap_pages: Option, @@ -581,9 +581,8 @@ impl NativeElseWasmExecutor { Self { native_version: D::native_version(), wasm: executor } } - /// *To be deprecated*: use [`Self::new_with_wasm_executor`] method to configure it. - /// /// Ignore missing function imports if set true. + #[deprecated(note = "use `Self::new_with_wasm_executor` method instead of it")] pub fn allow_missing_host_functions(&mut self, allow_missing_host_functions: bool) { self.wasm.allow_missing_host_functions = allow_missing_host_functions } From 157646efb2781b6afa31de11fa29a1a2cb304200 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 29 Mar 2023 23:37:46 +0800 Subject: [PATCH 14/32] set runtime_cache_size: 4 --- client/executor/src/executor.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/executor/src/executor.rs b/client/executor/src/executor.rs index ffcdac6342268..e75ceffded2a7 100644 --- a/client/executor/src/executor.rs +++ b/client/executor/src/executor.rs @@ -105,7 +105,7 @@ impl WasmExecutorBuilder { onchain_heap_alloc_strategy: None, offchain_heap_alloc_strategy: None, max_runtime_instances: 2, - runtime_cache_size: 8, + runtime_cache_size: 4, allow_missing_host_functions: false, cache_path: None, } @@ -171,7 +171,7 @@ impl WasmExecutorBuilder { /// Defines the number of different runtimes/instantiated wasm blobs the cache stores. /// Runtimes/wasm blobs are differentiated based on the hash and the number of heap pages. /// - /// By default this value is set to `8`. + /// By default this value is set to `4`. pub fn with_runtime_cache_size(mut self, runtime_cache_size: u8) -> Self { self.runtime_cache_size = runtime_cache_size; self From 3f43381e8273b5f2cd6853ab6bdf98373c52f3a3 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Thu, 30 Mar 2023 19:53:58 +0800 Subject: [PATCH 15/32] wip --- client/executor/benches/bench.rs | 19 +++++++------ client/executor/src/executor.rs | 8 ++++++ client/executor/src/wasm_runtime.rs | 44 ++++++++++++++--------------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/client/executor/benches/bench.rs b/client/executor/benches/bench.rs index 0194160e6dd51..9ef7e3073ea39 100644 --- a/client/executor/benches/bench.rs +++ b/client/executor/benches/bench.rs @@ -33,7 +33,7 @@ use std::sync::{ #[derive(Clone)] enum Method { - Interpreted, + // Interpreted, Compiled { instantiation_strategy: InstantiationStrategy, precompile: bool }, } @@ -50,17 +50,18 @@ fn initialize( method: Method, ) -> Arc { let blob = RuntimeBlob::uncompress_if_needed(runtime).unwrap(); - let host_functions = sp_io::SubstrateHostFunctions::host_functions(); + // 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| -> Arc { Arc::new(runtime) }), + // Method::Interpreted => sc_executor_wasmi::create_runtime( + // blob, + // DEFAULT_HEAP_ALLOC_STRATEGY, + // host_functions, + // allow_missing_func_imports, + // ) + // .map(|runtime| -> Arc { Arc::new(runtime) }), + Method::Compiled { instantiation_strategy, precompile } => { let config = sc_executor_wasmtime::Config { allow_missing_func_imports, diff --git a/client/executor/src/executor.rs b/client/executor/src/executor.rs index e75ceffded2a7..da1cdc1e990de 100644 --- a/client/executor/src/executor.rs +++ b/client/executor/src/executor.rs @@ -111,6 +111,14 @@ impl WasmExecutorBuilder { } } + /// The wasm execution method that should be used by the executor. + /// + /// Default to + pub fn with_execution_method(mut self, method: WasmExecutionMethod) -> Self { + self.method = method; + self + } + /// Create the wasm executor with the given number of `heap_alloc_strategy` for onchain runtime /// calls. pub fn with_onchain_heap_alloc_strategy( diff --git a/client/executor/src/wasm_runtime.rs b/client/executor/src/wasm_runtime.rs index fb42c1eca3dc8..c30ddc47ba160 100644 --- a/client/executor/src/wasm_runtime.rs +++ b/client/executor/src/wasm_runtime.rs @@ -40,11 +40,15 @@ use std::{ use sp_wasm_interface::HostFunctions; +pub const DEFAULT_WASM_METHOD: WasmExecutionMethod = WasmExecutionMethod::Compiled { + instantiation_strategy: sc_executor_wasmtime::InstantiationStrategy::PoolingCopyOnWrite, +}; + /// 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 Wasmi interpreter. + // Interpreted, /// Uses the Wasmtime compiled runtime. Compiled { /// The instantiation strategy to use. @@ -52,12 +56,6 @@ pub enum WasmExecutionMethod { }, } -impl Default for WasmExecutionMethod { - fn default() -> WasmExecutionMethod { - WasmExecutionMethod::Interpreted - } -} - #[derive(Debug, PartialEq, Eq, Hash, Clone)] struct VersionedRuntimeId { /// Runtime code hash. @@ -299,21 +297,21 @@ 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| -> Arc { Arc::new(runtime) }) - }, + // 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| -> Arc { Arc::new(runtime) }) + // }, WasmExecutionMethod::Compiled { instantiation_strategy } => sc_executor_wasmtime::create_runtime::( blob, From 2dfbe0e5146cfdeb6e749b57dcfc5bc4abeca371 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Thu, 30 Mar 2023 20:05:12 +0800 Subject: [PATCH 16/32] fix and improve --- client/executor/src/integration_tests/linux.rs | 4 ++-- client/executor/src/integration_tests/mod.rs | 4 ++-- client/executor/wasmtime/src/tests.rs | 6 ++++-- utils/frame/try-runtime/cli/src/lib.rs | 5 +++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/client/executor/src/integration_tests/linux.rs b/client/executor/src/integration_tests/linux.rs index 38d75da4eb7e8..7decbf31695fe 100644 --- a/client/executor/src/integration_tests/linux.rs +++ b/client/executor/src/integration_tests/linux.rs @@ -21,7 +21,7 @@ use super::mk_test_runtime; use crate::WasmExecutionMethod; use codec::Encode as _; -use sc_executor_common::wasm_runtime::HeapAllocStrategy; +use sc_executor_common::wasm_runtime::{HeapAllocStrategy, DEFAULT_HEAP_ALLOC_STRATEGY}; mod smaps; @@ -74,7 +74,7 @@ fn memory_consumption(wasm_method: WasmExecutionMethod) { // For that we make a series of runtime calls, probing the RSS for the VMA matching the linear // memory. After the call we expect RSS to be equal to 0. - let runtime = mk_test_runtime(wasm_method, HeapAllocStrategy::Static { extra_pages: 1024 }); + let runtime = mk_test_runtime(wasm_method, DEFAULT_HEAP_ALLOC_STRATEGY); let mut instance = runtime.new_instance().unwrap(); let heap_base = instance diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index 8259f90ab29e6..902c1ddc923eb 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -24,7 +24,7 @@ use codec::{Decode, Encode}; use sc_executor_common::{ error::{Error, WasmError}, runtime_blob::RuntimeBlob, - wasm_runtime::{HeapAllocStrategy, WasmModule}, + wasm_runtime::{HeapAllocStrategy, WasmModule, DEFAULT_HEAP_ALLOC_STRATEGY}, }; use sc_runtime_test::wasm_binary_unwrap; use sp_core::{ @@ -557,7 +557,7 @@ fn restoration_of_globals(wasm_method: WasmExecutionMethod) { 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, HeapAllocStrategy::Static { extra_pages: 1024 }); + let runtime = mk_test_runtime(wasm_method, DEFAULT_HEAP_ALLOC_STRATEGY); let mut instance = runtime.new_instance().unwrap(); let heap_base = instance diff --git a/client/executor/wasmtime/src/tests.rs b/client/executor/wasmtime/src/tests.rs index 493c96e5517a6..53b1eeb922071 100644 --- a/client/executor/wasmtime/src/tests.rs +++ b/client/executor/wasmtime/src/tests.rs @@ -20,7 +20,9 @@ use codec::{Decode as _, Encode as _}; use sc_executor_common::{ error::Error, runtime_blob::RuntimeBlob, - wasm_runtime::{HeapAllocStrategy, WasmModule, DEFAULT_HEAP_ALLOC_STRATEGY}, + wasm_runtime::{ + HeapAllocStrategy, WasmModule, DEFAULT_HEAP_ALLOC_PAGES, DEFAULT_HEAP_ALLOC_STRATEGY, + }, }; use sc_runtime_test::wasm_binary_unwrap; @@ -93,7 +95,7 @@ impl RuntimeBuilder { instantiation_strategy, canonicalize_nans: false, deterministic_stack: false, - heap_pages: HeapAllocStrategy::Static { extra_pages: 1024 }, + heap_pages: DEFAULT_HEAP_ALLOC_STRATEGY, precompile_runtime: false, tmpdir: None, } diff --git a/utils/frame/try-runtime/cli/src/lib.rs b/utils/frame/try-runtime/cli/src/lib.rs index 0bce93ae8b950..a9a92826f4314 100644 --- a/utils/frame/try-runtime/cli/src/lib.rs +++ b/utils/frame/try-runtime/cli/src/lib.rs @@ -368,8 +368,9 @@ use sc_cli::{ WasmtimeInstantiationStrategy, DEFAULT_WASMTIME_INSTANTIATION_STRATEGY, DEFAULT_WASM_EXECUTION_METHOD, }; -use sc_executor::{sp_wasm_interface::HostFunctions, HeapAllocStrategy, WasmExecutor}; -use sc_executor_common::wasm_runtime::DEFAULT_HEAP_ALLOC_PAGES; +use sc_executor::{ + sp_wasm_interface::HostFunctions, HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_PAGES, +}; use sp_api::HashT; use sp_core::{ hexdisplay::HexDisplay, From 36594122aa573d102e9763c3a2b4958aeef0e498 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Thu, 30 Mar 2023 20:19:50 +0800 Subject: [PATCH 17/32] remove sc-executor-wasmi deps --- Cargo.lock | 1 - bin/node/cli/benches/transaction_pool.rs | 5 ++++- bin/node/executor/benches/bench.rs | 2 +- bin/node/executor/tests/common.rs | 2 +- client/cli/src/arg_enums.rs | 5 ----- client/executor/Cargo.toml | 2 +- client/executor/src/executor.rs | 10 +++++----- client/executor/src/lib.rs | 4 +--- client/executor/src/wasm_runtime.rs | 12 ++++++++---- client/service/src/builder.rs | 3 ++- client/service/src/client/call_executor.rs | 2 +- client/service/src/client/wasm_override.rs | 2 +- client/service/test/src/lib.rs | 2 +- primitives/api/test/tests/runtime_calls.rs | 2 +- test-utils/client/src/lib.rs | 2 +- test-utils/runtime/client/src/lib.rs | 2 +- test-utils/runtime/src/system.rs | 2 +- utils/frame/benchmarking-cli/src/pallet/command.rs | 3 ++- 18 files changed, 32 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a49f8fc4208a2..8941ba6703c06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8816,7 +8816,6 @@ dependencies = [ "paste", "regex", "sc-executor-common", - "sc-executor-wasmi", "sc-executor-wasmtime", "sc-runtime-test", "sc-tracing", diff --git a/bin/node/cli/benches/transaction_pool.rs b/bin/node/cli/benches/transaction_pool.rs index 7488ec03363e7..afb02620d97ba 100644 --- a/bin/node/cli/benches/transaction_pool.rs +++ b/bin/node/cli/benches/transaction_pool.rs @@ -37,6 +37,7 @@ use sp_core::{crypto::Pair, sr25519}; use sp_keyring::Sr25519Keyring; use sp_runtime::{generic::BlockId, OpaqueExtrinsic}; use tokio::runtime::Handle; +use sc_executor::WasmtimeInstantiationStrategy; fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase { let base_path = BasePath::new_temp_dir().expect("Creates base path"); @@ -69,7 +70,9 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase { state_pruning: Some(PruningMode::ArchiveAll), blocks_pruning: BlocksPruning::KeepAll, chain_spec: spec, - wasm_method: WasmExecutionMethod::Interpreted, + wasm_method: WasmExecutionMethod::Compiled { + instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite, + }, // NOTE: we enforce the use of the native runtime to make the errors more debuggable execution_strategies: ExecutionStrategies { syncing: sc_client_api::ExecutionStrategy::NativeWhenPossible, diff --git a/bin/node/executor/benches/bench.rs b/bin/node/executor/benches/bench.rs index 05c406bb5274f..cb790728722c4 100644 --- a/bin/node/executor/benches/bench.rs +++ b/bin/node/executor/benches/bench.rs @@ -197,7 +197,7 @@ fn bench_execute_block(c: &mut Criterion) { }; let executor = NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), + WasmExecutor::builder().build(), ); let runtime_code = RuntimeCode { code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()), diff --git a/bin/node/executor/tests/common.rs b/bin/node/executor/tests/common.rs index d8699b9555d42..e4eae59837b81 100644 --- a/bin/node/executor/tests/common.rs +++ b/bin/node/executor/tests/common.rs @@ -99,7 +99,7 @@ pub fn from_block_number(n: u32) -> Header { pub fn executor() -> NativeElseWasmExecutor { NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), + WasmExecutor::builder().build(), ) } diff --git a/client/cli/src/arg_enums.rs b/client/cli/src/arg_enums.rs index 7e2498cec4b7f..d169168b8cce2 100644 --- a/client/cli/src/arg_enums.rs +++ b/client/cli/src/arg_enums.rs @@ -54,9 +54,6 @@ 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, /// Uses a compiled runtime. Compiled, } @@ -64,7 +61,6 @@ pub enum WasmExecutionMethod { 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"), } } @@ -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 => diff --git a/client/executor/Cargo.toml b/client/executor/Cargo.toml index 21a9bd70dde65..ce8b7270157fb 100644 --- a/client/executor/Cargo.toml +++ b/client/executor/Cargo.toml @@ -21,7 +21,7 @@ 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-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" } diff --git a/client/executor/src/executor.rs b/client/executor/src/executor.rs index da1cdc1e990de..a37f01a1bc1f9 100644 --- a/client/executor/src/executor.rs +++ b/client/executor/src/executor.rs @@ -98,10 +98,10 @@ impl WasmExecutorBuilder { /// Create a new instance of `Self` /// /// - `method`: The wasm execution method that should be used by the executor. - pub fn new(method: WasmExecutionMethod) -> Self { + pub fn new() -> Self { Self { _phantom: PhantomData, - method, + method: WasmExecutionMethod::default(), onchain_heap_alloc_strategy: None, offchain_heap_alloc_strategy: None, max_runtime_instances: 2, @@ -290,8 +290,8 @@ where } /// Instantiate a builder for creating an instance of `Self`. - pub fn builder(method: WasmExecutionMethod) -> WasmExecutorBuilder { - WasmExecutorBuilder::new(method) + pub fn builder() -> WasmExecutorBuilder { + WasmExecutorBuilder::new() } /// Ignore missing function imports if set true. @@ -726,7 +726,7 @@ mod tests { #[test] fn native_executor_registers_custom_interface() { let executor = NativeElseWasmExecutor::::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), + WasmExecutor::builder().build(), ); fn extract_host_functions( diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index 16ad0c6616f21..a1a4ecd48dbe9 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -79,9 +79,7 @@ mod tests { let mut ext = TestExternalities::default(); let mut ext = ext.ext(); - let executor = WasmExecutor::::builder( - WasmExecutionMethod::Interpreted, - ) + let executor = WasmExecutor::::builder() .build(); let res = executor .uncached_call( diff --git a/client/executor/src/wasm_runtime.rs b/client/executor/src/wasm_runtime.rs index c30ddc47ba160..0e3b4ef83a702 100644 --- a/client/executor/src/wasm_runtime.rs +++ b/client/executor/src/wasm_runtime.rs @@ -40,10 +40,6 @@ use std::{ use sp_wasm_interface::HostFunctions; -pub const DEFAULT_WASM_METHOD: WasmExecutionMethod = WasmExecutionMethod::Compiled { - instantiation_strategy: sc_executor_wasmtime::InstantiationStrategy::PoolingCopyOnWrite, -}; - /// Specification of different methods of executing the runtime Wasm code. #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)] pub enum WasmExecutionMethod { @@ -56,6 +52,14 @@ pub enum WasmExecutionMethod { }, } +impl Default for WasmExecutionMethod { + fn default() -> Self { + Self::Compiled { + instantiation_strategy: sc_executor_wasmtime::InstantiationStrategy::PoolingCopyOnWrite, + } + } +} + #[derive(Debug, PartialEq, Eq, Hash, Clone)] struct VersionedRuntimeId { /// Runtime code hash. diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 18b1e58f1b5b2..abf6d459fc491 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -244,7 +244,8 @@ pub fn new_wasm_executor(config: &Configuration) -> WasmExecut let extra_pages = config.default_heap_pages.map(|p| p as u32).unwrap_or(DEFAULT_HEAP_ALLOC_PAGES); let strategy = HeapAllocStrategy::Static { extra_pages }; - WasmExecutor::::builder(config.wasm_method) + WasmExecutor::::builder() + .with_execution_method(config.wasm_method) .with_onchain_heap_alloc_strategy(strategy) .with_onchain_heap_alloc_strategy(strategy) .with_max_runtime_instances(config.max_runtime_instances) diff --git a/client/service/src/client/call_executor.rs b/client/service/src/client/call_executor.rs index 9134f9fb2f286..06d0eb093dc2e 100644 --- a/client/service/src/client/call_executor.rs +++ b/client/service/src/client/call_executor.rs @@ -378,7 +378,7 @@ mod tests { fn executor() -> NativeElseWasmExecutor { NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted) + WasmExecutor::builder() .with_max_runtime_instances(1) .with_runtime_cache_size(2) .build(), diff --git a/client/service/src/client/wasm_override.rs b/client/service/src/client/wasm_override.rs index 868c719ab962a..81bbbaa055799 100644 --- a/client/service/src/client/wasm_override.rs +++ b/client/service/src/client/wasm_override.rs @@ -272,7 +272,7 @@ mod tests { fn executor() -> NativeElseWasmExecutor { NativeElseWasmExecutor::::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted) + WasmExecutor::builder() .with_onchain_heap_alloc_strategy(HeapAllocStrategy::Static {extra_pages: 128}) .with_offchain_heap_alloc_strategy(HeapAllocStrategy::Static {extra_pages: 128}) .with_max_runtime_instances(1) diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index 966ea238ef233..0f20376fe809e 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -246,7 +246,7 @@ fn node_config< state_pruning: Default::default(), blocks_pruning: BlocksPruning::KeepFinalized, chain_spec: Box::new((*spec).clone()), - wasm_method: sc_service::config::WasmExecutionMethod::Interpreted, + wasm_method: Default::default(), wasm_runtime_overrides: Default::default(), execution_strategies: Default::default(), rpc_http: None, diff --git a/primitives/api/test/tests/runtime_calls.rs b/primitives/api/test/tests/runtime_calls.rs index 5c3310dce7298..fe8c31ace8685 100644 --- a/primitives/api/test/tests/runtime_calls.rs +++ b/primitives/api/test/tests/runtime_calls.rs @@ -180,7 +180,7 @@ fn record_proof_works() { // Use the proof backend to execute `execute_block`. let mut overlay = Default::default(); let executor = NativeElseWasmExecutor::::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), + WasmExecutor::builder().build(), ); execution_proof_check_on_trie_backend( &backend, diff --git a/test-utils/client/src/lib.rs b/test-utils/client/src/lib.rs index fc44168ab3175..ac648b605c166 100644 --- a/test-utils/client/src/lib.rs +++ b/test-utils/client/src/lib.rs @@ -287,7 +287,7 @@ impl { let executor = executor.into().unwrap_or_else(|| { NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), + WasmExecutor::builder().build(), ) }); let executor = LocalCallExecutor::new( diff --git a/test-utils/runtime/client/src/lib.rs b/test-utils/runtime/client/src/lib.rs index 20c76bd994978..234f94064014b 100644 --- a/test-utils/runtime/client/src/lib.rs +++ b/test-utils/runtime/client/src/lib.rs @@ -293,6 +293,6 @@ pub fn new() -> Client { /// Create a new native executor. pub fn new_native_executor() -> NativeElseWasmExecutor { NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), + WasmExecutor::builder().build(), ) } diff --git a/test-utils/runtime/src/system.rs b/test-utils/runtime/src/system.rs index 0265b0a03295c..82490fb30c8cd 100644 --- a/test-utils/runtime/src/system.rs +++ b/test-utils/runtime/src/system.rs @@ -375,7 +375,7 @@ mod tests { fn executor() -> NativeElseWasmExecutor { NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), + WasmExecutor::builder().build(), ) } diff --git a/utils/frame/benchmarking-cli/src/pallet/command.rs b/utils/frame/benchmarking-cli/src/pallet/command.rs index 45e31575510ca..e7b98ccdace14 100644 --- a/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -214,7 +214,8 @@ impl PalletCmd { execution_method_from_cli(self.wasm_method, self.wasmtime_instantiation_strategy); let executor = NativeElseWasmExecutor::::new_with_wasm_executor( - WasmExecutor::builder(method) + WasmExecutor::builder() + .with_execution_method(method) .with_max_runtime_instances(2) .with_runtime_cache_size(2) .build(), From 9e068dac588f6e8c957cad8d85b720d9b2cf59ed Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Thu, 30 Mar 2023 20:22:08 +0800 Subject: [PATCH 18/32] clean up bench and tests --- bin/node/cli/benches/transaction_pool.rs | 2 +- bin/node/executor/benches/bench.rs | 5 +- bin/node/executor/tests/common.rs | 4 +- client/executor/benches/bench.rs | 10 --- client/executor/common/src/error.rs | 3 - .../executor/src/integration_tests/linux.rs | 4 +- client/executor/src/integration_tests/mod.rs | 70 ++++--------------- client/executor/src/lib.rs | 3 +- client/executor/src/wasm_runtime.rs | 17 ----- test-utils/client/src/lib.rs | 4 +- test-utils/runtime/client/src/lib.rs | 4 +- test-utils/runtime/src/system.rs | 4 +- 12 files changed, 25 insertions(+), 105 deletions(-) diff --git a/bin/node/cli/benches/transaction_pool.rs b/bin/node/cli/benches/transaction_pool.rs index afb02620d97ba..a1b9c6e067f1b 100644 --- a/bin/node/cli/benches/transaction_pool.rs +++ b/bin/node/cli/benches/transaction_pool.rs @@ -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; use sc_service::{ config::{ BlocksPruning, DatabaseSource, KeystoreConfig, NetworkConfiguration, OffchainWorkerConfig, @@ -37,7 +38,6 @@ use sp_core::{crypto::Pair, sr25519}; use sp_keyring::Sr25519Keyring; use sp_runtime::{generic::BlockId, OpaqueExtrinsic}; use tokio::runtime::Handle; -use sc_executor::WasmtimeInstantiationStrategy; fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase { let base_path = BasePath::new_temp_dir().expect("Creates base path"); diff --git a/bin/node/executor/benches/bench.rs b/bin/node/executor/benches/bench.rs index cb790728722c4..d36a15d2a4bbf 100644 --- a/bin/node/executor/benches/bench.rs +++ b/bin/node/executor/benches/bench.rs @@ -196,9 +196,8 @@ fn bench_execute_block(c: &mut Criterion) { ExecutionMethod::Wasm(wasm_method) => (false, wasm_method), }; - let executor = NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder().build(), - ); + let executor = + NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build()); let runtime_code = RuntimeCode { code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()), hash: vec![1, 2, 3], diff --git a/bin/node/executor/tests/common.rs b/bin/node/executor/tests/common.rs index e4eae59837b81..0d2339cd1645a 100644 --- a/bin/node/executor/tests/common.rs +++ b/bin/node/executor/tests/common.rs @@ -98,9 +98,7 @@ pub fn from_block_number(n: u32) -> Header { } pub fn executor() -> NativeElseWasmExecutor { - NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder().build(), - ) + NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build()) } pub fn executor_call( diff --git a/client/executor/benches/bench.rs b/client/executor/benches/bench.rs index 9ef7e3073ea39..1d07052f8b9aa 100644 --- a/client/executor/benches/bench.rs +++ b/client/executor/benches/bench.rs @@ -33,7 +33,6 @@ use std::sync::{ #[derive(Clone)] enum Method { - // Interpreted, Compiled { instantiation_strategy: InstantiationStrategy, precompile: bool }, } @@ -50,18 +49,9 @@ fn initialize( method: Method, ) -> Arc { 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| -> Arc { Arc::new(runtime) }), - Method::Compiled { instantiation_strategy, precompile } => { let config = sc_executor_wasmtime::Config { allow_missing_func_imports, diff --git a/client/executor/common/src/error.rs b/client/executor/common/src/error.rs index c47164a60655f..e6f5086157a70 100644 --- a/client/executor/common/src/error.rs +++ b/client/executor/common/src/error.rs @@ -48,9 +48,6 @@ pub enum Error { #[error("Invalid type returned (should be u64)")] InvalidReturn, - #[error("Runtime error")] - Runtime, - #[error("Runtime panicked: {0}")] RuntimePanicked(String), diff --git a/client/executor/src/integration_tests/linux.rs b/client/executor/src/integration_tests/linux.rs index 7decbf31695fe..f524cca9bf334 100644 --- a/client/executor/src/integration_tests/linux.rs +++ b/client/executor/src/integration_tests/linux.rs @@ -18,13 +18,13 @@ //! 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::{HeapAllocStrategy, DEFAULT_HEAP_ALLOC_STRATEGY}; -mod smaps; - use self::smaps::Smaps; #[test] diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index 902c1ddc923eb..5ab999b582427 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -24,7 +24,7 @@ use codec::{Decode, Encode}; use sc_executor_common::{ error::{Error, WasmError}, 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( @@ -114,7 +99,9 @@ fn call_in_wasm( execution_method: WasmExecutionMethod, ext: &mut E, ) -> Result, Error> { - let executor = crate::WasmExecutor::::builder(execution_method).build(); + let executor = crate::WasmExecutor::::builder() + .with_execution_method(execution_method) + .build(); executor.uncached_call( RuntimeBlob::uncompress_if_needed(wasm_binary_unwrap()).unwrap(), @@ -142,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); }, @@ -161,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); }, @@ -446,7 +433,8 @@ test_wasm_execution!(should_trap_when_heap_exhausted); fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) { let mut ext = TestExternalities::default(); - let executor = crate::WasmExecutor::::builder(wasm_method) + let executor = crate::WasmExecutor::::builder() + .with_execution_method(wasm_method) // `17` is the initial number of pages compiled into the binary. .with_onchain_heap_alloc_strategy(HeapAllocStrategy::Static { extra_pages: 17 }) .build(); @@ -470,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), } } @@ -555,28 +540,13 @@ 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(crate::WasmExecutor::::builder(wasm_method).build()); + let executor = Arc::new( + crate::WasmExecutor::::builder() + .with_execution_method(wasm_method) + .build(), + ); let threads: Vec<_> = (0..8) .map(|_| { let executor = executor.clone(); @@ -780,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", }; @@ -807,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::RuntimeConstruction(WasmError::Other(error)) => { assert_matches!(wasm_method, WasmExecutionMethod::Compiled { .. }); assert_eq!(error, "output exceeds bounds of wasm memory"); @@ -837,9 +803,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::RuntimeConstruction(WasmError::Other(error)) => { assert_matches!(wasm_method, WasmExecutionMethod::Compiled { .. }); assert_eq!(error, "output exceeds bounds of wasm memory"); @@ -854,9 +817,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::RuntimeConstruction(WasmError::Other(error)) => { assert_matches!(wasm_method, WasmExecutionMethod::Compiled { .. }); assert_eq!(error, "output exceeds bounds of wasm memory"); diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index a1a4ecd48dbe9..42e7dc7d16bd8 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -79,8 +79,7 @@ mod tests { let mut ext = TestExternalities::default(); let mut ext = ext.ext(); - let executor = WasmExecutor::::builder() - .build(); + let executor = WasmExecutor::::builder().build(); let res = executor .uncached_call( RuntimeBlob::uncompress_if_needed(wasm_binary_unwrap()).unwrap(), diff --git a/client/executor/src/wasm_runtime.rs b/client/executor/src/wasm_runtime.rs index 0e3b4ef83a702..ea5de8c9e02d6 100644 --- a/client/executor/src/wasm_runtime.rs +++ b/client/executor/src/wasm_runtime.rs @@ -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. @@ -301,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| -> Arc { Arc::new(runtime) }) - // }, WasmExecutionMethod::Compiled { instantiation_strategy } => sc_executor_wasmtime::create_runtime::( blob, diff --git a/test-utils/client/src/lib.rs b/test-utils/client/src/lib.rs index ac648b605c166..bfb0c79b628e6 100644 --- a/test-utils/client/src/lib.rs +++ b/test-utils/client/src/lib.rs @@ -286,9 +286,7 @@ impl Backend: sc_client_api::backend::Backend + 'static, { let executor = executor.into().unwrap_or_else(|| { - NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder().build(), - ) + NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build()) }); let executor = LocalCallExecutor::new( self.backend.clone(), diff --git a/test-utils/runtime/client/src/lib.rs b/test-utils/runtime/client/src/lib.rs index 234f94064014b..627ca99bb5749 100644 --- a/test-utils/runtime/client/src/lib.rs +++ b/test-utils/runtime/client/src/lib.rs @@ -292,7 +292,5 @@ pub fn new() -> Client { /// Create a new native executor. pub fn new_native_executor() -> NativeElseWasmExecutor { - NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder().build(), - ) + NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build()) } diff --git a/test-utils/runtime/src/system.rs b/test-utils/runtime/src/system.rs index 82490fb30c8cd..b00d403365d3d 100644 --- a/test-utils/runtime/src/system.rs +++ b/test-utils/runtime/src/system.rs @@ -374,9 +374,7 @@ mod tests { } fn executor() -> NativeElseWasmExecutor { - NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder().build(), - ) + NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build()) } fn new_test_ext() -> TestExternalities { From 16d2e5aaf1f24234e04f8420bc64b649d4dcc193 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Thu, 30 Mar 2023 20:29:41 +0800 Subject: [PATCH 19/32] delete "client/executor/wasmi" --- Cargo.toml | 1 - client/executor/wasmi/Cargo.toml | 22 -- client/executor/wasmi/README.md | 3 - client/executor/wasmi/src/lib.rs | 599 ------------------------------- 4 files changed, 625 deletions(-) delete mode 100644 client/executor/wasmi/Cargo.toml delete mode 100644 client/executor/wasmi/README.md delete mode 100644 client/executor/wasmi/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index de562ad79e47e..d1f5057ffcdb5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,6 @@ members = [ "client/executor", "client/executor/common", "client/executor/runtime-test", - "client/executor/wasmi", "client/executor/wasmtime", "client/informant", "client/keystore", diff --git a/client/executor/wasmi/Cargo.toml b/client/executor/wasmi/Cargo.toml deleted file mode 100644 index ded44f4ca77a9..0000000000000 --- a/client/executor/wasmi/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "sc-executor-wasmi" -version = "0.10.0-dev" -authors = ["Parity Technologies "] -edition = "2021" -license = "GPL-3.0-or-later WITH Classpath-exception-2.0" -homepage = "https://substrate.io" -repository = "https://github.com/paritytech/substrate/" -description = "This crate provides an implementation of `WasmRuntime` that is baked by wasmi." -documentation = "https://docs.rs/sc-executor-wasmi" -readme = "README.md" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -log = "0.4.17" -wasmi = { version = "0.13.2", features = [ "virtual_memory" ] } -sc-allocator = { version = "4.1.0-dev", path = "../../allocator" } -sc-executor-common = { version = "0.10.0-dev", path = "../common" } -sp-runtime-interface = { version = "7.0.0", path = "../../../primitives/runtime-interface" } -sp-wasm-interface = { version = "7.0.0", path = "../../../primitives/wasm-interface" } diff --git a/client/executor/wasmi/README.md b/client/executor/wasmi/README.md deleted file mode 100644 index ad613aa1245e3..0000000000000 --- a/client/executor/wasmi/README.md +++ /dev/null @@ -1,3 +0,0 @@ -This crate provides an implementation of `WasmModule` that is baked by wasmi. - -License: GPL-3.0-or-later WITH Classpath-exception-2.0 \ No newline at end of file diff --git a/client/executor/wasmi/src/lib.rs b/client/executor/wasmi/src/lib.rs deleted file mode 100644 index c757ff8afe43d..0000000000000 --- a/client/executor/wasmi/src/lib.rs +++ /dev/null @@ -1,599 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -//! This crate provides an implementation of `WasmModule` that is baked by wasmi. - -use std::{cell::RefCell, str, sync::Arc}; - -use log::{error, trace}; -use wasmi::{ - memory_units::Pages, - FuncInstance, ImportsBuilder, MemoryRef, Module, ModuleInstance, ModuleRef, - RuntimeValue::{self, I32, I64}, - TableRef, -}; - -use sc_allocator::{AllocationStats, FreeingBumpHeapAllocator}; -use sc_executor_common::{ - error::{Error, MessageWithBacktrace, WasmError}, - runtime_blob::{DataSegmentsSnapshot, RuntimeBlob}, - wasm_runtime::{HeapAllocStrategy, InvokeMethod, WasmInstance, WasmModule}, -}; -use sp_runtime_interface::unpack_ptr_and_len; -use sp_wasm_interface::{Function, FunctionContext, Pointer, Result as WResult, WordSize}; - -/// Wrapper around [`MemorRef`] that implements [`sc_allocator::Memory`]. -struct MemoryWrapper<'a>(&'a MemoryRef); - -impl sc_allocator::Memory for MemoryWrapper<'_> { - fn with_access_mut(&mut self, run: impl FnOnce(&mut [u8]) -> R) -> R { - self.0.with_direct_access_mut(run) - } - - fn with_access(&self, run: impl FnOnce(&[u8]) -> R) -> R { - self.0.with_direct_access(run) - } - - fn pages(&self) -> u32 { - self.0.current_size().0 as _ - } - - fn max_pages(&self) -> Option { - self.0.maximum().map(|p| p.0 as _) - } - - fn grow(&mut self, additional: u32) -> Result<(), ()> { - self.0 - .grow(Pages(additional as _)) - .map_err(|e| { - log::error!( - target: "wasm-executor", - "Failed to grow memory by {} pages: {}", - additional, - e, - ) - }) - .map(drop) - } -} - -struct FunctionExecutor { - heap: RefCell, - memory: MemoryRef, - host_functions: Arc>, - allow_missing_func_imports: bool, - missing_functions: Arc>, - panic_message: Option, -} - -impl FunctionExecutor { - fn new( - m: MemoryRef, - heap_base: u32, - host_functions: Arc>, - allow_missing_func_imports: bool, - missing_functions: Arc>, - ) -> Result { - Ok(FunctionExecutor { - heap: RefCell::new(FreeingBumpHeapAllocator::new(heap_base)), - memory: m, - host_functions, - allow_missing_func_imports, - missing_functions, - panic_message: None, - }) - } -} - -impl FunctionContext for FunctionExecutor { - fn read_memory_into(&self, address: Pointer, dest: &mut [u8]) -> WResult<()> { - self.memory.get_into(address.into(), dest).map_err(|e| e.to_string()) - } - - fn write_memory(&mut self, address: Pointer, data: &[u8]) -> WResult<()> { - self.memory.set(address.into(), data).map_err(|e| e.to_string()) - } - - fn allocate_memory(&mut self, size: WordSize) -> WResult> { - self.heap - .borrow_mut() - .allocate(&mut MemoryWrapper(&self.memory), size) - .map_err(|e| e.to_string()) - } - - fn deallocate_memory(&mut self, ptr: Pointer) -> WResult<()> { - self.heap - .borrow_mut() - .deallocate(&mut MemoryWrapper(&self.memory), ptr) - .map_err(|e| e.to_string()) - } - - fn register_panic_error_message(&mut self, message: &str) { - self.panic_message = Some(message.to_owned()); - } -} - -/// Will be used on initialization of a module to resolve function and memory imports. -struct Resolver<'a> { - /// All the hot functions that we export for the WASM blob. - host_functions: &'a [&'static dyn Function], - /// Should we allow missing function imports? - /// - /// If `true`, we return a stub that will return an error when being called. - allow_missing_func_imports: bool, - /// All the names of functions for that we did not provide a host function. - missing_functions: RefCell>, -} - -impl<'a> Resolver<'a> { - fn new( - host_functions: &'a [&'static dyn Function], - allow_missing_func_imports: bool, - ) -> Resolver<'a> { - Resolver { - host_functions, - allow_missing_func_imports, - missing_functions: RefCell::new(Vec::new()), - } - } -} - -impl<'a> wasmi::ModuleImportResolver for Resolver<'a> { - fn resolve_func( - &self, - name: &str, - signature: &wasmi::Signature, - ) -> std::result::Result { - let signature = sp_wasm_interface::Signature::from(signature); - for (function_index, function) in self.host_functions.iter().enumerate() { - if name == function.name() { - if signature == function.signature() { - return Ok(wasmi::FuncInstance::alloc_host(signature.into(), function_index)) - } else { - return Err(wasmi::Error::Instantiation(format!( - "Invalid signature for function `{}` expected `{:?}`, got `{:?}`", - function.name(), - signature, - function.signature(), - ))) - } - } - } - - if self.allow_missing_func_imports { - trace!( - target: "wasm-executor", - "Could not find function `{}`, a stub will be provided instead.", - name, - ); - let id = self.missing_functions.borrow().len() + self.host_functions.len(); - self.missing_functions.borrow_mut().push(name.to_string()); - - Ok(wasmi::FuncInstance::alloc_host(signature.into(), id)) - } else { - Err(wasmi::Error::Instantiation(format!("Export {} not found", name))) - } - } - - fn resolve_memory( - &self, - _: &str, - _: &wasmi::MemoryDescriptor, - ) -> Result { - Err(wasmi::Error::Instantiation( - "Internal error, wasmi expects that the wasm blob exports memory.".into(), - )) - } -} - -impl wasmi::Externals for FunctionExecutor { - fn invoke_index( - &mut self, - index: usize, - args: wasmi::RuntimeArgs, - ) -> Result, wasmi::Trap> { - let mut args = args.as_ref().iter().copied().map(Into::into); - - if let Some(function) = self.host_functions.clone().get(index) { - function - .execute(self, &mut args) - .map_err(|msg| Error::FunctionExecution(function.name().to_string(), msg)) - .map_err(wasmi::Trap::from) - .map(|v| v.map(Into::into)) - } else if self.allow_missing_func_imports && - index >= self.host_functions.len() && - index < self.host_functions.len() + self.missing_functions.len() - { - Err(Error::from(format!( - "Function `{}` is only a stub. Calling a stub is not allowed.", - self.missing_functions[index - self.host_functions.len()], - )) - .into()) - } else { - Err(Error::from(format!("Could not find host function with index: {}", index)).into()) - } - } -} - -fn get_mem_instance(module: &ModuleRef) -> Result { - Ok(module - .export_by_name("memory") - .ok_or(Error::InvalidMemoryReference)? - .as_memory() - .ok_or(Error::InvalidMemoryReference)? - .clone()) -} - -/// Find the global named `__heap_base` in the given wasm module instance and -/// tries to get its value. -fn get_heap_base(module: &ModuleRef) -> Result { - let heap_base_val = module - .export_by_name("__heap_base") - .ok_or(Error::HeapBaseNotFoundOrInvalid)? - .as_global() - .ok_or(Error::HeapBaseNotFoundOrInvalid)? - .get(); - - match heap_base_val { - wasmi::RuntimeValue::I32(v) => Ok(v as u32), - _ => Err(Error::HeapBaseNotFoundOrInvalid), - } -} - -/// Call a given method in the given wasm-module runtime. -fn call_in_wasm_module( - module_instance: &ModuleRef, - memory: &MemoryRef, - method: InvokeMethod, - data: &[u8], - host_functions: Arc>, - allow_missing_func_imports: bool, - missing_functions: Arc>, - allocation_stats: &mut Option, -) -> Result, Error> { - // Initialize FunctionExecutor. - let table: Option = module_instance - .export_by_name("__indirect_function_table") - .and_then(|e| e.as_table().cloned()); - let heap_base = get_heap_base(module_instance)?; - - let mut function_executor = FunctionExecutor::new( - memory.clone(), - heap_base, - host_functions, - allow_missing_func_imports, - missing_functions, - )?; - - // Write the call data - let offset = function_executor.allocate_memory(data.len() as u32)?; - function_executor.write_memory(offset, data)?; - - fn convert_trap(executor: &mut FunctionExecutor, trap: wasmi::Trap) -> Error { - if let Some(message) = executor.panic_message.take() { - Error::AbortedDueToPanic(MessageWithBacktrace { message, backtrace: None }) - } else { - Error::AbortedDueToTrap(MessageWithBacktrace { - message: trap.to_string(), - backtrace: None, - }) - } - } - - let result = match method { - InvokeMethod::Export(method) => module_instance - .invoke_export( - method, - &[I32(u32::from(offset) as i32), I32(data.len() as i32)], - &mut function_executor, - ) - .map_err(|error| { - if let wasmi::Error::Trap(trap) = error { - convert_trap(&mut function_executor, trap) - } else { - error.into() - } - }), - InvokeMethod::Table(func_ref) => { - let func = table - .ok_or(Error::NoTable)? - .get(func_ref)? - .ok_or(Error::NoTableEntryWithIndex(func_ref))?; - FuncInstance::invoke( - &func, - &[I32(u32::from(offset) as i32), I32(data.len() as i32)], - &mut function_executor, - ) - .map_err(|trap| convert_trap(&mut function_executor, trap)) - }, - InvokeMethod::TableWithWrapper { dispatcher_ref, func } => { - let dispatcher = table - .ok_or(Error::NoTable)? - .get(dispatcher_ref)? - .ok_or(Error::NoTableEntryWithIndex(dispatcher_ref))?; - - FuncInstance::invoke( - &dispatcher, - &[I32(func as _), I32(u32::from(offset) as i32), I32(data.len() as i32)], - &mut function_executor, - ) - .map_err(|trap| convert_trap(&mut function_executor, trap)) - }, - }; - - *allocation_stats = Some(function_executor.heap.borrow().stats()); - - match result { - Ok(Some(I64(r))) => { - let (ptr, length) = unpack_ptr_and_len(r as u64); - #[allow(deprecated)] - memory.get(ptr, length as usize).map_err(|_| Error::Runtime) - }, - Err(e) => { - trace!( - target: "wasm-executor", - "Failed to execute code with {} pages", - memory.current_size().0, - ); - Err(e) - }, - _ => Err(Error::InvalidReturn), - } -} - -/// Prepare module instance -fn instantiate_module( - module: &Module, - host_functions: &[&'static dyn Function], - allow_missing_func_imports: bool, -) -> Result<(ModuleRef, Vec, MemoryRef), Error> { - let resolver = Resolver::new(host_functions, allow_missing_func_imports); - // start module instantiation. Don't run 'start' function yet. - let intermediate_instance = - ModuleInstance::new(module, &ImportsBuilder::new().with_resolver("env", &resolver))?; - - // Verify that the module has the heap base global variable. - let _ = get_heap_base(intermediate_instance.not_started_instance())?; - - // The `module` should export the memory with the correct properties (min, max). - // - // This is ensured by modifying the `RuntimeBlob` before initializing the `Module`. - let memory = get_mem_instance(intermediate_instance.not_started_instance())?; - - if intermediate_instance.has_start() { - // Runtime is not allowed to have the `start` function. - Err(Error::RuntimeHasStartFn) - } else { - Ok(( - intermediate_instance.assert_no_start(), - resolver.missing_functions.into_inner(), - memory, - )) - } -} - -/// A state snapshot of an instance taken just after instantiation. -/// -/// It is used for restoring the state of the module after execution. -#[derive(Clone)] -struct GlobalValsSnapshot { - /// The list of all global mutable variables of the module in their sequential order. - global_mut_values: Vec, -} - -impl GlobalValsSnapshot { - // Returns `None` if instance is not valid. - fn take(module_instance: &ModuleRef) -> Self { - // Collect all values of mutable globals. - let global_mut_values = module_instance - .globals() - .iter() - .filter(|g| g.is_mutable()) - .map(|g| g.get()) - .collect(); - Self { global_mut_values } - } - - /// Reset the runtime instance to the initial version by restoring - /// the preserved memory and globals. - /// - /// Returns `Err` if applying the snapshot is failed. - fn apply(&self, instance: &ModuleRef) -> Result<(), WasmError> { - for (global_ref, global_val) in instance - .globals() - .iter() - .filter(|g| g.is_mutable()) - .zip(self.global_mut_values.iter()) - { - // the instance should be the same as used for preserving and - // we iterate the same way it as we do it for preserving values that means that the - // types should be the same and all the values are mutable. So no error is expected/ - global_ref.set(*global_val).map_err(|_| WasmError::ApplySnapshotFailed)?; - } - Ok(()) - } -} - -/// A runtime along with initial copy of data segments. -pub struct WasmiRuntime { - /// A wasm module. - module: Module, - /// The host functions registered for this instance. - host_functions: Arc>, - /// Enable stub generation for functions that are not available in `host_functions`. - /// These stubs will error when the wasm blob tries to call them. - allow_missing_func_imports: bool, - - global_vals_snapshot: GlobalValsSnapshot, - data_segments_snapshot: DataSegmentsSnapshot, -} - -impl WasmModule for WasmiRuntime { - fn new_instance(&self) -> Result, Error> { - // Instantiate this module. - let (instance, missing_functions, memory) = - instantiate_module(&self.module, &self.host_functions, self.allow_missing_func_imports) - .map_err(|e| WasmError::Instantiation(e.to_string()))?; - - Ok(Box::new(WasmiInstance { - instance, - memory, - global_vals_snapshot: self.global_vals_snapshot.clone(), - data_segments_snapshot: self.data_segments_snapshot.clone(), - host_functions: self.host_functions.clone(), - allow_missing_func_imports: self.allow_missing_func_imports, - missing_functions: Arc::new(missing_functions), - memory_zeroed: true, - })) - } -} - -/// Create a new `WasmiRuntime` given the code. This function loads the module and -/// stores it in the instance. -pub fn create_runtime( - mut blob: RuntimeBlob, - heap_alloc_strategy: HeapAllocStrategy, - host_functions: Vec<&'static dyn Function>, - allow_missing_func_imports: bool, -) -> Result { - let data_segments_snapshot = - DataSegmentsSnapshot::take(&blob).map_err(|e| WasmError::Other(e.to_string()))?; - - // Make sure we only have exported memory to simplify the code of the wasmi executor. - blob.convert_memory_import_into_export()?; - // Ensure that the memory uses the correct heap pages. - blob.setup_memory_according_to_heap_alloc_strategy(heap_alloc_strategy)?; - - let module = - Module::from_parity_wasm_module(blob.into_inner()).map_err(|_| WasmError::InvalidModule)?; - - let global_vals_snapshot = { - let (instance, _, _) = - instantiate_module(&module, &host_functions, allow_missing_func_imports) - .map_err(|e| WasmError::Instantiation(e.to_string()))?; - GlobalValsSnapshot::take(&instance) - }; - - Ok(WasmiRuntime { - module, - data_segments_snapshot, - global_vals_snapshot, - host_functions: Arc::new(host_functions), - allow_missing_func_imports, - }) -} - -/// Wasmi instance wrapper along with the state snapshot. -pub struct WasmiInstance { - /// A wasm module instance. - instance: ModuleRef, - /// The memory instance of used by the wasm module. - memory: MemoryRef, - /// Is the memory zeroed? - memory_zeroed: bool, - /// The snapshot of global variable values just after instantiation. - global_vals_snapshot: GlobalValsSnapshot, - /// The snapshot of data segments. - data_segments_snapshot: DataSegmentsSnapshot, - /// The host functions registered for this instance. - host_functions: Arc>, - /// Enable stub generation for functions that are not available in `host_functions`. - /// These stubs will error when the wasm blob trie to call them. - allow_missing_func_imports: bool, - /// List of missing functions detected during function resolution - missing_functions: Arc>, -} - -// This is safe because `WasmiInstance` does not leak any references to `self.memory` and -// `self.instance` -unsafe impl Send for WasmiInstance {} - -impl WasmiInstance { - fn call_impl( - &mut self, - method: InvokeMethod, - data: &[u8], - allocation_stats: &mut Option, - ) -> Result, Error> { - // We reuse a single wasm instance for multiple calls and a previous call (if any) - // altered the state. Therefore, we need to restore the instance to original state. - - if !self.memory_zeroed { - // First, zero initialize the linear memory. - self.memory.erase().map_err(|e| { - // Snapshot restoration failed. This is pretty unexpected since this can happen - // if some invariant is broken or if the system is under extreme memory pressure - // (so erasing fails). - error!(target: "wasm-executor", "snapshot restoration failed: {}", e); - WasmError::ErasingFailed(e.to_string()) - })?; - } - - // Second, reapply data segments into the linear memory. - self.data_segments_snapshot - .apply(|offset, contents| self.memory.set(offset, contents))?; - - // Third, restore the global variables to their initial values. - self.global_vals_snapshot.apply(&self.instance)?; - - let res = call_in_wasm_module( - &self.instance, - &self.memory, - method, - data, - self.host_functions.clone(), - self.allow_missing_func_imports, - self.missing_functions.clone(), - allocation_stats, - ); - - // If we couldn't unmap it, erase the memory. - self.memory_zeroed = self.memory.erase().is_ok(); - - res - } -} - -impl WasmInstance for WasmiInstance { - fn call_with_allocation_stats( - &mut self, - method: InvokeMethod, - data: &[u8], - ) -> (Result, Error>, Option) { - let mut allocation_stats = None; - let result = self.call_impl(method, data, &mut allocation_stats); - (result, allocation_stats) - } - - fn get_global_const(&mut self, name: &str) -> Result, Error> { - match self.instance.export_by_name(name) { - Some(global) => Ok(Some( - global - .as_global() - .ok_or_else(|| format!("`{}` is not a global", name))? - .get() - .into(), - )), - None => Ok(None), - } - } - - fn linear_memory_base_ptr(&self) -> Option<*const u8> { - Some(self.memory.direct_access().as_ref().as_ptr()) - } -} From 18bbf9613c76470dab12bb091659ce6b89f3d1e1 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Thu, 30 Mar 2023 20:31:40 +0800 Subject: [PATCH 20/32] cleanup --- Cargo.lock | 25 ---------------------- client/service/src/client/call_executor.rs | 2 +- client/service/src/client/wasm_override.rs | 2 +- 3 files changed, 2 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8941ba6703c06..cce2d267d3916 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7913,18 +7913,6 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" -[[package]] -name = "region" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76e189c2369884dce920945e2ddf79b3dff49e071a167dd1817fa9c4c00d512e" -dependencies = [ - "bitflags", - "libc", - "mach", - "winapi", -] - [[package]] name = "resolv-conf" version = "0.7.0" @@ -8852,18 +8840,6 @@ dependencies = [ "wasmi 0.13.2", ] -[[package]] -name = "sc-executor-wasmi" -version = "0.10.0-dev" -dependencies = [ - "log", - "sc-allocator", - "sc-executor-common", - "sp-runtime-interface", - "sp-wasm-interface", - "wasmi 0.13.2", -] - [[package]] name = "sc-executor-wasmtime" version = "0.10.0-dev" @@ -12391,7 +12367,6 @@ dependencies = [ "memory_units", "num-rational", "num-traits", - "region", ] [[package]] diff --git a/client/service/src/client/call_executor.rs b/client/service/src/client/call_executor.rs index 06d0eb093dc2e..a8ab98618506b 100644 --- a/client/service/src/client/call_executor.rs +++ b/client/service/src/client/call_executor.rs @@ -368,7 +368,7 @@ mod tests { use super::*; use backend::Backend; use sc_client_api::in_mem; - use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor}; + use sc_executor::{NativeElseWasmExecutor, WasmExecutor}; use sp_core::{ testing::TaskExecutor, traits::{FetchRuntimeCode, WrappedRuntimeCode}, diff --git a/client/service/src/client/wasm_override.rs b/client/service/src/client/wasm_override.rs index 81bbbaa055799..234ed0ae2763e 100644 --- a/client/service/src/client/wasm_override.rs +++ b/client/service/src/client/wasm_override.rs @@ -265,7 +265,7 @@ pub fn dummy_overrides() -> WasmOverride { mod tests { use super::*; use sc_executor::{ - HeapAllocStrategy, NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor, + HeapAllocStrategy, NativeElseWasmExecutor, WasmExecutor, }; use std::fs::{self, File}; use substrate_test_runtime_client::LocalExecutorDispatch; From 31ac1812d337ee36552340f0c9c930947d0f3fe4 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Thu, 30 Mar 2023 21:56:47 +0800 Subject: [PATCH 21/32] refactor builder --- bin/node/executor/benches/bench.rs | 7 ++-- bin/node/executor/tests/common.rs | 4 +-- bin/node/testing/src/bench.rs | 9 ++--- client/executor/src/executor.rs | 33 ++++++++++++------- client/executor/src/integration_tests/mod.rs | 13 ++++++-- client/executor/src/lib.rs | 5 +-- client/executor/wasmtime/src/tests.rs | 4 +-- client/service/src/builder.rs | 11 ++++--- client/service/src/client/call_executor.rs | 4 +-- client/service/src/client/wasm_override.rs | 6 ++-- primitives/api/test/tests/runtime_calls.rs | 2 +- test-utils/client/src/lib.rs | 4 +-- test-utils/runtime/client/src/lib.rs | 4 +-- test-utils/runtime/src/system.rs | 6 ++-- .../benchmarking-cli/src/pallet/command.rs | 3 +- utils/frame/try-runtime/cli/src/lib.rs | 28 ++++++++-------- 16 files changed, 73 insertions(+), 70 deletions(-) diff --git a/bin/node/executor/benches/bench.rs b/bin/node/executor/benches/bench.rs index 05c406bb5274f..7f7992e38177e 100644 --- a/bin/node/executor/benches/bench.rs +++ b/bin/node/executor/benches/bench.rs @@ -192,13 +192,12 @@ fn bench_execute_block(c: &mut Criterion) { group.bench_function(format!("{:?}", strategy), |b| { let genesis_config = node_testing::genesis::config(Some(compact_code_unwrap())); let (use_native, wasm_method) = match strategy { - ExecutionMethod::Native => (true, WasmExecutionMethod::Interpreted), + ExecutionMethod::Native => (true), ExecutionMethod::Wasm(wasm_method) => (false, wasm_method), }; - let executor = NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), - ); + let executor = + NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build()); let runtime_code = RuntimeCode { code_fetcher: &sp_core::traits::WrappedRuntimeCode(compact_code_unwrap().into()), hash: vec![1, 2, 3], diff --git a/bin/node/executor/tests/common.rs b/bin/node/executor/tests/common.rs index d8699b9555d42..0d2339cd1645a 100644 --- a/bin/node/executor/tests/common.rs +++ b/bin/node/executor/tests/common.rs @@ -98,9 +98,7 @@ pub fn from_block_number(n: u32) -> Header { } pub fn executor() -> NativeElseWasmExecutor { - NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), - ) + NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build()) } pub fn executor_call( diff --git a/bin/node/testing/src/bench.rs b/bin/node/testing/src/bench.rs index af95a4d4d5f8d..b3fcc063cff1e 100644 --- a/bin/node/testing/src/bench.rs +++ b/bin/node/testing/src/bench.rs @@ -393,10 +393,11 @@ impl BenchDb { let backend = sc_service::new_db_backend(db_config).expect("Should not fail"); let executor = NativeElseWasmExecutor::new_with_wasm_executor( - sc_executor::WasmExecutor::builder(WasmExecutionMethod::Compiled { - instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite, - }) - .build(), + sc_executor::WasmExecutor::builder() + .with_execution_method(WasmExecutionMethod::Compiled { + instantiation_strategy: WasmtimeInstantiationStrategy::PoolingCopyOnWrite, + }) + .build(), ); let client_config = sc_service::ClientConfig::default(); diff --git a/client/executor/src/executor.rs b/client/executor/src/executor.rs index e75ceffded2a7..79250ee0d621c 100644 --- a/client/executor/src/executor.rs +++ b/client/executor/src/executor.rs @@ -98,10 +98,10 @@ impl WasmExecutorBuilder { /// Create a new instance of `Self` /// /// - `method`: The wasm execution method that should be used by the executor. - pub fn new(method: WasmExecutionMethod) -> Self { + pub fn new() -> Self { Self { _phantom: PhantomData, - method, + method: WasmExecutionMethod::default(), onchain_heap_alloc_strategy: None, offchain_heap_alloc_strategy: None, max_runtime_instances: 2, @@ -111,6 +111,12 @@ impl WasmExecutorBuilder { } } + /// Create the wasm executor with execution method that should be used by the executor. + pub fn with_execution_method(mut self, method: WasmExecutionMethod) -> Self { + self.method = method; + self + } + /// Create the wasm executor with the given number of `heap_alloc_strategy` for onchain runtime /// calls. pub fn with_onchain_heap_alloc_strategy( @@ -282,8 +288,8 @@ where } /// Instantiate a builder for creating an instance of `Self`. - pub fn builder(method: WasmExecutionMethod) -> WasmExecutorBuilder { - WasmExecutorBuilder::new(method) + pub fn builder() -> WasmExecutorBuilder { + WasmExecutorBuilder::new() } /// Ignore missing function imports if set true. @@ -561,13 +567,16 @@ impl NativeElseWasmExecutor { max_runtime_instances: usize, runtime_cache_size: u8, ) -> Self { - let wasm = WasmExecutor::new( - fallback_method, - default_heap_pages, - max_runtime_instances, - None, - runtime_cache_size, - ); + let heap_pages = default_heap_pages.map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |h| { + HeapAllocStrategy::Static { extra_pages: h as _ } + }); + let wasm = WasmExecutor::builder() + .with_execution_method(fallback_method) + .with_onchain_heap_alloc_strategy(heap_pages) + .with_offchain_heap_alloc_strategy(heap_pages) + .with_max_runtime_instances(max_runtime_instances) + .with_runtime_cache_size(runtime_cache_size) + .build(); NativeElseWasmExecutor { native_version: D::native_version(), wasm } } @@ -718,7 +727,7 @@ mod tests { #[test] fn native_executor_registers_custom_interface() { let executor = NativeElseWasmExecutor::::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), + WasmExecutor::builder().build(), ); fn extract_host_functions( diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index 902c1ddc923eb..e3fd253905b1e 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -114,7 +114,9 @@ fn call_in_wasm( execution_method: WasmExecutionMethod, ext: &mut E, ) -> Result, Error> { - let executor = crate::WasmExecutor::::builder(execution_method).build(); + let executor = crate::WasmExecutor::::builder() + .with_execution_method(execution_method) + .build(); executor.uncached_call( RuntimeBlob::uncompress_if_needed(wasm_binary_unwrap()).unwrap(), @@ -446,7 +448,8 @@ test_wasm_execution!(should_trap_when_heap_exhausted); fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) { let mut ext = TestExternalities::default(); - let executor = crate::WasmExecutor::::builder(wasm_method) + let executor = crate::WasmExecutor::::builder() + .with_execution_method(wasm_method) // `17` is the initial number of pages compiled into the binary. .with_onchain_heap_alloc_strategy(HeapAllocStrategy::Static { extra_pages: 17 }) .build(); @@ -576,7 +579,11 @@ fn heap_is_reset_between_calls(wasm_method: WasmExecutionMethod) { test_wasm_execution!(parallel_execution); fn parallel_execution(wasm_method: WasmExecutionMethod) { - let executor = Arc::new(crate::WasmExecutor::::builder(wasm_method).build()); + let executor = Arc::new( + crate::WasmExecutor::::builder() + .with_execution_method(wasm_method) + .build(), + ); let threads: Vec<_> = (0..8) .map(|_| { let executor = executor.clone(); diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index 16ad0c6616f21..42e7dc7d16bd8 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -79,10 +79,7 @@ mod tests { let mut ext = TestExternalities::default(); let mut ext = ext.ext(); - let executor = WasmExecutor::::builder( - WasmExecutionMethod::Interpreted, - ) - .build(); + let executor = WasmExecutor::::builder().build(); let res = executor .uncached_call( RuntimeBlob::uncompress_if_needed(wasm_binary_unwrap()).unwrap(), diff --git a/client/executor/wasmtime/src/tests.rs b/client/executor/wasmtime/src/tests.rs index 53b1eeb922071..7384514b6bb04 100644 --- a/client/executor/wasmtime/src/tests.rs +++ b/client/executor/wasmtime/src/tests.rs @@ -20,9 +20,7 @@ use codec::{Decode as _, Encode as _}; use sc_executor_common::{ error::Error, runtime_blob::RuntimeBlob, - wasm_runtime::{ - HeapAllocStrategy, WasmModule, DEFAULT_HEAP_ALLOC_PAGES, DEFAULT_HEAP_ALLOC_STRATEGY, - }, + wasm_runtime::{HeapAllocStrategy, WasmModule, DEFAULT_HEAP_ALLOC_STRATEGY}, }; use sc_runtime_test::wasm_binary_unwrap; diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index 18b1e58f1b5b2..b79253bb754ca 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -38,7 +38,7 @@ use sc_client_db::{Backend, DatabaseSettings}; use sc_consensus::import_queue::ImportQueue; use sc_executor::{ sp_wasm_interface::HostFunctions, HeapAllocStrategy, NativeElseWasmExecutor, - NativeExecutionDispatch, RuntimeVersionOf, WasmExecutor, DEFAULT_HEAP_ALLOC_PAGES, + NativeExecutionDispatch, RuntimeVersionOf, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY, }; use sc_keystore::LocalKeystore; use sc_network::{ @@ -241,10 +241,11 @@ pub fn new_native_executor( /// Creates a [`WasmExecutor`] according to [`Configuration`]. pub fn new_wasm_executor(config: &Configuration) -> WasmExecutor { - let extra_pages = - config.default_heap_pages.map(|p| p as u32).unwrap_or(DEFAULT_HEAP_ALLOC_PAGES); - let strategy = HeapAllocStrategy::Static { extra_pages }; - WasmExecutor::::builder(config.wasm_method) + let strategy = config + .default_heap_pages + .map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |p| HeapAllocStrategy::Static { extra_pages: p as _ }); + WasmExecutor::::builder() + .with_execution_method(config.wasm_method) .with_onchain_heap_alloc_strategy(strategy) .with_onchain_heap_alloc_strategy(strategy) .with_max_runtime_instances(config.max_runtime_instances) diff --git a/client/service/src/client/call_executor.rs b/client/service/src/client/call_executor.rs index 9134f9fb2f286..a8ab98618506b 100644 --- a/client/service/src/client/call_executor.rs +++ b/client/service/src/client/call_executor.rs @@ -368,7 +368,7 @@ mod tests { use super::*; use backend::Backend; use sc_client_api::in_mem; - use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor}; + use sc_executor::{NativeElseWasmExecutor, WasmExecutor}; use sp_core::{ testing::TaskExecutor, traits::{FetchRuntimeCode, WrappedRuntimeCode}, @@ -378,7 +378,7 @@ mod tests { fn executor() -> NativeElseWasmExecutor { NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted) + WasmExecutor::builder() .with_max_runtime_instances(1) .with_runtime_cache_size(2) .build(), diff --git a/client/service/src/client/wasm_override.rs b/client/service/src/client/wasm_override.rs index 868c719ab962a..725c8ab9429ac 100644 --- a/client/service/src/client/wasm_override.rs +++ b/client/service/src/client/wasm_override.rs @@ -264,15 +264,13 @@ pub fn dummy_overrides() -> WasmOverride { #[cfg(test)] mod tests { use super::*; - use sc_executor::{ - HeapAllocStrategy, NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor, - }; + use sc_executor::{HeapAllocStrategy, NativeElseWasmExecutor, WasmExecutor}; use std::fs::{self, File}; use substrate_test_runtime_client::LocalExecutorDispatch; fn executor() -> NativeElseWasmExecutor { NativeElseWasmExecutor::::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted) + WasmExecutor::builder() .with_onchain_heap_alloc_strategy(HeapAllocStrategy::Static {extra_pages: 128}) .with_offchain_heap_alloc_strategy(HeapAllocStrategy::Static {extra_pages: 128}) .with_max_runtime_instances(1) diff --git a/primitives/api/test/tests/runtime_calls.rs b/primitives/api/test/tests/runtime_calls.rs index 5c3310dce7298..fe8c31ace8685 100644 --- a/primitives/api/test/tests/runtime_calls.rs +++ b/primitives/api/test/tests/runtime_calls.rs @@ -180,7 +180,7 @@ fn record_proof_works() { // Use the proof backend to execute `execute_block`. let mut overlay = Default::default(); let executor = NativeElseWasmExecutor::::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), + WasmExecutor::builder().build(), ); execution_proof_check_on_trie_backend( &backend, diff --git a/test-utils/client/src/lib.rs b/test-utils/client/src/lib.rs index fc44168ab3175..bfb0c79b628e6 100644 --- a/test-utils/client/src/lib.rs +++ b/test-utils/client/src/lib.rs @@ -286,9 +286,7 @@ impl Backend: sc_client_api::backend::Backend + 'static, { let executor = executor.into().unwrap_or_else(|| { - NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), - ) + NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build()) }); let executor = LocalCallExecutor::new( self.backend.clone(), diff --git a/test-utils/runtime/client/src/lib.rs b/test-utils/runtime/client/src/lib.rs index 20c76bd994978..627ca99bb5749 100644 --- a/test-utils/runtime/client/src/lib.rs +++ b/test-utils/runtime/client/src/lib.rs @@ -292,7 +292,5 @@ pub fn new() -> Client { /// Create a new native executor. pub fn new_native_executor() -> NativeElseWasmExecutor { - NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), - ) + NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build()) } diff --git a/test-utils/runtime/src/system.rs b/test-utils/runtime/src/system.rs index 0265b0a03295c..86b2b67c7d4e0 100644 --- a/test-utils/runtime/src/system.rs +++ b/test-utils/runtime/src/system.rs @@ -350,7 +350,7 @@ mod tests { use super::*; use crate::{wasm_binary_unwrap, Header, Transfer}; - use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor}; + use sc_executor::{NativeElseWasmExecutor, WasmExecutor}; use sp_core::{ map, traits::{CallContext, CodeExecutor, RuntimeCode}, @@ -374,9 +374,7 @@ mod tests { } fn executor() -> NativeElseWasmExecutor { - NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder(WasmExecutionMethod::Interpreted).build(), - ) + NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build()) } fn new_test_ext() -> TestExternalities { diff --git a/utils/frame/benchmarking-cli/src/pallet/command.rs b/utils/frame/benchmarking-cli/src/pallet/command.rs index 45e31575510ca..e7b98ccdace14 100644 --- a/utils/frame/benchmarking-cli/src/pallet/command.rs +++ b/utils/frame/benchmarking-cli/src/pallet/command.rs @@ -214,7 +214,8 @@ impl PalletCmd { execution_method_from_cli(self.wasm_method, self.wasmtime_instantiation_strategy); let executor = NativeElseWasmExecutor::::new_with_wasm_executor( - WasmExecutor::builder(method) + WasmExecutor::builder() + .with_execution_method(method) .with_max_runtime_instances(2) .with_runtime_cache_size(2) .build(), diff --git a/utils/frame/try-runtime/cli/src/lib.rs b/utils/frame/try-runtime/cli/src/lib.rs index a9a92826f4314..5ddfb3e7ea1e7 100644 --- a/utils/frame/try-runtime/cli/src/lib.rs +++ b/utils/frame/try-runtime/cli/src/lib.rs @@ -368,9 +368,8 @@ use sc_cli::{ WasmtimeInstantiationStrategy, DEFAULT_WASMTIME_INSTANTIATION_STRATEGY, DEFAULT_WASM_EXECUTION_METHOD, }; -use sc_executor::{ - sp_wasm_interface::HostFunctions, HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_PAGES, -}; +use sc_executor::{sp_wasm_interface::HostFunctions, HeapAllocStrategy, WasmExecutor}; +use sc_executor_common::wasm_runtime::DEFAULT_HEAP_ALLOC_STRATEGY; use sp_api::HashT; use sp_core::{ hexdisplay::HexDisplay, @@ -829,17 +828,18 @@ pub(crate) fn full_extensions() -> Extensions { /// Build wasm executor by default config. pub(crate) fn build_executor(shared: &SharedParams) -> WasmExecutor { - let heap_pages = HeapAllocStrategy::Static { - extra_pages: shared.heap_pages.map(|p| p as u32).unwrap_or(DEFAULT_HEAP_ALLOC_PAGES), - }; - - WasmExecutor::builder(execution_method_from_cli( - shared.wasm_method, - shared.wasmtime_instantiation_strategy, - )) - .with_onchain_heap_alloc_strategy(heap_pages) - .with_offchain_heap_alloc_strategy(heap_pages) - .build() + let heap_pages = shared + .heap_pages + .map_or(DEFAULT_HEAP_ALLOC_STRATEGY, |p| HeapAllocStrategy::Static { extra_pages: p as _ }); + + WasmExecutor::builder() + .with_execution_method(execution_method_from_cli( + shared.wasm_method, + shared.wasmtime_instantiation_strategy, + )) + .with_onchain_heap_alloc_strategy(heap_pages) + .with_offchain_heap_alloc_strategy(heap_pages) + .build() } /// Ensure that the given `ext` is compiled with `try-runtime` From d4cacc01ba74128cd46075fed60f3f229cbda4bc Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Thu, 30 Mar 2023 22:00:50 +0800 Subject: [PATCH 22/32] fix --- bin/node/executor/benches/bench.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/executor/benches/bench.rs b/bin/node/executor/benches/bench.rs index 7f7992e38177e..13231eb06efe1 100644 --- a/bin/node/executor/benches/bench.rs +++ b/bin/node/executor/benches/bench.rs @@ -192,7 +192,7 @@ fn bench_execute_block(c: &mut Criterion) { group.bench_function(format!("{:?}", strategy), |b| { let genesis_config = node_testing::genesis::config(Some(compact_code_unwrap())); let (use_native, wasm_method) = match strategy { - ExecutionMethod::Native => (true), + ExecutionMethod::Native => (true, WasmExecutionMethod::default()), ExecutionMethod::Wasm(wasm_method) => (false, wasm_method), }; From 7054f42abf5562b20fead6c26d3d1769c8558440 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Thu, 30 Mar 2023 22:01:36 +0800 Subject: [PATCH 23/32] fix bench --- bin/node/executor/benches/bench.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/node/executor/benches/bench.rs b/bin/node/executor/benches/bench.rs index 13231eb06efe1..aa7d9eb0f31ff 100644 --- a/bin/node/executor/benches/bench.rs +++ b/bin/node/executor/benches/bench.rs @@ -191,9 +191,9 @@ fn bench_execute_block(c: &mut Criterion) { for strategy in execution_methods { group.bench_function(format!("{:?}", strategy), |b| { let genesis_config = node_testing::genesis::config(Some(compact_code_unwrap())); - let (use_native, wasm_method) = match strategy { - ExecutionMethod::Native => (true, WasmExecutionMethod::default()), - ExecutionMethod::Wasm(wasm_method) => (false, wasm_method), + let use_native = match strategy { + ExecutionMethod::Native => true, + ExecutionMethod::Wasm(..) => false, }; let executor = From fd173f6cd52d319a62407af6620eb21af342e807 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Thu, 30 Mar 2023 22:03:50 +0800 Subject: [PATCH 24/32] fix tests --- primitives/runtime-interface/test/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/runtime-interface/test/src/lib.rs b/primitives/runtime-interface/test/src/lib.rs index 032224e97eeaf..039902c56227b 100644 --- a/primitives/runtime-interface/test/src/lib.rs +++ b/primitives/runtime-interface/test/src/lib.rs @@ -42,7 +42,7 @@ fn call_wasm_method_with_result( let executor = sc_executor::WasmExecutor::< ExtendedHostFunctions, - >::builder(sc_executor::WasmExecutionMethod::Interpreted) + >::builder() .build(); let (result, allocation_stats) = executor.uncached_call_with_allocation_stats( From c523c6eb28ea8bd2f0bfd8dbbaf827235d41c74d Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Thu, 30 Mar 2023 22:57:40 +0800 Subject: [PATCH 25/32] fix warnings --- client/executor/src/integration_tests/linux.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/executor/src/integration_tests/linux.rs b/client/executor/src/integration_tests/linux.rs index 7decbf31695fe..434cb69bfdd32 100644 --- a/client/executor/src/integration_tests/linux.rs +++ b/client/executor/src/integration_tests/linux.rs @@ -21,7 +21,7 @@ use super::mk_test_runtime; use crate::WasmExecutionMethod; use codec::Encode as _; -use sc_executor_common::wasm_runtime::{HeapAllocStrategy, DEFAULT_HEAP_ALLOC_STRATEGY}; +use sc_executor_common::wasm_runtime::DEFAULT_HEAP_ALLOC_STRATEGY; mod smaps; From 68661c0e7de2200451df0c29c16a93578e77c3d4 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Thu, 30 Mar 2023 23:33:51 +0800 Subject: [PATCH 26/32] fix warnings --- bin/node/cli/benches/transaction_pool.rs | 4 ++-- bin/node/executor/tests/common.rs | 2 +- client/executor/src/lib.rs | 2 +- client/service/test/src/lib.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/node/cli/benches/transaction_pool.rs b/bin/node/cli/benches/transaction_pool.rs index 7488ec03363e7..abee9c846245f 100644 --- a/bin/node/cli/benches/transaction_pool.rs +++ b/bin/node/cli/benches/transaction_pool.rs @@ -27,7 +27,7 @@ use sc_client_api::execution_extensions::ExecutionStrategies; use sc_service::{ config::{ BlocksPruning, DatabaseSource, KeystoreConfig, NetworkConfiguration, OffchainWorkerConfig, - PruningMode, TransactionPoolOptions, WasmExecutionMethod, + PruningMode, TransactionPoolOptions, }, BasePath, Configuration, Role, }; @@ -69,7 +69,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase { state_pruning: Some(PruningMode::ArchiveAll), blocks_pruning: BlocksPruning::KeepAll, chain_spec: spec, - wasm_method: WasmExecutionMethod::Interpreted, + wasm_method: Default::default(), // NOTE: we enforce the use of the native runtime to make the errors more debuggable execution_strategies: ExecutionStrategies { syncing: sc_client_api::ExecutionStrategy::NativeWhenPossible, diff --git a/bin/node/executor/tests/common.rs b/bin/node/executor/tests/common.rs index 0d2339cd1645a..6ce9ea3a01090 100644 --- a/bin/node/executor/tests/common.rs +++ b/bin/node/executor/tests/common.rs @@ -18,7 +18,7 @@ use codec::{Decode, Encode}; use frame_support::Hashable; use frame_system::offchain::AppCrypto; -use sc_executor::{error::Result, NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor}; +use sc_executor::{error::Result, NativeElseWasmExecutor, WasmExecutor}; use sp_consensus_babe::{ digests::{PreDigest, SecondaryPlainPreDigest}, Slot, BABE_ENGINE_ID, diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index 42e7dc7d16bd8..aa39df6c3d3e6 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -41,7 +41,7 @@ pub use self::{ executor::{ with_externalities_safe, NativeElseWasmExecutor, NativeExecutionDispatch, WasmExecutor, }, - wasm_runtime::{read_embedded_version, WasmExecutionMethod}, + wasm_runtime::read_embedded_version, }; pub use codec::Codec; #[doc(hidden)] diff --git a/client/service/test/src/lib.rs b/client/service/test/src/lib.rs index 966ea238ef233..0f20376fe809e 100644 --- a/client/service/test/src/lib.rs +++ b/client/service/test/src/lib.rs @@ -246,7 +246,7 @@ fn node_config< state_pruning: Default::default(), blocks_pruning: BlocksPruning::KeepFinalized, chain_spec: Box::new((*spec).clone()), - wasm_method: sc_service::config::WasmExecutionMethod::Interpreted, + wasm_method: Default::default(), wasm_runtime_overrides: Default::default(), execution_strategies: Default::default(), rpc_http: None, From 00bc0471b503ebb3e2948b48cf567516d0a6ec09 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Thu, 30 Mar 2023 23:43:09 +0800 Subject: [PATCH 27/32] fix --- client/executor/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index aa39df6c3d3e6..42e7dc7d16bd8 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -41,7 +41,7 @@ pub use self::{ executor::{ with_externalities_safe, NativeElseWasmExecutor, NativeExecutionDispatch, WasmExecutor, }, - wasm_runtime::read_embedded_version, + wasm_runtime::{read_embedded_version, WasmExecutionMethod}, }; pub use codec::Codec; #[doc(hidden)] From 35701ebbbc3f7b56b2cee37f1a10b14f50648c7c Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Fri, 31 Mar 2023 00:00:04 +0800 Subject: [PATCH 28/32] fix --- utils/frame/try-runtime/cli/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/frame/try-runtime/cli/src/lib.rs b/utils/frame/try-runtime/cli/src/lib.rs index 5ddfb3e7ea1e7..c91849c91639d 100644 --- a/utils/frame/try-runtime/cli/src/lib.rs +++ b/utils/frame/try-runtime/cli/src/lib.rs @@ -368,8 +368,9 @@ use sc_cli::{ WasmtimeInstantiationStrategy, DEFAULT_WASMTIME_INSTANTIATION_STRATEGY, DEFAULT_WASM_EXECUTION_METHOD, }; -use sc_executor::{sp_wasm_interface::HostFunctions, HeapAllocStrategy, WasmExecutor}; -use sc_executor_common::wasm_runtime::DEFAULT_HEAP_ALLOC_STRATEGY; +use sc_executor::{ + sp_wasm_interface::HostFunctions, HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY, +}; use sp_api::HashT; use sp_core::{ hexdisplay::HexDisplay, From 3571d48750c71362c0d228c71f7fba2a66cb6f26 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Sun, 2 Apr 2023 12:36:08 +0800 Subject: [PATCH 29/32] remove wasmi and fix tests --- Cargo.lock | 2 -- client/executor/Cargo.toml | 2 -- client/executor/common/Cargo.toml | 1 - client/executor/common/src/error.rs | 7 ------- client/executor/common/src/runtime_blob/mod.rs | 3 --- client/executor/src/lib.rs | 1 - primitives/runtime-interface/test/src/lib.rs | 4 ++-- 7 files changed, 2 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aeac0e04bb8c9..4841ea6264dab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8824,7 +8824,6 @@ dependencies = [ "tempfile", "tracing", "tracing-subscriber 0.2.25", - "wasmi 0.13.2", "wat", ] @@ -8837,7 +8836,6 @@ dependencies = [ "sp-wasm-interface", "thiserror", "wasm-instrument 0.3.0", - "wasmi 0.13.2", ] [[package]] diff --git a/client/executor/Cargo.toml b/client/executor/Cargo.toml index ce8b7270157fb..31ed3bfed196d 100644 --- a/client/executor/Cargo.toml +++ b/client/executor/Cargo.toml @@ -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" } diff --git a/client/executor/common/Cargo.toml b/client/executor/common/Cargo.toml index dd74ea2cfd209..19aebc70f0c0e 100644 --- a/client/executor/common/Cargo.toml +++ b/client/executor/common/Cargo.toml @@ -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" } diff --git a/client/executor/common/src/error.rs b/client/executor/common/src/error.rs index e6f5086157a70..c1937f643b9e9 100644 --- a/client/executor/common/src/error.rs +++ b/client/executor/common/src/error.rs @@ -18,8 +18,6 @@ //! Rust executor possible errors. -use wasmi; - /// Result type alias. pub type Result = std::result::Result; @@ -27,9 +25,6 @@ pub type Result = std::result::Result; #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] pub enum Error { - #[error(transparent)] - Wasmi(#[from] wasmi::Error), - #[error("Error calling api function: {0}")] ApiError(Box), @@ -103,8 +98,6 @@ pub enum Error { AbortedDueToTrap(MessageWithBacktrace), } -impl wasmi::HostError for Error {} - impl From<&'static str> for Error { fn from(err: &'static str) -> Error { Error::Other(err.into()) diff --git a/client/executor/common/src/runtime_blob/mod.rs b/client/executor/common/src/runtime_blob/mod.rs index 58278493af51b..07a0945cc2b66 100644 --- a/client/executor/common/src/runtime_blob/mod.rs +++ b/client/executor/common/src/runtime_blob/mod.rs @@ -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. diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index 42e7dc7d16bd8..6ee0ab3512ac0 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -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, diff --git a/primitives/runtime-interface/test/src/lib.rs b/primitives/runtime-interface/test/src/lib.rs index e1be3b5d99d9b..215704a112154 100644 --- a/primitives/runtime-interface/test/src/lib.rs +++ b/primitives/runtime-interface/test/src/lib.rs @@ -109,8 +109,8 @@ fn host_function_not_found() { .0 .unwrap_err(); - assert!(err.contains("Instantiation: Export ")); - assert!(err.contains(" not found")); + assert!(err.contains("test_return_data")); + assert!(err.contains(" Failed to create module")); } #[test] From 51b6bc347c9b1ccc18a7cbafa8493f5f8a7649d1 Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Tue, 11 Apr 2023 10:57:46 +0800 Subject: [PATCH 30/32] unused imports --- client/executor/src/integration_tests/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/executor/src/integration_tests/mod.rs b/client/executor/src/integration_tests/mod.rs index 533783c427580..c9b18d87d67aa 100644 --- a/client/executor/src/integration_tests/mod.rs +++ b/client/executor/src/integration_tests/mod.rs @@ -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::{ From dfe0e80024e7fb274d320f7c814f3d05e3c2b2ae Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Sat, 13 May 2023 12:07:34 +0800 Subject: [PATCH 31/32] improve by suggestions --- bin/node/cli/benches/transaction_pool.rs | 1 - client/cli/src/arg_enums.rs | 36 +++++++++++++++--------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/bin/node/cli/benches/transaction_pool.rs b/bin/node/cli/benches/transaction_pool.rs index 767dcecd95379..abee9c846245f 100644 --- a/bin/node/cli/benches/transaction_pool.rs +++ b/bin/node/cli/benches/transaction_pool.rs @@ -24,7 +24,6 @@ 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; use sc_service::{ config::{ BlocksPruning, DatabaseSource, KeystoreConfig, NetworkConfiguration, OffchainWorkerConfig, diff --git a/client/cli/src/arg_enums.rs b/client/cli/src/arg_enums.rs index d169168b8cce2..b5952f60677af 100644 --- a/client/cli/src/arg_enums.rs +++ b/client/cli/src/arg_enums.rs @@ -54,6 +54,9 @@ pub const DEFAULT_WASMTIME_INSTANTIATION_STRATEGY: WasmtimeInstantiationStrategy #[derive(Debug, Clone, Copy, ValueEnum)] #[value(rename_all = "kebab-case")] pub enum WasmExecutionMethod { + /// Uses an interpreter which now is deprecated. + #[clap(name = "interpreted-i-know-what-i-do")] + Interpreted, /// Uses a compiled runtime. Compiled, } @@ -61,6 +64,7 @@ pub enum WasmExecutionMethod { 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"), } } @@ -72,20 +76,24 @@ pub fn execution_method_from_cli( execution_method: WasmExecutionMethod, instantiation_strategy: WasmtimeInstantiationStrategy, ) -> sc_service::config::WasmExecutionMethod { - match execution_method { - 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 execution for wasm is deprecated. Compiled execution is used by default" + ); + } + + 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, }, } } From 1b7375af6e7ddf74b15fdb749df45732c6b19394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 15 May 2023 18:27:50 +0200 Subject: [PATCH 32/32] Update client/cli/src/arg_enums.rs --- client/cli/src/arg_enums.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/cli/src/arg_enums.rs b/client/cli/src/arg_enums.rs index b5952f60677af..89cb4500803b9 100644 --- a/client/cli/src/arg_enums.rs +++ b/client/cli/src/arg_enums.rs @@ -78,7 +78,7 @@ pub fn execution_method_from_cli( ) -> sc_service::config::WasmExecutionMethod { if let WasmExecutionMethod::Interpreted = execution_method { log::warn!( - "Interpreted execution for wasm is deprecated. Compiled execution is used by default" + "`interpreted-i-know-what-i-do` is deprecated and will be removed in the future. Defaults to `compiled` execution mode." ); }