Skip to content
This repository has been archived by the owner on Mar 30, 2023. It is now read-only.

Commit

Permalink
Companion for paritytech/cumulus#1782
Browse files Browse the repository at this point in the history
  • Loading branch information
jiguantong committed Jan 3, 2023
1 parent 341a001 commit 3c10385
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions node/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ use sp_runtime::app_crypto::AppKey;
type FullBackend = sc_service::TFullBackend<Block>;
type FullClient<RuntimeApi, Executor> =
sc_service::TFullClient<Block, RuntimeApi, sc_executor::NativeElseWasmExecutor<Executor>>;
type ParachainBlockImport<RuntimeApi> =
cumulus_client_consensus_common::ParachainBlockImport<Arc<ParachainClient<RuntimeApi>>>;

/// Can be called for a `Configuration` to check if it is a configuration for the `Crab` network.
pub trait IdentifyVariant {
Expand Down Expand Up @@ -123,6 +125,7 @@ pub fn new_partial<RuntimeApi, Executor>(
Option<fc_rpc_core::types::FilterPool>,
fc_rpc_core::types::FeeHistoryCache,
fc_rpc_core::types::FeeHistoryCacheLimit,
ParachainBlockImport<RuntimeApi>,
Option<sc_telemetry::Telemetry>,
Option<sc_telemetry::TelemetryWorkerHandle>,
),
Expand Down Expand Up @@ -172,8 +175,12 @@ where
task_manager.spawn_essential_handle(),
client.clone(),
);

let block_import = ParachainBlockImport::new(client.clone());

let import_queue = parachain_build_import_queue(
client.clone(),
block_import.clone(),
config,
telemetry.as_ref().map(|telemetry| telemetry.handle()),
&task_manager,
Expand Down Expand Up @@ -201,6 +208,7 @@ where
filter_pool,
fee_history_cache,
fee_history_cache_limit,
block_import,
telemetry,
telemetry_worker_handle,
),
Expand Down Expand Up @@ -240,7 +248,7 @@ async fn start_node_impl<RuntimeApi, Executor, RB, BIC>(
parachain_config: sc_service::Configuration,
polkadot_config: sc_service::Configuration,
collator_options: cumulus_client_cli::CollatorOptions,
id: cumulus_primitives_core::ParaId,
para_id: cumulus_primitives_core::ParaId,
_rpc_ext_builder: RB,
build_consensus: BIC,
hwbench: Option<sc_sysinfo::HwBench>,
Expand All @@ -254,13 +262,12 @@ where
RuntimeApi::RuntimeApi: RuntimeApiCollection,
sc_client_api::StateBackendFor<FullBackend, Block>: sp_api::StateBackend<Hashing>,
Executor: 'static + sc_executor::NativeExecutionDispatch,
RB: 'static
+ Send
+ Fn(
Arc<sc_service::TFullClient<Block, RuntimeApi, Executor>>,
) -> Result<jsonrpsee::RpcModule<()>, sc_service::Error>,
RB: Fn(
Arc<sc_service::TFullClient<Block, RuntimeApi, Executor>>,
) -> Result<jsonrpsee::RpcModule<()>, sc_service::Error>,
BIC: FnOnce(
Arc<FullClient<RuntimeApi, Executor>>,
ParachainBlockImport<RuntimeApi>,
Option<&substrate_prometheus_endpoint::Registry>,
Option<sc_telemetry::TelemetryHandle>,
&sc_service::TaskManager,
Expand Down Expand Up @@ -289,6 +296,7 @@ where
filter_pool,
fee_history_cache,
fee_history_cache_limit,
block_import,
mut telemetry,
telemetry_worker_handle,
),
Expand All @@ -311,7 +319,7 @@ where
})?;

let block_announce_validator =
cumulus_client_network::BlockAnnounceValidator::new(relay_chain_interface.clone(), id);
cumulus_client_network::BlockAnnounceValidator::new(relay_chain_interface.clone(), para_id);

let force_authoring = parachain_config.force_authoring;
let validator = parachain_config.role.is_authority();
Expand Down Expand Up @@ -418,6 +426,7 @@ where
if validator {
let parachain_consensus = build_consensus(
client.clone(),
block_import,
prometheus_registry.as_ref(),
telemetry.as_ref().map(|t| t.handle()),
&task_manager,
Expand All @@ -430,7 +439,7 @@ where

let spawner = task_manager.spawn_handle();
let params = cumulus_client_service::StartCollatorParams {
para_id: id,
para_id,
block_status: client.clone(),
announce_block,
client: client.clone(),
Expand All @@ -449,7 +458,7 @@ where
client: client.clone(),
announce_block,
task_manager: &mut task_manager,
para_id: id,
para_id,
relay_chain_interface,
relay_chain_slot_duration,
import_queue,
Expand All @@ -466,6 +475,7 @@ where
/// Build the import queue for the parachain runtime.
pub fn parachain_build_import_queue<RuntimeApi, Executor>(
client: Arc<FullClient<RuntimeApi, Executor>>,
block_import: ParachainBlockImport,
config: &sc_service::Configuration,
telemetry: Option<sc_telemetry::TelemetryHandle>,
task_manager: &sc_service::TaskManager,
Expand All @@ -491,7 +501,7 @@ where
_,
_,
>(cumulus_client_consensus_aura::ImportQueueParams {
block_import: client.clone(),
block_import,
client,
create_inherent_data_providers: move |_, _| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
Expand All @@ -516,7 +526,7 @@ pub async fn start_parachain_node<RuntimeApi, Executor>(
parachain_config: sc_service::Configuration,
polkadot_config: sc_service::Configuration,
collator_options: cumulus_client_cli::CollatorOptions,
id: cumulus_primitives_core::ParaId,
para_id: cumulus_primitives_core::ParaId,
hwbench: Option<sc_sysinfo::HwBench>,
eth_rpc_config: &crate::cli::EthRpcConfig,
) -> sc_service::error::Result<(
Expand All @@ -537,9 +547,10 @@ where
parachain_config,
polkadot_config,
collator_options,
id,
para_id,
|_| Ok(jsonrpsee::RpcModule::new(())),
|client,
block_import,
prometheus_registry,
telemetry,
task_manager,
Expand Down Expand Up @@ -576,7 +587,7 @@ where
relay_parent,
&relay_chain_interface,
&validation_data,
id,
para_id,
).await;
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();

Expand Down

0 comments on commit 3c10385

Please sign in to comment.