Skip to content

Commit

Permalink
Fix babe epoch config. (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neopallium authored May 2, 2024
1 parent 7e95bc9 commit 5abb07a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
17 changes: 10 additions & 7 deletions runtime/common/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ pub const BENCHMARK_MAX_INCREASE: u32 = 0;
#[macro_export]
macro_rules! misc_pallet_impls {
() => {
/// The BABE epoch configuration at genesis.
pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration =
sp_consensus_babe::BabeEpochConfiguration {
c: PRIMARY_PROBABILITY,
allowed_slots: sp_consensus_babe::AllowedSlots::PrimaryAndSecondaryPlainSlots,
};

/// Native version.
#[cfg(any(feature = "std", test))]
pub fn native_version() -> NativeVersion {
Expand Down Expand Up @@ -718,18 +725,14 @@ macro_rules! runtime_apis {

impl sp_consensus_babe::BabeApi<Block> for Runtime {
fn configuration() -> sp_consensus_babe::BabeConfiguration {
// The choice of `c` parameter (where `1 - c` represents the
// probability of a slot being empty), is done in accordance to the
// slot duration and expected target block time, for safely
// resisting network delays of maximum two seconds.
// <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results>
let epoch_config = Babe::epoch_config().unwrap_or(BABE_GENESIS_EPOCH_CONFIG);
sp_consensus_babe::BabeConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
c: PRIMARY_PROBABILITY,
c: epoch_config.c,
authorities: Babe::authorities().to_vec(),
randomness: Babe::randomness(),
allowed_slots: sp_consensus_babe::AllowedSlots::PrimaryAndSecondaryPlainSlots,
allowed_slots: epoch_config.allowed_slots,
}
}

Expand Down
27 changes: 12 additions & 15 deletions src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ const DEV_TREASURY: u128 = 50_000_000 * ONE_POLY;

const INITIAL_BOND: u128 = 500 * ONE_POLY;

// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration =
sp_consensus_babe::BabeEpochConfiguration {
c: PRIMARY_PROBABILITY,
allowed_slots: sp_consensus_babe::AllowedSlots::PrimaryAndSecondaryPlainSlots,
};
const BABE_GENESIS: pallet_babe::GenesisConfig = pallet_babe::GenesisConfig {
authorities: vec![],
epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG),
};

/// Node `ChainSpec` extensions.
///
/// Additional parameters for some Substrate core modules,
Expand Down Expand Up @@ -626,7 +614,10 @@ pub mod develop {
pips: pips!(time::MINUTES, MaybeBlock::None, 25),
im_online: Default::default(),
authority_discovery: Default::default(),
babe: BABE_GENESIS,
babe: pallet_babe::GenesisConfig {
authorities: vec![],
epoch_config: Some(rt::runtime::BABE_GENESIS_EPOCH_CONFIG),
},
grandpa: Default::default(),
// Governance Council:
committee_membership: group_membership!(1),
Expand Down Expand Up @@ -773,7 +764,10 @@ pub mod production {
pips: pips!(time::DAYS * 30, MaybeBlock::Some(time::DAYS * 90), 1000),
im_online: Default::default(),
authority_discovery: Default::default(),
babe: BABE_GENESIS,
babe: pallet_babe::GenesisConfig {
authorities: vec![],
epoch_config: Some(rt::runtime::BABE_GENESIS_EPOCH_CONFIG),
},
grandpa: Default::default(),
// Governing council
committee_membership: group_membership!(1, 2, 3), // 3 GC members
Expand Down Expand Up @@ -957,7 +951,10 @@ pub mod develop {
pips: pips!(time::DAYS * 7, MaybeBlock::None, 1000),
im_online: Default::default(),
authority_discovery: Default::default(),
babe: BABE_GENESIS,
babe: pallet_babe::GenesisConfig {
authorities: vec![],
epoch_config: Some(rt::runtime::BABE_GENESIS_EPOCH_CONFIG),
},
grandpa: Default::default(),
// Governing council
committee_membership: group_membership!(1, 2, 3, 5),
Expand Down

0 comments on commit 5abb07a

Please sign in to comment.