From 64bb020cb92e18e8928dc2b770c0e11d9ea5ae95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 29 Apr 2024 23:40:53 +0200 Subject: [PATCH 1/6] Deprecate `NativeElseWasmExecutor` The native executor is deprecated and downstream users should stop using it. --- cumulus/test/client/src/lib.rs | 26 ++------------- substrate/client/executor/src/executor.rs | 28 ++++++++++++---- substrate/client/executor/src/lib.rs | 10 +++--- .../src/chain_head/subscription/inner.rs | 2 +- .../rpc-spec-v2/src/chain_head/tests.rs | 6 ++-- substrate/client/service/src/builder.rs | 11 ++++--- .../service/src/client/call_executor.rs | 17 +++------- .../service/src/client/wasm_override.rs | 23 ++++++------- substrate/client/service/src/lib.rs | 9 +++--- .../client/service/test/src/client/mod.rs | 21 +++++------- substrate/frame/system/src/tests.rs | 12 +++---- .../api/test/tests/runtime_calls.rs | 4 +-- substrate/test-utils/client/src/lib.rs | 22 ++++--------- .../test-utils/runtime/client/src/lib.rs | 32 ++++++------------- 14 files changed, 88 insertions(+), 135 deletions(-) diff --git a/cumulus/test/client/src/lib.rs b/cumulus/test/client/src/lib.rs index a39a662553b0..e117380111dc 100644 --- a/cumulus/test/client/src/lib.rs +++ b/cumulus/test/client/src/lib.rs @@ -45,33 +45,11 @@ pub use substrate_test_client::*; pub type ParachainBlockData = cumulus_primitives_core::ParachainBlockData; -mod local_executor { - /// Native executor instance. - pub struct LocalExecutor; - - impl sc_executor::NativeExecutionDispatch for LocalExecutor { - type ExtendHostFunctions = - cumulus_primitives_proof_size_hostfunction::storage_proof_size::HostFunctions; - - fn dispatch(method: &str, data: &[u8]) -> Option> { - cumulus_test_runtime::api::dispatch(method, data) - } - - fn native_version() -> sc_executor::NativeVersion { - cumulus_test_runtime::native_version() - } - } -} - -/// Native executor used for tests. -pub use local_executor::LocalExecutor; - /// Test client database backend. pub type Backend = substrate_test_client::Backend; /// Test client executor. -pub type Executor = - client::LocalCallExecutor>; +pub type Executor = client::LocalCallExecutor; /// Test client builder for Cumulus pub type TestClientBuilder = @@ -100,7 +78,7 @@ impl substrate_test_client::GenesisInit for GenesisParameters { } } -/// A `test-runtime` extensions to `TestClientBuilder`. +/// A `test-runtime` extensions to [`TestClientBuilder`]. pub trait TestClientBuilderExt: Sized { /// Build the test client. fn build(self) -> Client { diff --git a/substrate/client/executor/src/executor.rs b/substrate/client/executor/src/executor.rs index d56a3b389ef4..382a021e302e 100644 --- a/substrate/client/executor/src/executor.rs +++ b/substrate/client/executor/src/executor.rs @@ -83,7 +83,7 @@ fn unwrap_heap_pages(pages: Option) -> HeapAllocStrategy { } /// Builder for creating a [`WasmExecutor`] instance. -pub struct WasmExecutorBuilder { +pub struct WasmExecutorBuilder { _phantom: PhantomData, method: WasmExecutionMethod, onchain_heap_alloc_strategy: Option, @@ -218,7 +218,7 @@ impl WasmExecutorBuilder { /// An abstraction over Wasm code executor. Supports selecting execution backend and /// manages runtime cache. -pub struct WasmExecutor { +pub struct WasmExecutor { /// Method used to execute fallback Wasm code. method: WasmExecutionMethod, /// The heap allocation strategy for onchain Wasm calls. @@ -252,10 +252,13 @@ impl Clone for WasmExecutor { } } -impl WasmExecutor -where - H: HostFunctions, -{ +impl Default for WasmExecutor { + fn default() -> Self { + WasmExecutorBuilder::new().build() + } +} + +impl WasmExecutor { /// Create new instance. /// /// # Parameters @@ -312,7 +315,12 @@ where pub fn allow_missing_host_functions(&mut self, allow_missing_host_functions: bool) { self.allow_missing_host_functions = allow_missing_host_functions } +} +impl WasmExecutor +where + H: HostFunctions, +{ /// Execute the given closure `f` with the latest runtime (based on `runtime_code`). /// /// The closure `f` is expected to return `Err(_)` when there happened a `panic!` in native code @@ -558,6 +566,7 @@ where /// A generic `CodeExecutor` implementation that uses a delegate to determine wasm code equivalence /// and dispatch to native code when possible, falling back on `WasmExecutor` when not. +#[deprecated(note = "Native execution will be deprecated, please replace with `WasmExecutor`")] pub struct NativeElseWasmExecutor { /// Native runtime version info. native_version: NativeVersion, @@ -568,6 +577,7 @@ pub struct NativeElseWasmExecutor { use_native: bool, } +#[allow(deprecated)] impl NativeElseWasmExecutor { /// /// Create new instance. @@ -628,6 +638,7 @@ impl NativeElseWasmExecutor { } } +#[allow(deprecated)] impl RuntimeVersionOf for NativeElseWasmExecutor { fn runtime_version( &self, @@ -638,12 +649,14 @@ impl RuntimeVersionOf for NativeElseWasmExecutor } } +#[allow(deprecated)] impl GetNativeVersion for NativeElseWasmExecutor { fn native_version(&self) -> &NativeVersion { &self.native_version } } +#[allow(deprecated)] impl CodeExecutor for NativeElseWasmExecutor { type Error = Error; @@ -718,6 +731,7 @@ impl CodeExecutor for NativeElseWasmExecut } } +#[allow(deprecated)] impl Clone for NativeElseWasmExecutor { fn clone(&self) -> Self { NativeElseWasmExecutor { @@ -728,6 +742,7 @@ impl Clone for NativeElseWasmExecutor { } } +#[allow(deprecated)] impl sp_core::traits::ReadRuntimeVersion for NativeElseWasmExecutor { fn read_runtime_version( &self, @@ -765,6 +780,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn native_executor_registers_custom_interface() { let executor = NativeElseWasmExecutor::::new_with_wasm_executor( WasmExecutor::builder().build(), diff --git a/substrate/client/executor/src/lib.rs b/substrate/client/executor/src/lib.rs index 6b99f0a6ee03..0eb2c6724305 100644 --- a/substrate/client/executor/src/lib.rs +++ b/substrate/client/executor/src/lib.rs @@ -36,18 +36,16 @@ mod executor; mod integration_tests; mod wasm_runtime; -pub use self::{ - executor::{ - with_externalities_safe, NativeElseWasmExecutor, NativeExecutionDispatch, WasmExecutor, - }, - wasm_runtime::{read_embedded_version, WasmExecutionMethod}, -}; pub use codec::Codec; +#[allow(deprecated)] +pub use executor::NativeElseWasmExecutor; +pub use executor::{with_externalities_safe, NativeExecutionDispatch, WasmExecutor}; #[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 sc_executor_common::{ error, diff --git a/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs b/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs index 0e5ccb91d39a..b3a22b48dbb0 100644 --- a/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs +++ b/substrate/client/rpc-spec-v2/src/chain_head/subscription/inner.rs @@ -864,7 +864,7 @@ mod tests { Arc>>, ) { let backend = Arc::new(sc_client_api::in_mem::Backend::new()); - let executor = substrate_test_runtime_client::new_native_or_wasm_executor(); + let executor = substrate_test_runtime_client::WasmExecutor::default(); let client_config = sc_service::ClientConfig::default(); let genesis_block_builder = sc_service::GenesisBlockBuilder::new( &substrate_test_runtime_client::GenesisParameters::default().genesis_storage(), diff --git a/substrate/client/rpc-spec-v2/src/chain_head/tests.rs b/substrate/client/rpc-spec-v2/src/chain_head/tests.rs index c2bff7c50d5e..d7fe98d0cc01 100644 --- a/substrate/client/rpc-spec-v2/src/chain_head/tests.rs +++ b/substrate/client/rpc-spec-v2/src/chain_head/tests.rs @@ -16,13 +16,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use super::*; use crate::{ chain_head::{api::ChainHeadApiClient, event::MethodResponse, test_utils::ChainHeadMockClient}, common::events::{StorageQuery, StorageQueryType, StorageResultType}, hex_string, }; - -use super::*; use assert_matches::assert_matches; use codec::{Decode, Encode}; use futures::Future; @@ -32,7 +31,6 @@ use jsonrpsee::{ }, rpc_params, MethodsError as Error, RpcModule, }; - use sc_block_builder::BlockBuilderBuilder; use sc_client_api::ChildInfo; use sc_service::client::new_in_mem; @@ -2517,7 +2515,7 @@ async fn follow_report_multiple_pruned_block() { async fn pin_block_references() { // Manually construct an in-memory backend and client. let backend = Arc::new(sc_client_api::in_mem::Backend::new()); - let executor = substrate_test_runtime_client::new_native_or_wasm_executor(); + let executor = substrate_test_runtime_client::WasmExecutor::default(); let client_config = sc_service::ClientConfig::default(); let genesis_block_builder = sc_service::GenesisBlockBuilder::new( diff --git a/substrate/client/service/src/builder.rs b/substrate/client/service/src/builder.rs index 830f9884719d..d551fc08e7f2 100644 --- a/substrate/client/service/src/builder.rs +++ b/substrate/client/service/src/builder.rs @@ -37,8 +37,8 @@ use sc_client_api::{ 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_STRATEGY, + sp_wasm_interface::HostFunctions, HeapAllocStrategy, NativeExecutionDispatch, RuntimeVersionOf, + WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY, }; use sc_keystore::LocalKeystore; use sc_network::{ @@ -263,10 +263,13 @@ where } /// Creates a [`NativeElseWasmExecutor`] according to [`Configuration`]. +#[deprecated(note = "Please switch to `new_wasm_executor`.")] +#[allow(deprecated)] pub fn new_native_or_wasm_executor( config: &Configuration, -) -> NativeElseWasmExecutor { - NativeElseWasmExecutor::new_with_wasm_executor(new_wasm_executor(config)) +) -> sc_executor::NativeElseWasmExecutor { + #[allow(deprecated)] + sc_executor::NativeElseWasmExecutor::new_with_wasm_executor(new_wasm_executor(config)) } /// Creates a [`WasmExecutor`] according to [`Configuration`]. diff --git a/substrate/client/service/src/client/call_executor.rs b/substrate/client/service/src/client/call_executor.rs index 86b5c7c61fcd..9da4d2192576 100644 --- a/substrate/client/service/src/client/call_executor.rs +++ b/substrate/client/service/src/client/call_executor.rs @@ -337,26 +337,17 @@ mod tests { use super::*; use backend::Backend; use sc_client_api::in_mem; - use sc_executor::{NativeElseWasmExecutor, WasmExecutor}; + use sc_executor::WasmExecutor; use sp_core::{ testing::TaskExecutor, traits::{FetchRuntimeCode, WrappedRuntimeCode}, }; use std::collections::HashMap; - use substrate_test_runtime_client::{runtime, GenesisInit, LocalExecutorDispatch}; - - fn executor() -> NativeElseWasmExecutor { - NativeElseWasmExecutor::new_with_wasm_executor( - WasmExecutor::builder() - .with_max_runtime_instances(1) - .with_runtime_cache_size(2) - .build(), - ) - } + use substrate_test_runtime_client::{runtime, GenesisInit}; #[test] fn should_get_override_if_exists() { - let executor = executor(); + let executor = WasmExecutor::default(); let overrides = crate::client::wasm_override::dummy_overrides(); let onchain_code = WrappedRuntimeCode(substrate_test_runtime::wasm_binary_unwrap().into()); @@ -425,7 +416,7 @@ mod tests { fn returns_runtime_version_from_substitute() { const SUBSTITUTE_SPEC_NAME: &str = "substitute-spec-name-cool"; - let executor = executor(); + let executor = WasmExecutor::default(); let backend = Arc::new(in_mem::Backend::::new()); diff --git a/substrate/client/service/src/client/wasm_override.rs b/substrate/client/service/src/client/wasm_override.rs index 725c8ab9429a..678ae22bec11 100644 --- a/substrate/client/service/src/client/wasm_override.rs +++ b/substrate/client/service/src/client/wasm_override.rs @@ -264,24 +264,21 @@ pub fn dummy_overrides() -> WasmOverride { #[cfg(test)] mod tests { use super::*; - use sc_executor::{HeapAllocStrategy, NativeElseWasmExecutor, WasmExecutor}; + use sc_executor::{HeapAllocStrategy, WasmExecutor}; use std::fs::{self, File}; - use substrate_test_runtime_client::LocalExecutorDispatch; - - fn executor() -> NativeElseWasmExecutor { - NativeElseWasmExecutor::::new_with_wasm_executor( - 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) - .with_runtime_cache_size(2) - .build() - ) + + fn executor() -> WasmExecutor { + 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) + .with_runtime_cache_size(2) + .build() } fn wasm_test(fun: F) where - F: Fn(&Path, &[u8], &NativeElseWasmExecutor), + F: Fn(&Path, &[u8], &WasmExecutor), { let exec = executor(); let bytes = substrate_test_runtime::wasm_binary_unwrap(); diff --git a/substrate/client/service/src/lib.rs b/substrate/client/service/src/lib.rs index e46cfab50a3e..d0f315c30c89 100644 --- a/substrate/client/service/src/lib.rs +++ b/substrate/client/service/src/lib.rs @@ -55,14 +55,15 @@ use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; pub use self::{ builder::{ build_network, new_client, new_db_backend, new_full_client, new_full_parts, - new_full_parts_record_import, new_full_parts_with_genesis_builder, - new_native_or_wasm_executor, new_wasm_executor, spawn_tasks, BuildNetworkParams, - KeystoreContainer, NetworkStarter, SpawnTasksParams, TFullBackend, TFullCallExecutor, - TFullClient, + new_full_parts_record_import, new_full_parts_with_genesis_builder, new_wasm_executor, + spawn_tasks, BuildNetworkParams, KeystoreContainer, NetworkStarter, SpawnTasksParams, + TFullBackend, TFullCallExecutor, TFullClient, }, client::{ClientConfig, LocalCallExecutor}, error::Error, }; +#[allow(deprecated)] +pub use builder::new_native_or_wasm_executor; pub use sc_chain_spec::{ construct_genesis_block, resolve_state_version_from_wasm, BuildGenesisBlock, diff --git a/substrate/client/service/test/src/client/mod.rs b/substrate/client/service/test/src/client/mod.rs index 51dcc4966e58..4fcb7c160cb4 100644 --- a/substrate/client/service/test/src/client/mod.rs +++ b/substrate/client/service/test/src/client/mod.rs @@ -28,6 +28,7 @@ use sc_client_db::{Backend, BlocksPruning, DatabaseSettings, DatabaseSource, Pru use sc_consensus::{ BlockCheckParams, BlockImport, BlockImportParams, ForkChoiceStrategy, ImportResult, }; +use sc_executor::WasmExecutor; use sc_service::client::{new_in_mem, Client, LocalCallExecutor}; use sp_api::ProvideRuntimeApi; use sp_consensus::{BlockOrigin, Error as ConsensusError, SelectChain}; @@ -42,8 +43,6 @@ use sp_storage::{ChildInfo, StorageKey}; use std::{collections::HashSet, sync::Arc}; use substrate_test_runtime::TestAPI; use substrate_test_runtime_client::{ - new_native_or_wasm_executor, - prelude::*, runtime::{ currency::DOLLARS, genesismap::{insert_genesis_block, GenesisStorageBuilder}, @@ -79,7 +78,7 @@ fn construct_block( StateMachine::new( backend, &mut overlay, - &new_native_or_wasm_executor(), + &WasmExecutor::default(), "Core_initialize_block", &header.encode(), &mut Default::default(), @@ -93,7 +92,7 @@ fn construct_block( StateMachine::new( backend, &mut overlay, - &new_native_or_wasm_executor(), + &WasmExecutor::default(), "BlockBuilder_apply_extrinsic", &tx.encode(), &mut Default::default(), @@ -107,7 +106,7 @@ fn construct_block( let ret_data = StateMachine::new( backend, &mut overlay, - &new_native_or_wasm_executor(), + &WasmExecutor::default(), "BlockBuilder_finalize_block", &[], &mut Default::default(), @@ -175,7 +174,7 @@ fn construct_genesis_should_work_with_native() { let _ = StateMachine::new( &backend, &mut overlay, - &new_native_or_wasm_executor(), + &WasmExecutor::default(), "Core_execute_block", &b1data, &mut Default::default(), @@ -206,7 +205,7 @@ fn construct_genesis_should_work_with_wasm() { let _ = StateMachine::new( &backend, &mut overlay, - &new_native_or_wasm_executor(), + &WasmExecutor::default(), "Core_execute_block", &b1data, &mut Default::default(), @@ -2072,7 +2071,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 = new_native_or_wasm_executor(); + let executor = WasmExecutor::default(); let client_config = sc_service::ClientConfig::default(); let genesis_block_builder = sc_service::GenesisBlockBuilder::new( @@ -2099,11 +2098,7 @@ fn cleans_up_closed_notification_sinks_on_block_import() { type TestClient = Client< in_mem::Backend, - LocalCallExecutor< - Block, - in_mem::Backend, - sc_executor::NativeElseWasmExecutor, - >, + LocalCallExecutor, WasmExecutor>, Block, RuntimeApi, >; diff --git a/substrate/frame/system/src/tests.rs b/substrate/frame/system/src/tests.rs index b889b5ca046e..22b98014db4e 100644 --- a/substrate/frame/system/src/tests.rs +++ b/substrate/frame/system/src/tests.rs @@ -21,14 +21,14 @@ use frame_support::{ dispatch::{Pays, PostDispatchInfo, WithPostDispatchInfo}, traits::{OnRuntimeUpgrade, WhitelistedStorageKeys}, }; -use std::collections::BTreeSet; - use mock::{RuntimeOrigin, *}; use sp_core::{hexdisplay::HexDisplay, H256}; use sp_runtime::{ traits::{BlakeTwo256, Header}, DispatchError, DispatchErrorWithPostInfo, }; +use std::collections::BTreeSet; +use substrate_test_runtime_client::WasmExecutor; #[test] fn check_whitelist() { @@ -653,7 +653,7 @@ fn assert_runtime_updated_digest(num: usize) { #[test] fn set_code_with_real_wasm_blob() { - let executor = substrate_test_runtime_client::new_native_or_wasm_executor(); + let executor = WasmExecutor::default(); let mut ext = new_test_ext(); ext.register_extension(sp_core::traits::ReadRuntimeVersionExt::new(executor)); ext.execute_with(|| { @@ -679,7 +679,7 @@ fn set_code_with_real_wasm_blob() { fn set_code_rejects_during_mbm() { Ongoing::set(true); - let executor = substrate_test_runtime_client::new_native_or_wasm_executor(); + let executor = substrate_test_runtime_client::WasmExecutor::default(); let mut ext = new_test_ext(); ext.register_extension(sp_core::traits::ReadRuntimeVersionExt::new(executor)); ext.execute_with(|| { @@ -699,7 +699,7 @@ fn set_code_rejects_during_mbm() { #[test] fn set_code_via_authorization_works() { - let executor = substrate_test_runtime_client::new_native_or_wasm_executor(); + let executor = substrate_test_runtime_client::WasmExecutor::default(); let mut ext = new_test_ext(); ext.register_extension(sp_core::traits::ReadRuntimeVersionExt::new(executor)); ext.execute_with(|| { @@ -739,7 +739,7 @@ fn set_code_via_authorization_works() { #[test] fn runtime_upgraded_with_set_storage() { - let executor = substrate_test_runtime_client::new_native_or_wasm_executor(); + let executor = substrate_test_runtime_client::WasmExecutor::default(); let mut ext = new_test_ext(); ext.register_extension(sp_core::traits::ReadRuntimeVersionExt::new(executor)); ext.execute_with(|| { diff --git a/substrate/primitives/api/test/tests/runtime_calls.rs b/substrate/primitives/api/test/tests/runtime_calls.rs index e66be7f9bf1a..5a524d1c7f4d 100644 --- a/substrate/primitives/api/test/tests/runtime_calls.rs +++ b/substrate/primitives/api/test/tests/runtime_calls.rs @@ -122,9 +122,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().build(), - ); + let executor: WasmExecutor = WasmExecutor::builder().build(); execution_proof_check_on_trie_backend( &backend, &mut overlay, diff --git a/substrate/test-utils/client/src/lib.rs b/substrate/test-utils/client/src/lib.rs index d283b24f286a..c82bbf80916a 100644 --- a/substrate/test-utils/client/src/lib.rs +++ b/substrate/test-utils/client/src/lib.rs @@ -24,7 +24,7 @@ pub mod client_ext; pub use self::client_ext::{BlockOrigin, ClientBlockImportExt, ClientExt}; pub use sc_client_api::{execution_extensions::ExecutionExtensions, BadBlocks, ForkBlocks}; pub use sc_client_db::{self, Backend, BlocksPruning}; -pub use sc_executor::{self, NativeElseWasmExecutor, WasmExecutionMethod, WasmExecutor}; +pub use sc_executor::{self, WasmExecutionMethod, WasmExecutor}; pub use sc_service::{client, RpcHandlers}; pub use sp_consensus; pub use sp_keyring::{ @@ -245,14 +245,8 @@ impl } } -impl - TestClientBuilder< - Block, - client::LocalCallExecutor>, - Backend, - G, - > where - D: sc_executor::NativeExecutionDispatch, +impl + TestClientBuilder, Backend, G> { /// Build the test client with the given native executor. pub fn build_with_native_executor( @@ -261,21 +255,17 @@ impl ) -> ( client::Client< Backend, - client::LocalCallExecutor>, + client::LocalCallExecutor, Block, RuntimeApi, >, sc_consensus::LongestChain, ) where - I: Into>>, - D: sc_executor::NativeExecutionDispatch + 'static, + I: Into>, Backend: sc_client_api::backend::Backend + 'static, { - let mut executor = executor.into().unwrap_or_else(|| { - NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build()) - }); - executor.disable_use_native(); + let executor = executor.into().unwrap_or_default(); let executor = LocalCallExecutor::new( self.backend.clone(), executor.clone(), diff --git a/substrate/test-utils/runtime/client/src/lib.rs b/substrate/test-utils/runtime/client/src/lib.rs index 7428a7de3a09..62d8f8cc13a2 100644 --- a/substrate/test-utils/runtime/client/src/lib.rs +++ b/substrate/test-utils/runtime/client/src/lib.rs @@ -42,8 +42,8 @@ pub mod prelude { }; // Client structs pub use super::{ - Backend, ExecutorDispatch, LocalExecutorDispatch, NativeElseWasmExecutor, TestClient, - TestClientBuilder, WasmExecutionMethod, + Backend, ExecutorDispatch, LocalExecutorDispatch, TestClient, TestClientBuilder, + WasmExecutionMethod, }; // Keyring pub use super::{AccountKeyring, Sr25519Keyring}; @@ -69,11 +69,8 @@ impl sc_executor::NativeExecutionDispatch for LocalExecutorDispatch { pub type Backend = substrate_test_client::Backend; /// Test client executor. -pub type ExecutorDispatch = client::LocalCallExecutor< - substrate_test_runtime::Block, - Backend, - NativeElseWasmExecutor, ->; +pub type ExecutorDispatch = + client::LocalCallExecutor; /// Parameters of test-client builder with test-runtime. #[derive(Default)] @@ -116,11 +113,7 @@ pub type TestClientBuilder = substrate_test_client::TestClientBuilder< /// Test client type with `LocalExecutorDispatch` and generic Backend. pub type Client = client::Client< B, - client::LocalCallExecutor< - substrate_test_runtime::Block, - B, - NativeElseWasmExecutor, - >, + client::LocalCallExecutor, substrate_test_runtime::Block, substrate_test_runtime::RuntimeApi, >; @@ -206,14 +199,8 @@ pub trait TestClientBuilderExt: Sized { } impl TestClientBuilderExt - for TestClientBuilder< - client::LocalCallExecutor< - substrate_test_runtime::Block, - B, - NativeElseWasmExecutor, - >, - B, - > where + for TestClientBuilder, B> +where B: sc_client_api::backend::Backend + 'static, { fn genesis_init_mut(&mut self) -> &mut GenesisParameters { @@ -238,6 +225,7 @@ pub fn new() -> Client { } /// Create a new native executor. -pub fn new_native_or_wasm_executor() -> NativeElseWasmExecutor { - NativeElseWasmExecutor::new_with_wasm_executor(WasmExecutor::builder().build()) +#[deprecated(note = "Switch to `WasmExecutor:default()`.")] +pub fn new_native_or_wasm_executor() -> WasmExecutor { + WasmExecutor::default() } From 845b744d79430fac77b5082c25d97e7bbf7cb99f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 30 Apr 2024 17:06:31 +0200 Subject: [PATCH 2/6] Mention removal date --- substrate/client/executor/src/executor.rs | 4 +++- substrate/client/service/src/builder.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/substrate/client/executor/src/executor.rs b/substrate/client/executor/src/executor.rs index 382a021e302e..913bcdfcfe59 100644 --- a/substrate/client/executor/src/executor.rs +++ b/substrate/client/executor/src/executor.rs @@ -566,7 +566,9 @@ where /// A generic `CodeExecutor` implementation that uses a delegate to determine wasm code equivalence /// and dispatch to native code when possible, falling back on `WasmExecutor` when not. -#[deprecated(note = "Native execution will be deprecated, please replace with `WasmExecutor`")] +#[deprecated( + note = "Native execution will be deprecated, please replace with `WasmExecutor`. Will be removed at end of 2024." +)] pub struct NativeElseWasmExecutor { /// Native runtime version info. native_version: NativeVersion, diff --git a/substrate/client/service/src/builder.rs b/substrate/client/service/src/builder.rs index 0bb3c0171977..185eff1e8df3 100644 --- a/substrate/client/service/src/builder.rs +++ b/substrate/client/service/src/builder.rs @@ -263,7 +263,7 @@ where } /// Creates a [`NativeElseWasmExecutor`] according to [`Configuration`]. -#[deprecated(note = "Please switch to `new_wasm_executor`.")] +#[deprecated(note = "Please switch to `new_wasm_executor`. Will be removed at end of 2024.")] #[allow(deprecated)] pub fn new_native_or_wasm_executor( config: &Configuration, From 5a7c52875bf24096210c776dd8d345111ee0a45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 30 Apr 2024 23:49:24 +0200 Subject: [PATCH 3/6] Fix tests --- cumulus/test/client/src/lib.rs | 9 ++++++++- substrate/client/executor/src/lib.rs | 1 + substrate/test-utils/client/src/lib.rs | 11 +++++----- .../test-utils/runtime/client/src/lib.rs | 20 ++----------------- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/cumulus/test/client/src/lib.rs b/cumulus/test/client/src/lib.rs index e117380111dc..d233ad269176 100644 --- a/cumulus/test/client/src/lib.rs +++ b/cumulus/test/client/src/lib.rs @@ -49,7 +49,14 @@ pub type ParachainBlockData = cumulus_primitives_core::ParachainBlockData pub type Backend = substrate_test_client::Backend; /// Test client executor. -pub type Executor = client::LocalCallExecutor; +pub type Executor = client::LocalCallExecutor< + Block, + Backend, + WasmExecutor<( + sp_io::SubstrateHostFunctions, + cumulus_primitives_proof_size_hostfunction::storage_proof_size::HostFunctions, + )>, +>; /// Test client builder for Cumulus pub type TestClientBuilder = diff --git a/substrate/client/executor/src/lib.rs b/substrate/client/executor/src/lib.rs index 0eb2c6724305..204f1ff22d74 100644 --- a/substrate/client/executor/src/lib.rs +++ b/substrate/client/executor/src/lib.rs @@ -45,6 +45,7 @@ pub use sp_core::traits::Externalities; pub use sp_version::{NativeVersion, RuntimeVersion}; #[doc(hidden)] pub use sp_wasm_interface; +pub use sp_wasm_interface::HostFunctions; pub use wasm_runtime::{read_embedded_version, WasmExecutionMethod}; pub use sc_executor_common::{ diff --git a/substrate/test-utils/client/src/lib.rs b/substrate/test-utils/client/src/lib.rs index c82bbf80916a..c07640653d56 100644 --- a/substrate/test-utils/client/src/lib.rs +++ b/substrate/test-utils/client/src/lib.rs @@ -245,8 +245,8 @@ impl } } -impl - TestClientBuilder, Backend, G> +impl + TestClientBuilder>, Backend, G> { /// Build the test client with the given native executor. pub fn build_with_native_executor( @@ -255,17 +255,18 @@ impl ) -> ( client::Client< Backend, - client::LocalCallExecutor, + client::LocalCallExecutor>, Block, RuntimeApi, >, sc_consensus::LongestChain, ) where - I: Into>, + I: Into>>, Backend: sc_client_api::backend::Backend + 'static, + H: sc_executor::HostFunctions, { - let executor = executor.into().unwrap_or_default(); + let executor = executor.into().unwrap_or_else(|| WasmExecutor::::builder().build()); let executor = LocalCallExecutor::new( self.backend.clone(), executor.clone(), diff --git a/substrate/test-utils/runtime/client/src/lib.rs b/substrate/test-utils/runtime/client/src/lib.rs index 62d8f8cc13a2..971e4d74b82b 100644 --- a/substrate/test-utils/runtime/client/src/lib.rs +++ b/substrate/test-utils/runtime/client/src/lib.rs @@ -42,29 +42,13 @@ pub mod prelude { }; // Client structs pub use super::{ - Backend, ExecutorDispatch, LocalExecutorDispatch, TestClient, TestClientBuilder, + Backend, ExecutorDispatch, TestClient, TestClientBuilder, WasmExecutionMethod, }; // Keyring pub use super::{AccountKeyring, Sr25519Keyring}; } -/// A unit struct which implements `NativeExecutionDispatch` feeding in the -/// hard-coded runtime. -pub struct LocalExecutorDispatch; - -impl sc_executor::NativeExecutionDispatch for LocalExecutorDispatch { - type ExtendHostFunctions = (); - - fn dispatch(method: &str, data: &[u8]) -> Option> { - substrate_test_runtime::api::dispatch(method, data) - } - - fn native_version() -> sc_executor::NativeVersion { - substrate_test_runtime::native_version() - } -} - /// Test client database backend. pub type Backend = substrate_test_client::Backend; @@ -110,7 +94,7 @@ pub type TestClientBuilder = substrate_test_client::TestClientBuilder< GenesisParameters, >; -/// Test client type with `LocalExecutorDispatch` and generic Backend. +/// Test client type with `WasmExecutor` and generic Backend. pub type Client = client::Client< B, client::LocalCallExecutor, From 5b70f884b2dca5ecb7fbe88068846cd1dc481d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Thu, 2 May 2024 14:08:54 +0200 Subject: [PATCH 4/6] FMT --- substrate/test-utils/runtime/client/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/substrate/test-utils/runtime/client/src/lib.rs b/substrate/test-utils/runtime/client/src/lib.rs index 971e4d74b82b..435f3f5ebacb 100644 --- a/substrate/test-utils/runtime/client/src/lib.rs +++ b/substrate/test-utils/runtime/client/src/lib.rs @@ -42,8 +42,7 @@ pub mod prelude { }; // Client structs pub use super::{ - Backend, ExecutorDispatch, TestClient, TestClientBuilder, - WasmExecutionMethod, + Backend, ExecutorDispatch, TestClient, TestClientBuilder, WasmExecutionMethod, }; // Keyring pub use super::{AccountKeyring, Sr25519Keyring}; From a7942cf73ff04b0a49f37b4e00a390e3014151e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Thu, 2 May 2024 16:13:27 +0200 Subject: [PATCH 5/6] Fix docs --- substrate/client/service/src/builder.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/substrate/client/service/src/builder.rs b/substrate/client/service/src/builder.rs index 185eff1e8df3..06fc2ea3b304 100644 --- a/substrate/client/service/src/builder.rs +++ b/substrate/client/service/src/builder.rs @@ -262,7 +262,8 @@ where Ok((client, backend, keystore_container, task_manager)) } -/// Creates a [`NativeElseWasmExecutor`] according to [`Configuration`]. +/// Creates a [`NativeElseWasmExecutor`](sc_executor::NativeElseWasmExecutor) according to +/// [`Configuration`]. #[deprecated(note = "Please switch to `new_wasm_executor`. Will be removed at end of 2024.")] #[allow(deprecated)] pub fn new_native_or_wasm_executor( From 9c0e3e94b3f878f83dee557fbfb64ae21e778e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Thu, 2 May 2024 16:44:00 +0200 Subject: [PATCH 6/6] PRDOC --- prdoc/pr_4329.prdoc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 prdoc/pr_4329.prdoc diff --git a/prdoc/pr_4329.prdoc b/prdoc/pr_4329.prdoc new file mode 100644 index 000000000000..2fe11a60f4ba --- /dev/null +++ b/prdoc/pr_4329.prdoc @@ -0,0 +1,14 @@ +title: "Deprecate `NativeElseWasmExecutor`" + +doc: + - audience: Node Dev + description: | + Deprecates the `NativeElseWasmExecutor` as native execution is already + discouraged and should be removed entirely. The executor should be + replaced by `WasmExecutor` which can be found in `sc-executor`. + + The `NativeElseWasmExecutor` will be removed at the end of 2024. + +crates: + - name: sc-executor + bump: minor