Skip to content

Commit

Permalink
Add prospective-parachain subsystem to minimal-relay-node + QoL impro…
Browse files Browse the repository at this point in the history
…vements (#2223)

This PR contains some fixes and cleanups for parachain nodes:

1. When using async backing, node no longer complains about being unable
to reach the prospective-parachain subsystem.
2. Parachain warp sync now informs users that the finalized para block
has been retrieved.
```
2023-11-08 13:24:42 [Parachain] 🎉 Received finalized parachain header #5747719 (0xa0aa…674b) from the relay chain.
```
3. When a user supplied an invalid `--relay-chain-rpc-url`, we were
crashing with a very verbose message. Removed the `expect` and improved
the error message.
```
2023-11-08 13:57:56 [Parachain] No valid RPC url found. Stopping RPC worker.
2023-11-08 13:57:56 [Parachain] Essential task `relay-chain-rpc-worker` failed. Shutting down service.
Error: Service(Application(WorkerCommunicationError("RPC worker channel closed. This can hint and connectivity issues with the supplied RPC endpoints. Message: oneshot canceled")))
```
  • Loading branch information
skunert authored Nov 8, 2023
1 parent eabf9fb commit 69494ea
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cumulus/client/relay-chain-minimal-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ polkadot-collator-protocol = { path = "../../../polkadot/node/network/collator-p
polkadot-network-bridge = { path = "../../../polkadot/node/network/bridge" }
polkadot-node-collation-generation = { path = "../../../polkadot/node/collation-generation" }
polkadot-node-core-runtime-api = { path = "../../../polkadot/node/core/runtime-api" }
polkadot-node-core-prospective-parachains = { path = "../../../polkadot/node/core/prospective-parachains" }

# substrate deps
sc-authority-discovery = { path = "../../../substrate/client/authority-discovery" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use polkadot_network_bridge::{
NetworkBridgeTx as NetworkBridgeTxSubsystem,
};
use polkadot_node_collation_generation::CollationGenerationSubsystem;
use polkadot_node_core_prospective_parachains::ProspectiveParachainsSubsystem;
use polkadot_node_core_runtime_api::RuntimeApiSubsystem;
use polkadot_node_network_protocol::{
peer_set::PeerSetProtocolNames,
Expand Down Expand Up @@ -144,7 +145,7 @@ fn build_overseer(
spawner.clone(),
))
.statement_distribution(DummySubsystem)
.prospective_parachains(DummySubsystem)
.prospective_parachains(ProspectiveParachainsSubsystem::new(Metrics::register(registry)?))
.approval_distribution(DummySubsystem)
.approval_voting(DummySubsystem)
.gossip_support(DummySubsystem)
Expand Down
7 changes: 1 addition & 6 deletions cumulus/client/relay-chain-minimal-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,7 @@ async fn new_minimal_relay_chain(
);
}

let genesis_hash = relay_chain_rpc_client
.block_get_hash(Some(0))
.await
.expect("Genesis block hash is always available; qed")
.unwrap_or_default();

let genesis_hash = relay_chain_rpc_client.block_get_hash(Some(0)).await?.unwrap_or_default();
let peer_set_protocol_names =
PeerSetProtocolNames::new(genesis_hash, config.chain_spec.fork_id());
let is_authority = if role.is_authority() { IsAuthority::Yes } else { IsAuthority::No };
Expand Down
2 changes: 1 addition & 1 deletion cumulus/client/relay-chain-rpc-interface/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl RelayChainRpcClient {

let value = rx.await.map_err(|err| {
RelayChainError::WorkerCommunicationError(format!(
"Unexpected channel close on RPC worker side: {}",
"RPC worker channel closed. This can hint and connectivity issues with the supplied RPC endpoints. Message: {}",
err
))
})??;
Expand Down
18 changes: 11 additions & 7 deletions cumulus/client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use sc_utils::mpsc::TracingUnboundedSender;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::{HeaderBackend, HeaderMetadata};
use sp_core::{traits::SpawnNamed, Decode};
use sp_runtime::traits::{Block as BlockT, BlockIdTo};
use sp_runtime::traits::{Block as BlockT, BlockIdTo, Header};
use std::{sync::Arc, time::Duration};

// Given the sporadic nature of the explicit recovery operation and the
Expand Down Expand Up @@ -505,11 +505,11 @@ where
None,
async move {
log::debug!(
target: "cumulus-network",
target: LOG_TARGET_SYNC,
"waiting for announce block in a background task...",
);

let _ = wait_for_target_block::<B, _>(sender, para_id, relay_chain_interface)
let _ = wait_for_finalized_para_head::<B, _>(sender, para_id, relay_chain_interface)
.await
.map_err(|e| {
log::error!(
Expand All @@ -527,7 +527,7 @@ where

/// Waits for the relay chain to have finished syncing and then gets the parachain header that
/// corresponds to the last finalized relay chain block.
async fn wait_for_target_block<B, RCInterface>(
async fn wait_for_finalized_para_head<B, RCInterface>(
sender: oneshot::Sender<<B as BlockT>::Header>,
para_id: ParaId,
relay_chain_interface: RCInterface,
Expand Down Expand Up @@ -560,11 +560,15 @@ where
.map_err(|e| format!("{e:?}"))?
.ok_or("Could not find parachain head in relay chain")?;

let target_block = B::Header::decode(&mut &validation_data.parent_head.0[..])
let finalized_header = B::Header::decode(&mut &validation_data.parent_head.0[..])
.map_err(|e| format!("Failed to decode parachain head: {e}"))?;

log::debug!(target: LOG_TARGET_SYNC, "Target block reached {:?}", target_block);
let _ = sender.send(target_block);
log::info!(
"🎉 Received target parachain header #{} ({}) from the relay chain.",
finalized_header.number(),
finalized_header.hash()
);
let _ = sender.send(finalized_header);
return Ok(())
}
}
Expand Down

0 comments on commit 69494ea

Please sign in to comment.