From f52d18210adefc69d9e19853bd54ad297bb2fdef Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Wed, 4 Aug 2021 17:14:33 +0200 Subject: [PATCH 01/15] Split native executor stuff from wasm executor stuff --- bin/node/executor/benches/bench.rs | 2 +- client/api/src/call_executor.rs | 3 - client/executor/src/lib.rs | 13 +++-- client/executor/src/native_executor.rs | 56 +++++++++++++++++-- client/service/src/builder.rs | 4 +- client/service/src/client/call_executor.rs | 25 +++++---- client/service/src/client/client.rs | 6 +- client/service/src/client/light.rs | 4 +- client/service/src/client/wasm_override.rs | 6 +- client/service/src/client/wasm_substitutes.rs | 4 +- primitives/consensus/common/src/lib.rs | 4 +- primitives/version/src/lib.rs | 23 +++++--- 12 files changed, 103 insertions(+), 47 deletions(-) diff --git a/bin/node/executor/benches/bench.rs b/bin/node/executor/benches/bench.rs index cd201cfc95987..485298e8c4287 100644 --- a/bin/node/executor/benches/bench.rs +++ b/bin/node/executor/benches/bench.rs @@ -25,7 +25,7 @@ use node_runtime::{ UncheckedExtrinsic, }; use node_testing::keyring::*; -use sc_executor::{Externalities, NativeExecutor, RuntimeInfo, WasmExecutionMethod}; +use sc_executor::{Externalities, NativeExecutor, RuntimeVersionOf, WasmExecutionMethod}; use sp_core::{ storage::well_known_keys, traits::{CodeExecutor, RuntimeCode}, diff --git a/client/api/src/call_executor.rs b/client/api/src/call_executor.rs index a19df74326068..f9a64a6490a25 100644 --- a/client/api/src/call_executor.rs +++ b/client/api/src/call_executor.rs @@ -106,7 +106,4 @@ pub trait CallExecutor { method: &str, call_data: &[u8], ) -> Result<(Vec, StorageProof), sp_blockchain::Error>; - - /// Get runtime version if supported. - fn native_runtime_version(&self) -> Option<&NativeVersion>; } diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index f4b972a86f27a..9247275f569cd 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -51,11 +51,8 @@ pub use wasmi; pub use sc_executor_common::{error, sandbox}; -/// Provides runtime information. -pub trait RuntimeInfo { - /// Native runtime information. - fn native_version(&self) -> &NativeVersion; - +/// Extracts the runtime version of a given runtime code. +pub trait RuntimeVersionOf { /// Extract [`RuntimeVersion`](sp_version::RuntimeVersion) of the given `runtime_code`. fn runtime_version( &self, @@ -64,6 +61,12 @@ pub trait RuntimeInfo { ) -> error::Result; } +/// Provides native runtime information. +pub trait NativeRuntimeInfo { + /// Native runtime information. + fn native_version(&self) -> &NativeVersion; +} + #[cfg(test)] mod tests { use super::*; diff --git a/client/executor/src/native_executor.rs b/client/executor/src/native_executor.rs index 8222e00b17615..435bfbeb8dd03 100644 --- a/client/executor/src/native_executor.rs +++ b/client/executor/src/native_executor.rs @@ -19,7 +19,7 @@ use crate::{ error::{Error, Result}, wasm_runtime::{RuntimeCache, WasmExecutionMethod}, - RuntimeInfo, + NativeRuntimeInfo, RuntimeVersionOf, }; use std::{ @@ -269,6 +269,48 @@ impl sp_core::traits::ReadRuntimeVersion for WasmExecutor { } } +impl CodeExecutor for WasmExecutor { + type Error = Error; + + fn call< + R: Decode + Encode + PartialEq, + NC: FnOnce() -> result::Result> + UnwindSafe, + >( + &self, + ext: &mut dyn Externalities, + runtime_code: &RuntimeCode, + method: &str, + data: &[u8], + _use_native: bool, + _native_call: Option, + ) -> (Result>, bool) { + let result = self.with_instance( + runtime_code, + ext, + false, + |module, instance, _onchain_version, mut ext| { + with_externalities_safe(&mut **ext, move || { + preregister_builtin_ext(module.clone()); + instance.call_export(method, data).map(NativeOrEncoded::Encoded) + }) + }, + ); + (result, false) + } +} + +impl RuntimeVersionOf for WasmExecutor { + fn runtime_version( + &self, + ext: &mut dyn Externalities, + runtime_code: &RuntimeCode, + ) -> Result { + self.with_instance(runtime_code, ext, false, |_module, _instance, version, _ext| { + Ok(version.cloned().ok_or_else(|| Error::ApiError("Unknown version".into()))) + }) + } +} + /// 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. pub struct NativeExecutor { @@ -324,11 +366,7 @@ impl NativeExecutor { } } -impl RuntimeInfo for NativeExecutor { - fn native_version(&self) -> &NativeVersion { - &self.native_version - } - +impl RuntimeVersionOf for NativeExecutor { fn runtime_version( &self, ext: &mut dyn Externalities, @@ -341,6 +379,12 @@ impl RuntimeInfo for NativeExecutor { } } +impl NativeRuntimeInfo for NativeExecutor { + fn native_version(&self) -> &NativeVersion { + &self.native_version + } +} + /// Helper inner struct to implement `RuntimeSpawn` extension. pub struct RuntimeInstanceSpawn { module: Arc, diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index fb24a890133c6..e71cf4ecd60f2 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -37,7 +37,7 @@ use sc_client_api::{ }; use sc_client_db::{Backend, DatabaseSettings}; use sc_consensus::import_queue::ImportQueue; -use sc_executor::{NativeExecutionDispatch, NativeExecutor, RuntimeInfo}; +use sc_executor::{NativeExecutionDispatch, NativeExecutor, RuntimeVersionOf}; use sc_keystore::LocalKeystore; use sc_network::{ block_request_handler::{self, BlockRequestHandler}, @@ -454,7 +454,7 @@ pub fn new_client( > where Block: BlockT, - E: CodeExecutor + RuntimeInfo, + E: CodeExecutor + RuntimeVersionOf, { let executor = crate::client::LocalCallExecutor::new( backend.clone(), diff --git a/client/service/src/client/call_executor.rs b/client/service/src/client/call_executor.rs index 2fae972d3472d..ed961fed75e54 100644 --- a/client/service/src/client/call_executor.rs +++ b/client/service/src/client/call_executor.rs @@ -19,7 +19,7 @@ use super::{client::ClientConfig, wasm_override::WasmOverride, wasm_substitutes::WasmSubstitutes}; use codec::{Decode, Encode}; use sc_client_api::{backend, call_executor::CallExecutor, HeaderBackend}; -use sc_executor::{NativeVersion, RuntimeInfo, RuntimeVersion}; +use sc_executor::{NativeRuntimeInfo, NativeVersion, RuntimeVersion, RuntimeVersionOf}; use sp_api::{ProofRecorder, StorageTransactionCache}; use sp_core::{ traits::{CodeExecutor, RuntimeCode, SpawnNamed}, @@ -49,7 +49,7 @@ pub struct LocalCallExecutor { impl LocalCallExecutor where - E: CodeExecutor + RuntimeInfo + Clone + 'static, + E: CodeExecutor + RuntimeVersionOf + Clone + 'static, B: backend::Backend, { /// Creates new instance of local call executor. @@ -137,7 +137,7 @@ where impl CallExecutor for LocalCallExecutor where B: backend::Backend, - E: CodeExecutor + RuntimeInfo + Clone + 'static, + E: CodeExecutor + RuntimeVersionOf + Clone + 'static, Block: BlockT, { type Error = E::Error; @@ -333,25 +333,28 @@ where ) .map_err(Into::into) } +} - fn native_runtime_version(&self) -> Option<&NativeVersion> { - Some(self.executor.native_version()) +impl sp_version::GetRuntimeVersionAt for LocalCallExecutor +where + B: backend::Backend, + E: CodeExecutor + RuntimeVersionOf + Clone + 'static, + Block: BlockT, +{ + fn runtime_version(&self, at: &BlockId) -> Result { + CallExecutor::runtime_version(self, at).map_err(|e| format!("{:?}", e)) } } -impl sp_version::GetRuntimeVersion for LocalCallExecutor +impl sp_version::GetNativeVersion for LocalCallExecutor where B: backend::Backend, - E: CodeExecutor + RuntimeInfo + Clone + 'static, + E: CodeExecutor + NativeRuntimeInfo + Clone + 'static, Block: BlockT, { fn native_version(&self) -> &sp_version::NativeVersion { self.executor.native_version() } - - fn runtime_version(&self, at: &BlockId) -> Result { - CallExecutor::runtime_version(self, at).map_err(|e| format!("{:?}", e)) - } } #[cfg(test)] diff --git a/client/service/src/client/client.rs b/client/service/src/client/client.rs index 01688f0c8e702..e5302f645e227 100644 --- a/client/service/src/client/client.rs +++ b/client/service/src/client/client.rs @@ -96,7 +96,7 @@ use std::{ use { super::call_executor::LocalCallExecutor, sc_client_api::in_mem, - sc_executor::RuntimeInfo, + sc_executor::RuntimeVersionOf, sp_core::traits::{CodeExecutor, SpawnNamed}, }; @@ -169,7 +169,7 @@ pub fn new_in_mem( Client, LocalCallExecutor, E>, Block, RA>, > where - E: CodeExecutor + RuntimeInfo, + E: CodeExecutor + RuntimeVersionOf, S: BuildStorage, Block: BlockT, { @@ -227,7 +227,7 @@ pub fn new_with_backend( config: ClientConfig, ) -> sp_blockchain::Result, Block, RA>> where - E: CodeExecutor + RuntimeInfo, + E: CodeExecutor + RuntimeVersionOf, S: BuildStorage, Block: BlockT, B: backend::LocalBackend + 'static, diff --git a/client/service/src/client/light.rs b/client/service/src/client/light.rs index 82fe17e6855e9..7c13b98843e05 100644 --- a/client/service/src/client/light.rs +++ b/client/service/src/client/light.rs @@ -21,7 +21,7 @@ use std::sync::Arc; use prometheus_endpoint::Registry; -use sc_executor::RuntimeInfo; +use sc_executor::RuntimeVersionOf; use sc_telemetry::TelemetryHandle; use sp_blockchain::Result as ClientResult; use sp_core::traits::{CodeExecutor, SpawnNamed}; @@ -59,7 +59,7 @@ pub fn new_light( where B: BlockT, S: BlockchainStorage + 'static, - E: CodeExecutor + RuntimeInfo + Clone + 'static, + E: CodeExecutor + RuntimeVersionOf + Clone + 'static, { let local_executor = LocalCallExecutor::new( backend.clone(), diff --git a/client/service/src/client/wasm_override.rs b/client/service/src/client/wasm_override.rs index 7abd04f2be236..a04a48f9c4b49 100644 --- a/client/service/src/client/wasm_override.rs +++ b/client/service/src/client/wasm_override.rs @@ -35,7 +35,7 @@ //! A custom WASM blob will override on-chain WASM if the spec version matches. If it is //! required to overrides multiple runtimes, multiple WASM blobs matching each of the spec versions //! needed must be provided in the given directory. -use sc_executor::RuntimeInfo; +use sc_executor::RuntimeVersionOf; use sp_blockchain::Result; use sp_core::traits::{FetchRuntimeCode, RuntimeCode}; use sp_state_machine::BasicExternalities; @@ -112,7 +112,7 @@ pub struct WasmOverride { impl WasmOverride where - E: RuntimeInfo + Clone + 'static, + E: RuntimeVersionOf + Clone + 'static, { pub fn new

(path: P, executor: E) -> Result where @@ -192,7 +192,7 @@ where #[cfg(test)] pub fn dummy_overrides(executor: &E) -> WasmOverride where - E: RuntimeInfo + Clone + 'static, + E: RuntimeVersionOf + Clone + 'static, { let mut overrides = HashMap::new(); overrides.insert(0, WasmBlob::new(vec![0, 0, 0, 0, 0, 0, 0, 0])); diff --git a/client/service/src/client/wasm_substitutes.rs b/client/service/src/client/wasm_substitutes.rs index ac48059fc2f37..28975790e9b57 100644 --- a/client/service/src/client/wasm_substitutes.rs +++ b/client/service/src/client/wasm_substitutes.rs @@ -20,7 +20,7 @@ use parking_lot::RwLock; use sc_client_api::backend; -use sc_executor::RuntimeInfo; +use sc_executor::RuntimeVersionOf; use sp_blockchain::{HeaderBackend, Result}; use sp_core::traits::{FetchRuntimeCode, RuntimeCode}; use sp_runtime::{ @@ -139,7 +139,7 @@ impl Clone for WasmSubstitutes WasmSubstitutes where - Executor: RuntimeInfo + Clone + 'static, + Executor: RuntimeVersionOf + Clone + 'static, Backend: backend::Backend, Block: BlockT, { diff --git a/primitives/consensus/common/src/lib.rs b/primitives/consensus/common/src/lib.rs index f6c1e028b9457..a214a2f415fa1 100644 --- a/primitives/consensus/common/src/lib.rs +++ b/primitives/consensus/common/src/lib.rs @@ -284,8 +284,8 @@ impl CanAuthorWithNativeVersion { } } -impl, Block: BlockT> CanAuthorWith - for CanAuthorWithNativeVersion +impl + sp_version::GetNativeVersion, Block: BlockT> + CanAuthorWith for CanAuthorWithNativeVersion { fn can_author_with(&self, at: &BlockId) -> Result<(), String> { match self.0.runtime_version(at) { diff --git a/primitives/version/src/lib.rs b/primitives/version/src/lib.rs index b3ddb7d7fecc2..17011d73eae8d 100644 --- a/primitives/version/src/lib.rs +++ b/primitives/version/src/lib.rs @@ -246,27 +246,36 @@ impl NativeVersion { } } -/// Something that can provide the runtime version at a given block and the native runtime version. #[cfg(feature = "std")] -pub trait GetRuntimeVersion { +/// Returns the version of the native runtime. +pub trait GetNativeVersion { /// Returns the version of the native runtime. fn native_version(&self) -> &NativeVersion; +} +/// Something that can provide the runtime version at a given block. +#[cfg(feature = "std")] +pub trait GetRuntimeVersionAt { /// Returns the version of runtime at the given block. fn runtime_version(&self, at: &BlockId) -> Result; } #[cfg(feature = "std")] -impl, Block: BlockT> GetRuntimeVersion for std::sync::Arc { - fn native_version(&self) -> &NativeVersion { - (&**self).native_version() - } - +impl, Block: BlockT> GetRuntimeVersionAt + for std::sync::Arc +{ fn runtime_version(&self, at: &BlockId) -> Result { (&**self).runtime_version(at) } } +#[cfg(feature = "std")] +impl GetNativeVersion for std::sync::Arc { + fn native_version(&self) -> &NativeVersion { + (&**self).native_version() + } +} + #[cfg(feature = "std")] mod apis_serialize { use super::*; From 11bd3aaee7fccbce3b865cd8b5574270de473181 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Wed, 4 Aug 2021 17:20:49 +0200 Subject: [PATCH 02/15] Remove `native_runtime_version` in places --- client/api/src/call_executor.rs | 2 +- client/light/src/call_executor.rs | 6 +----- client/service/test/src/client/light.rs | 4 ---- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/client/api/src/call_executor.rs b/client/api/src/call_executor.rs index f9a64a6490a25..22af495c06542 100644 --- a/client/api/src/call_executor.rs +++ b/client/api/src/call_executor.rs @@ -19,7 +19,7 @@ //! A method call executor interface. use codec::{Decode, Encode}; -use sc_executor::{NativeVersion, RuntimeVersion}; +use sc_executor::RuntimeVersion; use sp_core::NativeOrEncoded; use sp_externalities::Extensions; use sp_runtime::{generic::BlockId, traits::Block as BlockT}; diff --git a/client/light/src/call_executor.rs b/client/light/src/call_executor.rs index 144e0cbf96dcc..a0776131e406d 100644 --- a/client/light/src/call_executor.rs +++ b/client/light/src/call_executor.rs @@ -44,7 +44,7 @@ use sp_blockchain::{Error as ClientError, Result as ClientResult}; use sc_client_api::{ backend::RemoteBackend, call_executor::CallExecutor, light::RemoteCallRequest, }; -use sc_executor::{NativeVersion, RuntimeVersion}; +use sc_executor::RuntimeVersion; /// Call executor that is able to execute calls only on genesis state. /// @@ -162,10 +162,6 @@ where Err(ClientError::NotAvailableOnLightClient) } } - - fn native_runtime_version(&self) -> Option<&NativeVersion> { - None - } } /// Check remote contextual execution proof using given backend. diff --git a/client/service/test/src/client/light.rs b/client/service/test/src/client/light.rs index 90f87670c0cec..641d164c4c56a 100644 --- a/client/service/test/src/client/light.rs +++ b/client/service/test/src/client/light.rs @@ -256,10 +256,6 @@ impl CallExecutor for DummyCallExecutor { ) -> Result<(Vec, StorageProof), ClientError> { unreachable!() } - - fn native_runtime_version(&self) -> Option<&NativeVersion> { - unreachable!() - } } fn local_executor() -> NativeExecutor { From 766d691aa0424a7cb3532f1a0284bc2fdd0ac6f7 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Wed, 4 Aug 2021 17:23:38 +0200 Subject: [PATCH 03/15] Fix warning --- client/service/src/client/call_executor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/service/src/client/call_executor.rs b/client/service/src/client/call_executor.rs index ed961fed75e54..02ff54f9e8424 100644 --- a/client/service/src/client/call_executor.rs +++ b/client/service/src/client/call_executor.rs @@ -19,7 +19,7 @@ use super::{client::ClientConfig, wasm_override::WasmOverride, wasm_substitutes::WasmSubstitutes}; use codec::{Decode, Encode}; use sc_client_api::{backend, call_executor::CallExecutor, HeaderBackend}; -use sc_executor::{NativeRuntimeInfo, NativeVersion, RuntimeVersion, RuntimeVersionOf}; +use sc_executor::{NativeRuntimeInfo, RuntimeVersion, RuntimeVersionOf}; use sp_api::{ProofRecorder, StorageTransactionCache}; use sp_core::{ traits::{CodeExecutor, RuntimeCode, SpawnNamed}, From 6791af62bfbb2a4d278ffc094e95e21a17476ec4 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Wed, 4 Aug 2021 17:55:10 +0200 Subject: [PATCH 04/15] Fix test warning --- client/service/test/src/client/light.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/service/test/src/client/light.rs b/client/service/test/src/client/light.rs index 641d164c4c56a..da4363b881027 100644 --- a/client/service/test/src/client/light.rs +++ b/client/service/test/src/client/light.rs @@ -30,7 +30,7 @@ use sc_client_api::{ RemoteBodyRequest, RemoteCallRequest, RemoteChangesRequest, RemoteHeaderRequest, RemoteReadChildRequest, RemoteReadRequest, Storage, StorageProof, StorageProvider, }; -use sc_executor::{NativeExecutor, NativeVersion, RuntimeVersion, WasmExecutionMethod}; +use sc_executor::{NativeExecutor, RuntimeVersion, WasmExecutionMethod}; use sc_light::{ backend::{Backend, GenesisOrUnavailableState}, blockchain::{Blockchain, BlockchainCache}, From e4c72cdc6d36fe9acf737aa93814c4d138710b7d Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 9 Aug 2021 10:43:14 +0200 Subject: [PATCH 05/15] Remove redundant NativeRuntimeInfo trait --- client/executor/src/lib.rs | 6 ------ client/executor/src/native_executor.rs | 6 +++--- client/service/src/client/call_executor.rs | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index 9247275f569cd..e4442960ea24e 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -61,12 +61,6 @@ pub trait RuntimeVersionOf { ) -> error::Result; } -/// Provides native runtime information. -pub trait NativeRuntimeInfo { - /// Native runtime information. - fn native_version(&self) -> &NativeVersion; -} - #[cfg(test)] mod tests { use super::*; diff --git a/client/executor/src/native_executor.rs b/client/executor/src/native_executor.rs index 435bfbeb8dd03..dfd01ec11cc6a 100644 --- a/client/executor/src/native_executor.rs +++ b/client/executor/src/native_executor.rs @@ -19,7 +19,7 @@ use crate::{ error::{Error, Result}, wasm_runtime::{RuntimeCache, WasmExecutionMethod}, - NativeRuntimeInfo, RuntimeVersionOf, + RuntimeVersionOf, }; use std::{ @@ -45,7 +45,7 @@ use sp_core::{ }; use sp_externalities::ExternalitiesExt as _; use sp_tasks::new_async_externalities; -use sp_version::{NativeVersion, RuntimeVersion}; +use sp_version::{NativeVersion, RuntimeVersion, GetNativeVersion}; use sp_wasm_interface::{Function, HostFunctions}; /// Default num of pages for the heap @@ -379,7 +379,7 @@ impl RuntimeVersionOf for NativeExecutor { } } -impl NativeRuntimeInfo for NativeExecutor { +impl GetNativeVersion for NativeExecutor { fn native_version(&self) -> &NativeVersion { &self.native_version } diff --git a/client/service/src/client/call_executor.rs b/client/service/src/client/call_executor.rs index 02ff54f9e8424..0710c4ae870ee 100644 --- a/client/service/src/client/call_executor.rs +++ b/client/service/src/client/call_executor.rs @@ -19,7 +19,7 @@ use super::{client::ClientConfig, wasm_override::WasmOverride, wasm_substitutes::WasmSubstitutes}; use codec::{Decode, Encode}; use sc_client_api::{backend, call_executor::CallExecutor, HeaderBackend}; -use sc_executor::{NativeRuntimeInfo, RuntimeVersion, RuntimeVersionOf}; +use sc_executor::{RuntimeVersion, RuntimeVersionOf}; use sp_api::{ProofRecorder, StorageTransactionCache}; use sp_core::{ traits::{CodeExecutor, RuntimeCode, SpawnNamed}, @@ -349,7 +349,7 @@ where impl sp_version::GetNativeVersion for LocalCallExecutor where B: backend::Backend, - E: CodeExecutor + NativeRuntimeInfo + Clone + 'static, + E: CodeExecutor + sp_version::GetNativeVersion + Clone + 'static, Block: BlockT, { fn native_version(&self) -> &sp_version::NativeVersion { From 9494f765a06037e991dd60524f2ed1b14649bfd6 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 9 Aug 2021 10:46:46 +0200 Subject: [PATCH 06/15] Add a warning for use_native --- client/executor/src/native_executor.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/executor/src/native_executor.rs b/client/executor/src/native_executor.rs index dfd01ec11cc6a..8acc3c182aa70 100644 --- a/client/executor/src/native_executor.rs +++ b/client/executor/src/native_executor.rs @@ -281,9 +281,13 @@ impl CodeExecutor for WasmExecutor { runtime_code: &RuntimeCode, method: &str, data: &[u8], - _use_native: bool, + use_native: bool, _native_call: Option, ) -> (Result>, bool) { + if use_native { + log::warn!("`use_native` is set to `true` when calling the `WasmExecutor`. Ignoring."); + } + let result = self.with_instance( runtime_code, ext, From 14433424df90173dc8a6583fd9668a119e2ae329 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 9 Aug 2021 10:56:00 +0200 Subject: [PATCH 07/15] Run cargo fmt --- client/executor/src/native_executor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/executor/src/native_executor.rs b/client/executor/src/native_executor.rs index 8acc3c182aa70..96f017b5073a6 100644 --- a/client/executor/src/native_executor.rs +++ b/client/executor/src/native_executor.rs @@ -45,7 +45,7 @@ use sp_core::{ }; use sp_externalities::ExternalitiesExt as _; use sp_tasks::new_async_externalities; -use sp_version::{NativeVersion, RuntimeVersion, GetNativeVersion}; +use sp_version::{GetNativeVersion, NativeVersion, RuntimeVersion}; use sp_wasm_interface::{Function, HostFunctions}; /// Default num of pages for the heap From 0287bc9151dc9161e212528460b87974f086a1f6 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 9 Aug 2021 11:29:04 +0200 Subject: [PATCH 08/15] Revert "Add a warning for use_native" This reverts commit 9494f765a06037e991dd60524f2ed1b14649bfd6. --- client/executor/src/native_executor.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/client/executor/src/native_executor.rs b/client/executor/src/native_executor.rs index 96f017b5073a6..51b9a404bbcc4 100644 --- a/client/executor/src/native_executor.rs +++ b/client/executor/src/native_executor.rs @@ -281,13 +281,9 @@ impl CodeExecutor for WasmExecutor { runtime_code: &RuntimeCode, method: &str, data: &[u8], - use_native: bool, + _use_native: bool, _native_call: Option, ) -> (Result>, bool) { - if use_native { - log::warn!("`use_native` is set to `true` when calling the `WasmExecutor`. Ignoring."); - } - let result = self.with_instance( runtime_code, ext, From 76727b975bd1a06fe848723557afa25b97ceee27 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 9 Aug 2021 13:23:23 +0200 Subject: [PATCH 09/15] Make choosing an executor (native/wasm) an explicit part of service construction --- bin/node-template/node/src/service.rs | 20 ++++++-- bin/node/cli/Cargo.toml | 1 + bin/node/cli/src/service.rs | 23 +++++++-- bin/node/inspect/Cargo.toml | 1 + bin/node/inspect/src/command.rs | 9 +++- bin/node/test-runner-example/src/lib.rs | 3 +- client/service/src/builder.rs | 68 ++++++++++--------------- test-utils/test-runner/src/client.rs | 13 +++-- test-utils/test-runner/src/lib.rs | 17 ++++--- test-utils/test-runner/src/node.rs | 9 ++-- 10 files changed, 101 insertions(+), 63 deletions(-) diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index 9eba1d0e9e05f..639faabb7c6e2 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -21,7 +21,7 @@ native_executor_instance!( frame_benchmarking::benchmarking::HostFunctions, ); -type FullClient = sc_service::TFullClient; +type FullClient = sc_service::TFullClient>; type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; @@ -62,10 +62,17 @@ pub fn new_partial( }) .transpose()?; + let executor = NativeExecutor::::new( + config.wasm_method, + config.default_heap_pages, + config.max_runtime_instances, + ); + let (client, backend, keystore_container, task_manager) = - sc_service::new_full_parts::( + sc_service::new_full_parts::( &config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), + executor, )?; let client = Arc::new(client); @@ -330,10 +337,17 @@ pub fn new_light(mut config: Configuration) -> Result }) .transpose()?; + let executor = NativeExecutor::::new( + config.wasm_method, + config.default_heap_pages, + config.max_runtime_instances, + ); + let (client, backend, keystore_container, mut task_manager, on_demand) = - sc_service::new_light_parts::( + sc_service::new_light_parts::( &config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), + executor, )?; let mut telemetry = telemetry.map(|(worker, telemetry)| { diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index 12a76cf323e4b..f3bde3d1dd5df 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -76,6 +76,7 @@ sc-basic-authorship = { version = "0.10.0-dev", path = "../../../client/basic-au sc-service = { version = "0.10.0-dev", default-features = false, path = "../../../client/service" } sc-tracing = { version = "4.0.0-dev", path = "../../../client/tracing" } sc-telemetry = { version = "4.0.0-dev", path = "../../../client/telemetry" } +sc-executor = { version = "0.10.0-dev", path = "../../../client/executor" } sc-authority-discovery = { version = "0.10.0-dev", path = "../../../client/authority-discovery" } # frame dependencies diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index 301df01c55f80..d2c63d11a87a7 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -26,18 +26,19 @@ use node_primitives::Block; use node_runtime::RuntimeApi; use sc_client_api::{ExecutorProvider, RemoteBackend}; use sc_consensus_babe::{self, SlotProportion}; +use sc_executor::NativeExecutor; use sc_network::{Event, NetworkService}; use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager}; use sc_telemetry::{Telemetry, TelemetryWorker}; use sp_runtime::traits::Block as BlockT; use std::sync::Arc; -type FullClient = sc_service::TFullClient; +type FullClient = sc_service::TFullClient>; type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; type FullGrandpaBlockImport = grandpa::GrandpaBlockImport; -type LightClient = sc_service::TLightClient; +type LightClient = sc_service::TLightClient>; pub fn new_partial( config: &Configuration, @@ -72,10 +73,17 @@ pub fn new_partial( }) .transpose()?; + let executor = NativeExecutor::::new( + config.wasm_method, + config.default_heap_pages, + config.max_runtime_instances, + ); + let (client, backend, keystore_container, task_manager) = - sc_service::new_full_parts::( + sc_service::new_full_parts::( &config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), + executor, )?; let client = Arc::new(client); @@ -443,10 +451,17 @@ pub fn new_light_base( }) .transpose()?; + let executor = NativeExecutor::::new( + config.wasm_method, + config.default_heap_pages, + config.max_runtime_instances, + ); + let (client, backend, keystore_container, mut task_manager, on_demand) = - sc_service::new_light_parts::( + sc_service::new_light_parts::( &config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), + executor, )?; let mut telemetry = telemetry.map(|(worker, telemetry)| { diff --git a/bin/node/inspect/Cargo.toml b/bin/node/inspect/Cargo.toml index abd54cdbcd957..1162c3c930ae4 100644 --- a/bin/node/inspect/Cargo.toml +++ b/bin/node/inspect/Cargo.toml @@ -16,6 +16,7 @@ derive_more = "0.99" log = "0.4.8" sc-cli = { version = "0.10.0-dev", path = "../../../client/cli" } sc-client-api = { version = "4.0.0-dev", path = "../../../client/api" } +sc-executor = { version = "0.10.0-dev", path = "../../../client/executor" } sc-service = { version = "0.10.0-dev", default-features = false, path = "../../../client/service" } sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" } sp-core = { version = "4.0.0-dev", path = "../../../primitives/core" } diff --git a/bin/node/inspect/src/command.rs b/bin/node/inspect/src/command.rs index a2c63d684bf96..07860d053f25f 100644 --- a/bin/node/inspect/src/command.rs +++ b/bin/node/inspect/src/command.rs @@ -23,6 +23,7 @@ use crate::{ Inspector, }; use sc_cli::{CliConfiguration, ImportParams, Result, SharedParams}; +use sc_executor::NativeExecutor; use sc_service::{new_full_client, Configuration, NativeExecutionDispatch}; use sp_runtime::traits::Block; use std::str::FromStr; @@ -36,7 +37,13 @@ impl InspectCmd { RA: Send + Sync + 'static, EX: NativeExecutionDispatch + 'static, { - let client = new_full_client::(&config, None)?; + let executor = NativeExecutor::::new( + config.wasm_method, + config.default_heap_pages, + config.max_runtime_instances, + ); + + let client = new_full_client::(&config, None, executor)?; let inspect = Inspector::::new(client); match &self.command { diff --git a/bin/node/test-runner-example/src/lib.rs b/bin/node/test-runner-example/src/lib.rs index f0b306db6b0c1..25e75bedc0b20 100644 --- a/bin/node/test-runner-example/src/lib.rs +++ b/bin/node/test-runner-example/src/lib.rs @@ -22,6 +22,7 @@ use grandpa::GrandpaBlockImport; use sc_consensus_babe::BabeBlockImport; use sc_consensus_manual_seal::consensus::babe::SlotTimestampProvider; +use sc_executor::NativeExecutor; use sc_service::{TFullBackend, TFullClient}; use sp_runtime::generic::Era; use test_runner::{ChainInfo, SignatureVerificationOverride}; @@ -50,7 +51,7 @@ impl ChainInfo for NodeTemplateChainInfo { type BlockImport = BlockImport< Self::Block, TFullBackend, - TFullClient, + TFullClient>, Self::SelectChain, >; type SignedExtras = node_runtime::SignedExtra; diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index e71cf4ecd60f2..7e30cfb8a9b0f 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -37,7 +37,7 @@ use sc_client_api::{ }; use sc_client_db::{Backend, DatabaseSettings}; use sc_consensus::import_queue::ImportQueue; -use sc_executor::{NativeExecutionDispatch, NativeExecutor, RuntimeVersionOf}; +use sc_executor::RuntimeVersionOf; use sc_keystore::LocalKeystore; use sc_network::{ block_request_handler::{self, BlockRequestHandler}, @@ -129,39 +129,39 @@ where } /// Full client type. -pub type TFullClient = - Client, TFullCallExecutor, TBl, TRtApi>; +pub type TFullClient = + Client, TFullCallExecutor, TBl, TRtApi>; /// Full client backend type. pub type TFullBackend = sc_client_db::Backend; /// Full client call executor type. -pub type TFullCallExecutor = - crate::client::LocalCallExecutor, NativeExecutor>; +pub type TFullCallExecutor = + crate::client::LocalCallExecutor, TExec>; /// Light client type. -pub type TLightClient = - TLightClientWithBackend>; +pub type TLightClient = + TLightClientWithBackend>; /// Light client backend type. pub type TLightBackend = sc_light::Backend, HashFor>; /// Light call executor type. -pub type TLightCallExecutor = sc_light::GenesisCallExecutor< +pub type TLightCallExecutor = sc_light::GenesisCallExecutor< sc_light::Backend, HashFor>, crate::client::LocalCallExecutor< TBl, sc_light::Backend, HashFor>, - NativeExecutor, + TExec, >, >; -type TFullParts = - (TFullClient, Arc>, KeystoreContainer, TaskManager); +type TFullParts = + (TFullClient, Arc>, KeystoreContainer, TaskManager); -type TLightParts = ( - Arc>, +type TLightParts = ( + Arc>, Arc>, KeystoreContainer, TaskManager, @@ -173,12 +173,9 @@ pub type TLightBackendWithHash = sc_light::Backend, THash>; /// Light client type with a specific backend. -pub type TLightClientWithBackend = Client< +pub type TLightClientWithBackend = Client< TBackend, - sc_light::GenesisCallExecutor< - TBackend, - crate::client::LocalCallExecutor>, - >, + sc_light::GenesisCallExecutor>, TBl, TRtApi, >; @@ -262,26 +259,28 @@ impl KeystoreContainer { } /// Creates a new full client for the given config. -pub fn new_full_client( +pub fn new_full_client( config: &Configuration, telemetry: Option, -) -> Result, Error> + executor: TExec, +) -> Result, Error> where TBl: BlockT, - TExecDisp: NativeExecutionDispatch + 'static, + TExec: CodeExecutor + RuntimeVersionOf + Clone, TBl::Hash: FromStr, { - new_full_parts(config, telemetry).map(|parts| parts.0) + new_full_parts(config, telemetry, executor).map(|parts| parts.0) } /// Create the initial parts of a full node. -pub fn new_full_parts( +pub fn new_full_parts( config: &Configuration, telemetry: Option, -) -> Result, Error> + executor: TExec, +) -> Result, Error> where TBl: BlockT, - TExecDisp: NativeExecutionDispatch + 'static, + TExec: CodeExecutor + RuntimeVersionOf + Clone, TBl::Hash: FromStr, { let keystore_container = KeystoreContainer::new(&config.keystore)?; @@ -291,12 +290,6 @@ where TaskManager::new(config.task_executor.clone(), registry)? }; - let executor = NativeExecutor::::new( - config.wasm_method, - config.default_heap_pages, - config.max_runtime_instances, - ); - let chain_spec = &config.chain_spec; let fork_blocks = get_extension::>(chain_spec.extensions()) .cloned() @@ -368,13 +361,14 @@ where } /// Create the initial parts of a light node. -pub fn new_light_parts( +pub fn new_light_parts( config: &Configuration, telemetry: Option, -) -> Result, Error> + executor: TExec, +) -> Result, Error> where TBl: BlockT, - TExecDisp: NativeExecutionDispatch + 'static, + TExec: CodeExecutor + RuntimeVersionOf + Clone, { let keystore_container = KeystoreContainer::new(&config.keystore)?; let task_manager = { @@ -382,12 +376,6 @@ where TaskManager::new(config.task_executor.clone(), registry)? }; - let executor = NativeExecutor::::new( - config.wasm_method, - config.default_heap_pages, - config.max_runtime_instances, - ); - let db_storage = { let db_settings = sc_client_db::DatabaseSettings { state_cache_size: config.state_cache_size, diff --git a/test-utils/test-runner/src/client.rs b/test-utils/test-runner/src/client.rs index d130993bff4c7..ea07af0b0edae 100644 --- a/test-utils/test-runner/src/client.rs +++ b/test-utils/test-runner/src/client.rs @@ -26,6 +26,7 @@ use manual_seal::{ run_manual_seal, EngineCommand, ManualSealParams, }; use sc_client_api::backend::Backend; +use sc_executor::NativeExecutor; use sc_service::{ build_network, new_full_parts, spawn_tasks, BuildNetworkParams, ChainSpec, Configuration, SpawnTasksParams, TFullBackend, TFullClient, TaskExecutor, TaskManager, @@ -50,7 +51,7 @@ type ClientParts = ( TFullClient< ::Block, ::RuntimeApi, - ::Executor, + NativeExecutor<::Executor>, >, >, Arc< @@ -83,7 +84,7 @@ where T: ChainInfo + 'static, , + TFullClient>, >>::RuntimeApi: Core + Metadata + OffchainWorkerApi @@ -105,8 +106,14 @@ where default_config(task_executor, chain_spec), }; + let executor = NativeExecutor::::new( + config.wasm_method, + config.default_heap_pages, + config.max_runtime_instances, + ); + let (client, backend, keystore, mut task_manager) = - new_full_parts::(&config, None)?; + new_full_parts::(&config, None, executor)?; let client = Arc::new(client); let select_chain = sc_consensus::LongestChain::new(backend.clone()); diff --git a/test-utils/test-runner/src/lib.rs b/test-utils/test-runner/src/lib.rs index 9f0a8d5d6cb6a..ca3959ca07119 100644 --- a/test-utils/test-runner/src/lib.rs +++ b/test-utils/test-runner/src/lib.rs @@ -86,7 +86,7 @@ //! type BlockImport = BlockImport< //! Self::Block, //! TFullBackend, -//! TFullClient, +//! TFullClient>, //! Self::SelectChain, //! >; //! /// and a dash of SignedExtensions @@ -112,7 +112,7 @@ //! /// The function signature tells you all you need to know. ;) //! fn create_client_parts(config: &Configuration) -> Result< //! ( -//! Arc>, +//! Arc>>, //! Arc>, //! KeyStorePtr, //! TaskManager, @@ -121,7 +121,7 @@ //! dyn ConsensusDataProvider< //! Self::Block, //! Transaction = TransactionFor< -//! TFullClient, +//! TFullClient>, //! Self::Block //! >, //! > @@ -136,7 +136,7 @@ //! backend, //! keystore, //! task_manager, -//! ) = new_full_parts::(config)?; +//! ) = new_full_parts::>(config)?; //! let client = Arc::new(client); //! //! let inherent_providers = InherentDataProviders::new(); @@ -228,7 +228,7 @@ //! ``` use sc_consensus::BlockImport; -use sc_executor::NativeExecutionDispatch; +use sc_executor::{NativeExecutionDispatch, NativeExecutor}; use sc_service::TFullClient; use sp_api::{ConstructRuntimeApi, TransactionFor}; use sp_consensus::SelectChain; @@ -260,7 +260,10 @@ pub trait ChainInfo: Sized { type RuntimeApi: Send + Sync + 'static - + ConstructRuntimeApi>; + + ConstructRuntimeApi< + Self::Block, + TFullClient>, + >; /// select chain type. type SelectChain: SelectChain + 'static; @@ -273,7 +276,7 @@ pub trait ChainInfo: Sized { Self::Block, Error = sp_consensus::Error, Transaction = TransactionFor< - TFullClient, + TFullClient>, Self::Block, >, > + 'static; diff --git a/test-utils/test-runner/src/node.rs b/test-utils/test-runner/src/node.rs index 83fc23681345d..d9dbf15c05d64 100644 --- a/test-utils/test-runner/src/node.rs +++ b/test-utils/test-runner/src/node.rs @@ -29,6 +29,7 @@ use sc_client_api::{ backend::{self, Backend}, CallExecutor, ExecutorProvider, }; +use sc_executor::NativeExecutor; use sc_service::{TFullBackend, TFullCallExecutor, TFullClient, TaskManager}; use sc_transaction_pool_api::TransactionPool; use sp_api::{OverlayedChanges, StorageTransactionCache}; @@ -51,7 +52,7 @@ pub struct Node { /// handle to the running node. task_manager: Option, /// client instance - client: Arc>, + client: Arc>>, /// transaction pool pool: Arc< dyn TransactionPool< @@ -86,7 +87,7 @@ where pub fn new( rpc_handler: Arc>, task_manager: TaskManager, - client: Arc>, + client: Arc>>, pool: Arc< dyn TransactionPool< Block = ::Block, @@ -126,14 +127,14 @@ where } /// Return a reference to the Client - pub fn client(&self) -> Arc> { + pub fn client(&self) -> Arc>> { self.client.clone() } /// Executes closure in an externalities provided environment. pub fn with_state(&self, closure: impl FnOnce() -> R) -> R where - as CallExecutor>::Error: + > as CallExecutor>::Error: std::fmt::Debug, { let id = BlockId::Hash(self.client.info().best_hash); From 4603a7b66807e00c5eea4dbe3cde139ce9697977 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 9 Aug 2021 14:29:29 +0200 Subject: [PATCH 10/15] Add Cargo.lock --- Cargo.lock | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 11359c078140b..9bcdbecf2d944 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4215,6 +4215,7 @@ dependencies = [ "sc-consensus-epochs", "sc-consensus-slots", "sc-consensus-uncles", + "sc-executor", "sc-finality-grandpa", "sc-keystore", "sc-network", @@ -4299,6 +4300,7 @@ dependencies = [ "parity-scale-codec", "sc-cli", "sc-client-api", + "sc-executor", "sc-service", "sp-blockchain", "sp-core", From 9b0c1d462eea4cc88d8fbc9cd850780bd9ef0794 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Mon, 16 Aug 2021 17:15:41 +0200 Subject: [PATCH 11/15] Rename Executor to ExecutorDispatch --- bin/node-template/node/src/command.rs | 2 +- bin/node-template/node/src/service.rs | 9 +++--- bin/node/cli/src/command.rs | 6 ++-- bin/node/cli/src/service.rs | 12 ++++---- bin/node/executor/benches/bench.rs | 6 ++-- bin/node/executor/src/lib.rs | 2 +- bin/node/executor/tests/common.rs | 4 +-- bin/node/test-runner-example/src/lib.rs | 6 ++-- bin/node/testing/src/client.rs | 6 ++-- client/executor/src/lib.rs | 2 +- client/executor/src/native_executor.rs | 9 +++--- client/network/test/src/lib.rs | 2 +- client/service/src/client/call_executor.rs | 4 +-- client/service/src/client/wasm_override.rs | 8 +++--- client/service/test/src/client/light.rs | 4 +-- client/service/test/src/client/mod.rs | 8 +++--- primitives/api/test/tests/runtime_calls.rs | 2 +- test-utils/client/src/lib.rs | 32 +++++++++++----------- test-utils/runtime/client/src/lib.rs | 20 +++++++------- test-utils/test-runner/src/client.rs | 6 ++-- test-utils/test-runner/src/lib.rs | 22 +++++++-------- test-utils/test-runner/src/node.rs | 8 +++--- 22 files changed, 92 insertions(+), 88 deletions(-) diff --git a/bin/node-template/node/src/command.rs b/bin/node-template/node/src/command.rs index b4f0a1804f66c..1e7e4edb79950 100644 --- a/bin/node-template/node/src/command.rs +++ b/bin/node-template/node/src/command.rs @@ -119,7 +119,7 @@ pub fn run() -> sc_cli::Result<()> { if cfg!(feature = "runtime-benchmarks") { let runner = cli.create_runner(cmd)?; - runner.sync_run(|config| cmd.run::(config)) + runner.sync_run(|config| cmd.run::(config)) } else { Err("Benchmarking wasn't enabled when building the node. You can enable it with \ `--features runtime-benchmarks`." diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index cc7e4ad075587..12f4abbb652ee 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -15,13 +15,14 @@ use std::{sync::Arc, time::Duration}; // Our native executor instance. native_executor_instance!( - pub Executor, + pub ExecutorDispatch, node_template_runtime::api::dispatch, node_template_runtime::native_version, frame_benchmarking::benchmarking::HostFunctions, ); -type FullClient = sc_service::TFullClient>; +type FullClient = + sc_service::TFullClient>; type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; @@ -62,7 +63,7 @@ pub fn new_partial( }) .transpose()?; - let executor = NativeElseWasmExecutor::::new( + let executor = NativeElseWasmExecutor::::new( config.wasm_method, config.default_heap_pages, config.max_runtime_instances, @@ -337,7 +338,7 @@ pub fn new_light(mut config: Configuration) -> Result }) .transpose()?; - let executor = NativeElseWasmExecutor::::new( + let executor = NativeElseWasmExecutor::::new( config.wasm_method, config.default_heap_pages, config.max_runtime_instances, diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index b904ea99e8f9f..d8ec146526077 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -17,7 +17,7 @@ // along with this program. If not, see . use crate::{chain_spec, service, service::new_partial, Cli, Subcommand}; -use node_executor::Executor; +use node_executor::ExecutorDispatch; use node_runtime::{Block, RuntimeApi}; use sc_cli::{ChainSpec, Result, Role, RuntimeVersion, SubstrateCli}; use sc_service::PartialComponents; @@ -87,13 +87,13 @@ pub fn run() -> Result<()> { Some(Subcommand::Inspect(cmd)) => { let runner = cli.create_runner(cmd)?; - runner.sync_run(|config| cmd.run::(config)) + runner.sync_run(|config| cmd.run::(config)) }, Some(Subcommand::Benchmark(cmd)) => if cfg!(feature = "runtime-benchmarks") { let runner = cli.create_runner(cmd)?; - runner.sync_run(|config| cmd.run::(config)) + runner.sync_run(|config| cmd.run::(config)) } else { Err("Benchmarking wasn't enabled when building the node. \ You can enable it with `--features runtime-benchmarks`." diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index 9ec824a3e2ffd..fcf25d4886556 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -21,7 +21,7 @@ //! Service implementation. Specialized wrapper over substrate service. use futures::prelude::*; -use node_executor::Executor; +use node_executor::ExecutorDispatch; use node_primitives::Block; use node_runtime::RuntimeApi; use sc_client_api::{ExecutorProvider, RemoteBackend}; @@ -33,12 +33,14 @@ use sc_telemetry::{Telemetry, TelemetryWorker}; use sp_runtime::traits::Block as BlockT; use std::sync::Arc; -type FullClient = sc_service::TFullClient>; +type FullClient = + sc_service::TFullClient>; type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; type FullGrandpaBlockImport = grandpa::GrandpaBlockImport; -type LightClient = sc_service::TLightClient>; +type LightClient = + sc_service::TLightClient>; pub fn new_partial( config: &Configuration, @@ -76,7 +78,7 @@ pub fn new_partial( }) .transpose()?; - let executor = NativeElseWasmExecutor::::new( + let executor = NativeElseWasmExecutor::::new( config.wasm_method, config.default_heap_pages, config.max_runtime_instances, @@ -460,7 +462,7 @@ pub fn new_light_base( }) .transpose()?; - let executor = NativeElseWasmExecutor::::new( + let executor = NativeElseWasmExecutor::::new( config.wasm_method, config.default_heap_pages, config.max_runtime_instances, diff --git a/bin/node/executor/benches/bench.rs b/bin/node/executor/benches/bench.rs index 81ac42a263ef6..0058a5c70340f 100644 --- a/bin/node/executor/benches/bench.rs +++ b/bin/node/executor/benches/bench.rs @@ -18,7 +18,7 @@ use codec::{Decode, Encode}; use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; use frame_support::Hashable; -use node_executor::Executor; +use node_executor::ExecutorDispatch; use node_primitives::{BlockNumber, Hash}; use node_runtime::{ constants::currency::*, Block, BuildStorage, Call, CheckedExtrinsic, GenesisConfig, Header, @@ -77,7 +77,7 @@ fn new_test_ext(genesis_config: &GenesisConfig) -> TestExternalities( - executor: &NativeElseWasmExecutor, + executor: &NativeElseWasmExecutor, ext: &mut E, number: BlockNumber, parent_hash: Hash, @@ -157,7 +157,7 @@ fn construct_block( fn test_blocks( genesis_config: &GenesisConfig, - executor: &NativeElseWasmExecutor, + executor: &NativeElseWasmExecutor, ) -> Vec<(Vec, Hash)> { let mut test_ext = new_test_ext(genesis_config); let mut block1_extrinsics = vec![CheckedExtrinsic { diff --git a/bin/node/executor/src/lib.rs b/bin/node/executor/src/lib.rs index 0e56ae718f696..b4ed54ec4aad6 100644 --- a/bin/node/executor/src/lib.rs +++ b/bin/node/executor/src/lib.rs @@ -24,7 +24,7 @@ pub use sc_executor::NativeElseWasmExecutor; // Declare an instance of the native executor named `Executor`. Include the wasm binary as the // equivalent wasm code. native_executor_instance!( - pub Executor, + pub ExecutorDispatch, node_runtime::api::dispatch, node_runtime::native_version, frame_benchmarking::benchmarking::HostFunctions, diff --git a/bin/node/executor/tests/common.rs b/bin/node/executor/tests/common.rs index e2ccd45c87cdd..d4b7edfe5ca90 100644 --- a/bin/node/executor/tests/common.rs +++ b/bin/node/executor/tests/common.rs @@ -35,7 +35,7 @@ use sp_runtime::{ }; use sp_state_machine::TestExternalities as CoreTestExternalities; -use node_executor::Executor; +use node_executor::ExecutorDispatch; use node_primitives::{BlockNumber, Hash}; use node_runtime::{ constants::currency::*, Block, BuildStorage, CheckedExtrinsic, Header, Runtime, @@ -96,7 +96,7 @@ pub fn from_block_number(n: u32) -> Header { Header::new(n, Default::default(), Default::default(), [69; 32].into(), Default::default()) } -pub fn executor() -> NativeElseWasmExecutor { +pub fn executor() -> NativeElseWasmExecutor { NativeElseWasmExecutor::new(WasmExecutionMethod::Interpreted, None, 8) } diff --git a/bin/node/test-runner-example/src/lib.rs b/bin/node/test-runner-example/src/lib.rs index a8aa8ba912d0a..a569b4ad0db0c 100644 --- a/bin/node/test-runner-example/src/lib.rs +++ b/bin/node/test-runner-example/src/lib.rs @@ -30,7 +30,7 @@ use test_runner::{ChainInfo, SignatureVerificationOverride}; type BlockImport = BabeBlockImport>; sc_executor::native_executor_instance!( - pub Executor, + pub ExecutorDispatch, node_runtime::api::dispatch, node_runtime::native_version, ( @@ -44,14 +44,14 @@ struct NodeTemplateChainInfo; impl ChainInfo for NodeTemplateChainInfo { type Block = node_primitives::Block; - type Executor = Executor; + type ExecutorDispatch = ExecutorDispatch; type Runtime = node_runtime::Runtime; type RuntimeApi = node_runtime::RuntimeApi; type SelectChain = sc_consensus::LongestChain, Self::Block>; type BlockImport = BlockImport< Self::Block, TFullBackend, - TFullClient>, + TFullClient>, Self::SelectChain, >; type SignedExtras = node_runtime::SignedExtra; diff --git a/bin/node/testing/src/client.rs b/bin/node/testing/src/client.rs index ce69ded7043f8..8bd75834c5496 100644 --- a/bin/node/testing/src/client.rs +++ b/bin/node/testing/src/client.rs @@ -24,7 +24,7 @@ use sp_runtime::BuildStorage; pub use substrate_test_client::*; /// Call executor for `node-runtime` `TestClient`. -pub type Executor = sc_executor::NativeElseWasmExecutor; +pub type ExecutorDispatch = sc_executor::NativeElseWasmExecutor; /// Default backend type. pub type Backend = sc_client_db::Backend; @@ -32,7 +32,7 @@ pub type Backend = sc_client_db::Backend; /// Test client type. pub type Client = client::Client< Backend, - client::LocalCallExecutor, + client::LocalCallExecutor, node_primitives::Block, node_runtime::RuntimeApi, >; @@ -64,7 +64,7 @@ pub trait TestClientBuilderExt: Sized { impl TestClientBuilderExt for substrate_test_client::TestClientBuilder< node_primitives::Block, - client::LocalCallExecutor, + client::LocalCallExecutor, Backend, GenesisParameters, > diff --git a/client/executor/src/lib.rs b/client/executor/src/lib.rs index 11619f116ce7e..041db87bc82ab 100644 --- a/client/executor/src/lib.rs +++ b/client/executor/src/lib.rs @@ -39,7 +39,7 @@ mod wasm_runtime; pub use codec::Codec; pub use native_executor::{ - with_externalities_safe, NativeExecutionDispatch, NativeElseWasmExecutor, WasmExecutor, + with_externalities_safe, NativeElseWasmExecutor, NativeExecutionDispatch, WasmExecutor, }; #[doc(hidden)] pub use sp_core::traits::Externalities; diff --git a/client/executor/src/native_executor.rs b/client/executor/src/native_executor.rs index 205c0eaebbe07..6226374e4d425 100644 --- a/client/executor/src/native_executor.rs +++ b/client/executor/src/native_executor.rs @@ -612,7 +612,7 @@ impl sp_core::traits::ReadRuntimeVersion for NativeE /// /// ``` /// sc_executor::native_executor_instance!( -/// pub MyExecutor, +/// pub MyExecutorDispatch, /// substrate_test_runtime::api::dispatch, /// substrate_test_runtime::native_version, /// ); @@ -634,7 +634,7 @@ impl sp_core::traits::ReadRuntimeVersion for NativeE /// } /// /// sc_executor::native_executor_instance!( -/// pub MyExecutor, +/// pub MyExecutorDispatch, /// substrate_test_runtime::api::dispatch, /// substrate_test_runtime::native_version, /// my_interface::HostFunctions, @@ -692,7 +692,7 @@ mod tests { } native_executor_instance!( - pub MyExecutor, + pub MyExecutorDispatch, substrate_test_runtime::api::dispatch, substrate_test_runtime::native_version, (my_interface::HostFunctions, my_interface::HostFunctions), @@ -700,7 +700,8 @@ mod tests { #[test] fn native_executor_registers_custom_interface() { - let executor = NativeElseWasmExecutor::::new(WasmExecutionMethod::Interpreted, None, 8); + let executor = + NativeElseWasmExecutor::::new(WasmExecutionMethod::Interpreted, None, 8); my_interface::HostFunctions::host_functions().iter().for_each(|function| { assert_eq!(executor.wasm.host_functions.iter().filter(|f| f == &function).count(), 2); }); diff --git a/client/network/test/src/lib.rs b/client/network/test/src/lib.rs index 7668aa8fd56e3..bb49cef8c642c 100644 --- a/client/network/test/src/lib.rs +++ b/client/network/test/src/lib.rs @@ -126,7 +126,7 @@ impl Verifier for PassThroughVerifier { pub type PeersFullClient = Client< substrate_test_runtime_client::Backend, - substrate_test_runtime_client::Executor, + substrate_test_runtime_client::ExecutorDispatch, Block, substrate_test_runtime_client::runtime::RuntimeApi, >; diff --git a/client/service/src/client/call_executor.rs b/client/service/src/client/call_executor.rs index 6055e674c2227..ee67e1a3ea145 100644 --- a/client/service/src/client/call_executor.rs +++ b/client/service/src/client/call_executor.rs @@ -365,12 +365,12 @@ mod tests { testing::TaskExecutor, traits::{FetchRuntimeCode, WrappedRuntimeCode}, }; - use substrate_test_runtime_client::{runtime, GenesisInit, LocalExecutor}; + use substrate_test_runtime_client::{runtime, GenesisInit, LocalExecutorDispatch}; #[test] fn should_get_override_if_exists() { let executor = - NativeElseWasmExecutor::::new(WasmExecutionMethod::Interpreted, Some(128), 1); + NativeElseWasmExecutor::::new(WasmExecutionMethod::Interpreted, Some(128), 1); let overrides = crate::client::wasm_override::dummy_overrides(&executor); let onchain_code = WrappedRuntimeCode(substrate_test_runtime::wasm_binary_unwrap().into()); diff --git a/client/service/src/client/wasm_override.rs b/client/service/src/client/wasm_override.rs index 13cd6c0cf7960..0c3116334d458 100644 --- a/client/service/src/client/wasm_override.rs +++ b/client/service/src/client/wasm_override.rs @@ -206,13 +206,13 @@ mod tests { use super::*; use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod}; use std::fs::{self, File}; - use substrate_test_runtime_client::LocalExecutor; + use substrate_test_runtime_client::LocalExecutorDispatch; fn wasm_test(fun: F) where - F: Fn(&Path, &[u8], &NativeElseWasmExecutor), + F: Fn(&Path, &[u8], &NativeElseWasmExecutor), { - let exec = NativeElseWasmExecutor::::new( + let exec = NativeElseWasmExecutor::::new( WasmExecutionMethod::Interpreted, Some(128), 1, @@ -227,7 +227,7 @@ mod tests { fn should_get_runtime_version() { let wasm = WasmBlob::new(substrate_test_runtime::wasm_binary_unwrap().to_vec()); let executor = - NativeElseWasmExecutor::::new(WasmExecutionMethod::Interpreted, Some(128), 1); + NativeElseWasmExecutor::::new(WasmExecutionMethod::Interpreted, Some(128), 1); let version = WasmOverride::runtime_version(&executor, &wasm, Some(128)) .expect("should get the `RuntimeVersion` of the test-runtime wasm blob"); diff --git a/client/service/test/src/client/light.rs b/client/service/test/src/client/light.rs index ba3d28c31b93e..ac188ed32a4c6 100644 --- a/client/service/test/src/client/light.rs +++ b/client/service/test/src/client/light.rs @@ -258,7 +258,7 @@ impl CallExecutor for DummyCallExecutor { } } -fn local_executor() -> NativeElseWasmExecutor { +fn local_executor() -> NativeElseWasmExecutor { NativeElseWasmExecutor::new(WasmExecutionMethod::Interpreted, None, 8) } @@ -446,7 +446,7 @@ fn code_is_executed_at_genesis_only() { } type TestChecker = LightDataChecker< - NativeElseWasmExecutor, + NativeElseWasmExecutor, Block, DummyStorage, >; diff --git a/client/service/test/src/client/mod.rs b/client/service/test/src/client/mod.rs index ee3a12c5458ca..04f7b75064ef1 100644 --- a/client/service/test/src/client/mod.rs +++ b/client/service/test/src/client/mod.rs @@ -64,19 +64,19 @@ mod light; const TEST_ENGINE_ID: ConsensusEngineId = *b"TEST"; native_executor_instance!( - Executor, + ExecutorDispatch, substrate_test_runtime_client::runtime::api::dispatch, substrate_test_runtime_client::runtime::native_version, ); -fn executor() -> sc_executor::NativeElseWasmExecutor { +fn executor() -> sc_executor::NativeElseWasmExecutor { sc_executor::NativeElseWasmExecutor::new(sc_executor::WasmExecutionMethod::Interpreted, None, 8) } pub fn prepare_client_with_key_changes() -> ( client::Client< substrate_test_runtime_client::Backend, - substrate_test_runtime_client::Executor, + substrate_test_runtime_client::ExecutorDispatch, Block, RuntimeApi, >, @@ -2099,7 +2099,7 @@ fn cleans_up_closed_notification_sinks_on_block_import() { LocalCallExecutor< Block, in_mem::Backend, - sc_executor::NativeElseWasmExecutor, + sc_executor::NativeElseWasmExecutor, >, substrate_test_runtime_client::runtime::Block, substrate_test_runtime_client::runtime::RuntimeApi, diff --git a/primitives/api/test/tests/runtime_calls.rs b/primitives/api/test/tests/runtime_calls.rs index 2530a1c98d033..4dff23a0675d8 100644 --- a/primitives/api/test/tests/runtime_calls.rs +++ b/primitives/api/test/tests/runtime_calls.rs @@ -206,7 +206,7 @@ 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); + let executor = NativeElseWasmExecutor::::new(WasmExecutionMethod::Interpreted, None, 8); execution_proof_check_on_trie_backend::<_, u64, _, _>( &backend, &mut overlay, diff --git a/test-utils/client/src/lib.rs b/test-utils/client/src/lib.rs index d3ede71623b99..a38b7ad09d771 100644 --- a/test-utils/client/src/lib.rs +++ b/test-utils/client/src/lib.rs @@ -73,14 +73,14 @@ impl GenesisInit for () { } /// A builder for creating a test client instance. -pub struct TestClientBuilder { +pub struct TestClientBuilder { execution_strategies: ExecutionStrategies, genesis_init: G, /// The key is an unprefixed storage key, this only contains /// default child trie content. child_storage_extension: HashMap, StorageChild>, backend: Arc, - _executor: std::marker::PhantomData, + _executor: std::marker::PhantomData, keystore: Option, fork_blocks: ForkBlocks, bad_blocks: BadBlocks, @@ -88,16 +88,16 @@ pub struct TestClientBuilder { no_genesis: bool, } -impl Default - for TestClientBuilder, G> +impl Default + for TestClientBuilder, G> { fn default() -> Self { Self::with_default_backend() } } -impl - TestClientBuilder, G> +impl + TestClientBuilder, G> { /// Create new `TestClientBuilder` with default backend. pub fn with_default_backend() -> Self { @@ -122,8 +122,8 @@ impl } } -impl - TestClientBuilder +impl + TestClientBuilder { /// Create a new instance of the test client builder. pub fn with_backend(backend: Arc) -> Self { @@ -210,13 +210,13 @@ impl /// Build the test client with the given native executor. pub fn build_with_executor( self, - executor: Executor, + executor: ExecutorDispatch, ) -> ( - client::Client, + client::Client, sc_consensus::LongestChain, ) where - Executor: sc_client_api::CallExecutor + 'static, + ExecutorDispatch: sc_client_api::CallExecutor + 'static, Backend: sc_client_api::backend::Backend, >::OffchainStorage: 'static, { @@ -264,8 +264,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( @@ -274,15 +274,15 @@ impl ) -> ( client::Client< Backend, - client::LocalCallExecutor>, + client::LocalCallExecutor>, Block, RuntimeApi, >, sc_consensus::LongestChain, ) where - I: Into>>, - E: sc_executor::NativeExecutionDispatch + 'static, + I: Into>>, + D: sc_executor::NativeExecutionDispatch + 'static, Backend: sc_client_api::backend::Backend + 'static, { let executor = executor diff --git a/test-utils/runtime/client/src/lib.rs b/test-utils/runtime/client/src/lib.rs index 5152fca4eaac6..85fbdb14ea50a 100644 --- a/test-utils/runtime/client/src/lib.rs +++ b/test-utils/runtime/client/src/lib.rs @@ -51,7 +51,7 @@ pub mod prelude { }; // Client structs pub use super::{ - Backend, Executor, LightBackend, LightExecutor, LocalExecutor, NativeElseWasmExecutor, TestClient, + Backend, ExecutorDispatch, LightBackend, LightExecutor, LocalExecutorDispatch, NativeElseWasmExecutor, TestClient, TestClientBuilder, WasmExecutionMethod, }; // Keyring @@ -59,7 +59,7 @@ pub mod prelude { } sc_executor::native_executor_instance! { - pub LocalExecutor, + pub LocalExecutorDispatch, substrate_test_runtime::api::dispatch, substrate_test_runtime::native_version, } @@ -68,10 +68,10 @@ sc_executor::native_executor_instance! { pub type Backend = substrate_test_client::Backend; /// Test client executor. -pub type Executor = client::LocalCallExecutor< +pub type ExecutorDispatch = client::LocalCallExecutor< substrate_test_runtime::Block, Backend, - NativeElseWasmExecutor, + NativeElseWasmExecutor, >; /// Test client light database backend. @@ -86,7 +86,7 @@ pub type LightExecutor = sc_light::GenesisCallExecutor< sc_client_db::light::LightStorage, HashFor, >, - NativeElseWasmExecutor, + NativeElseWasmExecutor, >, >; @@ -164,13 +164,13 @@ pub type TestClientBuilder = substrate_test_client::TestClientBuilder< GenesisParameters, >; -/// Test client type with `LocalExecutor` and generic Backend. +/// Test client type with `LocalExecutorDispatch` and generic Backend. pub type Client = client::Client< B, client::LocalCallExecutor< substrate_test_runtime::Block, B, - sc_executor::NativeElseWasmExecutor, + sc_executor::NativeElseWasmExecutor, >, substrate_test_runtime::Block, substrate_test_runtime::RuntimeApi, @@ -185,7 +185,7 @@ pub trait DefaultTestClientBuilderExt: Sized { fn new() -> Self; } -impl DefaultTestClientBuilderExt for TestClientBuilder { +impl DefaultTestClientBuilderExt for TestClientBuilder { fn new() -> Self { Self::with_default_backend() } @@ -267,7 +267,7 @@ impl TestClientBuilderExt client::LocalCallExecutor< substrate_test_runtime::Block, B, - sc_executor::NativeElseWasmExecutor, + sc_executor::NativeElseWasmExecutor, >, B, > where @@ -426,6 +426,6 @@ pub fn new_light_fetcher() -> LightFetcher { } /// Create a new native executor. -pub fn new_native_executor() -> sc_executor::NativeElseWasmExecutor { +pub fn new_native_executor() -> sc_executor::NativeElseWasmExecutor { sc_executor::NativeElseWasmExecutor::new(sc_executor::WasmExecutionMethod::Interpreted, None, 8) } diff --git a/test-utils/test-runner/src/client.rs b/test-utils/test-runner/src/client.rs index fc87afc59a544..6622c1f919428 100644 --- a/test-utils/test-runner/src/client.rs +++ b/test-utils/test-runner/src/client.rs @@ -51,7 +51,7 @@ type ClientParts = ( TFullClient< ::Block, ::RuntimeApi, - NativeElseWasmExecutor<::Executor>, + NativeElseWasmExecutor<::ExecutorDispatch>, >, >, Arc< @@ -84,7 +84,7 @@ where T: ChainInfo + 'static, >, + TFullClient>, >>::RuntimeApi: Core + Metadata + OffchainWorkerApi @@ -107,7 +107,7 @@ where default_config(task_executor, chain_spec), }; - let executor = NativeElseWasmExecutor::::new( + let executor = NativeElseWasmExecutor::::new( config.wasm_method, config.default_heap_pages, config.max_runtime_instances, diff --git a/test-utils/test-runner/src/lib.rs b/test-utils/test-runner/src/lib.rs index c6bc7b9bc1c81..4f90b1ecfcbb4 100644 --- a/test-utils/test-runner/src/lib.rs +++ b/test-utils/test-runner/src/lib.rs @@ -63,7 +63,7 @@ //! type BlockImport = BabeBlockImport>; //! //! sc_executor::native_executor_instance!( -//! pub Executor, +//! pub ExecutorDispatch, //! node_runtime::api::dispatch, //! node_runtime::native_version, //! SignatureVerificationOverride, @@ -74,8 +74,8 @@ //! impl ChainInfo for Requirements { //! /// Provide a Block type with an OpaqueExtrinsic //! type Block = node_primitives::Block; -//! /// Provide an Executor type for the runtime -//! type Executor = Executor; +//! /// Provide an ExecutorDispatch type for the runtime +//! type ExecutorDispatch = ExecutorDispatch; //! /// Provide the runtime itself //! type Runtime = node_runtime::Runtime; //! /// A touch of runtime api @@ -86,7 +86,7 @@ //! type BlockImport = BlockImport< //! Self::Block, //! TFullBackend, -//! TFullClient>, +//! TFullClient>, //! Self::SelectChain, //! >; //! /// and a dash of SignedExtensions @@ -112,7 +112,7 @@ //! /// The function signature tells you all you need to know. ;) //! fn create_client_parts(config: &Configuration) -> Result< //! ( -//! Arc>>, +//! Arc>>, //! Arc>, //! KeyStorePtr, //! TaskManager, @@ -121,7 +121,7 @@ //! dyn ConsensusDataProvider< //! Self::Block, //! Transaction = TransactionFor< -//! TFullClient>, +//! TFullClient>, //! Self::Block //! >, //! > @@ -136,7 +136,7 @@ //! backend, //! keystore, //! task_manager, -//! ) = new_full_parts::>(config)?; +//! ) = new_full_parts::>(config)?; //! let client = Arc::new(client); //! //! let inherent_providers = InherentDataProviders::new(); @@ -250,8 +250,8 @@ pub trait ChainInfo: Sized { /// Opaque block type type Block: BlockT; - /// Executor type - type Executor: NativeExecutionDispatch + 'static; + /// ExecutorDispatch dispatch type + type ExecutorDispatch: NativeExecutionDispatch + 'static; /// Runtime type Runtime: frame_system::Config; @@ -262,7 +262,7 @@ pub trait ChainInfo: Sized { + 'static + ConstructRuntimeApi< Self::Block, - TFullClient>, + TFullClient>, >; /// select chain type. @@ -276,7 +276,7 @@ pub trait ChainInfo: Sized { Self::Block, Error = sp_consensus::Error, Transaction = TransactionFor< - TFullClient>, + TFullClient>, Self::Block, >, > + 'static; diff --git a/test-utils/test-runner/src/node.rs b/test-utils/test-runner/src/node.rs index 330a186b2b9e2..dc395139b6e45 100644 --- a/test-utils/test-runner/src/node.rs +++ b/test-utils/test-runner/src/node.rs @@ -52,7 +52,7 @@ pub struct Node { /// handle to the running node. task_manager: Option, /// client instance - client: Arc>>, + client: Arc>>, /// transaction pool pool: Arc< dyn TransactionPool< @@ -87,7 +87,7 @@ where pub fn new( rpc_handler: Arc>, task_manager: TaskManager, - client: Arc>>, + client: Arc>>, pool: Arc< dyn TransactionPool< Block = ::Block, @@ -127,7 +127,7 @@ where } /// Return a reference to the Client - pub fn client(&self) -> Arc>> { + pub fn client(&self) -> Arc>> { self.client.clone() } @@ -151,7 +151,7 @@ where /// Executes closure in an externalities provided environment. pub fn with_state(&self, closure: impl FnOnce() -> R) -> R where - > as CallExecutor>::Error: + > as CallExecutor>::Error: std::fmt::Debug, { let id = BlockId::Hash(self.client.info().best_hash); From a617b9dcd30d227df4b5a86c823e2ae634c92d77 Mon Sep 17 00:00:00 2001 From: Ashley Date: Tue, 17 Aug 2021 12:17:03 +0200 Subject: [PATCH 12/15] Update bin/node/executor/src/lib.rs Co-authored-by: Squirrel --- bin/node/executor/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/executor/src/lib.rs b/bin/node/executor/src/lib.rs index c3a74d336f12f..313b6331bfe0a 100644 --- a/bin/node/executor/src/lib.rs +++ b/bin/node/executor/src/lib.rs @@ -20,7 +20,7 @@ pub use sc_executor::NativeExecutor; -// Declare an instance of the native executor named `Executor`. Include the wasm binary as the +// Declare an instance of the native executor named `ExecutorDispatch`. Include the wasm binary as the // equivalent wasm code. pub struct ExecutorDispatch; From f0cc61c682d0e7beda5e7aa9bb791d25c476bdfb Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Tue, 17 Aug 2021 12:23:32 +0200 Subject: [PATCH 13/15] Fix tests --- bin/node/executor/src/lib.rs | 4 ++-- client/consensus/babe/src/tests.rs | 2 +- primitives/api/test/tests/decl_and_impl.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/node/executor/src/lib.rs b/bin/node/executor/src/lib.rs index 313b6331bfe0a..6905e0f76c15f 100644 --- a/bin/node/executor/src/lib.rs +++ b/bin/node/executor/src/lib.rs @@ -20,8 +20,8 @@ pub use sc_executor::NativeExecutor; -// Declare an instance of the native executor named `ExecutorDispatch`. Include the wasm binary as the -// equivalent wasm code. +// Declare an instance of the native executor named `ExecutorDispatch`. Include the wasm binary as +// the equivalent wasm code. pub struct ExecutorDispatch; impl sc_executor::NativeExecutionDispatch for ExecutorDispatch { diff --git a/client/consensus/babe/src/tests.rs b/client/consensus/babe/src/tests.rs index 4b4e0a9d0f3d3..c033f4535be0b 100644 --- a/client/consensus/babe/src/tests.rs +++ b/client/consensus/babe/src/tests.rs @@ -55,7 +55,7 @@ type Error = sp_blockchain::Error; type TestClient = substrate_test_runtime_client::client::Client< substrate_test_runtime_client::Backend, - substrate_test_runtime_client::Executor, + substrate_test_runtime_client::ExecutorDispatch, TestBlock, substrate_test_runtime_client::runtime::RuntimeApi, >; diff --git a/primitives/api/test/tests/decl_and_impl.rs b/primitives/api/test/tests/decl_and_impl.rs index ae24ed1cb8fec..8d1b04a37a9fa 100644 --- a/primitives/api/test/tests/decl_and_impl.rs +++ b/primitives/api/test/tests/decl_and_impl.rs @@ -136,7 +136,7 @@ mock_impl_runtime_apis! { type TestClient = substrate_test_runtime_client::client::Client< substrate_test_runtime_client::Backend, - substrate_test_runtime_client::Executor, + substrate_test_runtime_client::ExecutorDispatch, Block, RuntimeApi, >; From 80059d22551ec2975f629f8754e6ee8bb5712592 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Tue, 17 Aug 2021 12:36:34 +0200 Subject: [PATCH 14/15] Fix minor node-executor error --- bin/node/executor/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/executor/src/lib.rs b/bin/node/executor/src/lib.rs index 6905e0f76c15f..9a7a0c4d3c110 100644 --- a/bin/node/executor/src/lib.rs +++ b/bin/node/executor/src/lib.rs @@ -18,7 +18,7 @@ //! A `CodeExecutor` specialization which uses natively compiled runtime when the wasm to be //! executed is equivalent to the natively compiled code. -pub use sc_executor::NativeExecutor; +pub use sc_executor::NativeElseWasmExecutor; // Declare an instance of the native executor named `ExecutorDispatch`. Include the wasm binary as // the equivalent wasm code. From 369ee66e78db1756f391a1d861002bff01370c6a Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Tue, 17 Aug 2021 12:53:53 +0200 Subject: [PATCH 15/15] Fix node cli command thing --- bin/node/cli/src/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/cli/src/command.rs b/bin/node/cli/src/command.rs index d8ec146526077..a660b8985b644 100644 --- a/bin/node/cli/src/command.rs +++ b/bin/node/cli/src/command.rs @@ -159,7 +159,7 @@ pub fn run() -> Result<()> { sc_service::TaskManager::new(config.task_executor.clone(), registry) .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?; - Ok((cmd.run::(config), task_manager)) + Ok((cmd.run::(config), task_manager)) }) }, #[cfg(not(feature = "try-runtime"))]