From b5c84371cdc53e19e9fdbcb75eb5b28ddcc210f3 Mon Sep 17 00:00:00 2001 From: bgallois <benjamin@gallois.cc> Date: Wed, 13 Mar 2024 17:17:58 +0100 Subject: [PATCH] refactor client --- node/src/service.rs | 77 ++++++++---------------------------- node/src/service/client.rs | 80 ++++++++++++-------------------------- runtime/g1/src/lib.rs | 1 + 3 files changed, 43 insertions(+), 115 deletions(-) diff --git a/node/src/service.rs b/node/src/service.rs index fdd27b221..1369217a3 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -62,6 +62,7 @@ pub mod runtime_executor { 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 Executor; @@ -136,66 +137,22 @@ pub fn new_chain_ops( ), ServiceError, > { - match config.chain_spec.runtime_type() { - #[cfg(feature = "g1")] - RuntimeType::G1::G1 => { - let PartialComponents { - client, - backend, - import_queue, - task_manager, - .. - } = new_partial::<g1_runtime::RuntimeApi, runtime_executor::G1Executor>( - config, - manual_consensus, - )?; - Ok(( - Arc::new(Client::G1(client)), - backend, - import_queue, - task_manager, - )) - } - #[cfg(feature = "gtest")] - RuntimeType::GTest => { - let PartialComponents { - client, - backend, - import_queue, - task_manager, - .. - } = new_partial::<gtest_runtime::RuntimeApi, runtime_executor::GTestExecutor>( - config, - manual_consensus, - )?; - Ok(( - Arc::new(Client::GTest(client)), - backend, - import_queue, - task_manager, - )) - } - #[cfg(feature = "gdev")] - RuntimeType::GDev => { - let PartialComponents { - client, - backend, - import_queue, - task_manager, - .. - } = new_partial::<gdev_runtime::RuntimeApi, runtime_executor::Executor>( - config, - manual_consensus, - )?; - Ok(( - Arc::new(Client::GDev(client)), - backend, - import_queue, - task_manager, - )) - } - _ => panic!("unknown runtime"), - } + let PartialComponents { + client, + backend, + import_queue, + task_manager, + .. + } = new_partial::<runtime_executor::runtime::RuntimeApi, runtime_executor::Executor>( + config, + manual_consensus, + )?; + Ok(( + Arc::new(Client::Client(client)), + backend, + import_queue, + task_manager, + )) } type FullGrandpaBlockImport<RuntimeApi, Executor> = sc_consensus_grandpa::GrandpaBlockImport< diff --git a/node/src/service/client.rs b/node/src/service/client.rs index 8deea4aec..04331317f 100644 --- a/node/src/service/client.rs +++ b/node/src/service/client.rs @@ -145,12 +145,14 @@ impl<Api> RuntimeApiCollection for Api where /// A client instance. #[derive(Clone)] pub enum Client { - #[cfg(feature = "g1")] - G1(Arc<super::FullClient<g1_runtime::RuntimeApi, super::runtime_executor::Executor>>), - #[cfg(feature = "gtest")] - GTest(Arc<super::FullClient<gtest_runtime::RuntimeApi, super::runtime_executor::Executor>>), - #[cfg(feature = "gdev")] - GDev(Arc<super::FullClient<gdev_runtime::RuntimeApi, super::runtime_executor::Executor>>), + Client( + Arc< + super::FullClient< + super::runtime_executor::runtime::RuntimeApi, + super::runtime_executor::Executor, + >, + >, + ), } macro_rules! with_client { @@ -162,22 +164,8 @@ macro_rules! with_client { } } => { match $self { - #[cfg(feature = "g1")] - Self::G1($client) => { - #[allow(unused_imports)] - use g1_runtime as runtime; - $( $code )* - } - #[cfg(feature = "gtest")] - Self::GTest($client) => { - #[allow(unused_imports)] - use gtest_runtime as runtime; - $( $code )* - } - #[cfg(feature = "gdev")] - Self::GDev($client) => { + Self::Client($client) => { #[allow(unused_imports)] - use gdev_runtime as runtime; $( $code )* } } @@ -196,50 +184,32 @@ impl ClientHandle for Client { } } -#[cfg(feature = "g1")] -impl From<Arc<super::FullClient<g1_runtime::RuntimeApi, super::runtime_executor::Executor>>> - for Client -{ - fn from( - 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::runtime_executor::Executor>>> - for Client +impl + From< + Arc< + super::FullClient< + super::runtime_executor::runtime::RuntimeApi, + super::runtime_executor::Executor, + >, + >, + > for Client { fn from( client: Arc< - super::FullClient<gtest_runtime::RuntimeApi, super::runtime_executor::Executor>, + super::FullClient< + super::runtime_executor::runtime::RuntimeApi, + super::runtime_executor::Executor, + >, >, ) -> Self { - Self::GTest(client) - } -} - -#[cfg(feature = "gdev")] -impl From<Arc<super::FullClient<gdev_runtime::RuntimeApi, super::runtime_executor::Executor>>> - for Client -{ - fn from( - client: Arc<super::FullClient<gdev_runtime::RuntimeApi, super::runtime_executor::Executor>>, - ) -> Self { - Self::GDev(client) + Self::Client(client) } } macro_rules! match_client { ($self:ident, $method:ident($($param:ident),*)) => { match $self { - #[cfg(feature = "g1")] - Self::G1(client) => client.$method($($param),*), - #[cfg(feature = "gtest")] - Self::GTest(client) => client.$method($($param),*), - #[cfg(feature = "gdev")] - Self::GDev(client) => client.$method($($param),*), + Self::Client(client) => client.$method($($param),*), } }; } @@ -336,7 +306,7 @@ use gtest_runtime as runtime; #[cfg(feature = "gtest")] type FullClient = super::FullClient<runtime::RuntimeApi, super::runtime_executor::Executor>; -#[cfg(any(feature = "gdev", feature = "gtest"))] +#[cfg(any(feature = "gdev", feature = "gtest", feature = "g1"))] impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullClient { fn sign_call( &self, diff --git a/runtime/g1/src/lib.rs b/runtime/g1/src/lib.rs index 64b716370..3ce455b52 100644 --- a/runtime/g1/src/lib.rs +++ b/runtime/g1/src/lib.rs @@ -33,6 +33,7 @@ pub use common_runtime::{ constants::*, entities::*, handlers::*, AccountId, Address, Balance, BlockNumber, FullIdentificationOfImpl, GetCurrentEpochIndex, Hash, Header, IdtyIndex, Index, Signature, }; +pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; pub use pallet_identity::{IdtyStatus, IdtyValue}; pub use pallet_im_online::sr25519::AuthorityId as ImOnlineId; -- GitLab