diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index a070dbd1a10..4f132d436a1 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -34,17 +34,30 @@ use sp_consensus::{ import_queue::{ImportQueue, IncomingBlock, Link, Origin}, BlockImport, BlockOrigin, }; -use sp_core::traits::SpawnNamed; +use sp_core::{traits::SpawnNamed, Pair}; use sp_runtime::{ traits::{BlakeTwo256, Block as BlockT, NumberFor}, Justifications, }; -use std::{marker::PhantomData, sync::Arc}; +use std::{marker::PhantomData, ops::Deref, sync::Arc}; pub mod genesis; -/// Relay chain full node handles. -type RFullNode = polkadot_service::NewFull; +/// The relay chain full node handle. +pub struct RFullNode { + /// The relay chain full node handles. + pub relay_chain_full_node: polkadot_service::NewFull, + /// The collator key used by the node. + pub collator_key: CollatorPair, +} + +impl Deref for RFullNode { + type Target = polkadot_service::NewFull; + + fn deref(&self) -> &Self::Target { + &self.relay_chain_full_node + } +} /// Parameters given to [`start_collator`]. pub struct StartCollatorParams<'a, Block: BlockT, BS, Client, Spawner, RClient, IQ> { @@ -53,7 +66,6 @@ pub struct StartCollatorParams<'a, Block: BlockT, BS, Client, Spawner, RClient, pub announce_block: Arc>) + Send + Sync>, pub spawner: Spawner, pub para_id: ParaId, - pub collator_key: CollatorPair, pub relay_chain_full_node: RFullNode, pub task_manager: &'a mut TaskManager, pub parachain_consensus: Box>, @@ -72,7 +84,6 @@ pub async fn start_collator<'a, Block, BS, Client, Backend, Spawner, RClient, IQ announce_block, spawner, para_id, - collator_key, task_manager, relay_chain_full_node, parachain_consensus, @@ -106,17 +117,19 @@ where _phantom: PhantomData, }); - relay_chain_full_node.client.execute_with(StartPoVRecovery { - para_id, - client: client.clone(), - import_queue, - task_manager, - overseer_handler: relay_chain_full_node - .overseer_handler - .clone() - .ok_or_else(|| "Polkadot full node did not provided an `OverseerHandler`!")?, - _phantom: PhantomData, - })?; + relay_chain_full_node + .client + .execute_with(StartPoVRecovery { + para_id, + client: client.clone(), + import_queue, + task_manager, + overseer_handler: relay_chain_full_node + .overseer_handler + .clone() + .ok_or_else(|| "Polkadot full node did not provided an `OverseerHandler`!")?, + _phantom: PhantomData, + })?; cumulus_client_collator::start_collator(cumulus_client_collator::StartCollatorParams { runtime_api: client.clone(), @@ -124,15 +137,16 @@ where announce_block, overseer_handler: relay_chain_full_node .overseer_handler + .clone() .ok_or_else(|| "Polkadot full node did not provided an `OverseerHandler`!")?, spawner, para_id, - key: collator_key, + key: relay_chain_full_node.collator_key.clone(), parachain_consensus, }) .await; - task_manager.add_child(relay_chain_full_node.task_manager); + task_manager.add_child(relay_chain_full_node.relay_chain_full_node.task_manager); Ok(()) } @@ -180,7 +194,7 @@ where _phantom: PhantomData, }); - task_manager.add_child(relay_chain_full_node.task_manager); + task_manager.add_child(relay_chain_full_node.relay_chain_full_node.task_manager); Ok(()) } @@ -234,12 +248,17 @@ struct StartPoVRecovery<'a, Block: BlockT, Client, IQ> { para_id: ParaId, client: Arc, task_manager: &'a mut TaskManager, + overseer_handler: OverseerHandler, import_queue: IQ, + + _phantom: PhantomData, } + -impl<'a, Block, Client, IQ> polkadot_service::ExecuteWithClient for StartPoVRecovery<'a, Block, Client, IQ> +impl<'a, Block, Client, IQ> polkadot_service::ExecuteWithClient + for StartPoVRecovery<'a, Block, Client, IQ> where Block: BlockT, Client: UsageProvider @@ -291,7 +310,6 @@ pub fn prepare_node_config(mut parachain_config: Configuration) -> Configuration #[sc_tracing::logging::prefix_logs_with("Relaychain")] pub fn build_polkadot_full_node( config: Configuration, - collator_pair: CollatorPair, telemetry_worker_handle: Option, ) -> Result, polkadot_service::Error> { let is_light = matches!(config.role, Role::Light); @@ -300,14 +318,22 @@ pub fn build_polkadot_full_node( "Light client not supported.".into(), )) } else { - polkadot_service::build_full( + let collator_key = CollatorPair::generate().0; + + let relay_chain_full_node = polkadot_service::build_full( config, - polkadot_service::IsCollator::Yes(collator_pair), + polkadot_service::IsCollator::Yes(collator_key.clone()), None, true, None, telemetry_worker_handle, - ) + )?; + + Ok(RFullNode { + relay_chain_full_node, + collator_key, + }) + } } diff --git a/polkadot-parachains/Cargo.toml b/polkadot-parachains/Cargo.toml index 51bf31fc3ff..73357c427a5 100644 --- a/polkadot-parachains/Cargo.toml +++ b/polkadot-parachains/Cargo.toml @@ -82,8 +82,6 @@ polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "m polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "master" } polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "master" } - - [build-dependencies] substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/polkadot-parachains/src/command.rs b/polkadot-parachains/src/command.rs index 920888bc2f1..d468298dfea 100644 --- a/polkadot-parachains/src/command.rs +++ b/polkadot-parachains/src/command.rs @@ -391,9 +391,6 @@ pub fn run() -> Result<()> { let runner = cli.create_runner(&cli.run.normalize())?; runner.run_node_until_exit(|config| async move { - // TODO - let key = sp_core::Pair::generate().0; - let para_id = chain_spec::Extensions::try_get(&*config.chain_spec).map(|e| e.para_id); @@ -433,7 +430,6 @@ pub fn run() -> Result<()> { if config.chain_spec.is_statemint() { crate::service::start_statemint_node::( config, - key, polkadot_config, id, ) @@ -443,7 +439,6 @@ pub fn run() -> Result<()> { } else if config.chain_spec.is_statemine() { crate::service::start_statemint_node::( config, - key, polkadot_config, id, ) @@ -453,7 +448,6 @@ pub fn run() -> Result<()> { } else if config.chain_spec.is_westmint() { crate::service::start_statemint_node::( config, - key, polkadot_config, id, ) @@ -461,12 +455,12 @@ pub fn run() -> Result<()> { .map(|r| r.0) .map_err(Into::into) } else if config.chain_spec.is_shell() { - crate::service::start_shell_node(config, key, polkadot_config, id) + crate::service::start_shell_node(config, polkadot_config, id) .await .map(|r| r.0) .map_err(Into::into) } else { - crate::service::start_rococo_parachain_node(config, key, polkadot_config, id) + crate::service::start_rococo_parachain_node(config, polkadot_config, id) .await .map(|r| r.0) .map_err(Into::into) diff --git a/polkadot-parachains/src/service.rs b/polkadot-parachains/src/service.rs index 681a16a7912..6e88945abc9 100644 --- a/polkadot-parachains/src/service.rs +++ b/polkadot-parachains/src/service.rs @@ -27,7 +27,6 @@ use cumulus_client_service::{ use cumulus_primitives_core::{ ParaId, relay_chain::v1::{Hash as PHash, PersistedValidationData}, }; -use polkadot_primitives::v1::CollatorPair; use sc_client_api::ExecutorProvider; use sc_executor::native_executor_instance; @@ -195,7 +194,6 @@ where #[sc_tracing::logging::prefix_logs_with("Parachain")] async fn start_node_impl( parachain_config: Configuration, - collator_key: CollatorPair, polkadot_config: Configuration, id: ParaId, rpc_ext_builder: RB, @@ -255,7 +253,6 @@ where let relay_chain_full_node = cumulus_client_service::build_polkadot_full_node( polkadot_config, - collator_key.clone(), telemetry_worker_handle, ) .map_err(|e| match e { @@ -333,7 +330,6 @@ where announce_block, client: client.clone(), task_manager: &mut task_manager, - collator_key, relay_chain_full_node, spawner, parachain_consensus, @@ -404,7 +400,6 @@ pub fn rococo_parachain_build_import_queue( /// Start a rococo parachain node. pub async fn start_rococo_parachain_node( parachain_config: Configuration, - collator_key: CollatorPair, polkadot_config: Configuration, id: ParaId, ) -> sc_service::error::Result<( @@ -413,7 +408,6 @@ pub async fn start_rococo_parachain_node( )> { start_node_impl::( parachain_config, - collator_key, polkadot_config, id, |_| Default::default(), @@ -522,7 +516,6 @@ pub fn shell_build_import_queue( /// Start a polkadot-shell parachain node. pub async fn start_shell_node( parachain_config: Configuration, - collator_key: CollatorPair, polkadot_config: Configuration, id: ParaId, ) -> sc_service::error::Result<( @@ -531,7 +524,6 @@ pub async fn start_shell_node( )> { start_node_impl::( parachain_config, - collator_key, polkadot_config, id, |_| Default::default(), @@ -790,7 +782,6 @@ where /// Start a statemint/statemine/westmint parachain node. pub async fn start_statemint_node( parachain_config: Configuration, - collator_key: CollatorPair, polkadot_config: Configuration, id: ParaId, ) -> sc_service::error::Result<( @@ -817,7 +808,6 @@ where { start_node_impl::( parachain_config, - collator_key, polkadot_config, id, |_| Default::default(), diff --git a/test/service/src/lib.rs b/test/service/src/lib.rs index d5f93f195b1..d7c62fd781b 100644 --- a/test/service/src/lib.rs +++ b/test/service/src/lib.rs @@ -303,9 +303,11 @@ where spawner: task_manager.spawn_handle(), task_manager: &mut task_manager, para_id, - collator_key, parachain_consensus, - relay_chain_full_node, + relay_chain_full_node: cumulus_client_service::RFullNode { + relay_chain_full_node, + collator_key, + }, import_queue, }; @@ -319,7 +321,10 @@ where announce_block, task_manager: &mut task_manager, para_id, - relay_chain_full_node, + relay_chain_full_node: cumulus_client_service::RFullNode { + relay_chain_full_node, + collator_key: CollatorPair::generate().0, + }, }; start_full_node(params)?;