From f542af4d41ce5beeb1946e2d43b328f5a8e4903b Mon Sep 17 00:00:00 2001 From: brenzi Date: Tue, 1 Oct 2024 17:37:13 +0200 Subject: [PATCH] [encointer] set target blocktime to 6s (#462) Encointer communities could benefit from 6s block time because the network is used for IRL point-of-sale or person-to-person transactions Encointer is unaffected by https://github.com/paritytech/polkadot-sdk/issues/3268 as its pallets have since ever based time on block timestamps The parameters are copy-paste from people, as introduced by #308 --------- Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> --- CHANGELOG.md | 1 + system-parachains/encointer/src/lib.rs | 53 ++++++++++++++++++++------ 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51a512f01b..38e51447b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Allow signed origins to send arbitrary XCMs from some system chains ([polkadot-fellows/runtimes#407](https://github.com/polkadot-fellows/runtimes/pull/407)) - Include the Core and Salary pallets into the Fellowship proxy ([polkadot-fellows/runtimes#454](https://github.com/polkadot-fellows/runtimes/pull/454)) - Add new community democracy and treasuries pallets to Encointer ([polkadot-fellows/runtimes#456](https://github.com/polkadot-fellows/runtimes/pull/456)) +- Change target block time for Encointer to 6s ([polkadot-fellows/runtimes#462](https://github.com/polkadot-fellows/runtimes/pull/462)) ### Fixed diff --git a/system-parachains/encointer/src/lib.rs b/system-parachains/encointer/src/lib.rs index bf7308ed37..8d50624f33 100644 --- a/system-parachains/encointer/src/lib.rs +++ b/system-parachains/encointer/src/lib.rs @@ -62,7 +62,9 @@ use frame_support::{ ConstBool, ConstU128, ConstU64, Contains, EitherOfDiverse, EqualPrivilegeOnly, InstanceFilter, TransformOrigin, }, - weights::{ConstantMultiplier, Weight, WeightToFee as _}, + weights::{ + constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFee as _, + }, PalletId, }; use frame_system::{ @@ -98,11 +100,7 @@ use sp_std::prelude::*; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use system_parachains_constants::{ - kusama::{consensus::*, currency::*, fee::WeightToFee}, - AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, - SLOT_DURATION, -}; +use system_parachains_constants::kusama::{consensus::*, currency::*, fee::WeightToFee}; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; use xcm::{ latest::prelude::{AssetId as XcmAssetId, BodyId}, @@ -292,15 +290,11 @@ impl frame_system::Config for Runtime { type PostTransactions = (); } -parameter_types! { - pub const MinimumPeriod: u64 = SLOT_DURATION / 2; -} - impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = Moment; type OnTimestampSet = EncointerScheduler; - type MinimumPeriod = MinimumPeriod; + type MinimumPeriod = ConstU64<0>; type WeightInfo = weights::pallet_timestamp::WeightInfo; } @@ -572,7 +566,7 @@ impl pallet_aura::Config for Runtime { type AuthorityId = AuraId; type DisabledValidators = (); type MaxAuthorities = MaxAuthorities; - type AllowMultipleBlocksPerSlot = ConstBool; + type AllowMultipleBlocksPerSlot = ConstBool; type SlotDuration = ConstU64; } @@ -752,6 +746,41 @@ construct_runtime! { } } +/// This determines the average expected block time that we are targeting. Blocks will be +/// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by +/// `pallet_timestamp`, which is in turn picked up by `pallet_aura` to implement `fn +/// slot_duration()`. +/// +/// Change this to adjust the block time. +pub const MILLISECS_PER_BLOCK: u64 = 6_000; +pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; + +// Time is measured by number of blocks. +pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); +pub const HOURS: BlockNumber = MINUTES * 60; +pub const DAYS: BlockNumber = HOURS * 24; + +/// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is +/// used to limit the maximal weight of a single extrinsic. +pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5); +/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by +/// `Operational` extrinsics. +pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); + +/// We allow for 2 seconds of compute with a 6 second average block time. +pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( + WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2), + polkadot_primitives::MAX_POV_SIZE as u64, +); + +/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included +/// into the relay chain. +pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 2; + +/// 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; + /// The address format for describing accounts. pub type Address = sp_runtime::MultiAddress; /// Block type as expected by this runtime.