diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index 945014c606..6ed625d191 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -396,6 +396,8 @@ pub fn run() -> Result<()> { } } #[cfg(feature = "try-runtime")] + // embedded try-runtime cli will be removed soon. + #[allow(deprecated)] Some(Subcommand::TryRuntime(cmd)) => { use std::{future::Future, pin::Pin}; diff --git a/pallets/inflation/src/lib.rs b/pallets/inflation/src/lib.rs index 6b9bf3a3e4..2ecbd88dff 100644 --- a/pallets/inflation/src/lib.rs +++ b/pallets/inflation/src/lib.rs @@ -71,7 +71,9 @@ pub mod pallet { type TreasuryAccountId: Get; // The block number provider, which should be callable from `on_initialize` hook. - type OnInitializeBlockNumberProvider: BlockNumberProvider>; + type OnInitializeBlockNumberProvider: BlockNumberProvider< + BlockNumber = BlockNumberFor, + >; /// Number of blocks that pass between treasury balance updates due to inflation #[pallet::constant] 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/pallets/mod.rs b/runtime/common/config/pallets/mod.rs index 5df782afdb..0da0638340 100644 --- a/runtime/common/config/pallets/mod.rs +++ b/runtime/common/config/pallets/mod.rs @@ -21,7 +21,7 @@ use frame_support::{ traits::{ConstU32, ConstU64, Currency}, }; use sp_arithmetic::Perbill; -use sp_runtime::traits::{BlockNumberProvider, AccountIdConversion}; +use sp_runtime::traits::{AccountIdConversion, BlockNumberProvider}; use up_common::{ constants::*, types::{AccountId, Balance, BlockNumber}, @@ -111,8 +111,8 @@ impl BlockNumberProvider for OnInitializeBlockNumberProvider { type BlockNumber = BlockNumber; fn current_block_number() -> Self::BlockNumber { - use parity_scale_codec::Decode; use hex_literal::hex; + use parity_scale_codec::Decode; use sp_io::storage; // TODO: Replace with the following code after https://github.com/paritytech/polkadot-sdk/commit/3ea497b5a0fdda252f9c5a3c257cfaf8685f02fd lands // >::last_relay_block_number() @@ -122,7 +122,8 @@ impl BlockNumberProvider for OnInitializeBlockNumberProvider { // First parachain block return Default::default() }; - BlockNumber::decode(&mut encoded.as_ref()).expect("typeof(RelayBlockNumber) == typeof(BlockNumber) == u32; qed") + BlockNumber::decode(&mut encoded.as_ref()) + .expect("typeof(RelayBlockNumber) == typeof(BlockNumber) == u32; qed") } } diff --git a/runtime/common/config/parachain.rs b/runtime/common/config/parachain.rs index ad42e39958..d56da711ca 100644 --- a/runtime/common/config/parachain.rs +++ b/runtime/common/config/parachain.rs @@ -38,9 +38,29 @@ 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..f15a5c6ae6 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) } }