Support variable session length for Rococo chains at genesis (#2167)

This pr adds support to change the session length of a Rococo chain at
genesis. This is rather useful because Rococo has a session length of
1 hour, while on rococo-local you will now get 1 minute. This improves
the dev experience, because a parachain is only going live at the
start of a new session.
This commit is contained in:
Bastian Köcher
2020-12-24 21:25:15 +01:00
committed by GitHub
parent 2557181ecf
commit bb856698a4
5 changed files with 44 additions and 9 deletions
+3 -1
View File
@@ -33,7 +33,9 @@ pub mod time {
use primitives::v0::{Moment, BlockNumber};
pub const MILLISECS_PER_BLOCK: Moment = 6000;
pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 1 * HOURS;
frame_support::parameter_types! {
pub storage EpochDurationInBlocks: BlockNumber = 1 * HOURS;
}
// These time units are defined in number of blocks.
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
+4 -5
View File
@@ -328,13 +328,13 @@ parameter_types! {
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 64;
// quarter of the last session will be for election.
pub const ElectionLookahead: BlockNumber = EPOCH_DURATION_IN_BLOCKS / 4;
pub ElectionLookahead: BlockNumber = EpochDurationInBlocks::get() / 4;
pub const MaxIterations: u32 = 10;
pub MinSolutionScoreBump: Perbill = Perbill::from_rational_approximation(5u32, 10_000);
}
parameter_types! {
pub const SessionDuration: BlockNumber = EPOCH_DURATION_IN_BLOCKS as _;
pub SessionDuration: BlockNumber = EpochDurationInBlocks::get() as _;
}
parameter_types! {
@@ -457,12 +457,11 @@ impl pallet_session::Config for Runtime {
}
parameter_types! {
pub const EpochDuration: u64 = EPOCH_DURATION_IN_BLOCKS as u64;
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
}
impl pallet_babe::Config for Runtime {
type EpochDuration = EpochDuration;
type EpochDuration = EpochDurationInBlocks;
type ExpectedBlockTime = ExpectedBlockTime;
// session module is the trigger
@@ -798,7 +797,7 @@ sp_api::impl_runtime_apis! {
// <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results>
babe_primitives::BabeGenesisConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
epoch_length: EpochDurationInBlocks::get().into(),
c: PRIMARY_PROBABILITY,
genesis_authorities: Babe::authorities(),
randomness: Babe::randomness(),