Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Companion PR for 'Make choosing an executor an explicit part of servi…
Browse files Browse the repository at this point in the history
…ce construction' (#9525) (#3615)

* Companion PR

* Update a few files

* Run cargo fmt

* Do better at renaming things

* More renamings

* More fixes

* oops

* Fix simnet problems

* fix compilation

* Update substrate

Co-authored-by: thiolliere <gui.thiolliere@gmail.com>
  • Loading branch information
expenses and gui1117 authored Aug 18, 2021
1 parent 7d80dbf commit 616667f
Show file tree
Hide file tree
Showing 9 changed files with 277 additions and 237 deletions.
306 changes: 153 additions & 153 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions bridges/bin/millau/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use millau_runtime::{self, opaque::Block, RuntimeApi};
use sc_client_api::{ExecutorProvider, RemoteBackend};
use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams};
pub use sc_executor::NativeExecutor;
pub use sc_executor::NativeElseWasmExecutor;

use sc_keystore::LocalKeystore;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager};
Expand All @@ -41,9 +41,9 @@ use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use std::{sync::Arc, time::Duration};

// Our native executor instance.
pub struct Executor;
pub struct ExecutorDispatch;

impl sc_executor::NativeExecutionDispatch for Executor {
impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
Expand All @@ -55,7 +55,7 @@ impl sc_executor::NativeExecutionDispatch for Executor {
}
}

type FullClient = sc_service::TFullClient<Block, RuntimeApi, Executor>;
type FullClient = sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;

Expand Down
8 changes: 4 additions & 4 deletions bridges/bin/rialto/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
use rialto_runtime::{self, opaque::Block, RuntimeApi};
use sc_client_api::{ExecutorProvider, RemoteBackend};
use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams};
pub use sc_executor::NativeExecutor;
pub use sc_executor::NativeElseWasmExecutor;

use sc_keystore::LocalKeystore;
use sc_service::{error::Error as ServiceError, Configuration, TaskManager};
Expand All @@ -43,9 +43,9 @@ use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use std::{sync::Arc, time::Duration};

// Our native executor instance.
pub struct Executor;
pub struct ExecutorDispatch;

impl sc_executor::NativeExecutionDispatch for Executor {
impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
Expand All @@ -57,7 +57,7 @@ impl sc_executor::NativeExecutionDispatch for Executor {
}
}

type FullClient = sc_service::TFullClient<Block, RuntimeApi, Executor>;
type FullClient = sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;

Expand Down
18 changes: 12 additions & 6 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,23 +376,29 @@ pub fn run() -> Result<()> {
#[cfg(feature = "kusama-native")]
if chain_spec.is_kusama() {
return Ok(runner.sync_run(|config| {
cmd.run::<service::kusama_runtime::Block, service::KusamaExecutor>(config)
.map_err(|e| Error::SubstrateCli(e))
cmd.run::<service::kusama_runtime::Block, service::KusamaExecutorDispatch>(
config,
)
.map_err(|e| Error::SubstrateCli(e))
})?)
}

#[cfg(feature = "westend-native")]
if chain_spec.is_westend() {
return Ok(runner.sync_run(|config| {
cmd.run::<service::westend_runtime::Block, service::WestendExecutor>(config)
.map_err(|e| Error::SubstrateCli(e))
cmd.run::<service::westend_runtime::Block, service::WestendExecutorDispatch>(
config,
)
.map_err(|e| Error::SubstrateCli(e))
})?)
}

// else we assume it is polkadot.
Ok(runner.sync_run(|config| {
cmd.run::<service::polkadot_runtime::Block, service::PolkadotExecutor>(config)
.map_err(|e| Error::SubstrateCli(e))
cmd.run::<service::polkadot_runtime::Block, service::PolkadotExecutorDispatch>(
config,
)
.map_err(|e| Error::SubstrateCli(e))
})?)
},
Some(Subcommand::Key(cmd)) => Ok(cmd.run(&cli)?),
Expand Down
28 changes: 15 additions & 13 deletions node/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use polkadot_primitives::v1::{
AccountId, Balance, Block, BlockNumber, Hash, Header, Nonce, ParachainHost,
};
use sc_client_api::{AuxStore, Backend as BackendT, BlockchainEvents, KeyIterator, UsageProvider};
use sc_executor::NativeElseWasmExecutor;
use sp_api::{CallApiAt, NumberFor, ProvideRuntimeApi};
use sp_blockchain::HeaderBackend;
use sp_consensus::BlockStatus;
Expand All @@ -36,12 +37,13 @@ use std::sync::Arc;

pub type FullBackend = sc_service::TFullBackend<Block>;

pub type FullClient<RuntimeApi, Executor> = sc_service::TFullClient<Block, RuntimeApi, Executor>;
pub type FullClient<RuntimeApi, ExecutorDispatch> =
sc_service::TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;

/// The native executor instance for Polkadot.
pub struct PolkadotExecutor;
pub struct PolkadotExecutorDispatch;

impl sc_executor::NativeExecutionDispatch for PolkadotExecutor {
impl sc_executor::NativeExecutionDispatch for PolkadotExecutorDispatch {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
Expand All @@ -55,10 +57,10 @@ impl sc_executor::NativeExecutionDispatch for PolkadotExecutor {

#[cfg(feature = "kusama")]
/// The native executor instance for Kusama.
pub struct KusamaExecutor;
pub struct KusamaExecutorDispatch;

#[cfg(feature = "kusama")]
impl sc_executor::NativeExecutionDispatch for KusamaExecutor {
impl sc_executor::NativeExecutionDispatch for KusamaExecutorDispatch {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
Expand All @@ -72,10 +74,10 @@ impl sc_executor::NativeExecutionDispatch for KusamaExecutor {

#[cfg(feature = "westend")]
/// The native executor instance for Westend.
pub struct WestendExecutor;
pub struct WestendExecutorDispatch;

#[cfg(feature = "westend")]
impl sc_executor::NativeExecutionDispatch for WestendExecutor {
impl sc_executor::NativeExecutionDispatch for WestendExecutorDispatch {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
Expand All @@ -89,10 +91,10 @@ impl sc_executor::NativeExecutionDispatch for WestendExecutor {

#[cfg(feature = "rococo")]
/// The native executor instance for Rococo.
pub struct RococoExecutor;
pub struct RococoExecutorDispatch;

#[cfg(feature = "rococo")]
impl sc_executor::NativeExecutionDispatch for RococoExecutor {
impl sc_executor::NativeExecutionDispatch for RococoExecutorDispatch {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
Expand Down Expand Up @@ -247,13 +249,13 @@ macro_rules! with_client {
/// See [`ExecuteWithClient`] for more information.
#[derive(Clone)]
pub enum Client {
Polkadot(Arc<FullClient<polkadot_runtime::RuntimeApi, PolkadotExecutor>>),
Polkadot(Arc<FullClient<polkadot_runtime::RuntimeApi, PolkadotExecutorDispatch>>),
#[cfg(feature = "westend")]
Westend(Arc<FullClient<westend_runtime::RuntimeApi, WestendExecutor>>),
Westend(Arc<FullClient<westend_runtime::RuntimeApi, WestendExecutorDispatch>>),
#[cfg(feature = "kusama")]
Kusama(Arc<FullClient<kusama_runtime::RuntimeApi, KusamaExecutor>>),
Kusama(Arc<FullClient<kusama_runtime::RuntimeApi, KusamaExecutorDispatch>>),
#[cfg(feature = "rococo")]
Rococo(Arc<FullClient<rococo_runtime::RuntimeApi, RococoExecutor>>),
Rococo(Arc<FullClient<rococo_runtime::RuntimeApi, RococoExecutorDispatch>>),
}

impl ClientHandle for Client {
Expand Down
Loading

0 comments on commit 616667f

Please sign in to comment.