Skip to content
Snippets Groups Projects
Unverified Commit f13408d5 authored by s0me0ne-unkn0wn's avatar s0me0ne-unkn0wn Committed by GitHub
Browse files

Enable mainnet system parachains to use async backing-enabled collator (#3630)

This is phase 2 of async backing enablement for the system parachains on
the production networks. ~~It should be merged after
polkadot-fellows/runtimes#228 is enacted. After it is released,~~ all
the system parachain collators should be upgraded, and then we can
proceed with phase 3, which will enable async backing in the runtimes.

UPDATE: Indeed, we don't need to wait for the runtime upgrade enactions.
The lookahead collator handles the transition by itself, so we can
upgrade ASAP.

## Scope of changes

Here, we eliminate the dichotomy of having "generic Aura collators" for
the production system parachains and "lookahead Aura collators" for the
testnet system parachains. Now, all the collators are started as
lookahead ones, preserving the logic of transferring from the shell node
to Aura-enabled collators for the asset hubs. So, indeed, it simplifies
the parachain service logic, which cannot but rejoice.
parent 83257054
Branches
No related merge requests found
Pipeline #464753 canceled with stages
in 29 minutes and 45 seconds
......@@ -315,9 +315,10 @@ where
let mut parent_header = initial_parent.header;
let overseer_handle = &mut params.overseer_handle;
// We mainly call this to inform users at genesis if there is a mismatch with the
// on-chain data.
collator.collator_service().check_block_status(parent_hash, &parent_header);
// Do not try to build upon an unknown, pruned or bad block
if !collator.collator_service().check_block_status(parent_hash, &parent_header) {
continue
}
// This needs to change to support elastic scaling, but for continuously
// scheduled chains this ensures that the backlog will grow steadily.
......
......@@ -702,7 +702,7 @@ async fn start_node<Network: sc_network::NetworkBackend<Block, Hash>>(
hwbench: Option<sc_sysinfo::HwBench>,
) -> Result<sc_service::TaskManager> {
match config.chain_spec.runtime()? {
Runtime::AssetHubPolkadot => crate::service::start_asset_hub_node::<
Runtime::AssetHubPolkadot => crate::service::start_asset_hub_lookahead_node::<
AssetHubPolkadotRuntimeApi,
AssetHubPolkadotAuraId,
Network,
......@@ -711,16 +711,7 @@ async fn start_node<Network: sc_network::NetworkBackend<Block, Hash>>(
.map(|r| r.0)
.map_err(Into::into),
Runtime::AssetHubKusama => crate::service::start_asset_hub_node::<
RuntimeApi,
AuraId,
Network,
>(config, polkadot_config, collator_options, id, hwbench)
.await
.map(|r| r.0)
.map_err(Into::into),
Runtime::AssetHubRococo | Runtime::AssetHubWestend =>
Runtime::AssetHubRococo | Runtime::AssetHubWestend | Runtime::AssetHubKusama =>
crate::service::start_asset_hub_lookahead_node::<RuntimeApi, AuraId, Network>(
config,
polkadot_config,
......@@ -732,18 +723,7 @@ async fn start_node<Network: sc_network::NetworkBackend<Block, Hash>>(
.map(|r| r.0)
.map_err(Into::into),
Runtime::CollectivesPolkadot => crate::service::start_generic_aura_node::<Network>(
config,
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0)
.map_err(Into::into),
Runtime::CollectivesWestend =>
Runtime::CollectivesWestend | Runtime::CollectivesPolkadot =>
crate::service::start_generic_aura_lookahead_node::<Network>(
config,
polkadot_config,
......@@ -779,39 +759,12 @@ async fn start_node<Network: sc_network::NetworkBackend<Block, Hash>>(
Runtime::BridgeHub(bridge_hub_runtime_type) => match bridge_hub_runtime_type {
chain_spec::bridge_hubs::BridgeHubRuntimeType::Polkadot |
chain_spec::bridge_hubs::BridgeHubRuntimeType::PolkadotLocal =>
crate::service::start_generic_aura_node::<Network>(
config,
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0),
chain_spec::bridge_hubs::BridgeHubRuntimeType::PolkadotLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::Kusama |
chain_spec::bridge_hubs::BridgeHubRuntimeType::KusamaLocal =>
crate::service::start_generic_aura_node::<Network>(
config,
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0),
chain_spec::bridge_hubs::BridgeHubRuntimeType::KusamaLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::Westend |
chain_spec::bridge_hubs::BridgeHubRuntimeType::WestendLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::WestendDevelopment =>
crate::service::start_generic_aura_lookahead_node::<Network>(
config,
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0),
chain_spec::bridge_hubs::BridgeHubRuntimeType::WestendDevelopment |
chain_spec::bridge_hubs::BridgeHubRuntimeType::Rococo |
chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoLocal |
chain_spec::bridge_hubs::BridgeHubRuntimeType::RococoDevelopment =>
......
......@@ -17,10 +17,7 @@
use codec::{Codec, Decode};
use cumulus_client_cli::CollatorOptions;
use cumulus_client_collator::service::CollatorService;
use cumulus_client_consensus_aura::collators::{
basic::{self as basic_aura, Params as BasicAuraParams},
lookahead::{self as aura, Params as AuraParams},
};
use cumulus_client_consensus_aura::collators::lookahead::{self as aura, Params as AuraParams};
use cumulus_client_consensus_common::{
ParachainBlockImport as TParachainBlockImport, ParachainCandidate, ParachainConsensus,
};
......@@ -687,82 +684,6 @@ where
Ok(BasicQueue::new(verifier, Box::new(block_import), None, &spawner, registry))
}
/// Start an aura powered parachain node. Some system chains use this.
pub async fn start_generic_aura_node<Net: NetworkBackend<Block, Hash>>(
parachain_config: Configuration,
polkadot_config: Configuration,
collator_options: CollatorOptions,
para_id: ParaId,
hwbench: Option<sc_sysinfo::HwBench>,
) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient<FakeRuntimeApi>>)> {
start_node_impl::<FakeRuntimeApi, _, _, _, Net>(
parachain_config,
polkadot_config,
collator_options,
CollatorSybilResistance::Resistant, // Aura
para_id,
build_parachain_rpc_extensions::<FakeRuntimeApi>,
build_relay_to_aura_import_queue::<_, AuraId>,
|client,
block_import,
prometheus_registry,
telemetry,
task_manager,
relay_chain_interface,
transaction_pool,
sync_oracle,
keystore,
relay_chain_slot_duration,
para_id,
collator_key,
overseer_handle,
announce_block,
_backend| {
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
task_manager.spawn_handle(),
client.clone(),
transaction_pool,
prometheus_registry,
telemetry.clone(),
);
let proposer = Proposer::new(proposer_factory);
let collator_service = CollatorService::new(
client.clone(),
Arc::new(task_manager.spawn_handle()),
announce_block,
client.clone(),
);
let params = BasicAuraParams {
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
block_import,
para_client: client,
relay_client: relay_chain_interface,
sync_oracle,
keystore,
collator_key,
para_id,
overseer_handle,
relay_chain_slot_duration,
proposer,
collator_service,
// Very limited proposal time.
authoring_duration: Duration::from_millis(500),
collation_request_receiver: None,
};
let fut =
basic_aura::run::<Block, <AuraId as AppCrypto>::Pair, _, _, _, _, _, _, _>(params);
task_manager.spawn_essential_handle().spawn("aura", None, fut);
Ok(())
},
hwbench,
)
.await
}
/// Uses the lookahead collator to support async backing.
///
/// Start an aura powered parachain node. Some system chains use this.
......@@ -787,142 +708,6 @@ pub async fn start_generic_aura_lookahead_node<Net: NetworkBackend<Block, Hash>>
.await
}
/// Start a shell node which should later transition into an Aura powered parachain node. Asset Hub
/// uses this because at genesis, Asset Hub was on the `shell` runtime which didn't have Aura and
/// needs to sync and upgrade before it can run `AuraApi` functions.
pub async fn start_asset_hub_node<RuntimeApi, AuraId: AppCrypto + Send + Codec + Sync, Net>(
parachain_config: Configuration,
polkadot_config: Configuration,
collator_options: CollatorOptions,
para_id: ParaId,
hwbench: Option<sc_sysinfo::HwBench>,
) -> sc_service::error::Result<(TaskManager, Arc<ParachainClient<RuntimeApi>>)>
where
RuntimeApi: ConstructRuntimeApi<Block, ParachainClient<RuntimeApi>> + Send + Sync + 'static,
RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
+ sp_api::Metadata<Block>
+ sp_session::SessionKeys<Block>
+ sp_api::ApiExt<Block>
+ sp_offchain::OffchainWorkerApi<Block>
+ sp_block_builder::BlockBuilder<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block>
+ sp_consensus_aura::AuraApi<Block, <<AuraId as AppCrypto>::Pair as Pair>::Public>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
<<AuraId as AppCrypto>::Pair as Pair>::Signature:
TryFrom<Vec<u8>> + std::hash::Hash + sp_runtime::traits::Member + Codec,
Net: NetworkBackend<Block, Hash>,
{
start_node_impl::<RuntimeApi, _, _, _, Net>(
parachain_config,
polkadot_config,
collator_options,
CollatorSybilResistance::Resistant, // Aura
para_id,
build_parachain_rpc_extensions::<RuntimeApi>,
build_relay_to_aura_import_queue::<_, AuraId>,
|client,
block_import,
prometheus_registry,
telemetry,
task_manager,
relay_chain_interface,
transaction_pool,
sync_oracle,
keystore,
relay_chain_slot_duration,
para_id,
collator_key,
overseer_handle,
announce_block,
_backend| {
let relay_chain_interface2 = relay_chain_interface.clone();
let collator_service = CollatorService::new(
client.clone(),
Arc::new(task_manager.spawn_handle()),
announce_block,
client.clone(),
);
let spawner = task_manager.spawn_handle();
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
spawner,
client.clone(),
transaction_pool,
prometheus_registry,
telemetry.clone(),
);
let collation_future = Box::pin(async move {
// Start collating with the `shell` runtime while waiting for an upgrade to an Aura
// compatible runtime.
let mut request_stream = cumulus_client_collator::relay_chain_driven::init(
collator_key.clone(),
para_id,
overseer_handle.clone(),
)
.await;
while let Some(request) = request_stream.next().await {
let pvd = request.persisted_validation_data().clone();
let last_head_hash =
match <Block as BlockT>::Header::decode(&mut &pvd.parent_head.0[..]) {
Ok(header) => header.hash(),
Err(e) => {
log::error!("Could not decode the head data: {e}");
request.complete(None);
continue
},
};
// Check if we have upgraded to an Aura compatible runtime and transition if
// necessary.
if client
.runtime_api()
.has_api::<dyn AuraApi<Block, AuraId>>(last_head_hash)
.unwrap_or(false)
{
// Respond to this request before transitioning to Aura.
request.complete(None);
break
}
}
let proposer = Proposer::new(proposer_factory);
let params = BasicAuraParams {
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
block_import,
para_client: client,
relay_client: relay_chain_interface2,
sync_oracle,
keystore,
collator_key,
para_id,
overseer_handle,
relay_chain_slot_duration,
proposer,
collator_service,
// Very limited proposal time.
authoring_duration: Duration::from_millis(500),
collation_request_receiver: Some(request_stream),
};
basic_aura::run::<Block, <AuraId as AppCrypto>::Pair, _, _, _, _, _, _, _>(params)
.await
});
let spawner = task_manager.spawn_essential_handle();
spawner.spawn_essential("cumulus-asset-hub-collator", None, collation_future);
Ok(())
},
hwbench,
)
.await
}
/// Start a shell node which should later transition into an Aura powered parachain node. Asset Hub
/// uses this because at genesis, Asset Hub was on the `shell` runtime which didn't have Aura and
/// needs to sync and upgrade before it can run `AuraApi` functions.
......
title: "Use async backing enabled collator for all the parachains"
doc:
- audience: Node Operator
description: |
Promotes all the parachains supported by `polkadot-parachain`, including all the systems
parachains, to use the async backing enabled lookahead Aura collator instead of the generic
one.
crates:
- name: polkadot-parachain-bin
bump: major
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment