Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Trappist node refactor #206

Merged
merged 17 commits into from
Jun 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
compiling :)
hbulgarini committed May 26, 2023

Verified

This commit was signed with the committer’s verified signature.
hbulgarini Hector Bulgarini
commit c199a57528445252083338adadb034fbb52b396d
13 changes: 6 additions & 7 deletions node/src/command.rs
Original file line number Diff line number Diff line change
@@ -17,8 +17,7 @@
use crate::{
chain_spec,
cli::{Cli, RelayChainCli, Subcommand},
service::{new_partial, Block, TrappistRuntimeExecutor},
service_stout::{new_stout_partial, StoutRuntimeExecutor},
service::{new_partial, new_generic_partial, Block, TrappistRuntimeExecutor, StoutRuntimeExecutor},
};
use codec::Encode;
use cumulus_client_cli::generate_genesis_block;
@@ -205,9 +204,9 @@ macro_rules! construct_benchmark_partials {
$code
},
Runtime::Stout => {
let $partials = new_stout_partial::<stout_runtime::RuntimeApi, _>(
let $partials = new_generic_partial::<stout_runtime::RuntimeApi, _>(
&$config,
crate::service_stout::aura_stout_build_import_queue::<_, AuraId>,
crate::service::aura_build_generic_import_queue::<_, AuraId>,
)?;
$code
},
@@ -232,9 +231,9 @@ macro_rules! construct_async_run {
},
Runtime::Stout => {
runner.async_run(|$config| {
let $components = new_stout_partial::<stout_runtime::RuntimeApi, _>(
let $components = new_generic_partial::<stout_runtime::RuntimeApi, _>(
&$config,
crate::service_stout::aura_stout_build_import_queue::<_, AuraId>,
crate::service::aura_build_generic_import_queue::<_, AuraId>,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
@@ -445,7 +444,7 @@ pub fn run() -> Result<()> {
.await
.map(|r| r.0)
.map_err(Into::into),
Runtime::Stout => crate::service_stout::start_stout_aura_node::<
Runtime::Stout => crate::service::start_generic_2_aura_node::<
stout_runtime::RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
1 change: 0 additions & 1 deletion node/src/main.rs
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ mod service;
mod cli;
mod command;
mod rpc;
mod service_stout;

fn main() -> sc_cli::Result<()> {
command::run()
106 changes: 72 additions & 34 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
@@ -83,64 +83,102 @@ where
Ok(module)
}

pub trait RuntimeApiCollection:
frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ BlockBuilder<Block>
+ 'static
{
}

pub trait ClientRequiredTraits:
ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
+ AuxStore
+ HeaderMetadata<Block, Error = BlockChainError>
+ Send
+ Sync
+ 'static
where
<Self as ProvideRuntimeApi<Block>>::Api: RuntimeApiCollection,
{
}

pub trait PoolRequiredTraits: TransactionPool + Sync + Send + 'static {}

pub trait BackendRequiredTraits: sc_client_api::Backend<Block> + Send + Sync + 'static
where
<Self as sc_client_api::Backend<Block>>::State:
sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
{
/* pub trait ClientRequiredTraits {
type Client: ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
+ AuxStore
+ HeaderMetadata<Block, Error = BlockChainError>
+ Send
+ Sync
+ 'static;
type Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ BlockBuilder<Block>;
}

impl<T> ClientRequiredTraits for T
impl<C> ClientRequiredTraits for C
where
T: ProvideRuntimeApi<Block>
C: ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
+ AuxStore
+ HeaderMetadata<Block, Error = BlockChainError>
+ Send
+ Sync
+ 'static,
T::Api: RuntimeApiCollection,
C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ BlockBuilder<Block>,
{
type Client = C;
type Api = C::Api;
}

pub trait PoolRequiredTraits {
type Pool: TransactionPool + Sync + Send + 'static;
}

impl<T> PoolRequiredTraits for T where T: TransactionPool + Sync + Send + 'static {}
impl<T> PoolRequiredTraits for T
where
T: TransactionPool + Sync + Send + 'static,
{
type Pool = T;
}

pub trait BackendRequiredTraits {
type Backend: sc_client_api::Backend<Block> + Send + Sync + 'static;
type State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>;
}

impl<T> BackendRequiredTraits for T
where
T: sc_client_api::Backend<Block> + Send + Sync + 'static,
T::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
{
type Backend = T;
type State = T::State;
}

pub fn create_stout_full<C: ClientRequiredTraits, P: PoolRequiredTraits, B: BackendRequiredTraits>(
pub fn create_stout_full_bck<C, P, B>(
deps: FullDeps<C, P>,
backend: Arc<B>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ClientRequiredTraits,
P: PoolRequiredTraits,
B: BackendRequiredTraits,
{
use frame_rpc_system::{System, SystemApiServer};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use substrate_state_trie_migration_rpc::{StateMigration, StateMigrationApiServer};

let mut module = RpcExtension::new(());
let FullDeps { client, pool, deny_unsafe } = deps;

module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
module.merge(StateMigration::new(client.clone(), backend, deny_unsafe).into_rpc())?;

Ok(module)
} */

pub fn create_stout_full<C, P, B>(
deps: FullDeps<C, P>,
backend: Arc<B>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C::Api: RuntimeApiCollection,
C: ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
+ AuxStore
+ HeaderMetadata<Block, Error = BlockChainError>
+ Send
+ Sync
+ 'static,
C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
{
use frame_rpc_system::{System, SystemApiServer};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
52 changes: 42 additions & 10 deletions node/src/service.rs
Original file line number Diff line number Diff line change
@@ -144,7 +144,14 @@ pub fn new_generic_partial<RuntimeApi, BIQ>(
>
where
RuntimeApi: ConstructRuntimeApi<Block, ParachainClient<RuntimeApi>> + Send + Sync + 'static,
RuntimeApi::RuntimeApi: RuntimeApiExt,
RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
+ sp_api::Metadata<Block>
+ sp_session::SessionKeys<Block>
+ sp_api::ApiExt<
Block,
StateBackend = sc_client_api::StateBackendFor<ParachainBackend, Block>,
> + sp_offchain::OffchainWorkerApi<Block>
+ sp_block_builder::BlockBuilder<Block>,
sc_client_api::StateBackendFor<ParachainBackend, Block>: sp_api::StateBackend<BlakeTwo256>,
BIQ: FnOnce(
Arc<ParachainClient<RuntimeApi>>,
@@ -239,7 +246,15 @@ pub fn new_trappist_partial<RuntimeApi, BIQ>(
>
where
RuntimeApi: ConstructRuntimeApi<Block, ParachainClient<RuntimeApi>> + Send + Sync + 'static,
RuntimeApi::RuntimeApi: RuntimeApiExt + pallet_dex_rpc::DexRuntimeApi<Block, AssetId, Balance, Balance> ,
RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
+ sp_api::Metadata<Block>
+ sp_session::SessionKeys<Block>
+ sp_api::ApiExt<
Block,
StateBackend = sc_client_api::StateBackendFor<ParachainBackend, Block>,
> + sp_offchain::OffchainWorkerApi<Block>
+ sp_block_builder::BlockBuilder<Block>
+ pallet_dex_rpc::DexRuntimeApi<Block, AssetId, Balance, Balance> ,
sc_client_api::StateBackendFor<ParachainBackend, Block>: sp_api::StateBackend<BlakeTwo256>,
BIQ: FnOnce(
Arc<ParachainClient<RuntimeApi>>,
@@ -257,18 +272,17 @@ where



fn create_stout_full_rpc<C, P, B>(
/* fn create_stout_full_rpc<C, P, B>(
deps: rpc::FullDeps<C, P>,
backend: Arc<B>,
) -> Result<jsonrpsee::RpcModule<()>, sc_service::Error>
where
C: rpc::ClientRequiredTraits,
P: rpc::PoolRequiredTraits,
B: rpc::BackendRequiredTraits,
C::Api: rpc::RuntimeApiCollection,
{
rpc::create_stout_full(deps, backend.clone()).map_err(Into::into)
}
} */

/// Start a node with the given parachain `Configuration` and relay chain `Configuration`.
///
@@ -286,7 +300,17 @@ async fn start_generic_node_impl<RuntimeApi, BIQ, RB, BIC>(
) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient<RuntimeApi>>)>
where
RuntimeApi: ConstructRuntimeApi<Block, ParachainClient<RuntimeApi>> + Send + Sync + 'static,
RuntimeApi::RuntimeApi: NodeRuntimeApiExt,
RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
+ sp_api::Metadata<Block>
+ sp_session::SessionKeys<Block>
+ sp_api::ApiExt<
Block,
StateBackend = sc_client_api::StateBackendFor<ParachainBackend, Block>,
> + sp_offchain::OffchainWorkerApi<Block>
+ sp_block_builder::BlockBuilder<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
sc_client_api::StateBackendFor<ParachainBackend, Block>: sp_api::StateBackend<BlakeTwo256>,
RB: Fn(
rpc::FullDeps<
@@ -887,9 +911,18 @@ pub async fn start_generic_2_aura_node<RuntimeApi, AuraId: AppKey>(
) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient<RuntimeApi>>)>
where
RuntimeApi: ConstructRuntimeApi<Block, ParachainClient<RuntimeApi>> + Send + Sync + 'static,
RuntimeApi::RuntimeApi: NodeRuntimeApiExt
RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
+ sp_api::Metadata<Block>
+ sp_session::SessionKeys<Block>
+ sp_api::ApiExt<
Block,
StateBackend = sc_client_api::StateBackendFor<ParachainBackend, Block>,
> + sp_offchain::OffchainWorkerApi<Block>
+ sp_block_builder::BlockBuilder<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block>
+ sp_consensus_aura::AuraApi<Block, <<AuraId as AppKey>::Pair as Pair>::Public>
+ rpc::RuntimeApiCollection,
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
sc_client_api::StateBackendFor<ParachainBackend, Block>: sp_api::StateBackend<BlakeTwo256>,
<<AuraId as AppKey>::Pair as Pair>::Signature:
TryFrom<Vec<u8>> + std::hash::Hash + sp_runtime::traits::Member + Codec,
@@ -899,7 +932,7 @@ where
polkadot_config,
collator_options,
para_id,
|deps, backend| create_stout_full_rpc::<_, _, _>(deps, backend),
|deps, backend| rpc::create_stout_full::<_, _, _>(deps, backend).map_err(Into::into),
aura_build_generic_import_queue::<RuntimeApi, AuraId>,
|client,
block_import,
@@ -1211,7 +1244,6 @@ pub fn aura_build_generic_import_queue<RuntimeApi, AuraId: AppKey>(
) -> Result<sc_consensus::DefaultImportQueue<Block, ParachainClient<RuntimeApi>>, sc_service::Error>
where
RuntimeApi: ConstructRuntimeApi<Block, ParachainClient<RuntimeApi>> + Send + Sync + 'static,
//RuntimeApi::RuntimeApi: NodeRuntimeApiExt,
RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
+ sp_api::Metadata<Block>
+ sp_session::SessionKeys<Block>