Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refact collator #263

Merged
merged 2 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
toolchain: nightly-2021-06-17
components: rustfmt
target: wasm32-unknown-unknown
default: true
- name: Check All
Expand Down
32 changes: 14 additions & 18 deletions node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<V
.ok_or_else(|| "Could not find wasm file in genesis state!".into())
}

use service::collator::new_partial;
#[cfg(feature = "with-asgard-runtime")]
use service::collator::{asgard_runtime, AsgardExecutor};
#[cfg(feature = "with-bifrost-runtime")]
Expand All @@ -225,18 +224,16 @@ macro_rules! construct_async_run {
let runner = $cli.create_runner($cmd)?;
#[cfg(feature = "with-asgard-runtime")]
return runner.async_run(|$config| {
let $components = new_partial::<asgard_runtime::RuntimeApi, AsgardExecutor, _>(
let $components = crate::service::collator::new_partial::<asgard_runtime::RuntimeApi, AsgardExecutor>(
&$config,
crate::service::collator::asgard_parachain_build_import_queue,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
});
#[cfg(feature = "with-bifrost-runtime")]
return runner.async_run(|$config| {
let $components = new_partial::<bifrost_runtime::RuntimeApi, BifrostExecutor, _>(
let $components = crate::service::collator::new_partial::<bifrost_runtime::RuntimeApi, BifrostExecutor>(
&$config,
crate::service::collator::bifrost_parachain_build_import_queue,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
Expand Down Expand Up @@ -279,16 +276,6 @@ macro_rules! with_runtime_or_err {
#[cfg(not(feature = "with-asgard-runtime"))]
return Err(service::ASGARD_RUNTIME_NOT_AVAILABLE.into());
} else {
#[cfg(feature = "with-dev-runtime")]
#[allow(unused_imports)]
use service::dev::dev_runtime::{Block, RuntimeApi};
#[cfg(feature = "with-dev-runtime")]
#[allow(unused_imports)]
use service::dev::DevExecutor as Executor;
#[cfg(feature = "with-dev-runtime")]
$( $code )*

#[cfg(not(feature = "with-dev-runtime"))]
return Err(service::DEV_RUNTIME_NOT_AVAILABLE.into());
}
}
Expand Down Expand Up @@ -356,9 +343,18 @@ pub fn run() -> Result<()> {
info!("Parachain genesis state: {}", genesis_state);
info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });

service::collator::start_node(config, polkadot_config, id)
.await
.map_err(Into::into)
with_runtime_or_err!(config.chain_spec, {
{
service::collator::start_node::<RuntimeApi, Executor>(
config,
polkadot_config,
id,
)
.await
.map(|r| r.0)
.map_err(Into::into)
}
})
})
},
Some(Subcommand::Inspect(cmd)) => {
Expand Down
11 changes: 2 additions & 9 deletions node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ pub use sc_rpc_api::DenyUnsafe;
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use zenlink_protocol_rpc::{ZenlinkProtocol, ZenlinkProtocolApi};
use zenlink_protocol_runtime_api::ZenlinkProtocolApi as ZenlinkProtocolRuntimeApi;

/// Full client dependencies.
pub struct FullDeps<C, P> {
Expand All @@ -63,16 +61,13 @@ pub type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>;
///
/// NOTE: It's a `PATCH` for the RPC of asgard runtime.
#[allow(non_snake_case)]
pub fn PATCH_FOR_ASGARD_create_full<C, P>(
deps: FullDeps<C, P>,
) -> Result<jsonrpc_core::IoHandler<sc_rpc_api::Metadata>, Box<dyn std::error::Error + Send + Sync>>
pub fn create_full<C, P>(deps: FullDeps<C, P>) -> RpcExtension
where
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,
C: Send + Sync + 'static,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: FeeRuntimeApi<Block, AccountId>,
C::Api: ZenlinkProtocolRuntimeApi<Block, AccountId>,
C::Api: SalpRuntimeApi<Block, ParaId, AccountId, Balance>,
P: TransactionPool + 'static,
{
Expand All @@ -84,9 +79,7 @@ where

io.extend_with(FeeRpcApi::to_delegate(FlexibleFeeStruct::new(client.clone())));

io.extend_with(ZenlinkProtocolApi::to_delegate(ZenlinkProtocol::new(client.clone())));

io.extend_with(SalpRpcApi::to_delegate(SalpRpcWrapper::new(client.clone())));

Ok(io)
io
}
Loading