Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cumulus/client/consensus/aura/src/collators/lookahead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
59 changes: 6 additions & 53 deletions cumulus/polkadot-parachain/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 =>
Expand Down
217 changes: 1 addition & 216 deletions cumulus/polkadot-parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions prdoc/pr_3630.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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
Loading