Skip to content

Commit

Permalink
[encointer] set target blocktime to 6s (#462)
Browse files Browse the repository at this point in the history
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
paritytech/polkadot-sdk#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 <[email protected]>
  • Loading branch information
brenzi and joepetrowski authored Oct 1, 2024
1 parent 646031d commit f542af4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:/polkadot-fellows/runtimes/pull/407))
- Include the Core and Salary pallets into the Fellowship proxy ([polkadot-fellows/runtimes#454](https:/polkadot-fellows/runtimes/pull/454))
- Add new community democracy and treasuries pallets to Encointer ([polkadot-fellows/runtimes#456](https:/polkadot-fellows/runtimes/pull/456))
- Change target block time for Encointer to 6s ([polkadot-fellows/runtimes#462](https:/polkadot-fellows/runtimes/pull/462))

### Fixed

Expand Down
53 changes: 41 additions & 12 deletions system-parachains/encointer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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<Runtime>;
}

Expand Down Expand Up @@ -572,7 +566,7 @@ impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
type DisabledValidators = ();
type MaxAuthorities = MaxAuthorities;
type AllowMultipleBlocksPerSlot = ConstBool<false>;
type AllowMultipleBlocksPerSlot = ConstBool<true>;
type SlotDuration = ConstU64<SLOT_DURATION>;
}

Expand Down Expand Up @@ -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<AccountId, ()>;
/// Block type as expected by this runtime.
Expand Down

0 comments on commit f542af4

Please sign in to comment.