mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 02:51:08 +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:
@@ -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