diff --git a/Cargo.lock b/Cargo.lock index 512fa3fb65d..f4b54481780 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2093,7 +2093,7 @@ dependencies = [ "futures-timer", "jsonrpsee 0.9.0", "parity-scale-codec", - "parking_lot 0.11.2", + "parking_lot 0.12.0", "polkadot-service", "sc-client-api", "sc-rpc-api", diff --git a/client/relay-chain-inprocess-interface/src/lib.rs b/client/relay-chain-inprocess-interface/src/lib.rs index e6df0ea0ad2..83cb4d13361 100644 --- a/client/relay-chain-inprocess-interface/src/lib.rs +++ b/client/relay-chain-inprocess-interface/src/lib.rs @@ -325,42 +325,44 @@ impl ExecuteWithClient for RelayChainInProcessInterfaceBuilder { #[sc_tracing::logging::prefix_logs_with("Relaychain")] fn build_polkadot_full_node( config: Configuration, + parachain_config: &Configuration, telemetry_worker_handle: Option, -) -> Result<(NewFull, CollatorPair), polkadot_service::Error> { +) -> Result<(NewFull, Option), polkadot_service::Error> { let is_light = matches!(config.role, Role::Light); if is_light { Err(polkadot_service::Error::Sub("Light client not supported.".into())) } else { - let collator_key = CollatorPair::generate().0; + let (is_collator, maybe_collator_key) = if parachain_config.role.is_authority() { + let collator_key = CollatorPair::generate().0; + (polkadot_service::IsCollator::Yes(collator_key.clone()), Some(collator_key)) + } else { + (polkadot_service::IsCollator::No, None) + }; let relay_chain_full_node = polkadot_service::build_full( config, - polkadot_service::IsCollator::Yes(collator_key.clone()), + is_collator, None, true, None, telemetry_worker_handle, - false, + true, polkadot_service::RealOverseerGen, )?; - Ok((relay_chain_full_node, collator_key)) + Ok((relay_chain_full_node, maybe_collator_key)) } } /// Builds a relay chain interface by constructing a full relay chain node pub fn build_inprocess_relay_chain( polkadot_config: Configuration, + parachain_config: &Configuration, telemetry_worker_handle: Option, task_manager: &mut TaskManager, -) -> Result<(Arc<(dyn RelayChainInterface + 'static)>, CollatorPair), polkadot_service::Error> { +) -> RelayChainResult<(Arc<(dyn RelayChainInterface + 'static)>, Option)> { let (full_node, collator_key) = - build_polkadot_full_node(polkadot_config, telemetry_worker_handle).map_err( - |e| match e { - polkadot_service::Error::Sub(x) => x, - s => format!("{}", s).into(), - }, - )?; + build_polkadot_full_node(polkadot_config, parachain_config, telemetry_worker_handle)?; let sync_oracle: Box = Box::new(full_node.network.clone()); let sync_oracle = Arc::new(Mutex::new(sync_oracle)); @@ -370,6 +372,7 @@ pub fn build_inprocess_relay_chain( sync_oracle, overseer_handle: full_node.overseer_handle.clone(), }; + task_manager.add_child(full_node.task_manager); Ok((relay_chain_interface_builder.build(), collator_key)) diff --git a/client/relay-chain-rpc-interface/Cargo.toml b/client/relay-chain-rpc-interface/Cargo.toml index 7a36779993f..da1c02277aa 100644 --- a/client/relay-chain-rpc-interface/Cargo.toml +++ b/client/relay-chain-rpc-interface/Cargo.toml @@ -22,7 +22,7 @@ sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "master futures = "0.3.21" futures-timer = "3.0.2" parity-scale-codec = "3.0.0" -parking_lot = "0.11.1" +parking_lot = "0.12.0" jsonrpsee = { version = "0.9.0", features = ["client"] } tracing = "0.1.25" async-trait = "0.1.52" diff --git a/parachain-template/node/src/service.rs b/parachain-template/node/src/service.rs index f7093222af2..108d7c18511 100644 --- a/parachain-template/node/src/service.rs +++ b/parachain-template/node/src/service.rs @@ -166,6 +166,7 @@ where async fn build_relay_chain_interface( polkadot_config: Configuration, + parachain_config: &Configuration, telemetry_worker_handle: Option, task_manager: &mut TaskManager, collator_options: CollatorOptions, @@ -173,14 +174,12 @@ async fn build_relay_chain_interface( match collator_options.relay_chain_rpc_url { Some(relay_chain_url) => Ok((Arc::new(RelayChainRPCInterface::new(relay_chain_url).await?) as Arc<_>, None)), - None => { - let relay_chain_local = build_inprocess_relay_chain( - polkadot_config, - telemetry_worker_handle, - task_manager, - )?; - Ok((relay_chain_local.0, Some(relay_chain_local.1))) - }, + None => build_inprocess_relay_chain( + polkadot_config, + parachain_config, + telemetry_worker_handle, + task_manager, + ), } } @@ -267,6 +266,7 @@ where let (relay_chain_interface, collator_key) = build_relay_chain_interface( polkadot_config, + ¶chain_config, telemetry_worker_handle, &mut task_manager, collator_options.clone(), diff --git a/polkadot-parachains/src/service.rs b/polkadot-parachains/src/service.rs index ea890fd33fe..b72753590c6 100644 --- a/polkadot-parachains/src/service.rs +++ b/polkadot-parachains/src/service.rs @@ -287,6 +287,7 @@ where async fn build_relay_chain_interface( polkadot_config: Configuration, + parachain_config: &Configuration, telemetry_worker_handle: Option, task_manager: &mut TaskManager, collator_options: CollatorOptions, @@ -294,14 +295,12 @@ async fn build_relay_chain_interface( match collator_options.relay_chain_rpc_url { Some(relay_chain_url) => Ok((Arc::new(RelayChainRPCInterface::new(relay_chain_url).await?) as Arc<_>, None)), - None => { - let relay_chain_local = build_inprocess_relay_chain( - polkadot_config, - telemetry_worker_handle, - task_manager, - )?; - Ok((relay_chain_local.0, Some(relay_chain_local.1))) - }, + None => build_inprocess_relay_chain( + polkadot_config, + parachain_config, + telemetry_worker_handle, + task_manager, + ), } } @@ -386,6 +385,7 @@ where let (relay_chain_interface, collator_key) = build_relay_chain_interface( polkadot_config, + ¶chain_config, telemetry_worker_handle, &mut task_manager, collator_options.clone(), @@ -571,6 +571,7 @@ where let mut task_manager = params.task_manager; let (relay_chain_interface, collator_key) = build_relay_chain_interface( polkadot_config, + ¶chain_config, telemetry_worker_handle, &mut task_manager, collator_options.clone(), @@ -1372,6 +1373,7 @@ where let (relay_chain_interface, collator_key) = build_relay_chain_interface( polkadot_config, + ¶chain_config, telemetry_worker_handle, &mut task_manager, collator_options.clone(),