From 875945f2b947ad1afdc4fd3c622030c7d90a4850 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Mon, 16 Oct 2023 14:38:31 +0200 Subject: [PATCH] fix: enable throttling --- primitives/common/src/constants.rs | 3 +++ runtime/common/config/parachain.rs | 19 +++++++++++++++++++ runtime/common/runtime_apis.rs | 7 +++---- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/primitives/common/src/constants.rs b/primitives/common/src/constants.rs index ced66a2f6c..df7ae1db60 100644 --- a/primitives/common/src/constants.rs +++ b/primitives/common/src/constants.rs @@ -23,7 +23,10 @@ use sp_runtime::Perbill; use crate::types::{Balance, BlockNumber}; +#[cfg(not(feature = "lookahead"))] pub const MILLISECS_PER_BLOCK: u64 = 12000; +#[cfg(feature = "lookahead")] +pub const MILLISECS_PER_BLOCK: u64 = 3000; pub const MILLISECS_PER_RELAY_BLOCK: u64 = 6000; pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; diff --git a/runtime/common/config/parachain.rs b/runtime/common/config/parachain.rs index ad42e39958..4622b71f5a 100644 --- a/runtime/common/config/parachain.rs +++ b/runtime/common/config/parachain.rs @@ -38,9 +38,28 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ReservedDmpWeight = ReservedDmpWeight; type ReservedXcmpWeight = ReservedXcmpWeight; type XcmpMessageHandler = XcmpQueue; + #[cfg(not(feature = "lookahead"))] type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; + #[cfg(feature = "lookahead")] + type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; } impl parachain_info::Config for Runtime {} impl cumulus_pallet_aura_ext::Config for Runtime {} + +/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included +/// into the relay chain. +#[cfg(feature = "lookahead")] +const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3; +/// How many parachain blocks are processed by the relay chain per parent. Limits the +/// number of blocks authored per slot. +#[cfg(feature = "lookahead")] +const BLOCK_PROCESSING_VELOCITY: u32 = 2; +#[cfg(feature = "lookahead")] +pub type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< + Runtime, + {MILLISECS_PER_RELAY_BLOCK as u32}, + BLOCK_PROCESSING_VELOCITY, + UNINCLUDED_SEGMENT_CAPACITY, +>; diff --git a/runtime/common/runtime_apis.rs b/runtime/common/runtime_apis.rs index 3c42220c1e..c7b8276b05 100644 --- a/runtime/common/runtime_apis.rs +++ b/runtime/common/runtime_apis.rs @@ -682,11 +682,10 @@ macro_rules! impl_common_runtime_apis { #[cfg(feature = "lookahead")] impl cumulus_primitives_aura::AuraUnincludedSegmentApi for Runtime { fn can_build_upon( - _included_hash: ::Hash, - _slot: cumulus_primitives_aura::Slot, + included_hash: ::Hash, + slot: cumulus_primitives_aura::Slot, ) -> bool { - // FIXME: Limit velocity - true + crate::config::parachain::ConsensusHook::can_build_upon(included_hash, slot) } }