Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Companion - Read babe config parameters from runtime #5842

Merged
merged 6 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion node/core/runtime-api/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ sp_api::mock_impl_runtime_apis! {
}

impl BabeApi<Block> for MockRuntimeApi {
fn configuration(&self) -> sp_consensus_babe::BabeGenesisConfiguration {
fn configuration(&self) -> sp_consensus_babe::BabeConfiguration {
unimplemented!()
}

Expand Down
2 changes: 1 addition & 1 deletion node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ where
client.clone(),
);

let babe_config = babe::Config::get(&*client)?;
let babe_config = babe::configuration(&*client)?;
let (block_import, babe_link) =
babe::block_import(babe_config.clone(), beefy_block_import, client.clone())?;

Expand Down
4 changes: 2 additions & 2 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::sync::Arc;
use jsonrpsee::RpcModule;
use polkadot_primitives::v2::{AccountId, Balance, Block, BlockNumber, Hash, Nonce};
use sc_client_api::AuxStore;
use sc_consensus_babe::Epoch;
use sc_consensus_babe::{BabeConfiguration, Epoch};
use sc_finality_grandpa::FinalityProofProvider;
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
use sp_api::ProvideRuntimeApi;
Expand All @@ -40,7 +40,7 @@ pub type RpcExtension = RpcModule<()>;
/// Extra dependencies for BABE.
pub struct BabeDeps {
/// BABE protocol config.
pub babe_config: sc_consensus_babe::Config,
pub babe_config: BabeConfiguration,
/// BABE pending epoch changes.
pub shared_epoch_changes: sc_consensus_epochs::SharedEpochChanges<Block, Epoch>,
/// The keystore that manages the keys of the node.
Expand Down
3 changes: 3 additions & 0 deletions runtime/kusama/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub mod time {
pub const WEEKS: BlockNumber = DAYS * 7;

// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
// The choice of 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>
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
}

Expand Down
16 changes: 6 additions & 10 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1766,19 +1766,15 @@ sp_api::impl_runtime_apis! {
}

impl babe_primitives::BabeApi<Block> for Runtime {
fn configuration() -> babe_primitives::BabeGenesisConfiguration {
// 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>
babe_primitives::BabeGenesisConfiguration {
fn configuration() -> babe_primitives::BabeConfiguration {
let epoch_config = Babe::epoch_config().unwrap_or(BABE_GENESIS_EPOCH_CONFIG);
babe_primitives::BabeConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
c: BABE_GENESIS_EPOCH_CONFIG.c,
genesis_authorities: Babe::authorities().to_vec(),
c: epoch_config.c,
authorities: Babe::authorities().to_vec(),
randomness: Babe::randomness(),
allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots,
allowed_slots: epoch_config.allowed_slots,
}
}

Expand Down
3 changes: 3 additions & 0 deletions runtime/polkadot/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub mod time {
pub const WEEKS: BlockNumber = DAYS * 7;

// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
// The choice of 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>
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
}

Expand Down
16 changes: 6 additions & 10 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1895,19 +1895,15 @@ sp_api::impl_runtime_apis! {
}

impl babe_primitives::BabeApi<Block> for Runtime {
fn configuration() -> babe_primitives::BabeGenesisConfiguration {
// 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>
babe_primitives::BabeGenesisConfiguration {
fn configuration() -> babe_primitives::BabeConfiguration {
let epoch_config = Babe::epoch_config().unwrap_or(BABE_GENESIS_EPOCH_CONFIG);
babe_primitives::BabeConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
c: BABE_GENESIS_EPOCH_CONFIG.c,
genesis_authorities: Babe::authorities().to_vec(),
c: epoch_config.c,
authorities: Babe::authorities().to_vec(),
randomness: Babe::randomness(),
allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots,
allowed_slots: epoch_config.allowed_slots,
}
}

Expand Down
3 changes: 3 additions & 0 deletions runtime/rococo/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub mod time {
pub const DAYS: BlockNumber = HOURS * 24;

// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
// The choice of 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>
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
}

Expand Down
16 changes: 6 additions & 10 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,19 +1141,15 @@ sp_api::impl_runtime_apis! {
}

impl babe_primitives::BabeApi<Block> for Runtime {
fn configuration() -> babe_primitives::BabeGenesisConfiguration {
// 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>
babe_primitives::BabeGenesisConfiguration {
fn configuration() -> babe_primitives::BabeConfiguration {
let epoch_config = Babe::epoch_config().unwrap_or(BABE_GENESIS_EPOCH_CONFIG);
babe_primitives::BabeConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDurationInBlocks::get().into(),
c: BABE_GENESIS_EPOCH_CONFIG.c,
genesis_authorities: Babe::authorities().to_vec(),
c: epoch_config.c,
authorities: Babe::authorities().to_vec(),
randomness: Babe::randomness(),
allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots,
allowed_slots: epoch_config.allowed_slots,
}
}

Expand Down
3 changes: 3 additions & 0 deletions runtime/test-runtime/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ pub mod time {
pub const DAYS: BlockNumber = HOURS * 24;

// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
// The choice of 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>
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
}

Expand Down
16 changes: 6 additions & 10 deletions runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,19 +992,15 @@ sp_api::impl_runtime_apis! {
}

impl babe_primitives::BabeApi<Block> for Runtime {
fn configuration() -> babe_primitives::BabeGenesisConfiguration {
// 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>
babe_primitives::BabeGenesisConfiguration {
fn configuration() -> babe_primitives::BabeConfiguration {
let epoch_config = Babe::epoch_config().unwrap_or(BABE_GENESIS_EPOCH_CONFIG);
babe_primitives::BabeConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
c: BABE_GENESIS_EPOCH_CONFIG.c,
genesis_authorities: Babe::authorities().to_vec(),
c: epoch_config.c,
authorities: Babe::authorities().to_vec(),
randomness: Babe::randomness(),
allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots,
allowed_slots: epoch_config.allowed_slots,
}
}

Expand Down
3 changes: 3 additions & 0 deletions runtime/westend/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub mod time {
pub const DAYS: BlockNumber = HOURS * 24;

// 1 in 4 blocks (on average, not counting collisions) will be primary babe blocks.
// The choice of 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>
pub const PRIMARY_PROBABILITY: (u64, u64) = (1, 4);
}

Expand Down
16 changes: 6 additions & 10 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,19 +1476,15 @@ sp_api::impl_runtime_apis! {
}

impl babe_primitives::BabeApi<Block> for Runtime {
fn configuration() -> babe_primitives::BabeGenesisConfiguration {
// 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>
babe_primitives::BabeGenesisConfiguration {
fn configuration() -> babe_primitives::BabeConfiguration {
let epoch_config = Babe::epoch_config().unwrap_or(BABE_GENESIS_EPOCH_CONFIG);
babe_primitives::BabeConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
c: BABE_GENESIS_EPOCH_CONFIG.c,
genesis_authorities: Babe::authorities().to_vec(),
c: epoch_config.c,
authorities: Babe::authorities().to_vec(),
randomness: Babe::randomness(),
allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots,
allowed_slots: epoch_config.allowed_slots,
}
}

Expand Down