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

Fix Asset Hub collator crashing when starting from genesis #1788

Merged
merged 21 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
73a6e0b
Updating glutton for async backing
BradleyOlson64 Sep 18, 2023
45a3dea
Leaving seedling and shell as is
BradleyOlson64 Sep 18, 2023
2a7cf34
fmt
BradleyOlson64 Sep 18, 2023
a22c87b
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
BradleyOlson64 Sep 18, 2023
5c31194
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
BradleyOlson64 Sep 20, 2023
8dfff49
Propagate feature std
BradleyOlson64 Sep 20, 2023
1fa8149
Bool to bool
BradleyOlson64 Sep 20, 2023
d394c76
Add cumulus-primitives-aura
BradleyOlson64 Sep 20, 2023
55055d6
Fixed file path
BradleyOlson64 Sep 20, 2023
5828dff
Introducing new start_node_impl
BradleyOlson64 Sep 20, 2023
2171970
fmt
BradleyOlson64 Sep 20, 2023
eeb3e6d
fmt
BradleyOlson64 Sep 20, 2023
dea2625
Restore asset hub node to transition from shell
georgepisaltu Sep 28, 2023
49e91a5
Move to new impl
georgepisaltu Sep 29, 2023
f0a8159
Hook to new fn
georgepisaltu Sep 30, 2023
a675cdc
Merge remote-tracking branch 'origin' into george/asset-hub-shell-run…
georgepisaltu Oct 5, 2023
c8fcc99
Remove redundant block production in shell
georgepisaltu Oct 6, 2023
1303102
Merge remote-tracking branch 'origin' into george/asset-hub-shell-run…
georgepisaltu Oct 9, 2023
f52675e
Refine impl
georgepisaltu Oct 9, 2023
03a472f
Merge remote-tracking branch 'origin' into george/asset-hub-shell-run…
georgepisaltu Oct 9, 2023
a684fd3
Merge remote-tracking branch 'origin' into george/asset-hub-shell-run…
georgepisaltu Oct 9, 2023
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
6 changes: 3 additions & 3 deletions cumulus/polkadot-parachain/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,21 +836,21 @@ pub fn run() -> Result<()> {
info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });

match config.chain_spec.runtime() {
Runtime::AssetHubPolkadot => crate::service::start_generic_aura_node::<
Runtime::AssetHubPolkadot => crate::service::start_asset_hub_node::<
asset_hub_polkadot_runtime::RuntimeApi,
AssetHubPolkadotAuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
.map(|r| r.0)
.map_err(Into::into),
Runtime::AssetHubKusama => crate::service::start_generic_aura_node::<
Runtime::AssetHubKusama => crate::service::start_asset_hub_node::<
asset_hub_kusama_runtime::RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
.await
.map(|r| r.0)
.map_err(Into::into),
Runtime::AssetHubWestend => crate::service::start_generic_aura_node::<
Runtime::AssetHubWestend => crate::service::start_asset_hub_node::<
asset_hub_westend_runtime::RuntimeApi,
AuraId,
>(config, polkadot_config, collator_options, id, hwbench)
Expand Down
155 changes: 151 additions & 4 deletions cumulus/polkadot-parachain/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

use codec::Codec;
use codec::{Codec, Decode};
use cumulus_client_cli::CollatorOptions;
use cumulus_client_collator::service::CollatorService;
use cumulus_client_consensus_aura::collators::{
Expand Down Expand Up @@ -44,7 +44,7 @@ use crate::rpc;
pub use parachains_common::{AccountId, Balance, Block, BlockNumber, Hash, Header, Nonce};

use cumulus_client_consensus_relay_chain::Verifier as RelayChainVerifier;
use futures::lock::Mutex;
use futures::{lock::Mutex, prelude::*};
use sc_consensus::{
import_queue::{BasicQueue, Verifier as VerifierT},
BlockImportParams, ImportQueue,
Expand All @@ -54,10 +54,13 @@ use sc_network::{config::FullNetworkConfiguration, NetworkBlock};
use sc_network_sync::SyncingService;
use sc_service::{Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager};
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
use sp_api::{ApiExt, ConstructRuntimeApi};
use sp_api::{ApiExt, ConstructRuntimeApi, ProvideRuntimeApi};
use sp_consensus_aura::AuraApi;
use sp_keystore::KeystorePtr;
use sp_runtime::{app_crypto::AppCrypto, traits::Header as HeaderT};
use sp_runtime::{
app_crypto::AppCrypto,
traits::{Block as BlockT, Header as HeaderT},
};
use std::{marker::PhantomData, sync::Arc, time::Duration};
use substrate_prometheus_endpoint::Registry;

Expand Down Expand Up @@ -1389,6 +1392,150 @@ 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.
pub async fn start_asset_hub_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>,
<<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| {
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_header =
match <Block as BlockT>::Header::decode(&mut &pvd.parent_head.0[..]) {
Ok(x) => x,
Err(e) => {
log::error!("Could not decode the head data: {e}");
request.complete(None);
continue
},
};

let last_head_hash = last_header.hash();

if !collator_service.check_block_status(last_head_hash, &last_header) {
request.complete(None);
continue
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if !collator_service.check_block_status(last_head_hash, &last_header) {
request.complete(None);
continue
}

No need to do this.


// 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 = cumulus_client_consensus_aura::slot_duration(&*client).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No unwrap. Please print the error and return.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I forgot about this.


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,
slot_duration,
relay_chain_slot_duration,
proposer,
collator_service,
// Very limited proposal time.
authoring_duration: Duration::from_millis(500),
};

basic_aura::run::<Block, <AuraId as AppCrypto>::Pair, _, _, _, _, _, _, _>(params)
.await
});

let spawner = task_manager.spawn_handle();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let spawner = task_manager.spawn_handle();
let spawner = task_manager.spawn_essential_handle();

spawner.spawn("cumulus-asset-hub-collator", None, collation_future);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
spawner.spawn("cumulus-asset-hub-collator", None, collation_future);
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.
Expand Down