Skip to content
Snippets Groups Projects

Refactor node implementation

Merged Benjamin Gallois requested to merge 216-refactor-node into master
Files
12
+ 58
82
@@ -145,12 +145,14 @@ impl<Api> RuntimeApiCollection for Api where
@@ -145,12 +145,14 @@ impl<Api> RuntimeApiCollection for Api where
/// A client instance.
/// A client instance.
#[derive(Clone)]
#[derive(Clone)]
pub enum Client {
pub enum Client {
#[cfg(feature = "g1")]
Client(
G1(Arc<super::FullClient<g1_runtime::RuntimeApi, super::g1_executor::G1Executor>>),
Arc<
#[cfg(feature = "gtest")]
super::FullClient<
GTest(Arc<super::FullClient<gtest_runtime::RuntimeApi, super::gtest_executor::GTestExecutor>>),
super::runtime_executor::runtime::RuntimeApi,
#[cfg(feature = "gdev")]
super::runtime_executor::Executor,
GDev(Arc<super::FullClient<gdev_runtime::RuntimeApi, super::gdev_executor::GDevExecutor>>),
>,
 
>,
 
),
}
}
macro_rules! with_client {
macro_rules! with_client {
@@ -162,22 +164,8 @@ macro_rules! with_client {
@@ -162,22 +164,8 @@ macro_rules! with_client {
}
}
} => {
} => {
match $self {
match $self {
#[cfg(feature = "g1")]
Self::Client($client) => {
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) => {
#[allow(unused_imports)]
#[allow(unused_imports)]
use gdev_runtime as runtime;
$( $code )*
$( $code )*
}
}
}
}
@@ -196,52 +184,32 @@ impl ClientHandle for Client {
@@ -196,52 +184,32 @@ impl ClientHandle for Client {
}
}
}
}
#[cfg(feature = "g1")]
impl
impl From<Arc<super::FullClient<g1_runtime::RuntimeApi, super::g1_executor::G1Executor>>>
From<
for Client
Arc<
{
super::FullClient<
fn from(
super::runtime_executor::runtime::RuntimeApi,
client: Arc<super::FullClient<g1_runtime::RuntimeApi, super::g1_executor::G1Executor>>,
super::runtime_executor::Executor,
) -> Self {
>,
Self::G1(client)
}
}
#[cfg(feature = "gtest")]
impl From<Arc<super::FullClient<gtest_runtime::RuntimeApi, super::gtest_executor::GTestExecutor>>>
for Client
{
fn from(
client: Arc<
super::FullClient<gtest_runtime::RuntimeApi, super::gtest_executor::GTestExecutor>,
>,
>,
) -> Self {
> for Client
Self::GTest(client)
}
}
#[cfg(feature = "gdev")]
impl From<Arc<super::FullClient<gdev_runtime::RuntimeApi, super::gdev_executor::GDevExecutor>>>
for Client
{
{
fn from(
fn from(
client: Arc<
client: Arc<
super::FullClient<gdev_runtime::RuntimeApi, super::gdev_executor::GDevExecutor>,
super::FullClient<
 
super::runtime_executor::runtime::RuntimeApi,
 
super::runtime_executor::Executor,
 
>,
>,
>,
) -> Self {
) -> Self {
Self::GDev(client)
Self::Client(client)
}
}
}
}
macro_rules! match_client {
macro_rules! match_client {
($self:ident, $method:ident($($param:ident),*)) => {
($self:ident, $method:ident($($param:ident),*)) => {
match $self {
match $self {
#[cfg(feature = "g1")]
Self::Client(client) => client.$method($($param),*),
Self::G1(client) => client.$method($($param),*),
#[cfg(feature = "gtest")]
Self::GTest(client) => client.$method($($param),*),
#[cfg(feature = "gdev")]
Self::GDev(client) => client.$method($($param),*),
}
}
};
};
}
}
@@ -326,23 +294,28 @@ trait BenchmarkCallSigner<RuntimeCall: Encode + Clone, Signer: Pair> {
@@ -326,23 +294,28 @@ trait BenchmarkCallSigner<RuntimeCall: Encode + Clone, Signer: Pair> {
}
}
#[cfg(feature = "g1")]
#[cfg(feature = "g1")]
use g1_runtime as runtime;
type FullClient = super::FullClient<
#[cfg(feature = "g1")]
super::runtime_executor::runtime::RuntimeApi,
type FullClient = super::FullClient<runtime::RuntimeApi, super::g1_executor::G1Executor>;
super::runtime_executor::Executor,
#[cfg(feature = "gdev")]
>;
use gdev_runtime as runtime;
#[cfg(feature = "gdev")]
#[cfg(feature = "gdev")]
type FullClient = super::FullClient<runtime::RuntimeApi, super::gdev_executor::GDevExecutor>;
type FullClient = super::FullClient<
 
super::runtime_executor::runtime::RuntimeApi,
 
super::runtime_executor::Executor,
 
>;
#[cfg(feature = "gtest")]
#[cfg(feature = "gtest")]
use gtest_runtime as runtime;
type FullClient = super::FullClient<
#[cfg(feature = "gtest")]
super::runtime_executor::runtime::RuntimeApi,
type FullClient = super::FullClient<runtime::RuntimeApi, super::gtest_executor::GTestExecutor>;
super::runtime_executor::Executor,
>;
#[cfg(any(feature = "gdev", feature = "gtest"))]
impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullClient {
#[cfg(any(feature = "gdev", feature = "gtest", feature = "g1"))]
 
impl BenchmarkCallSigner<super::runtime_executor::runtime::RuntimeCall, sp_core::sr25519::Pair>
 
for FullClient
 
{
fn sign_call(
fn sign_call(
&self,
&self,
call: runtime::RuntimeCall,
call: super::runtime_executor::runtime::RuntimeCall,
nonce: u32,
nonce: u32,
current_block: u64,
current_block: u64,
period: u64,
period: u64,
@@ -351,17 +324,20 @@ impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullC
@@ -351,17 +324,20 @@ impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullC
) -> sp_runtime::OpaqueExtrinsic {
) -> sp_runtime::OpaqueExtrinsic {
// use runtime;
// use runtime;
let extra: runtime::SignedExtra = (
let extra: super::runtime_executor::runtime::SignedExtra = (
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
frame_system::CheckNonZeroSender::<super::runtime_executor::runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<super::runtime_executor::runtime::Runtime>::new(),
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
frame_system::CheckTxVersion::<super::runtime_executor::runtime::Runtime>::new(),
frame_system::CheckGenesis::<runtime::Runtime>::new(),
frame_system::CheckGenesis::<super::runtime_executor::runtime::Runtime>::new(),
frame_system::CheckMortality::<runtime::Runtime>::from(
frame_system::CheckMortality::<super::runtime_executor::runtime::Runtime>::from(
sp_runtime::generic::Era::mortal(period, current_block),
sp_runtime::generic::Era::mortal(period, current_block),
),
),
frame_system::CheckNonce::<runtime::Runtime>::from(nonce).into(),
frame_system::CheckNonce::<super::runtime_executor::runtime::Runtime>::from(nonce)
frame_system::CheckWeight::<runtime::Runtime>::new(),
.into(),
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
frame_system::CheckWeight::<super::runtime_executor::runtime::Runtime>::new(),
 
pallet_transaction_payment::ChargeTransactionPayment::<
 
super::runtime_executor::runtime::Runtime,
 
>::from(0),
);
);
let payload = sp_runtime::generic::SignedPayload::from_raw(
let payload = sp_runtime::generic::SignedPayload::from_raw(
@@ -369,8 +345,8 @@ impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullC
@@ -369,8 +345,8 @@ impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullC
extra.clone(),
extra.clone(),
(
(
(),
(),
runtime::VERSION.spec_version,
super::runtime_executor::runtime::VERSION.spec_version,
runtime::VERSION.transaction_version,
super::runtime_executor::runtime::VERSION.transaction_version,
genesis,
genesis,
genesis,
genesis,
(),
(),
@@ -380,7 +356,7 @@ impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullC
@@ -380,7 +356,7 @@ impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullC
);
);
let signature = payload.using_encoded(|p| acc.sign(p));
let signature = payload.using_encoded(|p| acc.sign(p));
runtime::UncheckedExtrinsic::new_signed(
super::runtime_executor::runtime::UncheckedExtrinsic::new_signed(
call,
call,
sp_runtime::AccountId32::from(acc.public()).into(),
sp_runtime::AccountId32::from(acc.public()).into(),
common_runtime::Signature::Sr25519(signature),
common_runtime::Signature::Sr25519(signature),
@@ -402,10 +378,10 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for Client {
@@ -402,10 +378,10 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for Client {
fn build(&self, nonce: u32) -> std::result::Result<sp_runtime::OpaqueExtrinsic, &'static str> {
fn build(&self, nonce: u32) -> std::result::Result<sp_runtime::OpaqueExtrinsic, &'static str> {
with_client! {
with_client! {
self, client, {
self, client, {
let call = runtime::RuntimeCall::System(runtime::SystemCall::remark { remark: vec![] });
let call = super::runtime_executor::runtime::RuntimeCall::System(super::runtime_executor::runtime::SystemCall::remark { remark: vec![] });
let signer = sp_keyring::Sr25519Keyring::Bob.pair();
let signer = sp_keyring::Sr25519Keyring::Bob.pair();
let period = runtime::BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64;
let period = super::runtime_executor::runtime::BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64;
let genesis = client.usage_info().chain.best_hash;
let genesis = client.usage_info().chain.best_hash;
Ok(client.sign_call(call, nonce, 0, period, genesis, signer))
Ok(client.sign_call(call, nonce, 0, period, genesis, signer))
Loading