From c6c166d1137c685c39de6a5da9704cdad1106d72 Mon Sep 17 00:00:00 2001 From: alindima Date: Wed, 14 Aug 2024 15:34:21 +0300 Subject: [PATCH 01/26] expose claim queue on cumulus --- .../src/lib.rs | 18 +++++- .../client/relay-chain-interface/src/lib.rs | 24 +++++++- .../src/blockchain_rpc_client.rs | 56 +++++++------------ .../relay-chain-rpc-interface/src/lib.rs | 9 +++ 4 files changed, 64 insertions(+), 43 deletions(-) diff --git a/cumulus/client/relay-chain-inprocess-interface/src/lib.rs b/cumulus/client/relay-chain-inprocess-interface/src/lib.rs index 38ba84748c1e3..1d6b801e6dc2a 100644 --- a/cumulus/client/relay-chain-inprocess-interface/src/lib.rs +++ b/cumulus/client/relay-chain-inprocess-interface/src/lib.rs @@ -14,14 +14,19 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use std::{collections::btree_map::BTreeMap, pin::Pin, sync::Arc, time::Duration}; +use std::{ + collections::{BTreeMap, VecDeque}, + pin::Pin, + sync::Arc, + time::Duration, +}; use async_trait::async_trait; use cumulus_primitives_core::{ relay_chain::{ runtime_api::ParachainHost, Block as PBlock, BlockId, BlockNumber, - CommittedCandidateReceipt, CoreState, Hash as PHash, Header as PHeader, InboundHrmpMessage, - OccupiedCoreAssumption, SessionIndex, ValidationCodeHash, ValidatorId, + CommittedCandidateReceipt, CoreIndex, CoreState, Hash as PHash, Header as PHeader, + InboundHrmpMessage, OccupiedCoreAssumption, SessionIndex, ValidationCodeHash, ValidatorId, }, InboundDownwardMessage, ParaId, PersistedValidationData, }; @@ -270,6 +275,13 @@ impl RelayChainInterface for RelayChainInProcessInterface { ) -> RelayChainResult> { Ok(self.full_client.runtime_api().candidates_pending_availability(hash, para_id)?) } + + async fn claim_queue( + &self, + hash: PHash, + ) -> RelayChainResult>> { + Ok(self.full_client.runtime_api().claim_queue(hash)?) + } } pub enum BlockCheckStatus { diff --git a/cumulus/client/relay-chain-interface/src/lib.rs b/cumulus/client/relay-chain-interface/src/lib.rs index d02035e84e92f..866d125101f80 100644 --- a/cumulus/client/relay-chain-interface/src/lib.rs +++ b/cumulus/client/relay-chain-interface/src/lib.rs @@ -14,7 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use std::{collections::BTreeMap, pin::Pin, sync::Arc}; +use std::{ + collections::{BTreeMap, VecDeque}, + pin::Pin, + sync::Arc, +}; use futures::Stream; use polkadot_overseer::prometheus::PrometheusError; @@ -29,8 +33,9 @@ use sp_api::ApiError; use cumulus_primitives_core::relay_chain::BlockId; pub use cumulus_primitives_core::{ relay_chain::{ - BlockNumber, CommittedCandidateReceipt, CoreState, Hash as PHash, Header as PHeader, - InboundHrmpMessage, OccupiedCoreAssumption, SessionIndex, ValidationCodeHash, ValidatorId, + BlockNumber, CommittedCandidateReceipt, CoreIndex, CoreState, Hash as PHash, + Header as PHeader, InboundHrmpMessage, OccupiedCoreAssumption, SessionIndex, + ValidationCodeHash, ValidatorId, }, InboundDownwardMessage, ParaId, PersistedValidationData, }; @@ -225,6 +230,12 @@ pub trait RelayChainInterface: Send + Sync { &self, relay_parent: PHash, ) -> RelayChainResult>>; + + /// Fetch the claim queue. + async fn claim_queue( + &self, + relay_parent: PHash, + ) -> RelayChainResult>>; } #[async_trait] @@ -363,4 +374,11 @@ where async fn version(&self, relay_parent: PHash) -> RelayChainResult { (**self).version(relay_parent).await } + + async fn claim_queue( + &self, + relay_parent: PHash, + ) -> RelayChainResult>> { + (**self).claim_queue(relay_parent).await + } } diff --git a/cumulus/client/relay-chain-minimal-node/src/blockchain_rpc_client.rs b/cumulus/client/relay-chain-minimal-node/src/blockchain_rpc_client.rs index 06f19941165a2..7d6b5bfe3ec73 100644 --- a/cumulus/client/relay-chain-minimal-node/src/blockchain_rpc_client.rs +++ b/cumulus/client/relay-chain-minimal-node/src/blockchain_rpc_client.rs @@ -19,6 +19,7 @@ use std::{ pin::Pin, }; +use cumulus_primitives_core::{InboundDownwardMessage, ParaId, PersistedValidationData}; use cumulus_relay_chain_interface::{RelayChainError, RelayChainResult}; use cumulus_relay_chain_rpc_interface::RelayChainRpcClient; use futures::{Stream, StreamExt}; @@ -132,7 +133,7 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient { ) -> Result< ( Vec>, - polkadot_primitives::GroupRotationInfo, + polkadot_primitives::GroupRotationInfo, ), sp_api::ApiError, > { @@ -142,27 +143,16 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient { async fn availability_cores( &self, at: Hash, - ) -> Result< - Vec>, - sp_api::ApiError, - > { + ) -> Result>, sp_api::ApiError> { Ok(self.rpc_client.parachain_host_availability_cores(at).await?) } async fn persisted_validation_data( &self, at: Hash, - para_id: cumulus_primitives_core::ParaId, + para_id: ParaId, assumption: polkadot_primitives::OccupiedCoreAssumption, - ) -> Result< - Option< - cumulus_primitives_core::PersistedValidationData< - Hash, - polkadot_core_primitives::BlockNumber, - >, - >, - sp_api::ApiError, - > { + ) -> Result>, sp_api::ApiError> { Ok(self .rpc_client .parachain_host_persisted_validation_data(at, para_id, assumption) @@ -172,14 +162,11 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient { async fn assumed_validation_data( &self, at: Hash, - para_id: cumulus_primitives_core::ParaId, + para_id: ParaId, expected_persisted_validation_data_hash: Hash, ) -> Result< Option<( - cumulus_primitives_core::PersistedValidationData< - Hash, - polkadot_core_primitives::BlockNumber, - >, + PersistedValidationData, polkadot_primitives::ValidationCodeHash, )>, sp_api::ApiError, @@ -197,7 +184,7 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient { async fn check_validation_outputs( &self, at: Hash, - para_id: cumulus_primitives_core::ParaId, + para_id: ParaId, outputs: polkadot_primitives::CandidateCommitments, ) -> Result { Ok(self @@ -216,7 +203,7 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient { async fn validation_code( &self, at: Hash, - para_id: cumulus_primitives_core::ParaId, + para_id: ParaId, assumption: polkadot_primitives::OccupiedCoreAssumption, ) -> Result, sp_api::ApiError> { Ok(self.rpc_client.parachain_host_validation_code(at, para_id, assumption).await?) @@ -225,7 +212,7 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient { async fn candidate_pending_availability( &self, at: Hash, - para_id: cumulus_primitives_core::ParaId, + para_id: ParaId, ) -> Result>, sp_api::ApiError> { Ok(self .rpc_client @@ -243,24 +230,19 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient { async fn dmq_contents( &self, at: Hash, - recipient: cumulus_primitives_core::ParaId, - ) -> Result< - Vec>, - sp_api::ApiError, - > { + recipient: ParaId, + ) -> Result>, sp_api::ApiError> { Ok(self.rpc_client.parachain_host_dmq_contents(recipient, at).await?) } async fn inbound_hrmp_channels_contents( &self, at: Hash, - recipient: cumulus_primitives_core::ParaId, + recipient: ParaId, ) -> Result< std::collections::BTreeMap< - cumulus_primitives_core::ParaId, - Vec< - polkadot_core_primitives::InboundHrmpMessage, - >, + ParaId, + Vec>, >, sp_api::ApiError, > { @@ -329,7 +311,7 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient { async fn validation_code_hash( &self, at: Hash, - para_id: cumulus_primitives_core::ParaId, + para_id: ParaId, assumption: polkadot_primitives::OccupiedCoreAssumption, ) -> Result, sp_api::ApiError> { Ok(self @@ -424,7 +406,7 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient { async fn para_backing_state( &self, at: Hash, - para_id: cumulus_primitives_core::ParaId, + para_id: ParaId, ) -> Result, ApiError> { Ok(self.rpc_client.parachain_host_para_backing_state(at, para_id).await?) } @@ -448,14 +430,14 @@ impl RuntimeApiSubsystemClient for BlockChainRpcClient { async fn claim_queue( &self, at: Hash, - ) -> Result>, ApiError> { + ) -> Result>, ApiError> { Ok(self.rpc_client.parachain_host_claim_queue(at).await?) } async fn candidates_pending_availability( &self, at: Hash, - para_id: cumulus_primitives_core::ParaId, + para_id: ParaId, ) -> Result>, sp_api::ApiError> { Ok(self .rpc_client diff --git a/cumulus/client/relay-chain-rpc-interface/src/lib.rs b/cumulus/client/relay-chain-rpc-interface/src/lib.rs index e32ec6a41a4bf..7ef747cd26ac9 100644 --- a/cumulus/client/relay-chain-rpc-interface/src/lib.rs +++ b/cumulus/client/relay-chain-rpc-interface/src/lib.rs @@ -258,4 +258,13 @@ impl RelayChainInterface for RelayChainRpcInterface { ) -> RelayChainResult>> { self.rpc_client.parachain_host_availability_cores(relay_parent).await } + + async fn claim_queue( + &self, + relay_parent: RelayHash, + ) -> RelayChainResult< + BTreeMap>, + > { + self.rpc_client.parachain_host_claim_queue(relay_parent).await + } } From d7c595e64adbae337af3f1301528085b4219f50a Mon Sep 17 00:00:00 2001 From: alindima Date: Wed, 14 Aug 2024 15:35:56 +0300 Subject: [PATCH 02/26] add hardcoded claim queue offset and switch to using the claim queue api if available --- .../consensus/aura/src/collators/lookahead.rs | 2 +- .../consensus/aura/src/collators/mod.rs | 43 +++++- .../slot_based/block_builder_task.rs | 131 +++++++++++++----- .../aura/src/collators/slot_based/mod.rs | 4 +- cumulus/pallets/parachain-system/src/lib.rs | 5 + cumulus/polkadot-parachain/src/common/mod.rs | 4 +- .../asset_hub_polkadot_aura.rs | 6 + .../src/fake_runtime_api/aura.rs | 6 + cumulus/primitives/core/src/lib.rs | 6 + 9 files changed, 163 insertions(+), 44 deletions(-) diff --git a/cumulus/client/consensus/aura/src/collators/lookahead.rs b/cumulus/client/consensus/aura/src/collators/lookahead.rs index 02d60538a7323..96e5721e9d037 100644 --- a/cumulus/client/consensus/aura/src/collators/lookahead.rs +++ b/cumulus/client/consensus/aura/src/collators/lookahead.rs @@ -256,7 +256,7 @@ where while let Some(relay_parent_header) = import_notifications.next().await { let relay_parent = relay_parent_header.hash(); - let core_index = if let Some(core_index) = super::cores_scheduled_for_para( + let core_index = if let Some(core_index) = super::cores_scheduled_for_para_legacy( relay_parent, params.para_id, &mut params.relay_client, diff --git a/cumulus/client/consensus/aura/src/collators/mod.rs b/cumulus/client/consensus/aura/src/collators/mod.rs index 7d430ecdc727a..233ef373da40e 100644 --- a/cumulus/client/consensus/aura/src/collators/mod.rs +++ b/cumulus/client/consensus/aura/src/collators/mod.rs @@ -126,8 +126,9 @@ async fn async_backing_params( } } -// Return all the cores assigned to the para at the provided relay parent. -async fn cores_scheduled_for_para( +// Return all the cores assigned to the para at the provided relay parent, using the legacy method, +// availability-cores. Using the claim queue is the preferred alternative. +async fn cores_scheduled_for_para_legacy( relay_parent: RelayHash, para_id: ParaId, relay_client: &impl RelayChainInterface, @@ -173,6 +174,44 @@ async fn cores_scheduled_for_para( .collect() } +// Return all the cores assigned to the para at the provided relay parent, using the claim queue +// offset. This assumes the relay chain runtime supports the claimqueue runtime API. +// Will return an empty vec if the provided offset is higher than the claim queue length (which +// corresponds to the scheduling_lookahead on the relay chain). +async fn cores_scheduled_for_para( + relay_parent: RelayHash, + para_id: ParaId, + relay_client: &impl RelayChainInterface, + claim_queue_offset: u8, +) -> Vec { + // Get `ClaimQueue` from runtime + let claim_queue = match relay_client.claim_queue(relay_parent).await { + Ok(claim_queue) => claim_queue, + Err(error) => { + tracing::error!( + target: crate::LOG_TARGET, + ?error, + ?relay_parent, + "Failed to query claim queue runtime API", + ); + return Vec::new() + }, + }; + + claim_queue + .into_iter() + .filter_map(|(core_index, queue)| { + let core_para_id = queue.get(claim_queue_offset as usize); + + if core_para_id == Some(¶_id) { + Some(core_index) + } else { + None + } + }) + .collect() +} + // Checks if we own the slot at the given block and whether there // is space in the unincluded segment. async fn can_build_upon( diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs index 1fbc0689da862..d3e91067efe7b 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs @@ -20,7 +20,7 @@ use cumulus_client_collator::service::ServiceInterface as CollatorServiceInterfa use cumulus_client_consensus_common::{self as consensus_common, ParachainBlockImportMarker}; use cumulus_client_consensus_proposer::ProposerInterface; use cumulus_primitives_aura::AuraUnincludedSegmentApi; -use cumulus_primitives_core::{CollectCollationInfo, PersistedValidationData}; +use cumulus_primitives_core::{FetchClaimQueueOffset, PersistedValidationData}; use cumulus_relay_chain_interface::RelayChainInterface; use polkadot_primitives::{ @@ -31,7 +31,7 @@ use polkadot_primitives::{ use futures::prelude::*; use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf, UsageProvider}; use sc_consensus::BlockImport; -use sp_api::ProvideRuntimeApi; +use sp_api::{ApiExt, ProvideRuntimeApi, RuntimeApiInfo}; use sp_application_crypto::AppPublic; use sp_blockchain::HeaderBackend; use sp_consensus_aura::{AuraApi, Slot, SlotDuration}; @@ -45,7 +45,9 @@ use std::{sync::Arc, time::Duration}; use super::CollatorMessage; use crate::{ collator::{self as collator_util}, - collators::{check_validation_code_or_log, cores_scheduled_for_para}, + collators::{ + check_validation_code_or_log, cores_scheduled_for_para, cores_scheduled_for_para_legacy, + }, LOG_TARGET, }; @@ -177,7 +179,7 @@ where + Sync + 'static, Client::Api: - AuraApi + CollectCollationInfo + AuraUnincludedSegmentApi, + AuraApi + FetchClaimQueueOffset + AuraUnincludedSegmentApi, Backend: sc_client_api::Backend + 'static, RelayClient: RelayChainInterface + Clone + 'static, CIDP: CreateInherentDataProviders + 'static, @@ -239,12 +241,29 @@ where return }; - let Ok(RelayChainData { - relay_parent_header, - max_pov_size, - relay_parent_hash: relay_parent, - scheduled_cores, - }) = relay_chain_fetcher.get_relay_chain_data().await + let Ok(relay_parent) = relay_client.best_block_hash().await else { + tracing::warn!(target: crate::LOG_TARGET, "Unable to fetch latest relay chain block hash."); + continue + }; + + let Some((included_block, parent)) = + crate::collators::find_parent(relay_parent, para_id, &*para_backend, &relay_client) + .await + else { + continue + }; + + let parent_header = parent.header; + let parent_hash = parent.hash; + + // Retrieve claim queue offset, if present. + let Ok(maybe_cq_offset) = fetch_claim_queue_offset(&*para_client, parent_hash).await + else { + continue + }; + + let Ok(RelayChainData { relay_parent_header, max_pov_size, scheduled_cores }) = + relay_chain_fetcher.get_relay_chain_data(relay_parent, maybe_cq_offset).await else { continue; }; @@ -260,16 +279,6 @@ where continue; }; - let Some((included_block, parent)) = - crate::collators::find_parent(relay_parent, para_id, &*para_backend, &relay_client) - .await - else { - continue - }; - - let parent_header = parent.header; - let parent_hash = parent.hash; - // 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); @@ -414,8 +423,6 @@ struct RelayChainData { pub scheduled_cores: Vec, /// Maximum configured PoV size on the relay chain. pub max_pov_size: u32, - /// Current relay chain parent header. - pub relay_parent_hash: RelayHash, } /// Simple helper to fetch relay chain data and cache it based on the current relay chain best block @@ -437,12 +444,11 @@ where /// Fetch required [`RelayChainData`] from the relay chain. /// If this data has been fetched in the past for the incoming hash, it will reuse /// cached data. - pub async fn get_relay_chain_data(&mut self) -> Result { - let Ok(relay_parent) = self.relay_client.best_block_hash().await else { - tracing::warn!(target: crate::LOG_TARGET, "Unable to fetch latest relay chain block hash."); - return Err(()) - }; - + pub async fn get_relay_chain_data( + &mut self, + relay_parent: RelayHash, + maybe_claim_queue_offset: Option, + ) -> Result { match &self.last_data { Some((last_seen_hash, data)) if *last_seen_hash == relay_parent => { tracing::trace!(target: crate::LOG_TARGET, %relay_parent, "Using cached data for relay parent."); @@ -450,7 +456,8 @@ where }, _ => { tracing::trace!(target: crate::LOG_TARGET, %relay_parent, "Relay chain best block changed, fetching new data from relay chain."); - let data = self.update_for_relay_parent(relay_parent).await?; + let data = + self.update_for_relay_parent(relay_parent, maybe_claim_queue_offset).await?; self.last_data = Some((relay_parent, data.clone())); Ok(data) }, @@ -458,9 +465,45 @@ where } /// Fetch fresh data from the relay chain for the given relay parent hash. - async fn update_for_relay_parent(&self, relay_parent: RelayHash) -> Result { - let scheduled_cores = - cores_scheduled_for_para(relay_parent, self.para_id, &self.relay_client).await; + async fn update_for_relay_parent( + &self, + relay_parent: RelayHash, + maybe_claim_queue_offset: Option, + ) -> Result { + let runtime_api_version = self.relay_client.version(relay_parent).await.map_err(|e| { + tracing::error!( + target: LOG_TARGET, + error = ?e, + "Failed to fetch relay chain runtime version.", + ) + })?; + let parachain_host_runtime_api_version = + runtime_api_version + .api_version( + &>::ID, + ) + .unwrap_or_default(); + + // If the relay chain runtime does not support the new claim queue runtime API, fallback to + // the using availability cores. In this case the claim queue offset will not be used. + let supports_claim_queue = parachain_host_runtime_api_version >= + polkadot_node_subsystem::messages::RuntimeApiRequest::CLAIM_QUEUE_RUNTIME_REQUIREMENT; + + let scheduled_cores = if supports_claim_queue { + cores_scheduled_for_para( + relay_parent, + self.para_id, + &self.relay_client, + // TODO: make this a default somewhere. + maybe_claim_queue_offset.unwrap_or(0), + ) + .await + } else { + cores_scheduled_for_para_legacy(relay_parent, self.para_id, &self.relay_client).await + }; + let Ok(Some(relay_parent_header)) = self.relay_client.header(BlockId::Hash(relay_parent)).await else { @@ -481,11 +524,23 @@ where }, }; - Ok(RelayChainData { - relay_parent_hash: relay_parent, - relay_parent_header, - scheduled_cores, - max_pov_size, - }) + Ok(RelayChainData { relay_parent_header, scheduled_cores, max_pov_size }) + } +} + +async fn fetch_claim_queue_offset( + para_client: &Client, + block_hash: Block::Hash, +) -> Result, sp_api::ApiError> +where + Client: ProvideRuntimeApi + Send + Sync, + Client::Api: FetchClaimQueueOffset, +{ + let runtime_api = para_client.runtime_api(); + + if runtime_api.has_api::>(block_hash)? { + Ok(Some(runtime_api.fetch_claim_queue_offset(block_hash)?)) + } else { + Ok(None) } } diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs b/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs index 0fe49d58d25be..2ce3915a3b0e2 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs @@ -34,7 +34,7 @@ use cumulus_client_collator::service::ServiceInterface as CollatorServiceInterfa use cumulus_client_consensus_common::{self as consensus_common, ParachainBlockImportMarker}; use cumulus_client_consensus_proposer::ProposerInterface; use cumulus_primitives_aura::AuraUnincludedSegmentApi; -use cumulus_primitives_core::CollectCollationInfo; +use cumulus_primitives_core::FetchClaimQueueOffset; use cumulus_relay_chain_interface::RelayChainInterface; use polkadot_primitives::{ CollatorPair, CoreIndex, Hash as RelayHash, Id as ParaId, ValidationCodeHash, @@ -113,7 +113,7 @@ where + Sync + 'static, Client::Api: - AuraApi + CollectCollationInfo + AuraUnincludedSegmentApi, + AuraApi + FetchClaimQueueOffset + AuraUnincludedSegmentApi, Backend: sc_client_api::Backend + 'static, RClient: RelayChainInterface + Clone + 'static, CIDP: CreateInherentDataProviders + 'static, diff --git a/cumulus/pallets/parachain-system/src/lib.rs b/cumulus/pallets/parachain-system/src/lib.rs index 9e0a68d09a14a..77760851f6371 100644 --- a/cumulus/pallets/parachain-system/src/lib.rs +++ b/cumulus/pallets/parachain-system/src/lib.rs @@ -1443,6 +1443,11 @@ impl Pallet { } } + /// Returns the claim queue offset. + pub fn fetch_claim_queue_offset() -> u8 { + 1 + } + /// Set a custom head data that should be returned as result of `validate_block`. /// /// This will overwrite the head data that is returned as result of `validate_block` while diff --git a/cumulus/polkadot-parachain/src/common/mod.rs b/cumulus/polkadot-parachain/src/common/mod.rs index d7718931b8726..8100360d2f732 100644 --- a/cumulus/polkadot-parachain/src/common/mod.rs +++ b/cumulus/polkadot-parachain/src/common/mod.rs @@ -20,7 +20,7 @@ pub mod aura; -use cumulus_primitives_core::CollectCollationInfo; +use cumulus_primitives_core::{CollectCollationInfo, FetchClaimQueueOffset}; use sp_api::{ApiExt, CallApiAt, ConstructRuntimeApi, Metadata}; use sp_block_builder::BlockBuilder; use sp_runtime::traits::Block as BlockT; @@ -36,6 +36,7 @@ pub trait NodeRuntimeApi: + BlockBuilder + TaggedTransactionQueue + CollectCollationInfo + + FetchClaimQueueOffset + Sized { } @@ -46,6 +47,7 @@ impl NodeRuntimeApi for T where + SessionKeys + BlockBuilder + TaggedTransactionQueue + + FetchClaimQueueOffset + CollectCollationInfo { } diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs index 7d54e9b4be043..eba92003b19fa 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/asset_hub_polkadot_aura.rs @@ -144,6 +144,12 @@ sp_api::impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + unimplemented!() + } + } + #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { fn on_runtime_upgrade(_: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { diff --git a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs index ca5fc8bdf119b..a9af8858ab7f5 100644 --- a/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs +++ b/cumulus/polkadot-parachain/src/fake_runtime_api/aura.rs @@ -144,6 +144,12 @@ sp_api::impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + unimplemented!() + } + } + #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { fn on_runtime_upgrade(_: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { diff --git a/cumulus/primitives/core/src/lib.rs b/cumulus/primitives/core/src/lib.rs index 6eafecfc3ff57..252704c09156d 100644 --- a/cumulus/primitives/core/src/lib.rs +++ b/cumulus/primitives/core/src/lib.rs @@ -395,4 +395,10 @@ sp_api::decl_runtime_apis! { /// we are collecting the collation info for. fn collect_collation_info(header: &Block::Header) -> CollationInfo; } + + /// Runtime api to fetch the claim queue offset. + pub trait FetchClaimQueueOffset { + /// Fetch the claim queue offset. + fn fetch_claim_queue_offset() -> u8; + } } From bcae16d5073b0ebeb65c3d8f8944dcf117449534 Mon Sep 17 00:00:00 2001 From: alindima Date: Thu, 15 Aug 2024 12:16:54 +0300 Subject: [PATCH 03/26] continue --- .../slot_based/block_builder_task.rs | 13 +++++++++--- cumulus/pallets/parachain-system/src/lib.rs | 20 +++++++++++++++++-- .../testing/rococo-parachain/src/lib.rs | 6 ++++++ cumulus/primitives/core/src/lib.rs | 4 ++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs index d3e91067efe7b..291f5bc5f5cca 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs @@ -20,7 +20,9 @@ use cumulus_client_collator::service::ServiceInterface as CollatorServiceInterfa use cumulus_client_consensus_common::{self as consensus_common, ParachainBlockImportMarker}; use cumulus_client_consensus_proposer::ProposerInterface; use cumulus_primitives_aura::AuraUnincludedSegmentApi; -use cumulus_primitives_core::{FetchClaimQueueOffset, PersistedValidationData}; +use cumulus_primitives_core::{ + FetchClaimQueueOffset, PersistedValidationData, DEFAULT_CLAIM_QUEUE_OFFSET, +}; use cumulus_relay_chain_interface::RelayChainInterface; use polkadot_primitives::{ @@ -271,6 +273,12 @@ where if scheduled_cores.is_empty() { tracing::debug!(target: LOG_TARGET, "Parachain not scheduled, skipping slot."); continue; + } else { + tracing::debug!( + target: LOG_TARGET, + "Scheduled cores: {:?}", + scheduled_cores + ); } let core_index_in_scheduled: u64 = *para_slot.slot % expected_cores; @@ -496,8 +504,7 @@ where relay_parent, self.para_id, &self.relay_client, - // TODO: make this a default somewhere. - maybe_claim_queue_offset.unwrap_or(0), + maybe_claim_queue_offset.unwrap_or(DEFAULT_CLAIM_QUEUE_OFFSET), ) .await } else { diff --git a/cumulus/pallets/parachain-system/src/lib.rs b/cumulus/pallets/parachain-system/src/lib.rs index 77760851f6371..f9ffb8143f975 100644 --- a/cumulus/pallets/parachain-system/src/lib.rs +++ b/cumulus/pallets/parachain-system/src/lib.rs @@ -36,7 +36,7 @@ use cumulus_primitives_core::{ relay_chain, AbridgedHostConfiguration, ChannelInfo, ChannelStatus, CollationInfo, GetChannelInfo, InboundDownwardMessage, InboundHrmpMessage, ListChannelInfos, MessageSendError, OutboundHrmpMessage, ParaId, PersistedValidationData, UpwardMessage, UpwardMessageSender, - XcmpMessageHandler, XcmpMessageSource, + XcmpMessageHandler, XcmpMessageSource, DEFAULT_CLAIM_QUEUE_OFFSET, }; use cumulus_primitives_parachain_inherent::{MessageQueueChain, ParachainInherentData}; use frame_support::{ @@ -699,6 +699,16 @@ pub mod pallet { let post = frame_system::Pallet::::do_apply_authorize_upgrade(code)?; Ok(post) } + + /// Set the claim queue offset. + #[pallet::call_index(4)] + // TODO: set a proper weight here. + #[pallet::weight((1_000, DispatchClass::Operational))] + pub fn set_claim_queue_offset(origin: OriginFor, value: u8) -> DispatchResult { + ensure_root(origin)?; + ClaimQueueOffset::::set(Some(value)); + Ok(()) + } } #[pallet::event] @@ -914,6 +924,12 @@ pub mod pallet { #[pallet::storage] pub type CustomValidationHeadData = StorageValue<_, Vec, OptionQuery>; + /// The claim queue offset. + /// This value is expected to be mostly a constant. It's used by collators to determine when to + /// build a collation. + #[pallet::storage] + pub type ClaimQueueOffset = StorageValue<_, u8>; + #[pallet::inherent] impl ProvideInherent for Pallet { type Call = Call; @@ -1445,7 +1461,7 @@ impl Pallet { /// Returns the claim queue offset. pub fn fetch_claim_queue_offset() -> u8 { - 1 + ClaimQueueOffset::::get().unwrap_or(DEFAULT_CLAIM_QUEUE_OFFSET) } /// Set a custom head data that should be returned as result of `validate_block`. diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index dff7046f19726..43381becedc34 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -854,6 +854,12 @@ impl_runtime_apis! { ConsensusHook::can_build_upon(included_hash, slot) } } + + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/primitives/core/src/lib.rs b/cumulus/primitives/core/src/lib.rs index 252704c09156d..eb3122de38c0e 100644 --- a/cumulus/primitives/core/src/lib.rs +++ b/cumulus/primitives/core/src/lib.rs @@ -332,6 +332,10 @@ pub mod rpsr_digest { } } +/// The default claim queue offset to be used if it's not configured/accessible in the parachain +/// runtime +pub const DEFAULT_CLAIM_QUEUE_OFFSET: u8 = 1; + /// Information about a collation. /// /// This was used in version 1 of the [`CollectCollationInfo`] runtime api. From 7b3594ad34726964e5a84427ed3ef9a55a968584 Mon Sep 17 00:00:00 2001 From: alindima Date: Thu, 15 Aug 2024 13:06:27 +0300 Subject: [PATCH 04/26] logs --- .../src/collators/slot_based/block_builder_task.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs index 291f5bc5f5cca..b2ee51732987e 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs @@ -276,14 +276,20 @@ where } else { tracing::debug!( target: LOG_TARGET, - "Scheduled cores: {:?}", + ?relay_parent, + "Parachain is scheduled on cores: {:?}", scheduled_cores ); } let core_index_in_scheduled: u64 = *para_slot.slot % expected_cores; let Some(core_index) = scheduled_cores.get(core_index_in_scheduled as usize) else { - tracing::debug!(target: LOG_TARGET, core_index_in_scheduled, core_len = scheduled_cores.len(), "Para is scheduled, but not enough cores available."); + tracing::debug!( + target: LOG_TARGET, + core_index_in_scheduled, + core_len = scheduled_cores.len(), + "Para is scheduled, but not enough cores available." + ); continue; }; From 94bf1df1db67912996eb43cd219088302545bcbb Mon Sep 17 00:00:00 2001 From: alindima Date: Fri, 16 Aug 2024 14:20:57 +0300 Subject: [PATCH 05/26] add runtime API to westend/rococo system parachains --- .../runtimes/assets/asset-hub-rococo/src/lib.rs | 6 ++++++ .../runtimes/assets/asset-hub-westend/src/lib.rs | 6 ++++++ .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 6 ++++++ .../runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs | 6 ++++++ .../runtimes/collectives/collectives-westend/src/lib.rs | 6 ++++++ .../runtimes/contracts/contracts-rococo/src/lib.rs | 6 ++++++ .../runtimes/coretime/coretime-rococo/src/lib.rs | 6 ++++++ .../runtimes/coretime/coretime-westend/src/lib.rs | 6 ++++++ .../runtimes/glutton/glutton-westend/src/lib.rs | 8 +++++++- .../parachains/runtimes/people/people-rococo/src/lib.rs | 6 ++++++ .../parachains/runtimes/people/people-westend/src/lib.rs | 6 ++++++ cumulus/parachains/runtimes/starters/seedling/src/lib.rs | 6 ++++++ cumulus/parachains/runtimes/starters/shell/src/lib.rs | 6 ++++++ cumulus/parachains/runtimes/testing/penpal/src/lib.rs | 6 ++++++ .../runtimes/testing/rococo-parachain/src/lib.rs | 6 +++--- cumulus/test/runtime/src/lib.rs | 6 ++++++ 16 files changed, 94 insertions(+), 4 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 4c7356707ab61..e1f57207a20d3 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1394,6 +1394,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index ebbc000d14138..41e6da595373b 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -1490,6 +1490,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index c65880771e086..c3a7c86019ec2 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -1031,6 +1031,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + impl bp_westend::WestendFinalityApi for Runtime { fn best_finalized() -> Option> { BridgeWestendGrandpa::best_finalized() diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 1c26742fd67f8..01f563abf964a 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -798,6 +798,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + impl bp_rococo::RococoFinalityApi for Runtime { fn best_finalized() -> Option> { BridgeRococoGrandpa::best_finalized() diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 21206d26dd573..621e6ca9f483f 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -1004,6 +1004,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index bf173fb618afc..8dc64293c333e 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -653,6 +653,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + impl pallet_contracts::ContractsApi for Runtime { fn call( origin: AccountId, diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 25324bf177642..7485a4afb3121 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -724,6 +724,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index a3051e4bf2713..ffa8b2394b651 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -715,6 +715,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs index 942e11e0b2574..29a9b877e4611 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs @@ -425,7 +425,13 @@ impl_runtime_apis! { } } - impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { fn account_nonce(account: AccountId) -> Nonce { System::account_nonce(account) } diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index 77bfb99669c6c..a3bb296a9fc82 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -687,6 +687,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { diff --git a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs index 3343d2be749d6..375622d42cbc1 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs @@ -687,6 +687,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { diff --git a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs index 1fe72604d3731..b4c95c07d8dc8 100644 --- a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs @@ -371,6 +371,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + impl sp_genesis_builder::GenesisBuilder for Runtime { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) diff --git a/cumulus/parachains/runtimes/starters/shell/src/lib.rs b/cumulus/parachains/runtimes/starters/shell/src/lib.rs index 1dfbe2b6c41c8..e28feb2a264c9 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/lib.rs @@ -429,6 +429,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + impl sp_genesis_builder::GenesisBuilder for Runtime { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index bf39c02a3f594..ef4bfbe2c37eb 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -849,6 +849,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + impl xcm_runtime_apis::fees::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentApiError> { let acceptable_assets = vec![AssetLocationId(xcm_config::RelayLocation::get())]; diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 43381becedc34..6f350308270d6 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -283,8 +283,8 @@ parameter_types! { type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< Runtime, RELAY_CHAIN_SLOT_DURATION_MILLIS, - BLOCK_PROCESSING_VELOCITY, - UNINCLUDED_SEGMENT_CAPACITY, + 3, + 7, >; impl cumulus_pallet_parachain_system::Config for Runtime { @@ -604,7 +604,7 @@ impl pallet_aura::Config for Runtime { type DisabledValidators = (); type MaxAuthorities = ConstU32<100_000>; type AllowMultipleBlocksPerSlot = ConstBool; - type SlotDuration = ConstU64; + type SlotDuration = ConstU64<2000>; } construct_runtime! { diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index 274f16ab630d6..89ae6a12fa159 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -528,6 +528,12 @@ impl_runtime_apis! { } } + impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { + fn fetch_claim_queue_offset() -> u8 { + ParachainSystem::fetch_claim_queue_offset() + } + } + impl sp_genesis_builder::GenesisBuilder for Runtime { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) From 12aea2ae712e4e0e357f1cbd32c843c50f03a485 Mon Sep 17 00:00:00 2001 From: alindima Date: Fri, 16 Aug 2024 14:34:56 +0300 Subject: [PATCH 06/26] use ClaimQueueSnapshot --- Cargo.lock | 1 + cumulus/client/consensus/aura/Cargo.toml | 1 + .../client/consensus/aura/src/collators/mod.rs | 17 +++++------------ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67cfbb5968d54..22785390003c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3899,6 +3899,7 @@ dependencies = [ "parking_lot 0.12.3", "polkadot-node-primitives", "polkadot-node-subsystem", + "polkadot-node-subsystem-util", "polkadot-overseer", "polkadot-primitives", "sc-client-api", diff --git a/cumulus/client/consensus/aura/Cargo.toml b/cumulus/client/consensus/aura/Cargo.toml index 01e07cb395a95..1f17d3fbdcb68 100644 --- a/cumulus/client/consensus/aura/Cargo.toml +++ b/cumulus/client/consensus/aura/Cargo.toml @@ -53,4 +53,5 @@ cumulus-client-collator = { workspace = true, default-features = true } polkadot-primitives = { workspace = true, default-features = true } polkadot-node-primitives = { workspace = true, default-features = true } polkadot-node-subsystem = { workspace = true, default-features = true } +polkadot-node-subsystem-util = { workspace = true, default-features = true } polkadot-overseer = { workspace = true, default-features = true } diff --git a/cumulus/client/consensus/aura/src/collators/mod.rs b/cumulus/client/consensus/aura/src/collators/mod.rs index 233ef373da40e..4b9339001e5a2 100644 --- a/cumulus/client/consensus/aura/src/collators/mod.rs +++ b/cumulus/client/consensus/aura/src/collators/mod.rs @@ -28,6 +28,7 @@ use cumulus_client_consensus_common::{ use cumulus_primitives_aura::{AuraUnincludedSegmentApi, Slot}; use cumulus_primitives_core::{relay_chain::Hash as ParaHash, BlockT}; use cumulus_relay_chain_interface::RelayChainInterface; +use polkadot_node_subsystem_util::vstaging::ClaimQueueSnapshot; use polkadot_primitives::{ AsyncBackingParams, CoreIndex, CoreState, Hash as RelayHash, Id as ParaId, OccupiedCoreAssumption, ValidationCodeHash, @@ -185,8 +186,8 @@ async fn cores_scheduled_for_para( claim_queue_offset: u8, ) -> Vec { // Get `ClaimQueue` from runtime - let claim_queue = match relay_client.claim_queue(relay_parent).await { - Ok(claim_queue) => claim_queue, + let claim_queue: ClaimQueueSnapshot = match relay_client.claim_queue(relay_parent).await { + Ok(claim_queue) => claim_queue.into(), Err(error) => { tracing::error!( target: crate::LOG_TARGET, @@ -199,16 +200,8 @@ async fn cores_scheduled_for_para( }; claim_queue - .into_iter() - .filter_map(|(core_index, queue)| { - let core_para_id = queue.get(claim_queue_offset as usize); - - if core_para_id == Some(¶_id) { - Some(core_index) - } else { - None - } - }) + .iter_claims_at_depth(claim_queue_offset as usize) + .filter_map(|(core_index, core_para_id)| (core_para_id == para_id).then_some(core_index)) .collect() } From f1e2721ed7c8bf709f5cba5e2d810d066fe55a7b Mon Sep 17 00:00:00 2001 From: alindima Date: Fri, 16 Aug 2024 14:45:28 +0300 Subject: [PATCH 07/26] rollback changes to rococo-parachain --- .../parachains/runtimes/testing/rococo-parachain/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 6f350308270d6..43381becedc34 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -283,8 +283,8 @@ parameter_types! { type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< Runtime, RELAY_CHAIN_SLOT_DURATION_MILLIS, - 3, - 7, + BLOCK_PROCESSING_VELOCITY, + UNINCLUDED_SEGMENT_CAPACITY, >; impl cumulus_pallet_parachain_system::Config for Runtime { @@ -604,7 +604,7 @@ impl pallet_aura::Config for Runtime { type DisabledValidators = (); type MaxAuthorities = ConstU32<100_000>; type AllowMultipleBlocksPerSlot = ConstBool; - type SlotDuration = ConstU64<2000>; + type SlotDuration = ConstU64; } construct_runtime! { From f9268dd31193d87a406575d7e43dbf7c1fc7942c Mon Sep 17 00:00:00 2001 From: alindima Date: Fri, 16 Aug 2024 15:00:59 +0300 Subject: [PATCH 08/26] add prdoc --- prdoc/pr_5372.prdoc | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 prdoc/pr_5372.prdoc diff --git a/prdoc/pr_5372.prdoc b/prdoc/pr_5372.prdoc new file mode 100644 index 0000000000000..23546bbe3cfb5 --- /dev/null +++ b/prdoc/pr_5372.prdoc @@ -0,0 +1,61 @@ +title: "elastic scaling: add claim queue offset to cumulus" + +doc: + - audience: [Node Dev, Runtime Dev] + description: | + Add a claim queue offset storage item to the parachain-system pallet and a runtime API for querying it. + Also use the claim queue offset and the claim queue relay chain runtime API in the slot based collator (if available) + to determine which cores to build on. + Part of implementing https://github.com/polkadot-fellows/RFCs/pull/103. + +crates: + - name: cumulus-client-consensus-aura + bump: minor + - name: cumulus-relay-chain-inprocess-interface + bump: minor + - name: cumulus-relay-chain-interface + bump: major + - name: cumulus-relay-chain-minimal-node + bump: none + - name: cumulus-relay-chain-rpc-interface + bump: minor + - name: cumulus-pallet-parachain-system + bump: minor + - name: asset-hub-rococo-runtime + bump: minor + - name: asset-hub-westend-runtime + bump: minor + - name: bridge-hub-rococo-runtime + bump: minor + - name: bridge-hub-westend-runtime + bump: minor + - name: collectives-rococo-runtime + bump: minor + - name: collectives-westend-runtime + bump: minor + - name: contracts-rococo-runtime + bump: minor + - name: coretime-rococo-runtime + bump: minor + - name: coretime-westend-runtime + bump: minor + - name: glutton-westend-runtime + bump: minor + - name: people-rococo-runtime + bump: minor + - name: people-westend-runtime + bump: minor + - name: seedling-runtime + bump: minor + - name: shell-runtime + bump: minor + - name: penpal-runtime + bump: minor + - name: rococo-parachain-runtime + bump: minor + - name: polkadot-parachain-bin + bump: major + - name: cumulus-primitives-core + bump: minor + - name: cumulus-test-runtime + bump: minor From b825c2220a11cc75d7bb13cdc5255fb7f1d6d833 Mon Sep 17 00:00:00 2001 From: alindima Date: Fri, 16 Aug 2024 15:07:28 +0300 Subject: [PATCH 09/26] fix prdoc --- prdoc/pr_5372.prdoc | 2 -- 1 file changed, 2 deletions(-) diff --git a/prdoc/pr_5372.prdoc b/prdoc/pr_5372.prdoc index 23546bbe3cfb5..d1bd0868d00d5 100644 --- a/prdoc/pr_5372.prdoc +++ b/prdoc/pr_5372.prdoc @@ -31,8 +31,6 @@ crates: bump: minor - name: collectives-rococo-runtime bump: minor - - name: collectives-westend-runtime - bump: minor - name: contracts-rococo-runtime bump: minor - name: coretime-rococo-runtime From 7e2dc9a8f30cab7090ff403b05cc449173ad99b9 Mon Sep 17 00:00:00 2001 From: alindima Date: Fri, 16 Aug 2024 15:12:16 +0300 Subject: [PATCH 10/26] fix compilation --- cumulus/client/consensus/common/src/tests.rs | 11 +++++++++-- cumulus/client/network/src/tests.rs | 15 +++++++++++++-- cumulus/client/pov-recovery/src/tests.rs | 11 +++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/cumulus/client/consensus/common/src/tests.rs b/cumulus/client/consensus/common/src/tests.rs index 284fa39ed1e70..fccf011f7e952 100644 --- a/cumulus/client/consensus/common/src/tests.rs +++ b/cumulus/client/consensus/common/src/tests.rs @@ -24,7 +24,7 @@ use cumulus_primitives_core::{ CumulusDigestItem, InboundDownwardMessage, InboundHrmpMessage, }; use cumulus_relay_chain_interface::{ - CommittedCandidateReceipt, OccupiedCoreAssumption, OverseerHandle, PHeader, ParaId, + CommittedCandidateReceipt, CoreIndex, OccupiedCoreAssumption, OverseerHandle, PHeader, ParaId, RelayChainInterface, RelayChainResult, SessionIndex, StorageValue, ValidatorId, }; use cumulus_test_client::{ @@ -41,7 +41,7 @@ use sp_blockchain::Backend as BlockchainBackend; use sp_consensus::{BlockOrigin, BlockStatus}; use sp_version::RuntimeVersion; use std::{ - collections::{BTreeMap, HashMap}, + collections::{BTreeMap, HashMap, VecDeque}, pin::Pin, sync::{Arc, Mutex}, time::Duration, @@ -268,6 +268,13 @@ impl RelayChainInterface for Relaychain { async fn version(&self, _: PHash) -> RelayChainResult { unimplemented!("Not needed for test") } + + async fn claim_queue( + &self, + _: PHash, + ) -> RelayChainResult>> { + unimplemented!("Not needed for test"); + } } fn sproof_with_best_parent(client: &Client) -> RelayStateSproofBuilder { diff --git a/cumulus/client/network/src/tests.rs b/cumulus/client/network/src/tests.rs index 18d121c41d168..3e5370dc186c8 100644 --- a/cumulus/client/network/src/tests.rs +++ b/cumulus/client/network/src/tests.rs @@ -16,7 +16,7 @@ use super::*; use async_trait::async_trait; -use cumulus_primitives_core::relay_chain::BlockId; +use cumulus_primitives_core::relay_chain::{BlockId, CoreIndex}; use cumulus_relay_chain_inprocess_interface::{check_block_in_chain, BlockCheckStatus}; use cumulus_relay_chain_interface::{ OverseerHandle, PHeader, ParaId, RelayChainError, RelayChainResult, @@ -45,7 +45,11 @@ use sp_keystore::{testing::MemoryKeystore, Keystore, KeystorePtr}; use sp_runtime::RuntimeAppPublic; use sp_state_machine::StorageValue; use sp_version::RuntimeVersion; -use std::{borrow::Cow, collections::BTreeMap, time::Duration}; +use std::{ + borrow::Cow, + collections::{BTreeMap, VecDeque}, + time::Duration, +}; fn check_error(error: crate::BoxedError, check_error: impl Fn(&BlockAnnounceError) -> bool) { let error = *error @@ -326,6 +330,13 @@ impl RelayChainInterface for DummyRelayChainInterface { state_version: 1, }) } + + async fn claim_queue( + &self, + _: PHash, + ) -> RelayChainResult>> { + unimplemented!("Not needed for test"); + } } fn make_validator_and_api() -> ( diff --git a/cumulus/client/pov-recovery/src/tests.rs b/cumulus/client/pov-recovery/src/tests.rs index 6f274ed18b6bc..87ca978db2e31 100644 --- a/cumulus/client/pov-recovery/src/tests.rs +++ b/cumulus/client/pov-recovery/src/tests.rs @@ -18,7 +18,7 @@ use super::*; use assert_matches::assert_matches; use codec::{Decode, Encode}; use cumulus_primitives_core::relay_chain::{ - BlockId, CandidateCommitments, CandidateDescriptor, CoreState, + BlockId, CandidateCommitments, CandidateDescriptor, CoreIndex, CoreState, }; use cumulus_relay_chain_interface::{ InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption, PHash, PHeader, @@ -43,7 +43,7 @@ use sp_runtime::{generic::SignedBlock, Justifications}; use sp_version::RuntimeVersion; use std::{ borrow::Cow, - collections::BTreeMap, + collections::{BTreeMap, VecDeque}, ops::Range, sync::{Arc, Mutex}, }; @@ -487,6 +487,13 @@ impl RelayChainInterface for Relaychain { ) -> RelayChainResult>>> { unimplemented!("Not needed for test"); } + + async fn claim_queue( + &self, + _: PHash, + ) -> RelayChainResult>> { + unimplemented!("Not needed for test"); + } } fn make_candidate_chain(candidate_number_range: Range) -> Vec { From 48d19b9c3474cd9585f1ecd5fcb52a3192207487 Mon Sep 17 00:00:00 2001 From: alindima Date: Fri, 16 Aug 2024 15:27:05 +0300 Subject: [PATCH 11/26] fix prdoc again --- prdoc/pr_5372.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_5372.prdoc b/prdoc/pr_5372.prdoc index d1bd0868d00d5..cc4aa6dd7a895 100644 --- a/prdoc/pr_5372.prdoc +++ b/prdoc/pr_5372.prdoc @@ -29,7 +29,7 @@ crates: bump: minor - name: bridge-hub-westend-runtime bump: minor - - name: collectives-rococo-runtime + - name: collectives-westend-runtime bump: minor - name: contracts-rococo-runtime bump: minor From e82993472e74b75b3621fff2083239212c3f8a85 Mon Sep 17 00:00:00 2001 From: alindima Date: Mon, 19 Aug 2024 10:01:09 +0300 Subject: [PATCH 12/26] prdoc --- prdoc/pr_5372.prdoc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/prdoc/pr_5372.prdoc b/prdoc/pr_5372.prdoc index cc4aa6dd7a895..24ef08830e116 100644 --- a/prdoc/pr_5372.prdoc +++ b/prdoc/pr_5372.prdoc @@ -57,3 +57,9 @@ crates: bump: minor - name: cumulus-test-runtime bump: minor + - name: cumulus-client-consensus-common + bump: none + - name: cumulus-client-pov-recovery + bump: none + - name: cumulus-client-network + bump: none From e4478d1500ff4ca78639ba70fdd120907883c63e Mon Sep 17 00:00:00 2001 From: alindima Date: Mon, 19 Aug 2024 10:25:19 +0300 Subject: [PATCH 13/26] bootstrap weights --- cumulus/pallets/parachain-system/src/benchmarking.rs | 7 +++++++ cumulus/pallets/parachain-system/src/lib.rs | 3 +-- cumulus/pallets/parachain-system/src/weights.rs | 7 +++++++ .../src/weights/cumulus_pallet_parachain_system.rs | 4 ++++ .../src/weights/cumulus_pallet_parachain_system.rs | 4 ++++ .../src/weights/cumulus_pallet_parachain_system.rs | 4 ++++ .../src/weights/cumulus_pallet_parachain_system.rs | 4 ++++ .../src/weights/cumulus_pallet_parachain_system.rs | 4 ++++ .../src/weights/cumulus_pallet_parachain_system.rs | 4 ++++ .../src/weights/cumulus_pallet_parachain_system.rs | 4 ++++ .../src/weights/cumulus_pallet_parachain_system.rs | 4 ++++ .../src/weights/cumulus_pallet_parachain_system.rs | 4 ++++ .../src/weights/cumulus_pallet_parachain_system.rs | 4 ++++ 13 files changed, 55 insertions(+), 2 deletions(-) diff --git a/cumulus/pallets/parachain-system/src/benchmarking.rs b/cumulus/pallets/parachain-system/src/benchmarking.rs index 5cde8eb5b7885..a0cd0224fa47a 100644 --- a/cumulus/pallets/parachain-system/src/benchmarking.rs +++ b/cumulus/pallets/parachain-system/src/benchmarking.rs @@ -22,6 +22,7 @@ use super::*; use cumulus_primitives_core::relay_chain::Hash as RelayHash; use frame_benchmarking::v2::*; +use frame_system::RawOrigin; use sp_runtime::traits::BlakeTwo256; #[benchmarks] @@ -60,6 +61,12 @@ mod benchmarks { head } + #[benchmark] + fn set_claim_queue_offset() { + #[extrinsic_call] + Pallet::::set_claim_queue_offset(RawOrigin::Root, 2); + } + impl_benchmark_test_suite! { Pallet, crate::mock::new_test_ext(), diff --git a/cumulus/pallets/parachain-system/src/lib.rs b/cumulus/pallets/parachain-system/src/lib.rs index f9ffb8143f975..eeddca916af60 100644 --- a/cumulus/pallets/parachain-system/src/lib.rs +++ b/cumulus/pallets/parachain-system/src/lib.rs @@ -702,8 +702,7 @@ pub mod pallet { /// Set the claim queue offset. #[pallet::call_index(4)] - // TODO: set a proper weight here. - #[pallet::weight((1_000, DispatchClass::Operational))] + #[pallet::weight((T::WeightInfo::set_claim_queue_offset(), DispatchClass::Operational))] pub fn set_claim_queue_offset(origin: OriginFor, value: u8) -> DispatchResult { ensure_root(origin)?; ClaimQueueOffset::::set(Some(value)); diff --git a/cumulus/pallets/parachain-system/src/weights.rs b/cumulus/pallets/parachain-system/src/weights.rs index 5c61879b4d36b..8f15044697844 100644 --- a/cumulus/pallets/parachain-system/src/weights.rs +++ b/cumulus/pallets/parachain-system/src/weights.rs @@ -55,6 +55,7 @@ use core::marker::PhantomData; /// Weight functions needed for cumulus_pallet_parachain_system. pub trait WeightInfo { fn enqueue_inbound_downward_messages(n: u32, ) -> Weight; + fn set_claim_queue_offset() -> Weight; } /// Weights for cumulus_pallet_parachain_system using the Substrate node and recommended hardware. @@ -84,6 +85,9 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } + fn set_claim_queue_offset() -> Weight { + Weight::from_parts(1, 1) + } } // For backwards compatibility and tests @@ -112,4 +116,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } + fn set_claim_queue_offset() -> Weight { + Weight::from_parts(1, 1) + } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs index fc63a0814d0a4..d255589838c84 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs @@ -77,4 +77,8 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) } + + fn set_claim_queue_offset() -> Weight { + Weight::from_parts(1, 1) + } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs index fc63a0814d0a4..d255589838c84 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs @@ -77,4 +77,8 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) } + + fn set_claim_queue_offset() -> Weight { + Weight::from_parts(1, 1) + } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs index 8fcd7b10d931b..d59acfc7cbdd3 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs @@ -77,4 +77,8 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) } + + fn set_claim_queue_offset() -> Weight { + Weight::from_parts(1, 1) + } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/cumulus_pallet_parachain_system.rs index 8fcd7b10d931b..d59acfc7cbdd3 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/cumulus_pallet_parachain_system.rs @@ -77,4 +77,8 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) } + + fn set_claim_queue_offset() -> Weight { + Weight::from_parts(1, 1) + } } diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/cumulus_pallet_parachain_system.rs index 92c8c88b51547..1eb1e17c6a18c 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/cumulus_pallet_parachain_system.rs @@ -77,4 +77,8 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) } + + fn set_claim_queue_offset() -> Weight { + Weight::from_parts(1, 1) + } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/cumulus_pallet_parachain_system.rs index 139e37c544898..7e6b6863648af 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/cumulus_pallet_parachain_system.rs @@ -74,4 +74,8 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().writes(4)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) } + + fn set_claim_queue_offset() -> Weight { + Weight::from_parts(1, 1) + } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/cumulus_pallet_parachain_system.rs index 1c9119361985c..8f7e5427740b2 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/cumulus_pallet_parachain_system.rs @@ -74,4 +74,8 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().writes(4)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) } + + fn set_claim_queue_offset() -> Weight { + Weight::from_parts(1, 1) + } } diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/weights/cumulus_pallet_parachain_system.rs index bc8299ab1bd67..e1fea4c3efff5 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/weights/cumulus_pallet_parachain_system.rs @@ -72,4 +72,8 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().writes(4)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) } + + fn set_claim_queue_offset() -> Weight { + Weight::from_parts(1, 1) + } } diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/people/people-rococo/src/weights/cumulus_pallet_parachain_system.rs index 5715d56c21868..c51377dd9ed55 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/weights/cumulus_pallet_parachain_system.rs @@ -50,4 +50,8 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) } + + fn set_claim_queue_offset() -> Weight { + Weight::from_parts(1, 1) + } } diff --git a/cumulus/parachains/runtimes/people/people-westend/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/people/people-westend/src/weights/cumulus_pallet_parachain_system.rs index 5715d56c21868..c51377dd9ed55 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/weights/cumulus_pallet_parachain_system.rs @@ -50,4 +50,8 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) } + + fn set_claim_queue_offset() -> Weight { + Weight::from_parts(1, 1) + } } From ebf5e93fdb3616c5dabaa99ff4a8dc571c7b3ff2 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 20 Aug 2024 14:50:25 +0000 Subject: [PATCH 14/26] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=asset-hub-westend --runtime_dir=assets --target_dir=cumulus --pallet=cumulus_pallet_parachain_system --- .../cumulus_pallet_parachain_system.rs | 112 +++++++++--------- 1 file changed, 57 insertions(+), 55 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs index d255589838c84..e70f81033cd1f 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs @@ -1,50 +1,46 @@ // Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 +// This file is part of Cumulus. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . //! Autogenerated weights for `cumulus_pallet_parachain_system` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-03-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-08-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `i9`, CPU: `13th Gen Intel(R) Core(TM) i9-13900K` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemine-dev"), DB CACHE: 1024 +//! HOSTNAME: `runner-k1zul77x-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("asset-hub-westend-dev")`, DB CACHE: 1024 // Executed Command: -// ./target/release/polkadot-parachain +// target/production/polkadot-parachain // benchmark // pallet -// --chain -// statemine-dev -// --pallet -// cumulus_pallet_parachain_system -// --extrinsic -// * -// --execution -// wasm -// --wasm-execution -// compiled -// --output -// parachains/runtimes/assets/statemine/src/weights -// --steps -// 50 -// --repeat -// 20 +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=cumulus_pallet_parachain_system +// --chain=asset-hub-westend-dev +// --header=./cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/ #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] +#![allow(missing_docs)] use frame_support::{traits::Get, weights::Weight}; use core::marker::PhantomData; @@ -52,33 +48,39 @@ use core::marker::PhantomData; /// Weight functions for `cumulus_pallet_parachain_system`. pub struct WeightInfo(PhantomData); impl cumulus_pallet_parachain_system::WeightInfo for WeightInfo { - /// Storage: ParachainSystem LastDmqMqcHead (r:1 w:1) - /// Proof Skipped: ParachainSystem LastDmqMqcHead (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: ParachainSystem ReservedDmpWeightOverride (r:1 w:0) - /// Proof Skipped: ParachainSystem ReservedDmpWeightOverride (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: MessageQueue BookStateFor (r:1 w:1) - /// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - /// Storage: MessageQueue ServiceHead (r:1 w:1) - /// Proof: MessageQueue ServiceHead (max_values: Some(1), max_size: Some(5), added: 500, mode: MaxEncodedLen) - /// Storage: ParachainSystem ProcessedDownwardMessages (r:0 w:1) - /// Proof Skipped: ParachainSystem ProcessedDownwardMessages (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: MessageQueue Pages (r:0 w:16) - /// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen) + /// Storage: `ParachainSystem::LastDmqMqcHead` (r:1 w:1) + /// Proof: `ParachainSystem::LastDmqMqcHead` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `MessageQueue::BookStateFor` (r:1 w:1) + /// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `MessageQueue::ServiceHead` (r:1 w:1) + /// Proof: `MessageQueue::ServiceHead` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`) + /// Storage: `ParachainSystem::ProcessedDownwardMessages` (r:0 w:1) + /// Proof: `ParachainSystem::ProcessedDownwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `MessageQueue::Pages` (r:0 w:1000) + /// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(105521), added: 107996, mode: `MaxEncodedLen`) /// The range of component `n` is `[0, 1000]`. fn enqueue_inbound_downward_messages(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `12` - // Estimated: `8013` - // Minimum execution time: 1_622_000 picoseconds. - Weight::from_parts(1_709_000, 0) - .saturating_add(Weight::from_parts(0, 8013)) - // Standard Error: 22_138 - .saturating_add(Weight::from_parts(23_923_169, 0).saturating_mul(n.into())) - .saturating_add(T::DbWeight::get().reads(4)) + // Measured: `84` + // Estimated: `3517` + // Minimum execution time: 2_842_000 picoseconds. + Weight::from_parts(2_990_000, 0) + .saturating_add(Weight::from_parts(0, 3517)) + // Standard Error: 54_039 + .saturating_add(Weight::from_parts(315_605_099, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(4)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) } - + /// Storage: `ParachainSystem::ClaimQueueOffset` (r:0 w:1) + /// Proof: `ParachainSystem::ClaimQueueOffset` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn set_claim_queue_offset() -> Weight { - Weight::from_parts(1, 1) + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_430_000 picoseconds. + Weight::from_parts(2_613_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) } } From 8305048bf7f6cd3e9da6c7cfabed51e4287526d6 Mon Sep 17 00:00:00 2001 From: alindima Date: Fri, 13 Sep 2024 15:07:11 +0300 Subject: [PATCH 15/26] fix compilation --- .../polkadot-parachain-lib/src/fake_runtime_api/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/utils.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/utils.rs index f55fb2d7da41d..89de9c426119d 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/utils.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/utils.rs @@ -156,7 +156,7 @@ macro_rules! impl_node_runtime_apis { } } - impl cumulus_primitives_core::FetchClaimQueueOffset<$block> for Runtime { + impl cumulus_primitives_core::FetchClaimQueueOffset<$block> for $runtime { fn fetch_claim_queue_offset() -> u8 { unimplemented!() } From 982ce7fb26419ecb75deccffb6e2b7cbe0f89036 Mon Sep 17 00:00:00 2001 From: alindima Date: Fri, 13 Sep 2024 15:07:52 +0300 Subject: [PATCH 16/26] address some comments --- .../consensus/aura/src/collators/lookahead.rs | 4 +- .../consensus/aura/src/collators/mod.rs | 50 +------------------ .../slot_based/block_builder_task.rs | 45 ++++------------- 3 files changed, 13 insertions(+), 86 deletions(-) diff --git a/cumulus/client/consensus/aura/src/collators/lookahead.rs b/cumulus/client/consensus/aura/src/collators/lookahead.rs index 6408c8ce7446e..70d35dc084234 100644 --- a/cumulus/client/consensus/aura/src/collators/lookahead.rs +++ b/cumulus/client/consensus/aura/src/collators/lookahead.rs @@ -256,10 +256,12 @@ where while let Some(relay_parent_header) = import_notifications.next().await { let relay_parent = relay_parent_header.hash(); - let core_index = if let Some(core_index) = super::cores_scheduled_for_para_legacy( + let core_index = if let Some(core_index) = super::cores_scheduled_for_para( relay_parent, params.para_id, &mut params.relay_client, + // Use depth 0, to preserve behaviour. + 0, ) .await .get(0) diff --git a/cumulus/client/consensus/aura/src/collators/mod.rs b/cumulus/client/consensus/aura/src/collators/mod.rs index 4b9339001e5a2..f652c1875a442 100644 --- a/cumulus/client/consensus/aura/src/collators/mod.rs +++ b/cumulus/client/consensus/aura/src/collators/mod.rs @@ -28,7 +28,7 @@ use cumulus_client_consensus_common::{ use cumulus_primitives_aura::{AuraUnincludedSegmentApi, Slot}; use cumulus_primitives_core::{relay_chain::Hash as ParaHash, BlockT}; use cumulus_relay_chain_interface::RelayChainInterface; -use polkadot_node_subsystem_util::vstaging::ClaimQueueSnapshot; +use polkadot_node_subsystem_util::runtime::ClaimQueueSnapshot; use polkadot_primitives::{ AsyncBackingParams, CoreIndex, CoreState, Hash as RelayHash, Id as ParaId, OccupiedCoreAssumption, ValidationCodeHash, @@ -127,54 +127,6 @@ async fn async_backing_params( } } -// Return all the cores assigned to the para at the provided relay parent, using the legacy method, -// availability-cores. Using the claim queue is the preferred alternative. -async fn cores_scheduled_for_para_legacy( - relay_parent: RelayHash, - para_id: ParaId, - relay_client: &impl RelayChainInterface, -) -> Vec { - // Get `AvailabilityCores` from runtime - let cores = match relay_client.availability_cores(relay_parent).await { - Ok(cores) => cores, - Err(error) => { - tracing::error!( - target: crate::LOG_TARGET, - ?error, - ?relay_parent, - "Failed to query availability cores runtime API", - ); - return Vec::new() - }, - }; - - let max_candidate_depth = async_backing_params(relay_parent, relay_client) - .await - .map(|c| c.max_candidate_depth) - .unwrap_or(0); - - cores - .iter() - .enumerate() - .filter_map(|(index, core)| { - let core_para_id = match core { - CoreState::Scheduled(scheduled_core) => Some(scheduled_core.para_id), - CoreState::Occupied(occupied_core) if max_candidate_depth > 0 => occupied_core - .next_up_on_available - .as_ref() - .map(|scheduled_core| scheduled_core.para_id), - CoreState::Free | CoreState::Occupied(_) => None, - }; - - if core_para_id == Some(para_id) { - Some(CoreIndex(index as u32)) - } else { - None - } - }) - .collect() -} - // Return all the cores assigned to the para at the provided relay parent, using the claim queue // offset. This assumes the relay chain runtime supports the claimqueue runtime API. // Will return an empty vec if the provided offset is higher than the claim queue length (which diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs index c87110e141a5c..61992535171b5 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs @@ -47,9 +47,7 @@ use std::{sync::Arc, time::Duration}; use super::CollatorMessage; use crate::{ collator::{self as collator_util}, - collators::{ - check_validation_code_or_log, cores_scheduled_for_para, cores_scheduled_for_para_legacy, - }, + collators::{check_validation_code_or_log, cores_scheduled_for_para}, LOG_TARGET, }; @@ -288,7 +286,7 @@ where target: LOG_TARGET, core_index_in_scheduled, core_len = scheduled_cores.len(), - "Para is scheduled, but not enough cores available." + "Para is not scheduled on enough cores" ); continue; }; @@ -490,38 +488,13 @@ where relay_parent: RelayHash, maybe_claim_queue_offset: Option, ) -> Result { - let runtime_api_version = self.relay_client.version(relay_parent).await.map_err(|e| { - tracing::error!( - target: LOG_TARGET, - error = ?e, - "Failed to fetch relay chain runtime version.", - ) - })?; - let parachain_host_runtime_api_version = - runtime_api_version - .api_version( - &>::ID, - ) - .unwrap_or_default(); - - // If the relay chain runtime does not support the new claim queue runtime API, fallback to - // the using availability cores. In this case the claim queue offset will not be used. - let supports_claim_queue = parachain_host_runtime_api_version >= - polkadot_node_subsystem::messages::RuntimeApiRequest::CLAIM_QUEUE_RUNTIME_REQUIREMENT; - - let scheduled_cores = if supports_claim_queue { - cores_scheduled_for_para( - relay_parent, - self.para_id, - &self.relay_client, - maybe_claim_queue_offset.unwrap_or(DEFAULT_CLAIM_QUEUE_OFFSET), - ) - .await - } else { - cores_scheduled_for_para_legacy(relay_parent, self.para_id, &self.relay_client).await - }; + let scheduled_cores = cores_scheduled_for_para( + relay_parent, + self.para_id, + &self.relay_client, + maybe_claim_queue_offset.unwrap_or(DEFAULT_CLAIM_QUEUE_OFFSET), + ) + .await; let Ok(Some(relay_parent_header)) = self.relay_client.header(BlockId::Hash(relay_parent)).await From dec01b7fe4574b96a75a1c3043685efb74b055e9 Mon Sep 17 00:00:00 2001 From: alindima Date: Fri, 13 Sep 2024 15:24:54 +0300 Subject: [PATCH 17/26] unused imports --- cumulus/client/consensus/aura/src/collators/mod.rs | 4 ++-- .../aura/src/collators/slot_based/block_builder_task.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cumulus/client/consensus/aura/src/collators/mod.rs b/cumulus/client/consensus/aura/src/collators/mod.rs index f652c1875a442..1d1e029280940 100644 --- a/cumulus/client/consensus/aura/src/collators/mod.rs +++ b/cumulus/client/consensus/aura/src/collators/mod.rs @@ -30,8 +30,8 @@ use cumulus_primitives_core::{relay_chain::Hash as ParaHash, BlockT}; use cumulus_relay_chain_interface::RelayChainInterface; use polkadot_node_subsystem_util::runtime::ClaimQueueSnapshot; use polkadot_primitives::{ - AsyncBackingParams, CoreIndex, CoreState, Hash as RelayHash, Id as ParaId, - OccupiedCoreAssumption, ValidationCodeHash, + AsyncBackingParams, CoreIndex, Hash as RelayHash, Id as ParaId, OccupiedCoreAssumption, + ValidationCodeHash, }; use sc_consensus_aura::{standalone as aura_internal, AuraApi}; use sp_api::ProvideRuntimeApi; diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs index 61992535171b5..ab37eabf23d7c 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs @@ -33,7 +33,7 @@ use polkadot_primitives::{ use futures::prelude::*; use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf, UsageProvider}; use sc_consensus::BlockImport; -use sp_api::{ApiExt, ProvideRuntimeApi, RuntimeApiInfo}; +use sp_api::{ApiExt, ProvideRuntimeApi}; use sp_application_crypto::AppPublic; use sp_blockchain::HeaderBackend; use sp_consensus_aura::{AuraApi, Slot, SlotDuration}; From 4c6fb648d29b66762a85fb41906da357eb0bb303 Mon Sep 17 00:00:00 2001 From: alindima Date: Mon, 16 Sep 2024 15:48:35 +0300 Subject: [PATCH 18/26] make the core selection logic generic --- .../consensus/aura/src/collators/lookahead.rs | 4 +- .../consensus/aura/src/collators/mod.rs | 6 +- .../slot_based/block_builder_task.rs | 126 +++++++++--------- .../aura/src/collators/slot_based/mod.rs | 7 +- .../parachain-system/src/benchmarking.rs | 6 - cumulus/pallets/parachain-system/src/lib.rs | 56 +++++--- .../pallets/parachain-system/src/weights.rs | 7 - .../assets/asset-hub-rococo/src/lib.rs | 9 +- .../cumulus_pallet_parachain_system.rs | 4 - .../assets/asset-hub-westend/src/lib.rs | 9 +- .../cumulus_pallet_parachain_system.rs | 11 -- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 9 +- .../cumulus_pallet_parachain_system.rs | 4 - .../bridge-hubs/bridge-hub-westend/src/lib.rs | 9 +- .../cumulus_pallet_parachain_system.rs | 4 - .../collectives-westend/src/lib.rs | 9 +- .../cumulus_pallet_parachain_system.rs | 4 - .../contracts/contracts-rococo/src/lib.rs | 9 +- .../coretime/coretime-rococo/src/lib.rs | 9 +- .../cumulus_pallet_parachain_system.rs | 4 - .../coretime/coretime-westend/src/lib.rs | 9 +- .../cumulus_pallet_parachain_system.rs | 4 - .../glutton/glutton-westend/src/lib.rs | 15 ++- .../cumulus_pallet_parachain_system.rs | 4 - .../runtimes/people/people-rococo/src/lib.rs | 9 +- .../cumulus_pallet_parachain_system.rs | 4 - .../runtimes/people/people-westend/src/lib.rs | 9 +- .../cumulus_pallet_parachain_system.rs | 4 - .../runtimes/starters/seedling/src/lib.rs | 8 +- .../runtimes/starters/shell/src/lib.rs | 9 +- .../runtimes/testing/penpal/src/lib.rs | 9 +- .../testing/rococo-parachain/src/lib.rs | 9 +- .../polkadot-parachain-lib/src/common/mod.rs | 6 +- .../src/fake_runtime_api/utils.rs | 5 +- .../polkadot-parachain-lib/src/service.rs | 3 +- cumulus/primitives/core/src/lib.rs | 9 +- cumulus/test/runtime/src/lib.rs | 8 +- 37 files changed, 197 insertions(+), 233 deletions(-) diff --git a/cumulus/client/consensus/aura/src/collators/lookahead.rs b/cumulus/client/consensus/aura/src/collators/lookahead.rs index 70d35dc084234..322baaa01498c 100644 --- a/cumulus/client/consensus/aura/src/collators/lookahead.rs +++ b/cumulus/client/consensus/aura/src/collators/lookahead.rs @@ -36,7 +36,7 @@ use cumulus_client_collator::service::ServiceInterface as CollatorServiceInterfa use cumulus_client_consensus_common::{self as consensus_common, ParachainBlockImportMarker}; use cumulus_client_consensus_proposer::ProposerInterface; use cumulus_primitives_aura::AuraUnincludedSegmentApi; -use cumulus_primitives_core::{CollectCollationInfo, PersistedValidationData}; +use cumulus_primitives_core::{ClaimQueueOffset, CollectCollationInfo, PersistedValidationData}; use cumulus_relay_chain_interface::RelayChainInterface; use polkadot_node_primitives::{PoV, SubmitCollationParams}; @@ -261,7 +261,7 @@ where params.para_id, &mut params.relay_client, // Use depth 0, to preserve behaviour. - 0, + ClaimQueueOffset(0), ) .await .get(0) diff --git a/cumulus/client/consensus/aura/src/collators/mod.rs b/cumulus/client/consensus/aura/src/collators/mod.rs index 1d1e029280940..bcbdb5c585466 100644 --- a/cumulus/client/consensus/aura/src/collators/mod.rs +++ b/cumulus/client/consensus/aura/src/collators/mod.rs @@ -26,7 +26,7 @@ use cumulus_client_consensus_common::{ self as consensus_common, load_abridged_host_configuration, ParentSearchParams, }; use cumulus_primitives_aura::{AuraUnincludedSegmentApi, Slot}; -use cumulus_primitives_core::{relay_chain::Hash as ParaHash, BlockT}; +use cumulus_primitives_core::{relay_chain::Hash as ParaHash, BlockT, ClaimQueueOffset}; use cumulus_relay_chain_interface::RelayChainInterface; use polkadot_node_subsystem_util::runtime::ClaimQueueSnapshot; use polkadot_primitives::{ @@ -135,7 +135,7 @@ async fn cores_scheduled_for_para( relay_parent: RelayHash, para_id: ParaId, relay_client: &impl RelayChainInterface, - claim_queue_offset: u8, + claim_queue_offset: ClaimQueueOffset, ) -> Vec { // Get `ClaimQueue` from runtime let claim_queue: ClaimQueueSnapshot = match relay_client.claim_queue(relay_parent).await { @@ -152,7 +152,7 @@ async fn cores_scheduled_for_para( }; claim_queue - .iter_claims_at_depth(claim_queue_offset as usize) + .iter_claims_at_depth(claim_queue_offset.0 as usize) .filter_map(|(core_index, core_para_id)| (core_para_id == para_id).then_some(core_index)) .collect() } diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs index ab37eabf23d7c..1c24b60eca657 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs @@ -21,11 +21,12 @@ use cumulus_client_consensus_common::{self as consensus_common, ParachainBlockIm use cumulus_client_consensus_proposer::ProposerInterface; use cumulus_primitives_aura::AuraUnincludedSegmentApi; use cumulus_primitives_core::{ - FetchClaimQueueOffset, PersistedValidationData, DEFAULT_CLAIM_QUEUE_OFFSET, + GetCoreSelectorApi, PersistedValidationData, DEFAULT_CLAIM_QUEUE_OFFSET, }; use cumulus_relay_chain_interface::RelayChainInterface; use polkadot_primitives::{ + vstaging::{ClaimQueueOffset, CoreSelector}, BlockId, CoreIndex, Hash as RelayHash, Header as RelayHeader, Id as ParaId, OccupiedCoreAssumption, }; @@ -36,13 +37,13 @@ use sc_consensus::BlockImport; use sp_api::{ApiExt, ProvideRuntimeApi}; use sp_application_crypto::AppPublic; use sp_blockchain::HeaderBackend; -use sp_consensus_aura::{AuraApi, Slot, SlotDuration}; +use sp_consensus_aura::{AuraApi, Slot}; use sp_core::crypto::Pair; use sp_inherents::CreateInherentDataProviders; use sp_keystore::KeystorePtr; use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member}; use sp_timestamp::Timestamp; -use std::{sync::Arc, time::Duration}; +use std::{collections::BTreeSet, sync::Arc, time::Duration}; use super::CollatorMessage; use crate::{ @@ -89,8 +90,6 @@ pub struct BuilderTaskParams< pub authoring_duration: Duration, /// Channel to send built blocks to the collation task. pub collator_sender: sc_utils::mpsc::TracingUnboundedSender>, - /// Slot duration of the relay chain - pub relay_chain_slot_duration: Duration, /// Drift every slot by this duration. /// This is a time quantity that is subtracted from the actual timestamp when computing /// the time left to enter a new slot. In practice, this *left-shifts* the clock time with the @@ -104,7 +103,6 @@ pub struct BuilderTaskParams< struct SlotInfo { pub timestamp: Timestamp, pub slot: Slot, - pub slot_duration: SlotDuration, } #[derive(Debug)] @@ -155,11 +153,7 @@ where let time_until_next_slot = time_until_next_slot(slot_duration.as_duration(), self.drift); tokio::time::sleep(time_until_next_slot).await; let timestamp = sp_timestamp::Timestamp::current(); - Ok(SlotInfo { - slot: Slot::from_timestamp(timestamp, slot_duration), - timestamp, - slot_duration, - }) + Ok(SlotInfo { slot: Slot::from_timestamp(timestamp, slot_duration), timestamp }) } } @@ -179,7 +173,7 @@ where + Sync + 'static, Client::Api: - AuraApi + FetchClaimQueueOffset + AuraUnincludedSegmentApi, + AuraApi + GetCoreSelectorApi + AuraUnincludedSegmentApi, Backend: sc_client_api::Backend + 'static, RelayClient: RelayChainInterface + Clone + 'static, CIDP: CreateInherentDataProviders + 'static, @@ -207,7 +201,6 @@ where code_hash_provider, authoring_duration, para_backend, - relay_chain_slot_duration, slot_drift, } = params; @@ -235,12 +228,6 @@ where return; }; - let Some(expected_cores) = - expected_core_count(relay_chain_slot_duration, para_slot.slot_duration) - else { - return - }; - let Ok(relay_parent) = relay_client.best_block_hash().await else { tracing::warn!(target: crate::LOG_TARGET, "Unable to fetch latest relay chain block hash."); continue @@ -256,14 +243,25 @@ where let parent_header = parent.header; let parent_hash = parent.hash; - // Retrieve claim queue offset, if present. - let Ok(maybe_cq_offset) = fetch_claim_queue_offset(&*para_client, parent_hash).await - else { + // Retrieve the core selector. + let Ok(maybe_core_selector) = core_selector(&*para_client, parent_hash).await else { continue }; - - let Ok(RelayChainData { relay_parent_header, max_pov_size, scheduled_cores }) = - relay_chain_fetcher.get_relay_chain_data(relay_parent, maybe_cq_offset).await + // If the runtime API does not support the core selector API, fallback to some default + // values. + let (core_selector, claim_queue_offset) = maybe_core_selector.unwrap_or(( + CoreSelector(*para_slot.slot as u8), + ClaimQueueOffset(DEFAULT_CLAIM_QUEUE_OFFSET), + )); + + let Ok(RelayChainData { + relay_parent_header, + max_pov_size, + scheduled_cores, + claimed_cores, + }) = relay_chain_fetcher + .get_mut_relay_chain_data(relay_parent, claim_queue_offset) + .await else { continue; }; @@ -280,17 +278,26 @@ where ); } - let core_index_in_scheduled: u64 = *para_slot.slot % expected_cores; - let Some(core_index) = scheduled_cores.get(core_index_in_scheduled as usize) else { + let core_selector = core_selector.0 as usize % scheduled_cores.len(); + let Some(core_index) = scheduled_cores.get(core_selector) else { tracing::debug!( target: LOG_TARGET, - core_index_in_scheduled, + core_selector, core_len = scheduled_cores.len(), "Para is not scheduled on enough cores" ); continue; }; + if !claimed_cores.insert(*core_index) { + tracing::debug!( + target: LOG_TARGET, + "Core {:?} was already claimed at this relay chain slot", + core_index + ); + continue + } + // 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); @@ -336,7 +343,7 @@ where parent_head: parent_header.encode().into(), relay_parent_number: *relay_parent_header.number(), relay_parent_storage_root: *relay_parent_header.state_root(), - max_pov_size, + max_pov_size: *max_pov_size, }; let (parachain_inherent_data, other_inherent_data) = match collator @@ -415,32 +422,17 @@ where } } -/// Calculate the expected core count based on the slot duration of the relay and parachain. -/// -/// If `slot_duration` is smaller than `relay_chain_slot_duration` that means that we produce more -/// than one parachain block per relay chain block. In order to get these backed, we need multiple -/// cores. This method calculates how many cores we should expect to have scheduled under the -/// assumption that we have a fixed number of cores assigned to our parachain. -fn expected_core_count( - relay_chain_slot_duration: Duration, - slot_duration: SlotDuration, -) -> Option { - let slot_duration_millis = slot_duration.as_millis(); - u64::try_from(relay_chain_slot_duration.as_millis()) - .map_err(|e| tracing::error!("Unable to calculate expected parachain core count: {e}")) - .map(|relay_slot_duration| (relay_slot_duration / slot_duration_millis).max(1)) - .ok() -} - /// Contains relay chain data necessary for parachain block building. #[derive(Clone)] struct RelayChainData { /// Current relay chain parent header. pub relay_parent_header: RelayHeader, - /// The cores this para is scheduled on in the context of the relay parent. + /// The cores on which the para is scheduled at the configured claim queue offset. pub scheduled_cores: Vec, /// Maximum configured PoV size on the relay chain. pub max_pov_size: u32, + /// The claimed cores at a relay parent. + pub claimed_cores: BTreeSet, } /// Simple helper to fetch relay chain data and cache it based on the current relay chain best block @@ -462,22 +454,21 @@ where /// Fetch required [`RelayChainData`] from the relay chain. /// If this data has been fetched in the past for the incoming hash, it will reuse /// cached data. - pub async fn get_relay_chain_data( - &mut self, + pub async fn get_mut_relay_chain_data<'a>( + &'a mut self, relay_parent: RelayHash, - maybe_claim_queue_offset: Option, - ) -> Result { + claim_queue_offset: ClaimQueueOffset, + ) -> Result<&'a mut RelayChainData, ()> { match &self.last_data { - Some((last_seen_hash, data)) if *last_seen_hash == relay_parent => { + Some((last_seen_hash, _)) if *last_seen_hash == relay_parent => { tracing::trace!(target: crate::LOG_TARGET, %relay_parent, "Using cached data for relay parent."); - Ok(data.clone()) + Ok(&mut self.last_data.as_mut().expect("last_data is Some").1) }, _ => { tracing::trace!(target: crate::LOG_TARGET, %relay_parent, "Relay chain best block changed, fetching new data from relay chain."); - let data = - self.update_for_relay_parent(relay_parent, maybe_claim_queue_offset).await?; - self.last_data = Some((relay_parent, data.clone())); - Ok(data) + let data = self.update_for_relay_parent(relay_parent, claim_queue_offset).await?; + self.last_data = Some((relay_parent, data)); + Ok(&mut self.last_data.as_mut().expect("last_data was just set above").1) }, } } @@ -486,13 +477,13 @@ where async fn update_for_relay_parent( &self, relay_parent: RelayHash, - maybe_claim_queue_offset: Option, + claim_queue_offset: ClaimQueueOffset, ) -> Result { let scheduled_cores = cores_scheduled_for_para( relay_parent, self.para_id, &self.relay_client, - maybe_claim_queue_offset.unwrap_or(DEFAULT_CLAIM_QUEUE_OFFSET), + claim_queue_offset, ) .await; @@ -516,22 +507,27 @@ where }, }; - Ok(RelayChainData { relay_parent_header, scheduled_cores, max_pov_size }) + Ok(RelayChainData { + relay_parent_header, + scheduled_cores, + max_pov_size, + claimed_cores: BTreeSet::new(), + }) } } -async fn fetch_claim_queue_offset( +async fn core_selector( para_client: &Client, block_hash: Block::Hash, -) -> Result, sp_api::ApiError> +) -> Result, sp_api::ApiError> where Client: ProvideRuntimeApi + Send + Sync, - Client::Api: FetchClaimQueueOffset, + Client::Api: GetCoreSelectorApi, { let runtime_api = para_client.runtime_api(); - if runtime_api.has_api::>(block_hash)? { - Ok(Some(runtime_api.fetch_claim_queue_offset(block_hash)?)) + if runtime_api.has_api::>(block_hash)? { + Ok(Some(runtime_api.core_selector(block_hash)?)) } else { Ok(None) } diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs b/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs index 2ce3915a3b0e2..7453d3c89d08c 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs @@ -34,7 +34,7 @@ use cumulus_client_collator::service::ServiceInterface as CollatorServiceInterfa use cumulus_client_consensus_common::{self as consensus_common, ParachainBlockImportMarker}; use cumulus_client_consensus_proposer::ProposerInterface; use cumulus_primitives_aura::AuraUnincludedSegmentApi; -use cumulus_primitives_core::FetchClaimQueueOffset; +use cumulus_primitives_core::GetCoreSelectorApi; use cumulus_relay_chain_interface::RelayChainInterface; use polkadot_primitives::{ CollatorPair, CoreIndex, Hash as RelayHash, Id as ParaId, ValidationCodeHash, @@ -82,8 +82,6 @@ pub struct Params { pub collator_key: CollatorPair, /// The para's ID. pub para_id: ParaId, - /// The length of slots in the relay chain. - pub relay_chain_slot_duration: Duration, /// The underlying block proposer this should call into. pub proposer: Proposer, /// The generic collator service used to plug into this consensus engine. @@ -113,7 +111,7 @@ where + Sync + 'static, Client::Api: - AuraApi + FetchClaimQueueOffset + AuraUnincludedSegmentApi, + AuraApi + GetCoreSelectorApi + AuraUnincludedSegmentApi, Backend: sc_client_api::Backend + 'static, RClient: RelayChainInterface + Clone + 'static, CIDP: CreateInherentDataProviders + 'static, @@ -151,7 +149,6 @@ where collator_service: params.collator_service, authoring_duration: params.authoring_duration, collator_sender: tx, - relay_chain_slot_duration: params.relay_chain_slot_duration, slot_drift: params.slot_drift, }; diff --git a/cumulus/pallets/parachain-system/src/benchmarking.rs b/cumulus/pallets/parachain-system/src/benchmarking.rs index a0cd0224fa47a..9d51ec083b704 100644 --- a/cumulus/pallets/parachain-system/src/benchmarking.rs +++ b/cumulus/pallets/parachain-system/src/benchmarking.rs @@ -61,12 +61,6 @@ mod benchmarks { head } - #[benchmark] - fn set_claim_queue_offset() { - #[extrinsic_call] - Pallet::::set_claim_queue_offset(RawOrigin::Root, 2); - } - impl_benchmark_test_suite! { Pallet, crate::mock::new_test_ext(), diff --git a/cumulus/pallets/parachain-system/src/lib.rs b/cumulus/pallets/parachain-system/src/lib.rs index 9fb2d32f034a1..e25baa9e76bab 100644 --- a/cumulus/pallets/parachain-system/src/lib.rs +++ b/cumulus/pallets/parachain-system/src/lib.rs @@ -31,10 +31,14 @@ extern crate alloc; use alloc::{collections::btree_map::BTreeMap, vec, vec::Vec}; use codec::{Decode, Encode}; -use core::cmp; +use core::{cmp, marker::PhantomData}; use cumulus_primitives_core::{ - relay_chain, AbridgedHostConfiguration, ChannelInfo, ChannelStatus, CollationInfo, - GetChannelInfo, InboundDownwardMessage, InboundHrmpMessage, ListChannelInfos, MessageSendError, + relay_chain::{ + self, + vstaging::{ClaimQueueOffset, CoreSelector}, + }, + AbridgedHostConfiguration, ChannelInfo, ChannelStatus, CollationInfo, GetChannelInfo, + InboundDownwardMessage, InboundHrmpMessage, ListChannelInfos, MessageSendError, OutboundHrmpMessage, ParaId, PersistedValidationData, UpwardMessage, UpwardMessageSender, XcmpMessageHandler, XcmpMessageSource, DEFAULT_CLAIM_QUEUE_OFFSET, }; @@ -51,8 +55,9 @@ use frame_system::{ensure_none, ensure_root, pallet_prelude::HeaderFor}; use polkadot_parachain_primitives::primitives::RelayChainBlockNumber; use polkadot_runtime_parachains::FeeTracker; use scale_info::TypeInfo; +use sp_core::U256; use sp_runtime::{ - traits::{Block as BlockT, BlockNumberProvider, Hash}, + traits::{Block as BlockT, BlockNumberProvider, Hash, One}, BoundedSlice, FixedU128, RuntimeDebug, Saturating, }; use xcm::{latest::XcmHash, VersionedLocation, VersionedXcm}; @@ -186,6 +191,25 @@ pub mod ump_constants { pub const MESSAGE_SIZE_FEE_BASE: FixedU128 = FixedU128::from_rational(1, 1000); // 0.001 } +/// Trait for selecting the next core to build the candidate for. +pub trait SelectCore { + fn select_core_for_child() -> (CoreSelector, ClaimQueueOffset); +} + +/// The default core selection policy. +pub struct DefaultCoreSelector(PhantomData); + +impl SelectCore for DefaultCoreSelector { + fn select_core_for_child() -> (CoreSelector, ClaimQueueOffset) { + let core_selector: U256 = (frame_system::Pallet::::block_number() + One::one()).into(); + + ( + CoreSelector((core_selector.low_u32() & 255) as u8), + ClaimQueueOffset(DEFAULT_CLAIM_QUEUE_OFFSET), + ) + } +} + #[frame_support::pallet] pub mod pallet { use super::*; @@ -246,6 +270,9 @@ pub mod pallet { /// that collators aren't expected to have node versions that supply the included block /// in the relay-chain state proof. type ConsensusHook: ConsensusHook; + + /// Select core. + type SelectCore: SelectCore; } #[pallet::hooks] @@ -652,15 +679,6 @@ pub mod pallet { // WARNING: call indices 2 and 3 were used in a former version of this pallet. Using them // again will require to bump the transaction version of runtimes using this pallet. - - /// Set the claim queue offset. - #[pallet::call_index(4)] - #[pallet::weight((T::WeightInfo::set_claim_queue_offset(), DispatchClass::Operational))] - pub fn set_claim_queue_offset(origin: OriginFor, value: u8) -> DispatchResult { - ensure_root(origin)?; - ClaimQueueOffset::::set(Some(value)); - Ok(()) - } } #[pallet::event] @@ -876,12 +894,6 @@ pub mod pallet { #[pallet::storage] pub type CustomValidationHeadData = StorageValue<_, Vec, OptionQuery>; - /// The claim queue offset. - /// This value is expected to be mostly a constant. It's used by collators to determine when to - /// build a collation. - #[pallet::storage] - pub type ClaimQueueOffset = StorageValue<_, u8>; - #[pallet::inherent] impl ProvideInherent for Pallet { type Call = Call; @@ -1387,9 +1399,9 @@ impl Pallet { } } - /// Returns the claim queue offset. - pub fn fetch_claim_queue_offset() -> u8 { - ClaimQueueOffset::::get().unwrap_or(DEFAULT_CLAIM_QUEUE_OFFSET) + /// Returns the core selector. + pub fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + T::SelectCore::select_core_for_child() } /// Set a custom head data that should be returned as result of `validate_block`. diff --git a/cumulus/pallets/parachain-system/src/weights.rs b/cumulus/pallets/parachain-system/src/weights.rs index 8f15044697844..5c61879b4d36b 100644 --- a/cumulus/pallets/parachain-system/src/weights.rs +++ b/cumulus/pallets/parachain-system/src/weights.rs @@ -55,7 +55,6 @@ use core::marker::PhantomData; /// Weight functions needed for cumulus_pallet_parachain_system. pub trait WeightInfo { fn enqueue_inbound_downward_messages(n: u32, ) -> Weight; - fn set_claim_queue_offset() -> Weight; } /// Weights for cumulus_pallet_parachain_system using the Substrate node and recommended hardware. @@ -85,9 +84,6 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } - fn set_claim_queue_offset() -> Weight { - Weight::from_parts(1, 1) - } } // For backwards compatibility and tests @@ -116,7 +112,4 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } - fn set_claim_queue_offset() -> Weight { - Weight::from_parts(1, 1) - } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 86116cd33c77c..16fb0e7c33337 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -38,7 +38,7 @@ use assets_common::{ AssetIdForTrustBackedAssetsConvert, }; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use cumulus_primitives_core::AggregateMessageOrigin; +use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector}; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_genesis_builder::PresetId; @@ -667,6 +667,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< @@ -1384,9 +1385,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs index d255589838c84..fc63a0814d0a4 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs @@ -77,8 +77,4 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) } - - fn set_claim_queue_offset() -> Weight { - Weight::from_parts(1, 1) - } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 115e6803f933d..70463a5755efa 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -36,7 +36,7 @@ use assets_common::{ }; use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; +use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, @@ -663,6 +663,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< @@ -1478,9 +1479,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs index e70f81033cd1f..da644b2abefef 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs @@ -72,15 +72,4 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().writes(4)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) } - /// Storage: `ParachainSystem::ClaimQueueOffset` (r:0 w:1) - /// Proof: `ParachainSystem::ClaimQueueOffset` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - fn set_claim_queue_offset() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_430_000 picoseconds. - Weight::from_parts(2_613_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 162b8838f3216..1010449ee9ac7 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -55,7 +55,7 @@ use sp_runtime::{ use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use cumulus_primitives_core::ParaId; +use cumulus_primitives_core::{ClaimQueueOffset, CoreSelector, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, @@ -372,6 +372,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< @@ -876,9 +877,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs index d59acfc7cbdd3..8fcd7b10d931b 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/cumulus_pallet_parachain_system.rs @@ -77,8 +77,4 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) } - - fn set_claim_queue_offset() -> Weight { - Weight::from_parts(1, 1) - } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 31578bc9dfdaa..5a3ac6ef603be 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -40,7 +40,7 @@ use bridge_runtime_common::extensions::{ CheckAndBoostBridgeGrandpaTransactions, CheckAndBoostBridgeParachainsTransactions, }; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use cumulus_primitives_core::ParaId; +use cumulus_primitives_core::{ClaimQueueOffset, CoreSelector, ParaId}; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ @@ -347,6 +347,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< @@ -807,9 +808,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/cumulus_pallet_parachain_system.rs index d59acfc7cbdd3..8fcd7b10d931b 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/cumulus_pallet_parachain_system.rs @@ -77,8 +77,4 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) } - - fn set_claim_queue_offset() -> Weight { - Weight::from_parts(1, 1) - } } diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index e30cc6c649491..372f0d7b0ddb5 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -66,7 +66,7 @@ use sp_version::NativeVersion; use sp_version::RuntimeVersion; use codec::{Decode, Encode, MaxEncodedLen}; -use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; +use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, @@ -397,6 +397,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< @@ -1007,9 +1008,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/cumulus_pallet_parachain_system.rs index 1eb1e17c6a18c..92c8c88b51547 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/cumulus_pallet_parachain_system.rs @@ -77,8 +77,4 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) } - - fn set_claim_queue_offset() -> Weight { - Weight::from_parts(1, 1) - } } diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index ee4f79ac3df5a..5f03b6ab7e2cb 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -33,7 +33,7 @@ extern crate alloc; use alloc::{vec, vec::Vec}; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use cumulus_primitives_core::AggregateMessageOrigin; +use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector}; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ @@ -293,6 +293,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< @@ -653,9 +654,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index a5378e099057e..be332f67c9e6f 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -38,7 +38,7 @@ extern crate alloc; use alloc::{vec, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; +use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, @@ -284,6 +284,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< @@ -861,9 +862,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/cumulus_pallet_parachain_system.rs index 7e6b6863648af..139e37c544898 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/cumulus_pallet_parachain_system.rs @@ -74,8 +74,4 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().writes(4)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) } - - fn set_claim_queue_offset() -> Weight { - Weight::from_parts(1, 1) - } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 89de5116af054..cc43c95f005cb 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -38,7 +38,7 @@ extern crate alloc; use alloc::{vec, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; +use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, @@ -284,6 +284,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< @@ -852,9 +853,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/cumulus_pallet_parachain_system.rs index 8f7e5427740b2..1c9119361985c 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/cumulus_pallet_parachain_system.rs @@ -74,8 +74,4 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().writes(4)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) } - - fn set_claim_queue_offset() -> Weight { - Weight::from_parts(1, 1) - } } diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs index 4e4a7215a14b0..1b213785cf90e 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs @@ -64,7 +64,7 @@ use sp_runtime::{ use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use cumulus_primitives_core::AggregateMessageOrigin; +use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector}; pub use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, @@ -172,8 +172,8 @@ parameter_types! { type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< Runtime, RELAY_CHAIN_SLOT_DURATION_MILLIS, - BLOCK_PROCESSING_VELOCITY, - UNINCLUDED_SEGMENT_CAPACITY, + 3, + 9, >; impl cumulus_pallet_parachain_system::Config for Runtime { @@ -188,6 +188,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; type WeightInfo = weights::cumulus_pallet_parachain_system::WeightInfo; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } parameter_types! { @@ -234,7 +235,7 @@ impl pallet_aura::Config for Runtime { type DisabledValidators = (); type MaxAuthorities = ConstU32<100_000>; type AllowMultipleBlocksPerSlot = ConstBool; - type SlotDuration = ConstU64; + type SlotDuration = ConstU64<2000>; } impl pallet_glutton::Config for Runtime { @@ -425,9 +426,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/weights/cumulus_pallet_parachain_system.rs index e1fea4c3efff5..bc8299ab1bd67 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/weights/cumulus_pallet_parachain_system.rs @@ -72,8 +72,4 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().writes(4)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) } - - fn set_claim_queue_offset() -> Weight { - Weight::from_parts(1, 1) - } } diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index b14be15dc8808..150152964b90e 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -27,7 +27,7 @@ extern crate alloc; use alloc::{vec, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; +use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, @@ -259,6 +259,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; type WeightInfo = weights::cumulus_pallet_parachain_system::WeightInfo; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< @@ -804,9 +805,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/people/people-rococo/src/weights/cumulus_pallet_parachain_system.rs index c51377dd9ed55..5715d56c21868 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/weights/cumulus_pallet_parachain_system.rs @@ -50,8 +50,4 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) } - - fn set_claim_queue_offset() -> Weight { - Weight::from_parts(1, 1) - } } diff --git a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs index 399f31d75e163..60b861678c5ac 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs @@ -27,7 +27,7 @@ extern crate alloc; use alloc::{vec, vec::Vec}; use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; +use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, @@ -259,6 +259,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; type WeightInfo = weights::cumulus_pallet_parachain_system::WeightInfo; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< @@ -804,9 +805,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } diff --git a/cumulus/parachains/runtimes/people/people-westend/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/people/people-westend/src/weights/cumulus_pallet_parachain_system.rs index c51377dd9ed55..5715d56c21868 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/weights/cumulus_pallet_parachain_system.rs @@ -50,8 +50,4 @@ impl cumulus_pallet_parachain_system::WeightInfo for We .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) } - - fn set_claim_queue_offset() -> Weight { - Weight::from_parts(1, 1) - } } diff --git a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs index 47cdb5cbce3bb..bffedd5bdf576 100644 --- a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs @@ -31,6 +31,7 @@ extern crate alloc; use alloc::{vec, vec::Vec}; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; +use cumulus_primitives_core::{ClaimQueueOffset, CoreSelector}; use sp_api::impl_runtime_apis; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; @@ -204,6 +205,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { BLOCK_PROCESSING_VELOCITY, UNINCLUDED_SEGMENT_CAPACITY, >; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } impl parachain_info::Config for Runtime {} @@ -371,9 +373,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } diff --git a/cumulus/parachains/runtimes/starters/shell/src/lib.rs b/cumulus/parachains/runtimes/starters/shell/src/lib.rs index d2c503a881a4b..a7c8bc2393589 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/lib.rs @@ -36,7 +36,7 @@ extern crate alloc; use alloc::{vec, vec::Vec}; use codec::{Decode, Encode}; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; -use cumulus_primitives_core::AggregateMessageOrigin; +use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector}; use frame_support::unsigned::TransactionValidityError; use scale_info::TypeInfo; use sp_api::impl_runtime_apis; @@ -206,6 +206,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { BLOCK_PROCESSING_VELOCITY, UNINCLUDED_SEGMENT_CAPACITY, >; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } impl parachain_info::Config for Runtime {} @@ -429,9 +430,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 5aae1465cc707..a98c7b4886fdb 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -41,7 +41,7 @@ use assets_common::{ }; use codec::Encode; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; -use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; +use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId}; use frame_support::{ construct_runtime, derive_impl, dispatch::DispatchClass, @@ -632,6 +632,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { BLOCK_PROCESSING_VELOCITY, UNINCLUDED_SEGMENT_CAPACITY, >; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } impl parachain_info::Config for Runtime {} @@ -960,9 +961,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 723e5fed8d1b8..4d39728df83cb 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -68,7 +68,7 @@ pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::BuildStorage; pub use sp_runtime::{Perbill, Permill}; -use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; +use cumulus_primitives_core::{AggregateMessageOrigin, ClaimQueueOffset, CoreSelector, ParaId}; use frame_support::traits::TransformOrigin; use parachains_common::{ impls::{AssetsFrom, NonZeroIssuance}, @@ -299,6 +299,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } impl parachain_info::Config for Runtime {} @@ -855,9 +856,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } } diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/mod.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/mod.rs index cfd8f7c2aa5dc..c6dce521e4aeb 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/mod.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/common/mod.rs @@ -26,7 +26,7 @@ pub mod runtime; pub mod spec; pub mod types; -use cumulus_primitives_core::{CollectCollationInfo, FetchClaimQueueOffset}; +use cumulus_primitives_core::{CollectCollationInfo, GetCoreSelectorApi}; use sc_client_db::DbHash; use sp_api::{ApiExt, CallApiAt, ConstructRuntimeApi, Metadata}; use sp_block_builder::BlockBuilder; @@ -66,7 +66,7 @@ pub trait NodeRuntimeApi: + BlockBuilder + TaggedTransactionQueue + CollectCollationInfo - + FetchClaimQueueOffset + + GetCoreSelectorApi + Sized { } @@ -77,7 +77,7 @@ impl NodeRuntimeApi for T where + SessionKeys + BlockBuilder + TaggedTransactionQueue - + FetchClaimQueueOffset + + GetCoreSelectorApi + CollectCollationInfo { } diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/utils.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/utils.rs index 89de9c426119d..0b1ed5d82889e 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/utils.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/fake_runtime_api/utils.rs @@ -15,6 +15,7 @@ // along with Cumulus. If not, see . pub(crate) mod imports { + pub use cumulus_primitives_core::{ClaimQueueOffset, CoreSelector}; pub use parachains_common::{AccountId, Balance, Nonce}; pub use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; pub use sp_runtime::{ @@ -156,8 +157,8 @@ macro_rules! impl_node_runtime_apis { } } - impl cumulus_primitives_core::FetchClaimQueueOffset<$block> for $runtime { - fn fetch_claim_queue_offset() -> u8 { + impl cumulus_primitives_core::GetCoreSelectorApi<$block> for $runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { unimplemented!() } } diff --git a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/service.rs b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/service.rs index 303ec1e3b298b..b1c714784f4cd 100644 --- a/cumulus/polkadot-parachain/polkadot-parachain-lib/src/service.rs +++ b/cumulus/polkadot-parachain/polkadot-parachain-lib/src/service.rs @@ -392,7 +392,7 @@ where relay_chain_interface: Arc, transaction_pool: Arc>>, keystore: KeystorePtr, - relay_chain_slot_duration: Duration, + _relay_chain_slot_duration: Duration, para_id: ParaId, collator_key: CollatorPair, _overseer_handle: OverseerHandle, @@ -429,7 +429,6 @@ where keystore, collator_key, para_id, - relay_chain_slot_duration, proposer, collator_service, authoring_duration: Duration::from_millis(2000), diff --git a/cumulus/primitives/core/src/lib.rs b/cumulus/primitives/core/src/lib.rs index eb3122de38c0e..ac1f86998ecb3 100644 --- a/cumulus/primitives/core/src/lib.rs +++ b/cumulus/primitives/core/src/lib.rs @@ -32,6 +32,7 @@ pub use polkadot_parachain_primitives::primitives::{ XcmpMessageHandler, }; pub use polkadot_primitives::{ + vstaging::{ClaimQueueOffset, CoreSelector}, AbridgedHostConfiguration, AbridgedHrmpChannel, PersistedValidationData, }; @@ -400,9 +401,9 @@ sp_api::decl_runtime_apis! { fn collect_collation_info(header: &Block::Header) -> CollationInfo; } - /// Runtime api to fetch the claim queue offset. - pub trait FetchClaimQueueOffset { - /// Fetch the claim queue offset. - fn fetch_claim_queue_offset() -> u8; + /// Runtime api used to select the core for which the next block will be built. + pub trait GetCoreSelectorApi { + /// Retrieve core selector and claim queue offset for the next block. + fn core_selector() -> (CoreSelector, ClaimQueueOffset); } } diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index 77c16e0dcc49f..861d55c77cdc0 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -42,6 +42,7 @@ use sp_api::{decl_runtime_apis, impl_runtime_apis}; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{ConstBool, ConstU32, ConstU64, OpaqueMetadata}; +use cumulus_primitives_core::{ClaimQueueOffset, CoreSelector}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, Verify}, @@ -311,6 +312,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } impl parachain_info::Config for Runtime {} @@ -528,9 +530,9 @@ impl_runtime_apis! { } } - impl cumulus_primitives_core::FetchClaimQueueOffset for Runtime { - fn fetch_claim_queue_offset() -> u8 { - ParachainSystem::fetch_claim_queue_offset() + impl cumulus_primitives_core::GetCoreSelectorApi for Runtime { + fn core_selector() -> (CoreSelector, ClaimQueueOffset) { + ParachainSystem::core_selector() } } From 6ab29d92aa34c86db0ffc970d63bda300069a574 Mon Sep 17 00:00:00 2001 From: alindima Date: Mon, 16 Sep 2024 16:02:59 +0300 Subject: [PATCH 19/26] fix compilation --- cumulus/pallets/xcmp-queue/src/mock.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cumulus/pallets/xcmp-queue/src/mock.rs b/cumulus/pallets/xcmp-queue/src/mock.rs index 348939de1f146..470e00fe94e19 100644 --- a/cumulus/pallets/xcmp-queue/src/mock.rs +++ b/cumulus/pallets/xcmp-queue/src/mock.rs @@ -108,6 +108,7 @@ impl cumulus_pallet_parachain_system::Config for Test { type ReservedXcmpWeight = (); type CheckAssociatedRelayNumber = AnyRelayNumber; type ConsensusHook = cumulus_pallet_parachain_system::consensus_hook::ExpectParentIncluded; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } parameter_types! { From e8c7e9686089cd6308dfa719ac635e1722cf0e2c Mon Sep 17 00:00:00 2001 From: alindima Date: Mon, 16 Sep 2024 17:43:41 +0300 Subject: [PATCH 20/26] fix compilation again --- docs/sdk/src/polkadot_sdk/cumulus.rs | 1 + templates/parachain/runtime/src/configs/mod.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/sdk/src/polkadot_sdk/cumulus.rs b/docs/sdk/src/polkadot_sdk/cumulus.rs index 9bd957c7c1c07..c6abf9f7b4d17 100644 --- a/docs/sdk/src/polkadot_sdk/cumulus.rs +++ b/docs/sdk/src/polkadot_sdk/cumulus.rs @@ -96,6 +96,7 @@ mod tests { >; type WeightInfo = (); type DmpQueue = frame::traits::EnqueueWithOrigin<(), sp_core::ConstU8<0>>; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } impl parachain_info::Config for Runtime {} diff --git a/templates/parachain/runtime/src/configs/mod.rs b/templates/parachain/runtime/src/configs/mod.rs index 607797e690ba1..456187337121b 100644 --- a/templates/parachain/runtime/src/configs/mod.rs +++ b/templates/parachain/runtime/src/configs/mod.rs @@ -198,6 +198,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type ConsensusHook = ConsensusHook; + type SelectCore = cumulus_pallet_parachain_system::DefaultCoreSelector; } impl parachain_info::Config for Runtime {} From a2c4d9bdafd46167aa2375981aa6b5c4f9333e88 Mon Sep 17 00:00:00 2001 From: alindima Date: Tue, 17 Sep 2024 09:42:50 +0300 Subject: [PATCH 21/26] fix compilation take 3 --- cumulus/test/service/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cumulus/test/service/src/lib.rs b/cumulus/test/service/src/lib.rs index a600dcce3d66e..7e563f77b0ee2 100644 --- a/cumulus/test/service/src/lib.rs +++ b/cumulus/test/service/src/lib.rs @@ -486,7 +486,6 @@ where keystore, collator_key, para_id, - relay_chain_slot_duration, proposer, collator_service, authoring_duration: Duration::from_millis(2000), From 67b17faf1646f87b5a7d01cfa9d9d7428c46cb7b Mon Sep 17 00:00:00 2001 From: alindima Date: Tue, 17 Sep 2024 10:03:26 +0300 Subject: [PATCH 22/26] rollback weight generation --- .../cumulus_pallet_parachain_system.rs | 103 +++++++++--------- 1 file changed, 54 insertions(+), 49 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs index da644b2abefef..ef1a6a41cef9a 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_parachain_system.rs @@ -1,46 +1,50 @@ // Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Cumulus. +// SPDX-License-Identifier: Apache-2.0 -// Cumulus is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Cumulus is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Cumulus. If not, see . +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. //! Autogenerated weights for `cumulus_pallet_parachain_system` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-08-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-03-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-k1zul77x-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("asset-hub-westend-dev")`, DB CACHE: 1024 +//! HOSTNAME: `i9`, CPU: `13th Gen Intel(R) Core(TM) i9-13900K` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("statemine-dev"), DB CACHE: 1024 // Executed Command: -// target/production/polkadot-parachain +// ./target/release/polkadot-parachain // benchmark // pallet -// --steps=50 -// --repeat=20 -// --extrinsic=* -// --wasm-execution=compiled -// --heap-pages=4096 -// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json -// --pallet=cumulus_pallet_parachain_system -// --chain=asset-hub-westend-dev -// --header=./cumulus/file_header.txt -// --output=./cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/ +// --chain +// statemine-dev +// --pallet +// cumulus_pallet_parachain_system +// --extrinsic +// * +// --execution +// wasm +// --wasm-execution +// compiled +// --output +// parachains/runtimes/assets/statemine/src/weights +// --steps +// 50 +// --repeat +// 20 #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(missing_docs)] use frame_support::{traits::Get, weights::Weight}; use core::marker::PhantomData; @@ -48,28 +52,29 @@ use core::marker::PhantomData; /// Weight functions for `cumulus_pallet_parachain_system`. pub struct WeightInfo(PhantomData); impl cumulus_pallet_parachain_system::WeightInfo for WeightInfo { - /// Storage: `ParachainSystem::LastDmqMqcHead` (r:1 w:1) - /// Proof: `ParachainSystem::LastDmqMqcHead` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `MessageQueue::BookStateFor` (r:1 w:1) - /// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) - /// Storage: `MessageQueue::ServiceHead` (r:1 w:1) - /// Proof: `MessageQueue::ServiceHead` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`) - /// Storage: `ParachainSystem::ProcessedDownwardMessages` (r:0 w:1) - /// Proof: `ParachainSystem::ProcessedDownwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `MessageQueue::Pages` (r:0 w:1000) - /// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(105521), added: 107996, mode: `MaxEncodedLen`) + /// Storage: ParachainSystem LastDmqMqcHead (r:1 w:1) + /// Proof Skipped: ParachainSystem LastDmqMqcHead (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: ParachainSystem ReservedDmpWeightOverride (r:1 w:0) + /// Proof Skipped: ParachainSystem ReservedDmpWeightOverride (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: MessageQueue BookStateFor (r:1 w:1) + /// Proof: MessageQueue BookStateFor (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + /// Storage: MessageQueue ServiceHead (r:1 w:1) + /// Proof: MessageQueue ServiceHead (max_values: Some(1), max_size: Some(5), added: 500, mode: MaxEncodedLen) + /// Storage: ParachainSystem ProcessedDownwardMessages (r:0 w:1) + /// Proof Skipped: ParachainSystem ProcessedDownwardMessages (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: MessageQueue Pages (r:0 w:16) + /// Proof: MessageQueue Pages (max_values: None, max_size: Some(65585), added: 68060, mode: MaxEncodedLen) /// The range of component `n` is `[0, 1000]`. fn enqueue_inbound_downward_messages(n: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `84` - // Estimated: `3517` - // Minimum execution time: 2_842_000 picoseconds. - Weight::from_parts(2_990_000, 0) - .saturating_add(Weight::from_parts(0, 3517)) - // Standard Error: 54_039 - .saturating_add(Weight::from_parts(315_605_099, 0).saturating_mul(n.into())) - .saturating_add(T::DbWeight::get().reads(3)) + // Measured: `12` + // Estimated: `8013` + // Minimum execution time: 1_622_000 picoseconds. + Weight::from_parts(1_709_000, 0) + .saturating_add(Weight::from_parts(0, 8013)) + // Standard Error: 22_138 + .saturating_add(Weight::from_parts(23_923_169, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(4)) - .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(n.into()))) } -} +} \ No newline at end of file From b568cf43e61eb17dbe33087eb154fc007d5a8a05 Mon Sep 17 00:00:00 2001 From: alindima Date: Tue, 17 Sep 2024 10:40:50 +0300 Subject: [PATCH 23/26] fix compilation take 4 --- cumulus/pallets/parachain-system/src/mock.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cumulus/pallets/parachain-system/src/mock.rs b/cumulus/pallets/parachain-system/src/mock.rs index 247de3a29b69a..1f5e4f4dbcf3c 100644 --- a/cumulus/pallets/parachain-system/src/mock.rs +++ b/cumulus/pallets/parachain-system/src/mock.rs @@ -94,6 +94,7 @@ impl Config for Test { type CheckAssociatedRelayNumber = AnyRelayNumber; type ConsensusHook = TestConsensusHook; type WeightInfo = (); + type SelectCore = DefaultCoreSelector; } std::thread_local! { From 010f7b9ec0a1238f3684ced726a8bece39a7af5c Mon Sep 17 00:00:00 2001 From: alindima Date: Tue, 17 Sep 2024 10:51:44 +0300 Subject: [PATCH 24/26] remove unused --- cumulus/pallets/parachain-system/src/benchmarking.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cumulus/pallets/parachain-system/src/benchmarking.rs b/cumulus/pallets/parachain-system/src/benchmarking.rs index 9d51ec083b704..5cde8eb5b7885 100644 --- a/cumulus/pallets/parachain-system/src/benchmarking.rs +++ b/cumulus/pallets/parachain-system/src/benchmarking.rs @@ -22,7 +22,6 @@ use super::*; use cumulus_primitives_core::relay_chain::Hash as RelayHash; use frame_benchmarking::v2::*; -use frame_system::RawOrigin; use sp_runtime::traits::BlakeTwo256; #[benchmarks] From b6d1fb14ce83c0d6b129126496ffc8f997caeaff Mon Sep 17 00:00:00 2001 From: alindima Date: Fri, 20 Sep 2024 11:59:45 +0300 Subject: [PATCH 25/26] feedback and prdoc --- .../consensus/aura/src/collators/mod.rs | 2 +- .../slot_based/block_builder_task.rs | 55 ++++++++++--------- cumulus/pallets/parachain-system/src/lib.rs | 5 +- prdoc/pr_5372.prdoc | 38 ++++++------- 4 files changed, 51 insertions(+), 49 deletions(-) diff --git a/cumulus/client/consensus/aura/src/collators/mod.rs b/cumulus/client/consensus/aura/src/collators/mod.rs index bcbdb5c585466..89070607fbaba 100644 --- a/cumulus/client/consensus/aura/src/collators/mod.rs +++ b/cumulus/client/consensus/aura/src/collators/mod.rs @@ -128,7 +128,7 @@ async fn async_backing_params( } // Return all the cores assigned to the para at the provided relay parent, using the claim queue -// offset. This assumes the relay chain runtime supports the claimqueue runtime API. +// offset. // Will return an empty vec if the provided offset is higher than the claim queue length (which // corresponds to the scheduling_lookahead on the relay chain). async fn cores_scheduled_for_para( diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs index 1c24b60eca657..e75b52aeebd34 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs @@ -38,10 +38,10 @@ use sp_api::{ApiExt, ProvideRuntimeApi}; use sp_application_crypto::AppPublic; use sp_blockchain::HeaderBackend; use sp_consensus_aura::{AuraApi, Slot}; -use sp_core::crypto::Pair; +use sp_core::{crypto::Pair, U256}; use sp_inherents::CreateInherentDataProviders; use sp_keystore::KeystorePtr; -use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member}; +use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member, One}; use sp_timestamp::Timestamp; use std::{collections::BTreeSet, sync::Arc, time::Duration}; @@ -240,19 +240,21 @@ where continue }; - let parent_header = parent.header; let parent_hash = parent.hash; // Retrieve the core selector. - let Ok(maybe_core_selector) = core_selector(&*para_client, parent_hash).await else { - continue - }; - // If the runtime API does not support the core selector API, fallback to some default - // values. - let (core_selector, claim_queue_offset) = maybe_core_selector.unwrap_or(( - CoreSelector(*para_slot.slot as u8), - ClaimQueueOffset(DEFAULT_CLAIM_QUEUE_OFFSET), - )); + let (core_selector, claim_queue_offset) = + match core_selector(&*para_client, &parent).await { + Ok(core_selector) => core_selector, + Err(err) => { + tracing::trace!( + target: crate::LOG_TARGET, + "Unable to retrieve the core selector from the runtime API: {}", + err + ); + continue + }, + }; let Ok(RelayChainData { relay_parent_header, @@ -280,12 +282,8 @@ where let core_selector = core_selector.0 as usize % scheduled_cores.len(); let Some(core_index) = scheduled_cores.get(core_selector) else { - tracing::debug!( - target: LOG_TARGET, - core_selector, - core_len = scheduled_cores.len(), - "Para is not scheduled on enough cores" - ); + // This cannot really happen, as we modulo the core selector with the + // scheduled_cores length and we check that the scheduled_cores is not empty. continue; }; @@ -298,6 +296,8 @@ where continue } + let parent_header = parent.header; + // 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); @@ -454,11 +454,11 @@ where /// Fetch required [`RelayChainData`] from the relay chain. /// If this data has been fetched in the past for the incoming hash, it will reuse /// cached data. - pub async fn get_mut_relay_chain_data<'a>( - &'a mut self, + pub async fn get_mut_relay_chain_data( + &mut self, relay_parent: RelayHash, claim_queue_offset: ClaimQueueOffset, - ) -> Result<&'a mut RelayChainData, ()> { + ) -> Result<&mut RelayChainData, ()> { match &self.last_data { Some((last_seen_hash, _)) if *last_seen_hash == relay_parent => { tracing::trace!(target: crate::LOG_TARGET, %relay_parent, "Using cached data for relay parent."); @@ -518,17 +518,22 @@ where async fn core_selector( para_client: &Client, - block_hash: Block::Hash, -) -> Result, sp_api::ApiError> + parent: &consensus_common::PotentialParent, +) -> Result<(CoreSelector, ClaimQueueOffset), sp_api::ApiError> where Client: ProvideRuntimeApi + Send + Sync, Client::Api: GetCoreSelectorApi, { + let block_hash = parent.hash; let runtime_api = para_client.runtime_api(); if runtime_api.has_api::>(block_hash)? { - Ok(Some(runtime_api.core_selector(block_hash)?)) + Ok(runtime_api.core_selector(block_hash)?) } else { - Ok(None) + let next_block_number: U256 = (*parent.header.number() + One::one()).into(); + + // If the runtime API does not support the core selector API, fallback to some default + // values. + Ok((CoreSelector(next_block_number.byte(0)), ClaimQueueOffset(DEFAULT_CLAIM_QUEUE_OFFSET))) } } diff --git a/cumulus/pallets/parachain-system/src/lib.rs b/cumulus/pallets/parachain-system/src/lib.rs index e25baa9e76bab..9dc41aa03d9b1 100644 --- a/cumulus/pallets/parachain-system/src/lib.rs +++ b/cumulus/pallets/parachain-system/src/lib.rs @@ -203,10 +203,7 @@ impl SelectCore for DefaultCoreSelector { fn select_core_for_child() -> (CoreSelector, ClaimQueueOffset) { let core_selector: U256 = (frame_system::Pallet::::block_number() + One::one()).into(); - ( - CoreSelector((core_selector.low_u32() & 255) as u8), - ClaimQueueOffset(DEFAULT_CLAIM_QUEUE_OFFSET), - ) + (CoreSelector(core_selector.byte(0)), ClaimQueueOffset(DEFAULT_CLAIM_QUEUE_OFFSET)) } } diff --git a/prdoc/pr_5372.prdoc b/prdoc/pr_5372.prdoc index 24ef08830e116..e5004619d49f3 100644 --- a/prdoc/pr_5372.prdoc +++ b/prdoc/pr_5372.prdoc @@ -1,16 +1,16 @@ -title: "elastic scaling: add claim queue offset to cumulus" +title: "elastic scaling: add core selector to cumulus" doc: - audience: [Node Dev, Runtime Dev] description: | - Add a claim queue offset storage item to the parachain-system pallet and a runtime API for querying it. - Also use the claim queue offset and the claim queue relay chain runtime API in the slot based collator (if available) + Adds a runtime API for querying the core selector of a parachain. + Also use the core selector API and the claim queue relay chain runtime API in the slot based collator (if available) to determine which cores to build on. Part of implementing https://github.com/polkadot-fellows/RFCs/pull/103. crates: - name: cumulus-client-consensus-aura - bump: minor + bump: major - name: cumulus-relay-chain-inprocess-interface bump: minor - name: cumulus-relay-chain-interface @@ -22,36 +22,36 @@ crates: - name: cumulus-pallet-parachain-system bump: minor - name: asset-hub-rococo-runtime - bump: minor + bump: patch - name: asset-hub-westend-runtime - bump: minor + bump: patch - name: bridge-hub-rococo-runtime - bump: minor + bump: patch - name: bridge-hub-westend-runtime - bump: minor + bump: patch - name: collectives-westend-runtime - bump: minor + bump: patch - name: contracts-rococo-runtime - bump: minor + bump: patch - name: coretime-rococo-runtime - bump: minor + bump: patch - name: coretime-westend-runtime - bump: minor + bump: patch - name: glutton-westend-runtime - bump: minor + bump: patch - name: people-rococo-runtime - bump: minor + bump: patch - name: people-westend-runtime bump: minor - name: seedling-runtime - bump: minor + bump: patch - name: shell-runtime - bump: minor + bump: patch - name: penpal-runtime - bump: minor + bump: patch - name: rococo-parachain-runtime - bump: minor - - name: polkadot-parachain-bin + bump: patch + - name: polkadot-parachain-lib bump: major - name: cumulus-primitives-core bump: minor From 46fcf45944fe15f9859d4201355a06844c03e09a Mon Sep 17 00:00:00 2001 From: alindima Date: Fri, 20 Sep 2024 14:02:58 +0300 Subject: [PATCH 26/26] update prdoc --- prdoc/pr_5372.prdoc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/prdoc/pr_5372.prdoc b/prdoc/pr_5372.prdoc index e5004619d49f3..fec856b3c0d6a 100644 --- a/prdoc/pr_5372.prdoc +++ b/prdoc/pr_5372.prdoc @@ -12,15 +12,17 @@ crates: - name: cumulus-client-consensus-aura bump: major - name: cumulus-relay-chain-inprocess-interface - bump: minor + bump: patch - name: cumulus-relay-chain-interface bump: major + validate: false - name: cumulus-relay-chain-minimal-node bump: none - name: cumulus-relay-chain-rpc-interface - bump: minor + bump: patch - name: cumulus-pallet-parachain-system - bump: minor + bump: major + validate: false - name: asset-hub-rococo-runtime bump: patch - name: asset-hub-westend-runtime @@ -42,7 +44,7 @@ crates: - name: people-rococo-runtime bump: patch - name: people-westend-runtime - bump: minor + bump: patch - name: seedling-runtime bump: patch - name: shell-runtime @@ -53,8 +55,10 @@ crates: bump: patch - name: polkadot-parachain-lib bump: major + validate: false - name: cumulus-primitives-core bump: minor + validate: false - name: cumulus-test-runtime bump: minor - name: cumulus-client-consensus-common @@ -63,3 +67,5 @@ crates: bump: none - name: cumulus-client-network bump: none + - name: cumulus-pallet-xcmp-queue + bump: none