mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 15:41:02 +00:00
Make choosing an executor (native/wasm) an explicit part of service construction (#9525)
* Split native executor stuff from wasm executor stuff * Remove `native_runtime_version` in places * Fix warning * Fix test warning * Remove redundant NativeRuntimeInfo trait * Add a warning for use_native * Run cargo fmt * Revert "Add a warning for use_native" This reverts commit 9494f765a06037e991dd60524f2ed1b14649bfd6. * Make choosing an executor (native/wasm) an explicit part of service construction * Add Cargo.lock * Rename Executor to ExecutorDispatch * Update bin/node/executor/src/lib.rs Co-authored-by: Squirrel <gilescope@gmail.com> * Fix tests * Fix minor node-executor error * Fix node cli command thing Co-authored-by: Squirrel <gilescope@gmail.com>
This commit is contained in:
@@ -27,7 +27,7 @@ pub use sc_client_api::{
|
||||
BadBlocks, ForkBlocks,
|
||||
};
|
||||
pub use sc_client_db::{self, Backend};
|
||||
pub use sc_executor::{self, NativeExecutor, WasmExecutionMethod};
|
||||
pub use sc_executor::{self, NativeElseWasmExecutor, WasmExecutionMethod};
|
||||
pub use sc_service::{client, RpcHandlers, RpcSession};
|
||||
pub use sp_consensus;
|
||||
pub use sp_keyring::{
|
||||
@@ -73,14 +73,14 @@ impl GenesisInit for () {
|
||||
}
|
||||
|
||||
/// A builder for creating a test client instance.
|
||||
pub struct TestClientBuilder<Block: BlockT, Executor, Backend, G: GenesisInit> {
|
||||
pub struct TestClientBuilder<Block: BlockT, ExecutorDispatch, Backend, G: GenesisInit> {
|
||||
execution_strategies: ExecutionStrategies,
|
||||
genesis_init: G,
|
||||
/// The key is an unprefixed storage key, this only contains
|
||||
/// default child trie content.
|
||||
child_storage_extension: HashMap<Vec<u8>, StorageChild>,
|
||||
backend: Arc<Backend>,
|
||||
_executor: std::marker::PhantomData<Executor>,
|
||||
_executor: std::marker::PhantomData<ExecutorDispatch>,
|
||||
keystore: Option<SyncCryptoStorePtr>,
|
||||
fork_blocks: ForkBlocks<Block>,
|
||||
bad_blocks: BadBlocks<Block>,
|
||||
@@ -88,16 +88,16 @@ pub struct TestClientBuilder<Block: BlockT, Executor, Backend, G: GenesisInit> {
|
||||
no_genesis: bool,
|
||||
}
|
||||
|
||||
impl<Block: BlockT, Executor, G: GenesisInit> Default
|
||||
for TestClientBuilder<Block, Executor, Backend<Block>, G>
|
||||
impl<Block: BlockT, ExecutorDispatch, G: GenesisInit> Default
|
||||
for TestClientBuilder<Block, ExecutorDispatch, Backend<Block>, G>
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::with_default_backend()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block: BlockT, Executor, G: GenesisInit>
|
||||
TestClientBuilder<Block, Executor, Backend<Block>, G>
|
||||
impl<Block: BlockT, ExecutorDispatch, G: GenesisInit>
|
||||
TestClientBuilder<Block, ExecutorDispatch, Backend<Block>, G>
|
||||
{
|
||||
/// Create new `TestClientBuilder` with default backend.
|
||||
pub fn with_default_backend() -> Self {
|
||||
@@ -122,8 +122,8 @@ impl<Block: BlockT, Executor, G: GenesisInit>
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block: BlockT, Executor, Backend, G: GenesisInit>
|
||||
TestClientBuilder<Block, Executor, Backend, G>
|
||||
impl<Block: BlockT, ExecutorDispatch, Backend, G: GenesisInit>
|
||||
TestClientBuilder<Block, ExecutorDispatch, Backend, G>
|
||||
{
|
||||
/// Create a new instance of the test client builder.
|
||||
pub fn with_backend(backend: Arc<Backend>) -> Self {
|
||||
@@ -210,13 +210,13 @@ impl<Block: BlockT, Executor, Backend, G: GenesisInit>
|
||||
/// Build the test client with the given native executor.
|
||||
pub fn build_with_executor<RuntimeApi>(
|
||||
self,
|
||||
executor: Executor,
|
||||
executor: ExecutorDispatch,
|
||||
) -> (
|
||||
client::Client<Backend, Executor, Block, RuntimeApi>,
|
||||
client::Client<Backend, ExecutorDispatch, Block, RuntimeApi>,
|
||||
sc_consensus::LongestChain<Backend, Block>,
|
||||
)
|
||||
where
|
||||
Executor: sc_client_api::CallExecutor<Block> + 'static,
|
||||
ExecutorDispatch: sc_client_api::CallExecutor<Block> + 'static,
|
||||
Backend: sc_client_api::backend::Backend<Block>,
|
||||
<Backend as sc_client_api::backend::Backend<Block>>::OffchainStorage: 'static,
|
||||
{
|
||||
@@ -264,8 +264,13 @@ impl<Block: BlockT, Executor, Backend, G: GenesisInit>
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block: BlockT, E, Backend, G: GenesisInit>
|
||||
TestClientBuilder<Block, client::LocalCallExecutor<Block, Backend, NativeExecutor<E>>, Backend, G>
|
||||
impl<Block: BlockT, D, Backend, G: GenesisInit>
|
||||
TestClientBuilder<
|
||||
Block,
|
||||
client::LocalCallExecutor<Block, Backend, NativeElseWasmExecutor<D>>,
|
||||
Backend,
|
||||
G,
|
||||
>
|
||||
{
|
||||
/// Build the test client with the given native executor.
|
||||
pub fn build_with_native_executor<RuntimeApi, I>(
|
||||
@@ -274,20 +279,20 @@ impl<Block: BlockT, E, Backend, G: GenesisInit>
|
||||
) -> (
|
||||
client::Client<
|
||||
Backend,
|
||||
client::LocalCallExecutor<Block, Backend, NativeExecutor<E>>,
|
||||
client::LocalCallExecutor<Block, Backend, NativeElseWasmExecutor<D>>,
|
||||
Block,
|
||||
RuntimeApi,
|
||||
>,
|
||||
sc_consensus::LongestChain<Backend, Block>,
|
||||
)
|
||||
where
|
||||
I: Into<Option<NativeExecutor<E>>>,
|
||||
E: sc_executor::NativeExecutionDispatch + 'static,
|
||||
I: Into<Option<NativeElseWasmExecutor<D>>>,
|
||||
D: sc_executor::NativeExecutionDispatch + 'static,
|
||||
Backend: sc_client_api::backend::Backend<Block> + 'static,
|
||||
{
|
||||
let executor = executor
|
||||
.into()
|
||||
.unwrap_or_else(|| NativeExecutor::new(WasmExecutionMethod::Interpreted, None, 8));
|
||||
let executor = executor.into().unwrap_or_else(|| {
|
||||
NativeElseWasmExecutor::new(WasmExecutionMethod::Interpreted, None, 8)
|
||||
});
|
||||
let executor = LocalCallExecutor::new(
|
||||
self.backend.clone(),
|
||||
executor,
|
||||
|
||||
@@ -51,8 +51,8 @@ pub mod prelude {
|
||||
};
|
||||
// Client structs
|
||||
pub use super::{
|
||||
Backend, Executor, LightBackend, LightExecutor, LocalExecutor, NativeExecutor, TestClient,
|
||||
TestClientBuilder, WasmExecutionMethod,
|
||||
Backend, ExecutorDispatch, LightBackend, LightExecutor, LocalExecutorDispatch,
|
||||
NativeElseWasmExecutor, TestClient, TestClientBuilder, WasmExecutionMethod,
|
||||
};
|
||||
// Keyring
|
||||
pub use super::{AccountKeyring, Sr25519Keyring};
|
||||
@@ -60,9 +60,9 @@ pub mod prelude {
|
||||
|
||||
/// A unit struct which implements `NativeExecutionDispatch` feeding in the
|
||||
/// hard-coded runtime.
|
||||
pub struct LocalExecutor;
|
||||
pub struct LocalExecutorDispatch;
|
||||
|
||||
impl sc_executor::NativeExecutionDispatch for LocalExecutor {
|
||||
impl sc_executor::NativeExecutionDispatch for LocalExecutorDispatch {
|
||||
type ExtendHostFunctions = ();
|
||||
|
||||
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
|
||||
@@ -78,10 +78,10 @@ impl sc_executor::NativeExecutionDispatch for LocalExecutor {
|
||||
pub type Backend = substrate_test_client::Backend<substrate_test_runtime::Block>;
|
||||
|
||||
/// Test client executor.
|
||||
pub type Executor = client::LocalCallExecutor<
|
||||
pub type ExecutorDispatch = client::LocalCallExecutor<
|
||||
substrate_test_runtime::Block,
|
||||
Backend,
|
||||
NativeExecutor<LocalExecutor>,
|
||||
NativeElseWasmExecutor<LocalExecutorDispatch>,
|
||||
>;
|
||||
|
||||
/// Test client light database backend.
|
||||
@@ -96,7 +96,7 @@ pub type LightExecutor = sc_light::GenesisCallExecutor<
|
||||
sc_client_db::light::LightStorage<substrate_test_runtime::Block>,
|
||||
HashFor<substrate_test_runtime::Block>,
|
||||
>,
|
||||
NativeExecutor<LocalExecutor>,
|
||||
NativeElseWasmExecutor<LocalExecutorDispatch>,
|
||||
>,
|
||||
>;
|
||||
|
||||
@@ -174,13 +174,13 @@ pub type TestClientBuilder<E, B> = substrate_test_client::TestClientBuilder<
|
||||
GenesisParameters,
|
||||
>;
|
||||
|
||||
/// Test client type with `LocalExecutor` and generic Backend.
|
||||
/// Test client type with `LocalExecutorDispatch` and generic Backend.
|
||||
pub type Client<B> = client::Client<
|
||||
B,
|
||||
client::LocalCallExecutor<
|
||||
substrate_test_runtime::Block,
|
||||
B,
|
||||
sc_executor::NativeExecutor<LocalExecutor>,
|
||||
sc_executor::NativeElseWasmExecutor<LocalExecutorDispatch>,
|
||||
>,
|
||||
substrate_test_runtime::Block,
|
||||
substrate_test_runtime::RuntimeApi,
|
||||
@@ -195,7 +195,7 @@ pub trait DefaultTestClientBuilderExt: Sized {
|
||||
fn new() -> Self;
|
||||
}
|
||||
|
||||
impl DefaultTestClientBuilderExt for TestClientBuilder<Executor, Backend> {
|
||||
impl DefaultTestClientBuilderExt for TestClientBuilder<ExecutorDispatch, Backend> {
|
||||
fn new() -> Self {
|
||||
Self::with_default_backend()
|
||||
}
|
||||
@@ -277,7 +277,7 @@ impl<B> TestClientBuilderExt<B>
|
||||
client::LocalCallExecutor<
|
||||
substrate_test_runtime::Block,
|
||||
B,
|
||||
sc_executor::NativeExecutor<LocalExecutor>,
|
||||
sc_executor::NativeElseWasmExecutor<LocalExecutorDispatch>,
|
||||
>,
|
||||
B,
|
||||
> where
|
||||
@@ -436,6 +436,6 @@ pub fn new_light_fetcher() -> LightFetcher {
|
||||
}
|
||||
|
||||
/// Create a new native executor.
|
||||
pub fn new_native_executor() -> sc_executor::NativeExecutor<LocalExecutor> {
|
||||
sc_executor::NativeExecutor::new(sc_executor::WasmExecutionMethod::Interpreted, None, 8)
|
||||
pub fn new_native_executor() -> sc_executor::NativeElseWasmExecutor<LocalExecutorDispatch> {
|
||||
sc_executor::NativeElseWasmExecutor::new(sc_executor::WasmExecutionMethod::Interpreted, None, 8)
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
use crate::{wasm_binary_unwrap, Header, Transfer};
|
||||
use sc_executor::{NativeExecutor, WasmExecutionMethod};
|
||||
use sc_executor::{NativeElseWasmExecutor, WasmExecutionMethod};
|
||||
use sp_core::{
|
||||
map,
|
||||
traits::{CodeExecutor, RuntimeCode},
|
||||
@@ -373,8 +373,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn executor() -> NativeExecutor<NativeDispatch> {
|
||||
NativeExecutor::new(WasmExecutionMethod::Interpreted, None, 8)
|
||||
fn executor() -> NativeElseWasmExecutor<NativeDispatch> {
|
||||
NativeElseWasmExecutor::new(WasmExecutionMethod::Interpreted, None, 8)
|
||||
}
|
||||
|
||||
fn new_test_ext() -> TestExternalities {
|
||||
|
||||
@@ -26,6 +26,7 @@ use manual_seal::{
|
||||
run_manual_seal, EngineCommand, ManualSealParams,
|
||||
};
|
||||
use sc_client_api::backend::Backend;
|
||||
use sc_executor::NativeElseWasmExecutor;
|
||||
use sc_service::{
|
||||
build_network, new_full_parts, spawn_tasks, BuildNetworkParams, ChainSpec, Configuration,
|
||||
SpawnTasksParams, TFullBackend, TFullClient, TaskExecutor, TaskManager,
|
||||
@@ -50,7 +51,7 @@ type ClientParts<T> = (
|
||||
TFullClient<
|
||||
<T as ChainInfo>::Block,
|
||||
<T as ChainInfo>::RuntimeApi,
|
||||
<T as ChainInfo>::Executor,
|
||||
NativeElseWasmExecutor<<T as ChainInfo>::ExecutorDispatch>,
|
||||
>,
|
||||
>,
|
||||
Arc<
|
||||
@@ -83,7 +84,7 @@ where
|
||||
T: ChainInfo + 'static,
|
||||
<T::RuntimeApi as ConstructRuntimeApi<
|
||||
T::Block,
|
||||
TFullClient<T::Block, T::RuntimeApi, T::Executor>,
|
||||
TFullClient<T::Block, T::RuntimeApi, NativeElseWasmExecutor<T::ExecutorDispatch>>,
|
||||
>>::RuntimeApi: Core<T::Block>
|
||||
+ Metadata<T::Block>
|
||||
+ OffchainWorkerApi<T::Block>
|
||||
@@ -106,8 +107,14 @@ where
|
||||
default_config(task_executor, chain_spec),
|
||||
};
|
||||
|
||||
let executor = NativeElseWasmExecutor::<T::ExecutorDispatch>::new(
|
||||
config.wasm_method,
|
||||
config.default_heap_pages,
|
||||
config.max_runtime_instances,
|
||||
);
|
||||
|
||||
let (client, backend, keystore, mut task_manager) =
|
||||
new_full_parts::<T::Block, T::RuntimeApi, T::Executor>(&config, None)?;
|
||||
new_full_parts::<T::Block, T::RuntimeApi, _>(&config, None, executor)?;
|
||||
let client = Arc::new(client);
|
||||
|
||||
let select_chain = sc_consensus::LongestChain::new(backend.clone());
|
||||
|
||||
@@ -62,9 +62,9 @@
|
||||
//!
|
||||
//! type BlockImport<B, BE, C, SC> = BabeBlockImport<B, C, GrandpaBlockImport<BE, B, C, SC>>;
|
||||
//!
|
||||
//! pub struct Executor;
|
||||
//! pub struct ExecutorDispatch;
|
||||
//!
|
||||
//! impl sc_executor::NativeExecutionDispatch for Executor {
|
||||
//! impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
|
||||
//! type ExtendHostFunctions = SignatureVerificationOverride;
|
||||
//!
|
||||
//! fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
|
||||
@@ -81,8 +81,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
|
||||
@@ -93,7 +93,7 @@
|
||||
//! type BlockImport = BlockImport<
|
||||
//! Self::Block,
|
||||
//! TFullBackend<Self::Block>,
|
||||
//! TFullClient<Self::Block, Self::RuntimeApi, Self::Executor>,
|
||||
//! TFullClient<Self::Block, Self::RuntimeApi, NativeElseWasmExecutor<Self::ExecutorDispatch>>,
|
||||
//! Self::SelectChain,
|
||||
//! >;
|
||||
//! /// and a dash of SignedExtensions
|
||||
@@ -119,7 +119,7 @@
|
||||
//! /// The function signature tells you all you need to know. ;)
|
||||
//! fn create_client_parts(config: &Configuration) -> Result<
|
||||
//! (
|
||||
//! Arc<TFullClient<Self::Block, Self::RuntimeApi, Self::Executor>>,
|
||||
//! Arc<TFullClient<Self::Block, Self::RuntimeApi, NativeElseWasmExecutor<Self::ExecutorDispatch>>>,
|
||||
//! Arc<TFullBackend<Self::Block>>,
|
||||
//! KeyStorePtr,
|
||||
//! TaskManager,
|
||||
@@ -128,7 +128,7 @@
|
||||
//! dyn ConsensusDataProvider<
|
||||
//! Self::Block,
|
||||
//! Transaction = TransactionFor<
|
||||
//! TFullClient<Self::Block, Self::RuntimeApi, Self::Executor>,
|
||||
//! TFullClient<Self::Block, Self::RuntimeApi, NativeElseWasmExecutor<Self::ExecutorDispatch>>,
|
||||
//! Self::Block
|
||||
//! >,
|
||||
//! >
|
||||
@@ -143,7 +143,7 @@
|
||||
//! backend,
|
||||
//! keystore,
|
||||
//! task_manager,
|
||||
//! ) = new_full_parts::<Self::Block, Self::RuntimeApi, Self::Executor>(config)?;
|
||||
//! ) = new_full_parts::<Self::Block, Self::RuntimeApi, NativeElseWasmExecutor<Self::ExecutorDispatch>>(config)?;
|
||||
//! let client = Arc::new(client);
|
||||
//!
|
||||
//! let inherent_providers = InherentDataProviders::new();
|
||||
@@ -235,7 +235,7 @@
|
||||
//! ```
|
||||
|
||||
use sc_consensus::BlockImport;
|
||||
use sc_executor::NativeExecutionDispatch;
|
||||
use sc_executor::{NativeElseWasmExecutor, NativeExecutionDispatch};
|
||||
use sc_service::TFullClient;
|
||||
use sp_api::{ConstructRuntimeApi, TransactionFor};
|
||||
use sp_consensus::SelectChain;
|
||||
@@ -257,8 +257,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;
|
||||
@@ -267,7 +267,14 @@ pub trait ChainInfo: Sized {
|
||||
type RuntimeApi: Send
|
||||
+ Sync
|
||||
+ 'static
|
||||
+ ConstructRuntimeApi<Self::Block, TFullClient<Self::Block, Self::RuntimeApi, Self::Executor>>;
|
||||
+ ConstructRuntimeApi<
|
||||
Self::Block,
|
||||
TFullClient<
|
||||
Self::Block,
|
||||
Self::RuntimeApi,
|
||||
NativeElseWasmExecutor<Self::ExecutorDispatch>,
|
||||
>,
|
||||
>;
|
||||
|
||||
/// select chain type.
|
||||
type SelectChain: SelectChain<Self::Block> + 'static;
|
||||
@@ -280,7 +287,11 @@ pub trait ChainInfo: Sized {
|
||||
Self::Block,
|
||||
Error = sp_consensus::Error,
|
||||
Transaction = TransactionFor<
|
||||
TFullClient<Self::Block, Self::RuntimeApi, Self::Executor>,
|
||||
TFullClient<
|
||||
Self::Block,
|
||||
Self::RuntimeApi,
|
||||
NativeElseWasmExecutor<Self::ExecutorDispatch>,
|
||||
>,
|
||||
Self::Block,
|
||||
>,
|
||||
> + 'static;
|
||||
|
||||
@@ -29,6 +29,7 @@ use sc_client_api::{
|
||||
backend::{self, Backend},
|
||||
CallExecutor, ExecutorProvider,
|
||||
};
|
||||
use sc_executor::NativeElseWasmExecutor;
|
||||
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<T: ChainInfo> {
|
||||
/// handle to the running node.
|
||||
task_manager: Option<TaskManager>,
|
||||
/// client instance
|
||||
client: Arc<TFullClient<T::Block, T::RuntimeApi, T::Executor>>,
|
||||
client: Arc<TFullClient<T::Block, T::RuntimeApi, NativeElseWasmExecutor<T::ExecutorDispatch>>>,
|
||||
/// transaction pool
|
||||
pool: Arc<
|
||||
dyn TransactionPool<
|
||||
@@ -86,7 +87,9 @@ where
|
||||
pub fn new(
|
||||
rpc_handler: Arc<MetaIoHandler<sc_rpc::Metadata, sc_rpc_server::RpcMiddleware>>,
|
||||
task_manager: TaskManager,
|
||||
client: Arc<TFullClient<T::Block, T::RuntimeApi, T::Executor>>,
|
||||
client: Arc<
|
||||
TFullClient<T::Block, T::RuntimeApi, NativeElseWasmExecutor<T::ExecutorDispatch>>,
|
||||
>,
|
||||
pool: Arc<
|
||||
dyn TransactionPool<
|
||||
Block = <T as ChainInfo>::Block,
|
||||
@@ -126,7 +129,9 @@ where
|
||||
}
|
||||
|
||||
/// Return a reference to the Client
|
||||
pub fn client(&self) -> Arc<TFullClient<T::Block, T::RuntimeApi, T::Executor>> {
|
||||
pub fn client(
|
||||
&self,
|
||||
) -> Arc<TFullClient<T::Block, T::RuntimeApi, NativeElseWasmExecutor<T::ExecutorDispatch>>> {
|
||||
self.client.clone()
|
||||
}
|
||||
|
||||
@@ -150,7 +155,7 @@ where
|
||||
/// Executes closure in an externalities provided environment.
|
||||
pub fn with_state<R>(&self, closure: impl FnOnce() -> R) -> R
|
||||
where
|
||||
<TFullCallExecutor<T::Block, T::Executor> as CallExecutor<T::Block>>::Error:
|
||||
<TFullCallExecutor<T::Block, NativeElseWasmExecutor<T::ExecutorDispatch>> as CallExecutor<T::Block>>::Error:
|
||||
std::fmt::Debug,
|
||||
{
|
||||
let id = BlockId::Hash(self.client.info().best_hash);
|
||||
|
||||
Reference in New Issue
Block a user