mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 08:41:02 +00:00
Enable async backing on asset-hub-rococo (#2826)
The goal is to move all system chains on Rococo (+ other testnets?) to use async backing. Starting with `asset-hub-rococo` to get feedback, before I do the rest. ## Related Example: https://github.com/paritytech/polkadot-sdk/pull/1619/ Guide: https://github.com/w3f/polkadot-wiki/blob/master/docs/maintain/maintain-guides-async-backing.md --------- Co-authored-by: Branislav Kontur <bkontur@gmail.com> Co-authored-by: Dónal Murray <donal.murray@parity.io>
This commit is contained in:
@@ -976,6 +976,7 @@ pub async fn start_rococo_parachain_node(
|
||||
proposer,
|
||||
collator_service,
|
||||
authoring_duration: Duration::from_millis(1500),
|
||||
reinitialize: false,
|
||||
};
|
||||
|
||||
let fut = aura::run::<
|
||||
@@ -1291,7 +1292,7 @@ where
|
||||
Ok(BasicQueue::new(verifier, Box::new(block_import), None, &spawner, registry))
|
||||
}
|
||||
|
||||
/// Start an aura powered parachain node. Asset Hub and Collectives use this.
|
||||
/// Start an aura powered parachain node. Collectives uses this.
|
||||
pub async fn start_generic_aura_node<RuntimeApi, AuraId: AppCrypto>(
|
||||
parachain_config: Configuration,
|
||||
polkadot_config: Configuration,
|
||||
@@ -1530,6 +1531,159 @@ where
|
||||
.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.
|
||||
///
|
||||
/// Uses the lookahead collator to support async backing.
|
||||
#[sc_tracing::logging::prefix_logs_with("Parachain")]
|
||||
pub async fn start_asset_hub_lookahead_node<RuntimeApi, AuraId: AppCrypto + Send + Codec + Sync>(
|
||||
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>
|
||||
+ cumulus_primitives_aura::AuraUnincludedSegmentApi<Block>,
|
||||
<<AuraId as AppCrypto>::Pair as Pair>::Signature:
|
||||
TryFrom<Vec<u8>> + std::hash::Hash + sp_runtime::traits::Member + Codec,
|
||||
{
|
||||
start_node_impl::<RuntimeApi, _, _, _>(
|
||||
parachain_config,
|
||||
polkadot_config,
|
||||
collator_options,
|
||||
CollatorSybilResistance::Resistant, // Aura
|
||||
para_id,
|
||||
|_| Ok(RpcModule::new(())),
|
||||
aura_build_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
|
||||
}
|
||||
}
|
||||
|
||||
// Move to Aura consensus.
|
||||
let slot_duration = match cumulus_client_consensus_aura::slot_duration(&*client) {
|
||||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
log::error!("Could not get Aura slot duration: {e}");
|
||||
return
|
||||
},
|
||||
};
|
||||
|
||||
let proposer = Proposer::new(proposer_factory);
|
||||
|
||||
let params = AuraParams {
|
||||
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
|
||||
block_import,
|
||||
para_client: client.clone(),
|
||||
para_backend: backend,
|
||||
relay_client: relay_chain_interface2,
|
||||
code_hash_provider: move |block_hash| {
|
||||
client.code_at(block_hash).ok().map(|c| ValidationCode::from(c).hash())
|
||||
},
|
||||
sync_oracle,
|
||||
keystore,
|
||||
collator_key,
|
||||
para_id,
|
||||
overseer_handle,
|
||||
slot_duration,
|
||||
relay_chain_slot_duration,
|
||||
proposer,
|
||||
collator_service,
|
||||
authoring_duration: Duration::from_millis(1500),
|
||||
reinitialize: true, /* we need to always re-initialize for asset-hub moving
|
||||
* to aura */
|
||||
};
|
||||
|
||||
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 an aura powered parachain node which uses the lookahead collator to support async backing.
|
||||
/// This node is basic in the sense that its runtime api doesn't include common contents such as
|
||||
/// transaction payment. Used for aura glutton.
|
||||
@@ -1615,6 +1769,7 @@ where
|
||||
proposer,
|
||||
collator_service,
|
||||
authoring_duration: Duration::from_millis(1500),
|
||||
reinitialize: false,
|
||||
};
|
||||
|
||||
let fut =
|
||||
|
||||
Reference in New Issue
Block a user