Skip to content
Snippets Groups Projects
Commit 949716be authored by bgallois's avatar bgallois Committed by Hugo Trentesaux
Browse files

refactor executor

parent 07bb8814
No related branches found
No related tags found
1 merge request!256Refactor node implementation
......@@ -23,12 +23,7 @@ pub mod utils;
#[cfg(feature = "gtest")]
use crate::chain_spec::gtest;
use crate::cli::{Cli, Subcommand};
#[cfg(feature = "g1")]
use crate::service::g1_executor::G1Executor;
#[cfg(feature = "gdev")]
use crate::service::gdev_executor::GDevExecutor;
#[cfg(feature = "gtest")]
use crate::service::gtest_executor::GTestExecutor;
use crate::service::runtime_executor::Executor;
use crate::service::{IdentifyRuntimeType, RuntimeType};
use crate::{chain_spec, service};
use clap::CommandFactory;
......@@ -351,21 +346,21 @@ pub fn run() -> sc_cli::Result<()> {
RuntimeType::G1 => runner.sync_run(|config| {
cmd.run::<g1_runtime::Block, ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<G1Executor as NativeExecutionDispatch>::ExtendHostFunctions,
<Executor as NativeExecutionDispatch>::ExtendHostFunctions,
>>(config)
}),
#[cfg(feature = "gtest")]
RuntimeType::GTest => runner.sync_run(|config| {
cmd.run::<gtest_runtime::Block, ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<GTestExecutor as NativeExecutionDispatch>::ExtendHostFunctions,
<Executor as NativeExecutionDispatch>::ExtendHostFunctions,
>>(config)
}),
#[cfg(feature = "gdev")]
RuntimeType::GDev => runner.sync_run(|config| {
cmd.run::<gdev_runtime::Block, ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<GDevExecutor as NativeExecutionDispatch>::ExtendHostFunctions,
<Executor as NativeExecutionDispatch>::ExtendHostFunctions,
>>(config)
}),
_ => Err(sc_cli::Error::Application("unknown runtime type".into())),
......@@ -420,7 +415,7 @@ pub fn run() -> sc_cli::Result<()> {
//sp_core::crypto::set_default_ss58_version(Ss58AddressFormatRegistry::GDev);
runner.async_run(|config| {
Ok((
cmd.run::<gdev_runtime::Block, GDevExecutor>(config),
cmd.run::<gdev_runtime::Block, Executor>(config),
task_manager,
))
})
......@@ -444,22 +439,19 @@ pub fn run() -> sc_cli::Result<()> {
match config.chain_spec.runtime_type() {
#[cfg(feature = "g1")]
RuntimeType::G1 => {
service::new_full::<g1_runtime::RuntimeApi, G1Executor>(config, cli.sealing)
service::new_full::<g1_runtime::RuntimeApi, Executor>(config, cli.sealing)
.map_err(sc_cli::Error::Service)
}
#[cfg(feature = "gtest")]
RuntimeType::GTest => service::new_full::<
gtest_runtime::RuntimeApi,
GTestExecutor,
>(config, cli.sealing)
RuntimeType::GTest => service::new_full::<gtest_runtime::RuntimeApi, Executor>(
config,
cli.sealing,
)
.map_err(sc_cli::Error::Service),
#[cfg(feature = "gdev")]
RuntimeType::GDev => {
service::new_full::<gdev_runtime::RuntimeApi, GDevExecutor>(
config,
cli.sealing,
)
.map_err(sc_cli::Error::Service)
service::new_full::<gdev_runtime::RuntimeApi, Executor>(config, cli.sealing)
.map_err(sc_cli::Error::Service)
}
_ => Err(sc_cli::Error::Application("unknown runtime".into())),
}
......
......@@ -54,91 +54,29 @@ type FullClient<RuntimeApi, Executor> =
type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
#[cfg(feature = "gdev")]
pub mod gdev_executor {
pub mod runtime_executor {
use crate::service::HostFunctions;
pub use gdev_runtime;
#[cfg(feature = "g1")]
pub use g1_runtime as runtime;
#[cfg(feature = "gdev")]
pub use gdev_runtime as runtime;
#[cfg(feature = "gtest")]
pub use gtest_runtime as runtime;
use sc_executor::sp_wasm_interface::{Function, HostFunctionRegistry};
pub struct GDevExecutor;
impl sc_executor::NativeExecutionDispatch for GDevExecutor {
pub struct Executor;
impl sc_executor::NativeExecutionDispatch for Executor {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
gdev_runtime::api::dispatch(method, data)
runtime::api::dispatch(method, data)
}
fn native_version() -> sc_executor::NativeVersion {
gdev_runtime::native_version()
runtime::native_version()
}
}
impl sc_executor::sp_wasm_interface::HostFunctions for GDevExecutor {
fn host_functions() -> Vec<&'static dyn Function> {
HostFunctions::host_functions()
}
fn register_static<T>(registry: &mut T) -> Result<(), T::Error>
where
T: HostFunctionRegistry,
{
HostFunctions::register_static(registry)
}
}
}
#[allow(dead_code)]
#[cfg(feature = "g1")]
pub mod g1_executor {
use crate::service::HostFunctions;
pub use g1_runtime;
use sc_executor::sp_wasm_interface::{Function, HostFunctionRegistry};
pub struct G1Executor;
impl sc_executor::NativeExecutionDispatch for G1Executor {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
g1_runtime::api::dispatch(method, data)
}
fn native_version() -> sc_executor::NativeVersion {
g1_runtime::native_version()
}
}
impl sc_executor::sp_wasm_interface::HostFunctions for G1Executor {
fn host_functions() -> Vec<&'static dyn Function> {
HostFunctions::host_functions()
}
fn register_static<T>(registry: &mut T) -> Result<(), T::Error>
where
T: HostFunctionRegistry,
{
HostFunctions::register_static(registry)
}
}
}
#[allow(dead_code)]
#[cfg(feature = "gtest")]
pub mod gtest_executor {
use crate::service::HostFunctions;
pub use gtest_runtime;
use sc_executor::sp_wasm_interface::{Function, HostFunctionRegistry};
pub struct GTestExecutor;
impl sc_executor::NativeExecutionDispatch for GTestExecutor {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
gtest_runtime::api::dispatch(method, data)
}
fn native_version() -> sc_executor::NativeVersion {
gtest_runtime::native_version()
}
}
impl sc_executor::sp_wasm_interface::HostFunctions for GTestExecutor {
impl sc_executor::sp_wasm_interface::HostFunctions for Executor {
fn host_functions() -> Vec<&'static dyn Function> {
HostFunctions::host_functions()
}
......@@ -207,7 +145,7 @@ pub fn new_chain_ops(
import_queue,
task_manager,
..
} = new_partial::<g1_runtime::RuntimeApi, g1_executor::G1Executor>(
} = new_partial::<g1_runtime::RuntimeApi, runtime_executor::G1Executor>(
config,
manual_consensus,
)?;
......@@ -226,7 +164,7 @@ pub fn new_chain_ops(
import_queue,
task_manager,
..
} = new_partial::<gtest_runtime::RuntimeApi, gtest_executor::GTestExecutor>(
} = new_partial::<gtest_runtime::RuntimeApi, runtime_executor::GTestExecutor>(
config,
manual_consensus,
)?;
......@@ -245,7 +183,7 @@ pub fn new_chain_ops(
import_queue,
task_manager,
..
} = new_partial::<gdev_runtime::RuntimeApi, gdev_executor::GDevExecutor>(
} = new_partial::<gdev_runtime::RuntimeApi, runtime_executor::Executor>(
config,
manual_consensus,
)?;
......
......@@ -146,11 +146,11 @@ impl<Api> RuntimeApiCollection for Api where
#[derive(Clone)]
pub enum Client {
#[cfg(feature = "g1")]
G1(Arc<super::FullClient<g1_runtime::RuntimeApi, super::g1_executor::G1Executor>>),
G1(Arc<super::FullClient<g1_runtime::RuntimeApi, super::runtime_executor::Executor>>),
#[cfg(feature = "gtest")]
GTest(Arc<super::FullClient<gtest_runtime::RuntimeApi, super::gtest_executor::GTestExecutor>>),
GTest(Arc<super::FullClient<gtest_runtime::RuntimeApi, super::runtime_executor::Executor>>),
#[cfg(feature = "gdev")]
GDev(Arc<super::FullClient<gdev_runtime::RuntimeApi, super::gdev_executor::GDevExecutor>>),
GDev(Arc<super::FullClient<gdev_runtime::RuntimeApi, super::runtime_executor::Executor>>),
}
macro_rules! with_client {
......@@ -197,23 +197,23 @@ impl ClientHandle for Client {
}
#[cfg(feature = "g1")]
impl From<Arc<super::FullClient<g1_runtime::RuntimeApi, super::g1_executor::G1Executor>>>
impl From<Arc<super::FullClient<g1_runtime::RuntimeApi, super::runtime_executor::Executor>>>
for Client
{
fn from(
client: Arc<super::FullClient<g1_runtime::RuntimeApi, super::g1_executor::G1Executor>>,
client: Arc<super::FullClient<g1_runtime::RuntimeApi, super::runtime_executor::Executor>>,
) -> Self {
Self::G1(client)
}
}
#[cfg(feature = "gtest")]
impl From<Arc<super::FullClient<gtest_runtime::RuntimeApi, super::gtest_executor::GTestExecutor>>>
impl From<Arc<super::FullClient<gtest_runtime::RuntimeApi, super::runtime_executor::Executor>>>
for Client
{
fn from(
client: Arc<
super::FullClient<gtest_runtime::RuntimeApi, super::gtest_executor::GTestExecutor>,
super::FullClient<gtest_runtime::RuntimeApi, super::runtime_executor::Executor>,
>,
) -> Self {
Self::GTest(client)
......@@ -221,13 +221,11 @@ impl From<Arc<super::FullClient<gtest_runtime::RuntimeApi, super::gtest_executor
}
#[cfg(feature = "gdev")]
impl From<Arc<super::FullClient<gdev_runtime::RuntimeApi, super::gdev_executor::GDevExecutor>>>
impl From<Arc<super::FullClient<gdev_runtime::RuntimeApi, super::runtime_executor::Executor>>>
for Client
{
fn from(
client: Arc<
super::FullClient<gdev_runtime::RuntimeApi, super::gdev_executor::GDevExecutor>,
>,
client: Arc<super::FullClient<gdev_runtime::RuntimeApi, super::runtime_executor::Executor>>,
) -> Self {
Self::GDev(client)
}
......@@ -328,15 +326,15 @@ trait BenchmarkCallSigner<RuntimeCall: Encode + Clone, Signer: Pair> {
#[cfg(feature = "g1")]
use g1_runtime as runtime;
#[cfg(feature = "g1")]
type FullClient = super::FullClient<runtime::RuntimeApi, super::g1_executor::G1Executor>;
type FullClient = super::FullClient<runtime::RuntimeApi, super::runtime_executor::Executor>;
#[cfg(feature = "gdev")]
use gdev_runtime as runtime;
#[cfg(feature = "gdev")]
type FullClient = super::FullClient<runtime::RuntimeApi, super::gdev_executor::GDevExecutor>;
type FullClient = super::FullClient<runtime::RuntimeApi, super::runtime_executor::Executor>;
#[cfg(feature = "gtest")]
use gtest_runtime as runtime;
#[cfg(feature = "gtest")]
type FullClient = super::FullClient<runtime::RuntimeApi, super::gtest_executor::GTestExecutor>;
type FullClient = super::FullClient<runtime::RuntimeApi, super::runtime_executor::Executor>;
#[cfg(any(feature = "gdev", feature = "gtest"))]
impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullClient {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment