From dce85d6b7bcfafdd3f07a357539170bf659cbcec Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Thu, 24 Jul 2025 10:08:55 -0300 Subject: [PATCH 1/3] add changes to runtime, node service --- Cargo.lock | 50 +++++++++++++++++-------- Cargo.toml | 1 + node/Cargo.toml | 1 + node/src/service.rs | 61 +++++++++++++++++++----------- runtime/amplitude/Cargo.toml | 5 ++- runtime/amplitude/src/lib.rs | 65 ++++++++++++++++---------------- runtime/foucoco/Cargo.toml | 5 ++- runtime/foucoco/src/lib.rs | 72 +++++++++++++++++------------------- runtime/pendulum/Cargo.toml | 5 ++- runtime/pendulum/src/lib.rs | 65 ++++++++++++++++---------------- 10 files changed, 183 insertions(+), 147 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 541de13ea..f76d9f32b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,7 +118,7 @@ checksum = "4436e0292ab1bb631b42973c61205e704475fe8126af845c8d923c0996328127" [[package]] name = "amplitude-runtime" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "bifrost-farming", "bifrost-farming-rpc-runtime-api", @@ -130,6 +130,7 @@ dependencies = [ "cumulus-pallet-session-benchmarking", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", + "cumulus-primitives-aura 0.1.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.6.0)", "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", @@ -1649,7 +1650,7 @@ dependencies = [ [[package]] name = "chain-extension-common" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "frame-support", "frame-system", @@ -2225,7 +2226,7 @@ dependencies = [ "cumulus-client-consensus-common", "cumulus-client-consensus-proposer", "cumulus-client-parachain-inherent", - "cumulus-primitives-aura", + "cumulus-primitives-aura 0.1.0 (git+https://github.com/pendulum-chain/polkadot-sdk?branch=release-polkadot-v1.6.0)", "cumulus-primitives-core", "cumulus-relay-chain-interface", "futures", @@ -2544,6 +2545,20 @@ dependencies = [ "staging-xcm-executor", ] +[[package]] +name = "cumulus-primitives-aura" +version = "0.1.0" +source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.6.0#e36ffb3da50afff65f8ec99378fbfe14f9d340e7" +dependencies = [ + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-primitives", + "sp-api 4.0.0-dev (git+https://github.com/pendulum-chain/polkadot-sdk?branch=release-polkadot-v1.6.0)", + "sp-consensus-aura", + "sp-runtime 24.0.0 (git+https://github.com/pendulum-chain/polkadot-sdk?branch=release-polkadot-v1.6.0)", + "sp-std 8.0.0 (git+https://github.com/pendulum-chain/polkadot-sdk?branch=release-polkadot-v1.6.0)", +] + [[package]] name = "cumulus-primitives-aura" version = "0.1.0" @@ -3810,7 +3825,7 @@ dependencies = [ [[package]] name = "foucoco-runtime" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "bifrost-farming", "bifrost-farming-rpc-runtime-api", @@ -3822,6 +3837,7 @@ dependencies = [ "cumulus-pallet-session-benchmarking", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", + "cumulus-primitives-aura 0.1.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.6.0)", "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", @@ -6596,7 +6612,7 @@ dependencies = [ [[package]] name = "module-pallet-staking-rpc" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "jsonrpsee", "module-oracle-rpc-runtime-api", @@ -6609,7 +6625,7 @@ dependencies = [ [[package]] name = "module-pallet-staking-rpc-runtime-api" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "frame-support", "module-oracle-rpc-runtime-api", @@ -7251,7 +7267,7 @@ dependencies = [ [[package]] name = "orml-currencies-allowance-extension" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "frame-benchmarking", "frame-support", @@ -7307,7 +7323,7 @@ dependencies = [ [[package]] name = "orml-tokens-management-extension" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "frame-benchmarking", "frame-support", @@ -8589,7 +8605,7 @@ dependencies = [ [[package]] name = "parachain-staking" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "frame-benchmarking", "frame-support", @@ -8813,7 +8829,7 @@ dependencies = [ [[package]] name = "pendulum-node" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "amplitude-runtime", "bifrost-farming-rpc", @@ -8827,6 +8843,7 @@ dependencies = [ "cumulus-client-network", "cumulus-client-parachain-inherent", "cumulus-client-service", + "cumulus-primitives-aura 0.1.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.6.0)", "cumulus-primitives-core", "cumulus-primitives-parachain-inherent", "cumulus-relay-chain-inprocess-interface", @@ -8899,7 +8916,7 @@ dependencies = [ [[package]] name = "pendulum-runtime" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "bifrost-farming", "bifrost-farming-rpc-runtime-api", @@ -8911,6 +8928,7 @@ dependencies = [ "cumulus-pallet-session-benchmarking", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", + "cumulus-primitives-aura 0.1.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.6.0)", "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", @@ -10410,7 +10428,7 @@ dependencies = [ [[package]] name = "price-chain-extension" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "chain-extension-common", "dia-oracle", @@ -11282,7 +11300,7 @@ dependencies = [ [[package]] name = "runtime-common" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -15451,7 +15469,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "token-chain-extension" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "chain-extension-common", "frame-support", @@ -15755,7 +15773,7 @@ dependencies = [ [[package]] name = "treasury-buyout-extension" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "frame-benchmarking", "frame-support", @@ -16097,7 +16115,7 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "vesting-manager" -version = "1.6.0-b" +version = "1.6.0-c" dependencies = [ "frame-benchmarking", "frame-support", diff --git a/Cargo.toml b/Cargo.toml index 415d31dc4..c6095102d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,6 +49,7 @@ cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/polkadot-sdk" cumulus-pallet-session-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.6.0" } cumulus-pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.6.0" } cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.6.0" } +cumulus-primitives-aura = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.6.0" } cumulus-primitives-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.6.0" } cumulus-primitives-utility = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.6.0" } cumulus-client-cli = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.6.0" } diff --git a/node/Cargo.toml b/node/Cargo.toml index 6b2dd6ad0..ae0c7d3ff 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -85,6 +85,7 @@ cumulus-client-collator = { workspace = true, default-features = true } cumulus-client-network = { workspace = true, default-features = true } cumulus-client-parachain-inherent = { workspace = true, default-features = true } cumulus-client-service = { workspace = true, default-features = true } +cumulus-primitives-aura = { workspace = true, default-features = true } cumulus-primitives-core = { workspace = true, default-features = true } cumulus-primitives-parachain-inherent = { workspace = true, default-features = true } cumulus-relay-chain-inprocess-interface = { workspace = true, default-features = true } diff --git a/node/src/service.rs b/node/src/service.rs index 8b3c5594f..4d889976d 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -9,9 +9,7 @@ use runtime_common::{opaque::Block, AccountId, Balance, Index as Nonce}; // Cumulus Imports use cumulus_client_collator::service::CollatorService; -use cumulus_client_consensus_aura::collators::basic::{ - self as basic_aura, Params as BasicAuraParams, -}; +use cumulus_client_consensus_aura::collators::lookahead::{self as aura, Params as AuraParams}; use cumulus_client_consensus_common::ParachainBlockImport as TParachainBlockImport; use cumulus_client_consensus_proposer::Proposer; use cumulus_client_network::RequireSecondedInBlockAnnounce; @@ -19,7 +17,10 @@ use cumulus_client_parachain_inherent::{MockValidationDataInherentDataProvider, use cumulus_client_service::{ prepare_node_config, start_relay_chain_tasks, DARecoveryProfile, StartRelayChainTasksParams, }; -use cumulus_primitives_core::{relay_chain::Hash, ParaId}; +use cumulus_primitives_core::{ + relay_chain::{CollatorPair, Hash, ValidationCode}, + ParaId, +}; use cumulus_relay_chain_inprocess_interface::build_inprocess_relay_chain; use cumulus_relay_chain_interface::{RelayChainInterface, RelayChainResult}; use cumulus_relay_chain_minimal_node::build_minimal_relay_chain_node_with_rpc; @@ -37,6 +38,7 @@ use sc_service::{ use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; use sp_api::ConstructRuntimeApi; use sp_consensus_aura::{sr25519::AuthorityId, AuraApi}; +use cumulus_primitives_aura::AuraUnincludedSegmentApi; use sp_keystore::KeystorePtr; use sp_runtime::traits::{BlakeTwo256, Block as BlockT}; use substrate_prometheus_endpoint::Registry; @@ -44,7 +46,7 @@ use substrate_prometheus_endpoint::Registry; use crate::rpc::{ create_full_amplitude, create_full_foucoco, create_full_pendulum, FullDeps, ResultRpcExtension, }; -use polkadot_service::{CollatorPair, Handle}; +use polkadot_service::Handle; use sc_consensus::{import_queue::ImportQueueService, ImportQueue}; use sc_transaction_pool_api::OffchainTransactionPoolFactory; @@ -91,6 +93,7 @@ pub trait ParachainRuntimeApiImpl: + pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi + substrate_frame_rpc_system::AccountNonceApi + AuraApi + + AuraUnincludedSegmentApi { } @@ -353,9 +356,9 @@ where keystore: params.keystore_container.keystore(), backend: backend.clone(), network: network.clone(), + sync_service: sync_service.clone(), system_rpc_tx, tx_handler_controller, - sync_service: sync_service.clone(), telemetry: telemetry.as_mut(), })?; @@ -376,7 +379,7 @@ where + Send + Sync + 'static, - RuntimeApi::RuntimeApi: ParachainRuntimeApiImpl, + RuntimeApi::RuntimeApi: ParachainRuntimeApiImpl + cumulus_primitives_aura::AuraUnincludedSegmentApi, sc_client_api::StateBackendFor, Block>: sc_client_api::StateBackend, { @@ -385,6 +388,7 @@ where let mut params = new_partial(&mut parachain_config, is_standalone)?; let client = params.client.clone(); + let backend = params.backend.clone(); //just clone the last element of the "other" tuple let telemetry_worker_handle_clone = params.other.2.clone(); @@ -468,6 +472,7 @@ where if validator { start_consensus( client.clone(), + backend.clone(), block_import, prometheus_registry.as_ref(), telemetry.as_ref().map(|t| t.handle()), @@ -628,6 +633,7 @@ where #[allow(clippy::too_many_arguments)] fn start_consensus( client: Arc>, + backend: Arc>, block_import: ParachainBlockImport, prometheus_registry: Option<&Registry>, telemetry: Option, @@ -647,12 +653,12 @@ where + Send + Sync + 'static, - RuntimeApi::RuntimeApi: ParachainRuntimeApiImpl, + RuntimeApi::RuntimeApi: ParachainRuntimeApiImpl + cumulus_primitives_aura::AuraUnincludedSegmentApi, sc_client_api::StateBackendFor, Block>: sc_client_api::StateBackend, { let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?; - + let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( task_manager.spawn_handle(), client.clone(), @@ -669,29 +675,40 @@ where client.clone(), ); - let params = BasicAuraParams { - proposer, + let params = AuraParams { create_inherent_data_providers: move |_, ()| async move { Ok(()) }, block_import, - collator_key, - collator_service, - para_client: client, + para_client: client.clone(), + para_backend: backend.clone(), relay_client: relay_chain_interface, + code_hash_provider: move |block_hash| { + client.code_at(block_hash).ok().map(|c| ValidationCode::from(c).hash()) + }, sync_oracle, keystore, slot_duration, - authoring_duration: Duration::from_millis(500), - relay_chain_slot_duration, + collator_key, para_id: id, overseer_handle, - collation_request_receiver: None, + relay_chain_slot_duration, + proposer, + collator_service, + authoring_duration: Duration::from_millis(1500), }; - let fut = - basic_aura::run::( - params, - ); - + let fut = aura::run::< + Block, + sp_consensus_aura::sr25519::AuthorityPair, + _, + _, + _, + _, + _, + _, + _, + _, + _, + >(params); task_manager.spawn_essential_handle().spawn("aura", None, fut); Ok(()) } diff --git a/runtime/amplitude/Cargo.toml b/runtime/amplitude/Cargo.toml index e98c16f98..9315bee5e 100644 --- a/runtime/amplitude/Cargo.toml +++ b/runtime/amplitude/Cargo.toml @@ -133,10 +133,11 @@ staging-xcm-executor = { workspace = true } # Cumulus cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-dmp-queue = { workspace = true } -cumulus-pallet-parachain-system = { workspace = true } +cumulus-pallet-parachain-system = { workspace = true, features = ["parameterized-consensus-hook"] } cumulus-pallet-session-benchmarking = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } +cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } cumulus-primitives-timestamp = { workspace = true } cumulus-primitives-utility = { workspace = true } @@ -160,10 +161,10 @@ std = [ "codec/std", "log/std", "scale-info/std", + "cumulus-primitives-aura/std", "cumulus-pallet-aura-ext/std", "cumulus-pallet-dmp-queue/std", "cumulus-pallet-parachain-system/std", - "cumulus-pallet-parachain-system/parameterized-consensus-hook", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-core/std", diff --git a/runtime/amplitude/src/lib.rs b/runtime/amplitude/src/lib.rs index 9814e1a37..099adeffc 100644 --- a/runtime/amplitude/src/lib.rs +++ b/runtime/amplitude/src/lib.rs @@ -70,7 +70,7 @@ use runtime_common::{ ProxyType, ReserveIdentifier, Signature, EXISTENTIAL_DEPOSIT, MILLIUNIT, NANOUNIT, UNIT, }; -use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; pub use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use dia_oracle::DiaOracle; @@ -250,6 +250,15 @@ pub const MILLISECS_PER_BLOCK: u64 = 12000; // Attempting to do so will brick block production. pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; +/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the +/// relay chain. +pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; +/// How many parachain blocks are processed by the relay chain per parent. Limits the number of +/// blocks authored per slot. +pub const BLOCK_PROCESSING_VELOCITY: u32 = 1; +/// Relay chain slot duration, in milliseconds. +pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; + // Time is measured by number of blocks. pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); pub const HOURS: BlockNumber = MINUTES * 60; @@ -518,19 +527,25 @@ parameter_types! { pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); } +type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< + Runtime, + RELAY_CHAIN_SLOT_DURATION_MILLIS, + BLOCK_PROCESSING_VELOCITY, + UNINCLUDED_SEGMENT_CAPACITY, +>; + impl cumulus_pallet_parachain_system::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnSystemEvent = (); type SelfParaId = parachain_info::Pallet; + type DmpQueue = frame_support::traits::EnqueueWithOrigin; type ReservedDmpWeight = ReservedDmpWeight; type OutboundXcmpMessageSource = XcmpQueue; type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; - type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; - #[cfg(feature = "std")] - type ConsensusHook = cumulus_pallet_parachain_system::consensus_hook::ExpectParentIncluded; - type DmpQueue = frame_support::traits::EnqueueWithOrigin; + type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type WeightInfo = (); + type ConsensusHook = ConsensusHook; } impl parachain_info::Config for Runtime {} @@ -590,7 +605,9 @@ impl pallet_aura::Config for Runtime { type AuthorityId = AuraId; type DisabledValidators = (); type MaxAuthorities = MaxAuthorities; - type AllowMultipleBlocksPerSlot = AllowMultipleBlocksPerSlot; + type AllowMultipleBlocksPerSlot = ConstBool; + #[cfg(feature = "experimental")] + type SlotDuration = ConstU64; } parameter_types! { @@ -1605,7 +1622,7 @@ mod benches { impl_runtime_apis! { impl sp_consensus_aura::AuraApi for Runtime { fn slot_duration() -> sp_consensus_aura::SlotDuration { - sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration()) + sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION) } fn authorities() -> Vec { @@ -1613,6 +1630,15 @@ impl_runtime_apis! { } } + impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime { + fn can_build_upon( + included_hash: ::Hash, + slot: cumulus_primitives_aura::Slot, + ) -> bool { + ConsensusHook::can_build_upon(included_hash, slot) + } + } + impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { VERSION @@ -2086,33 +2112,8 @@ impl_runtime_apis! { } -#[allow(dead_code)] -struct CheckInherents; - -#[allow(deprecated)] -impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { - fn check_inherents( - block: &Block, - relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof, - ) -> sp_inherents::CheckInherentsResult { - let relay_chain_slot = relay_state_proof - .read_slot() - .expect("Could not read the relay chain slot from the proof"); - - let inherent_data = - cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration( - relay_chain_slot, - sp_std::time::Duration::from_secs(6), - ) - .create_inherent_data() - .expect("Could not create the timestamp inherent data"); - - inherent_data.check_extrinsics(block) - } -} cumulus_pallet_parachain_system::register_validate_block! { Runtime = Runtime, BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, - CheckInherents = CheckInherents, } diff --git a/runtime/foucoco/Cargo.toml b/runtime/foucoco/Cargo.toml index 79f2c32f1..179731c5b 100644 --- a/runtime/foucoco/Cargo.toml +++ b/runtime/foucoco/Cargo.toml @@ -131,10 +131,11 @@ staging-xcm-executor = { workspace = true } # Cumulus cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-dmp-queue = { workspace = true } -cumulus-pallet-parachain-system = { workspace = true } +cumulus-pallet-parachain-system = { workspace = true, features = ["parameterized-consensus-hook"] } cumulus-pallet-session-benchmarking = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } +cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } cumulus-primitives-timestamp = { workspace = true } cumulus-primitives-utility = { workspace = true } @@ -160,9 +161,9 @@ std = [ "cumulus-pallet-aura-ext/std", "cumulus-pallet-dmp-queue/std", "cumulus-pallet-parachain-system/std", - "cumulus-pallet-parachain-system/parameterized-consensus-hook", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", + "cumulus-primitives-aura/std", "cumulus-primitives-core/std", "cumulus-primitives-timestamp/std", "cumulus-primitives-utility/std", diff --git a/runtime/foucoco/src/lib.rs b/runtime/foucoco/src/lib.rs index c4be8edd7..283ccffe6 100644 --- a/runtime/foucoco/src/lib.rs +++ b/runtime/foucoco/src/lib.rs @@ -75,7 +75,7 @@ use crate::xcm_config::XcmConfig; #[cfg(any(feature = "runtime-benchmarks"))] use oracle::testing_utils::MockDataFeeder; -use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; pub use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use dia_oracle::DiaOracle; @@ -251,6 +251,15 @@ pub const MILLISECS_PER_BLOCK: u64 = 12000; // Attempting to do so will brick block production. pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; +/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the +/// relay chain. +pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; +/// How many parachain blocks are processed by the relay chain per parent. Limits the number of +/// blocks authored per slot. +pub const BLOCK_PROCESSING_VELOCITY: u32 = 1; +/// Relay chain slot duration, in milliseconds. +pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; + // Time is measured by number of blocks. pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); pub const HOURS: BlockNumber = MINUTES * 60; @@ -499,6 +508,13 @@ parameter_types! { pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); } +type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< + Runtime, + RELAY_CHAIN_SLOT_DURATION_MILLIS, + BLOCK_PROCESSING_VELOCITY, + UNINCLUDED_SEGMENT_CAPACITY, +>; + impl cumulus_pallet_parachain_system::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnSystemEvent = (); @@ -508,10 +524,9 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type OutboundXcmpMessageSource = XcmpQueue; type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; - type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; + type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type WeightInfo = (); - #[cfg(feature = "std")] - type ConsensusHook = cumulus_pallet_parachain_system::consensus_hook::ExpectParentIncluded; + type ConsensusHook = ConsensusHook; } impl parachain_info::Config for Runtime {} @@ -562,17 +577,13 @@ impl pallet_session::Config for Runtime { type WeightInfo = pallet_session::weights::SubstrateWeight; } -parameter_types! { - // as per documentation, typical value for this is false "unless this pallet is being augmented by another pallet" - // https://github.com/paritytech/polkadot-sdk/blob/release-polkadot-v1.1.0/substrate/frame/aura/src/lib.rs#L111 - pub const AllowMultipleBlocksPerSlot: bool = false; -} - impl pallet_aura::Config for Runtime { type AuthorityId = AuraId; type DisabledValidators = (); type MaxAuthorities = MaxAuthorities; - type AllowMultipleBlocksPerSlot = AllowMultipleBlocksPerSlot; + type AllowMultipleBlocksPerSlot = ConstBool; + #[cfg(feature = "experimental")] + type SlotDuration = ConstU64; } parameter_types! { @@ -1485,6 +1496,8 @@ where type OverarchingCall = RuntimeCall; } +pub type RuntimeApiImpl = Runtime; + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime @@ -1611,7 +1624,7 @@ mod benches { impl_runtime_apis! { impl sp_consensus_aura::AuraApi for Runtime { fn slot_duration() -> sp_consensus_aura::SlotDuration { - sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration()) + sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION) } fn authorities() -> Vec { @@ -1619,6 +1632,15 @@ impl_runtime_apis! { } } + impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime { + fn can_build_upon( + included_hash: ::Hash, + slot: cumulus_primitives_aura::Slot, + ) -> bool { + ConsensusHook::can_build_upon(included_hash, slot) + } + } + impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { VERSION @@ -2108,33 +2130,7 @@ impl_runtime_apis! { } -#[allow(dead_code)] -struct CheckInherents; - -#[allow(deprecated)] -impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { - fn check_inherents( - block: &Block, - relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof, - ) -> sp_inherents::CheckInherentsResult { - let relay_chain_slot = relay_state_proof - .read_slot() - .expect("Could not read the relay chain slot from the proof"); - - let inherent_data = - cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration( - relay_chain_slot, - sp_std::time::Duration::from_secs(6), - ) - .create_inherent_data() - .expect("Could not create the timestamp inherent data"); - - inherent_data.check_extrinsics(block) - } -} - cumulus_pallet_parachain_system::register_validate_block! { Runtime = Runtime, BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, - CheckInherents = CheckInherents, } diff --git a/runtime/pendulum/Cargo.toml b/runtime/pendulum/Cargo.toml index 34c1c97ce..24f12c1f6 100644 --- a/runtime/pendulum/Cargo.toml +++ b/runtime/pendulum/Cargo.toml @@ -132,10 +132,11 @@ staging-xcm-executor = { workspace = true } # Cumulus cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-dmp-queue = { workspace = true } -cumulus-pallet-parachain-system = { workspace = true } +cumulus-pallet-parachain-system = { workspace = true, features = ["parameterized-consensus-hook"] } cumulus-pallet-session-benchmarking = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } +cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } cumulus-primitives-timestamp = { workspace = true } cumulus-primitives-utility = { workspace = true } @@ -159,10 +160,10 @@ std = [ "log/std", "scale-info/std", "serde", + "cumulus-primitives-aura/std", "cumulus-pallet-aura-ext/std", "cumulus-pallet-dmp-queue/std", "cumulus-pallet-parachain-system/std", - "cumulus-pallet-parachain-system/parameterized-consensus-hook", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-core/std", diff --git a/runtime/pendulum/src/lib.rs b/runtime/pendulum/src/lib.rs index 52b1cf747..87edd7fde 100644 --- a/runtime/pendulum/src/lib.rs +++ b/runtime/pendulum/src/lib.rs @@ -81,7 +81,7 @@ use runtime_common::{ ProxyType, ReserveIdentifier, Signature, EXISTENTIAL_DEPOSIT, MILLIUNIT, NANOUNIT, UNIT, }; -use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; pub use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; pub use dia_oracle::dia::AssetId; @@ -253,6 +253,15 @@ pub const MILLISECS_PER_BLOCK: u64 = 12000; // Attempting to do so will brick block production. pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; +/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the +/// relay chain. +pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; +/// How many parachain blocks are processed by the relay chain per parent. Limits the number of +/// blocks authored per slot. +pub const BLOCK_PROCESSING_VELOCITY: u32 = 1; +/// Relay chain slot duration, in milliseconds. +pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; + // Time is measured by number of blocks. pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); pub const HOURS: BlockNumber = MINUTES * 60; @@ -520,6 +529,13 @@ parameter_types! { pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); } +type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< + Runtime, + RELAY_CHAIN_SLOT_DURATION_MILLIS, + BLOCK_PROCESSING_VELOCITY, + UNINCLUDED_SEGMENT_CAPACITY, +>; + impl cumulus_pallet_parachain_system::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OnSystemEvent = (); @@ -529,10 +545,9 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type OutboundXcmpMessageSource = XcmpQueue; type XcmpMessageHandler = XcmpQueue; type ReservedXcmpWeight = ReservedXcmpWeight; - type CheckAssociatedRelayNumber = RelayNumberStrictlyIncreases; + type CheckAssociatedRelayNumber = RelayNumberMonotonicallyIncreases; type WeightInfo = (); - #[cfg(feature = "std")] - type ConsensusHook = cumulus_pallet_parachain_system::consensus_hook::ExpectParentIncluded; + type ConsensusHook = ConsensusHook; } impl parachain_info::Config for Runtime {} @@ -593,9 +608,10 @@ impl pallet_aura::Config for Runtime { type AuthorityId = AuraId; type DisabledValidators = (); type MaxAuthorities = MaxAuthorities; - type AllowMultipleBlocksPerSlot = AllowMultipleBlocksPerSlot; + type AllowMultipleBlocksPerSlot = ConstBool; + #[cfg(feature = "experimental")] + type SlotDuration = ConstU64; } - parameter_types! { pub const LaunchPeriod: BlockNumber = 5 * DAYS; pub const VotingPeriod: BlockNumber = 5 * DAYS; @@ -1609,7 +1625,7 @@ mod benches { impl_runtime_apis! { impl sp_consensus_aura::AuraApi for Runtime { fn slot_duration() -> sp_consensus_aura::SlotDuration { - sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration()) + sp_consensus_aura::SlotDuration::from_millis(SLOT_DURATION) } fn authorities() -> Vec { @@ -1617,6 +1633,15 @@ impl_runtime_apis! { } } + impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime { + fn can_build_upon( + included_hash: ::Hash, + slot: cumulus_primitives_aura::Slot, + ) -> bool { + ConsensusHook::can_build_upon(included_hash, slot) + } + } + impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { VERSION @@ -2089,33 +2114,7 @@ impl_runtime_apis! { } -#[allow(dead_code)] -struct CheckInherents; - -#[allow(deprecated)] -impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { - fn check_inherents( - block: &Block, - relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof, - ) -> sp_inherents::CheckInherentsResult { - let relay_chain_slot = relay_state_proof - .read_slot() - .expect("Could not read the relay chain slot from the proof"); - - let inherent_data = - cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration( - relay_chain_slot, - sp_std::time::Duration::from_secs(6), - ) - .create_inherent_data() - .expect("Could not create the timestamp inherent data"); - - inherent_data.check_extrinsics(block) - } -} - cumulus_pallet_parachain_system::register_validate_block! { Runtime = Runtime, BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, - CheckInherents = CheckInherents, } From d3ce968b21d718e470639245973bc25efd707cd3 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Thu, 24 Jul 2025 10:41:02 -0300 Subject: [PATCH 2/3] remove unnecessary type --- runtime/foucoco/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/foucoco/src/lib.rs b/runtime/foucoco/src/lib.rs index 283ccffe6..4540c6bb9 100644 --- a/runtime/foucoco/src/lib.rs +++ b/runtime/foucoco/src/lib.rs @@ -1496,7 +1496,6 @@ where type OverarchingCall = RuntimeCall; } -pub type RuntimeApiImpl = Runtime; // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( From 61748f611cade9239e46bd63425fb8f657ebe014 Mon Sep 17 00:00:00 2001 From: Marcel Ebert Date: Thu, 24 Jul 2025 17:18:35 +0200 Subject: [PATCH 3/3] Add cumulus-primitives-aura dependency to Cargo.toml and update Cargo.lock --- Cargo.lock | 24 +++++------------------- Cargo.toml | 1 + 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f76d9f32b..d2da083a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -130,7 +130,7 @@ dependencies = [ "cumulus-pallet-session-benchmarking", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", - "cumulus-primitives-aura 0.1.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.6.0)", + "cumulus-primitives-aura", "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", @@ -2226,7 +2226,7 @@ dependencies = [ "cumulus-client-consensus-common", "cumulus-client-consensus-proposer", "cumulus-client-parachain-inherent", - "cumulus-primitives-aura 0.1.0 (git+https://github.com/pendulum-chain/polkadot-sdk?branch=release-polkadot-v1.6.0)", + "cumulus-primitives-aura", "cumulus-primitives-core", "cumulus-relay-chain-interface", "futures", @@ -2545,20 +2545,6 @@ dependencies = [ "staging-xcm-executor", ] -[[package]] -name = "cumulus-primitives-aura" -version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.6.0#e36ffb3da50afff65f8ec99378fbfe14f9d340e7" -dependencies = [ - "parity-scale-codec", - "polkadot-core-primitives", - "polkadot-primitives", - "sp-api 4.0.0-dev (git+https://github.com/pendulum-chain/polkadot-sdk?branch=release-polkadot-v1.6.0)", - "sp-consensus-aura", - "sp-runtime 24.0.0 (git+https://github.com/pendulum-chain/polkadot-sdk?branch=release-polkadot-v1.6.0)", - "sp-std 8.0.0 (git+https://github.com/pendulum-chain/polkadot-sdk?branch=release-polkadot-v1.6.0)", -] - [[package]] name = "cumulus-primitives-aura" version = "0.1.0" @@ -3837,7 +3823,7 @@ dependencies = [ "cumulus-pallet-session-benchmarking", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", - "cumulus-primitives-aura 0.1.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.6.0)", + "cumulus-primitives-aura", "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", @@ -8843,7 +8829,7 @@ dependencies = [ "cumulus-client-network", "cumulus-client-parachain-inherent", "cumulus-client-service", - "cumulus-primitives-aura 0.1.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.6.0)", + "cumulus-primitives-aura", "cumulus-primitives-core", "cumulus-primitives-parachain-inherent", "cumulus-relay-chain-inprocess-interface", @@ -8928,7 +8914,7 @@ dependencies = [ "cumulus-pallet-session-benchmarking", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", - "cumulus-primitives-aura 0.1.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.6.0)", + "cumulus-primitives-aura", "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", diff --git a/Cargo.toml b/Cargo.toml index c6095102d..ec71f9631 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -253,6 +253,7 @@ cumulus-pallet-dmp-queue = { git = "https://github.com/pendulum-chain/polkadot- cumulus-pallet-session-benchmarking = { git = "https://github.com/pendulum-chain/polkadot-sdk", branch = "release-polkadot-v1.6.0" } cumulus-pallet-xcm = { git = "https://github.com/pendulum-chain/polkadot-sdk", branch = "release-polkadot-v1.6.0" } cumulus-pallet-xcmp-queue = { git = "https://github.com/pendulum-chain/polkadot-sdk", branch = "release-polkadot-v1.6.0" } +cumulus-primitives-aura = { git = "https://github.com/pendulum-chain/polkadot-sdk", branch = "release-polkadot-v1.6.0" } cumulus-primitives-timestamp = { git = "https://github.com/pendulum-chain/polkadot-sdk", branch = "release-polkadot-v1.6.0" } cumulus-primitives-utility = { git = "https://github.com/pendulum-chain/polkadot-sdk", branch = "release-polkadot-v1.6.0" } cumulus-client-cli = { git = "https://github.com/pendulum-chain/polkadot-sdk", branch = "release-polkadot-v1.6.0" }