Unverified Commit e6b065f6 authored by Ashley's avatar Ashley Committed by GitHub
Browse files

Companion PR for substrate PR 8072 - Add a config field to babe epochs (#2467)

* Add a config field to babe epochs

* Fix test

* Add BABE_GENESIS_EPOCH_CONFIG consts

* Use PrimaryAndSecondaryVRFSlots and remove newlines

* Make epoch_configs Some

* Fix tests

* Fix test service tests

* Add a BabeEpochConfigMigrations OnRuntimeUpgrade

* Apply suggestions

* Use PrimaryAndSecondaryPlainSlots in kusama

* Remove migration from test runtime and rococo

* Add HasPalletPrefix

* Rename to BabePalletPrefix and change BabeApi -> Babe

* "Update Substrate"

* Update substrate

* Resolve parantheses errors

Co-authored-by: parity-processbot <>
parent 6b72d032
Pipeline #127581 passed with stages
in 34 minutes and 57 seconds
This diff is collapsed.
......@@ -711,7 +711,9 @@ mod tests {
use polkadot_node_subsystem::messages::AllMessages;
use sp_core::testing::TaskExecutor;
use sp_runtime::{Digest, DigestItem};
use sp_consensus_babe::Epoch as BabeEpoch;
use sp_consensus_babe::{
Epoch as BabeEpoch, BabeEpochConfiguration, AllowedSlots,
};
use sp_consensus_babe::digests::{CompatibleDigestItem, PreDigest, SecondaryVRFPreDigest};
use sp_keyring::sr25519::Keyring as Sr25519Keyring;
use assert_matches::assert_matches;
......@@ -1358,6 +1360,10 @@ mod tests {
duration: 200,
authorities: vec![(Sr25519Keyring::Alice.public().into(), 1)],
randomness: [0u8; 32],
config: BabeEpochConfiguration {
c: (1, 4),
allowed_slots: AllowedSlots::PrimarySlots,
},
}));
}
);
......@@ -1463,6 +1469,10 @@ mod tests {
duration: 200,
authorities: vec![(Sr25519Keyring::Alice.public().into(), 1)],
randomness: [0u8; 32],
config: BabeEpochConfiguration {
c: (1, 4),
allowed_slots: AllowedSlots::PrimarySlots,
},
}));
}
);
......@@ -1714,6 +1724,10 @@ mod tests {
duration: 200,
authorities: vec![(Sr25519Keyring::Alice.public().into(), 1)],
randomness: [0u8; 32],
config: BabeEpochConfiguration {
c: (1, 4),
allowed_slots: AllowedSlots::PrimarySlots,
},
}));
}
);
......
......@@ -422,7 +422,9 @@ mod tests {
use sp_core::testing::TaskExecutor;
use std::{collections::{HashMap, BTreeMap}, sync::{Arc, Mutex}};
use futures::channel::oneshot;
use polkadot_node_primitives::BabeEpoch;
use polkadot_node_primitives::{
BabeEpoch, BabeEpochConfiguration, BabeAllowedSlots,
};
#[derive(Default, Clone)]
struct MockRuntimeApi {
......@@ -1158,6 +1160,10 @@ mod tests {
duration: 10,
authorities: Vec::new(),
randomness: [1u8; 32],
config: BabeEpochConfiguration {
c: (1, 4),
allowed_slots: BabeAllowedSlots::PrimarySlots,
},
};
runtime_api.babe_epoch = Some(epoch.clone());
let runtime_api = Arc::new(runtime_api);
......
......@@ -32,7 +32,9 @@ use polkadot_primitives::v1::{
use std::pin::Pin;
pub use sp_core::traits::SpawnNamed;
pub use sp_consensus_babe::Epoch as BabeEpoch;
pub use sp_consensus_babe::{
Epoch as BabeEpoch, BabeEpochConfiguration, AllowedSlots as BabeAllowedSlots,
};
pub mod approval;
......
......@@ -261,7 +261,10 @@ fn polkadot_staging_testnet_config_genesis(wasm_binary: &[u8]) -> polkadot::Gene
phantom: Default::default(),
},
pallet_membership_Instance1: Default::default(),
pallet_babe: Default::default(),
pallet_babe: polkadot::BabeConfig {
authorities: Default::default(),
epoch_config: Some(polkadot::BABE_GENESIS_EPOCH_CONFIG),
},
pallet_grandpa: Default::default(),
pallet_im_online: Default::default(),
pallet_authority_discovery: polkadot::AuthorityDiscoveryConfig { keys: vec![] },
......@@ -448,7 +451,10 @@ fn westend_staging_testnet_config_genesis(wasm_binary: &[u8]) -> westend::Genesi
slash_reward_fraction: Perbill::from_percent(10),
..Default::default()
},
pallet_babe: Default::default(),
pallet_babe: westend::BabeConfig {
authorities: Default::default(),
epoch_config: Some(westend::BABE_GENESIS_EPOCH_CONFIG),
},
pallet_grandpa: Default::default(),
pallet_im_online: Default::default(),
pallet_authority_discovery: westend::AuthorityDiscoveryConfig { keys: vec![] },
......@@ -644,7 +650,10 @@ fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::GenesisC
phantom: Default::default(),
},
pallet_membership_Instance1: Default::default(),
pallet_babe: Default::default(),
pallet_babe: kusama::BabeConfig {
authorities: Default::default(),
epoch_config: Some(kusama::BABE_GENESIS_EPOCH_CONFIG),
},
pallet_grandpa: Default::default(),
pallet_im_online: Default::default(),
pallet_authority_discovery: kusama::AuthorityDiscoveryConfig { keys: vec![] },
......@@ -850,7 +859,10 @@ fn rococo_staging_testnet_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::
),
)).collect::<Vec<_>>(),
},
pallet_babe: Default::default(),
pallet_babe: rococo_runtime::BabeConfig {
authorities: Default::default(),
epoch_config: Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG),
},
pallet_grandpa: Default::default(),
pallet_im_online: Default::default(),
pallet_authority_discovery: rococo_runtime::AuthorityDiscoveryConfig {
......@@ -1130,7 +1142,10 @@ pub fn polkadot_testnet_genesis(
phantom: Default::default(),
},
pallet_membership_Instance1: Default::default(),
pallet_babe: Default::default(),
pallet_babe: polkadot::BabeConfig {
authorities: Default::default(),
epoch_config: Some(polkadot::BABE_GENESIS_EPOCH_CONFIG),
},
pallet_grandpa: Default::default(),
pallet_im_online: Default::default(),
pallet_authority_discovery: polkadot::AuthorityDiscoveryConfig { keys: vec![] },
......@@ -1225,7 +1240,10 @@ pub fn kusama_testnet_genesis(
phantom: Default::default(),
},
pallet_membership_Instance1: Default::default(),
pallet_babe: Default::default(),
pallet_babe: kusama::BabeConfig {
authorities: Default::default(),
epoch_config: Some(kusama::BABE_GENESIS_EPOCH_CONFIG),
},
pallet_grandpa: Default::default(),
pallet_im_online: Default::default(),
pallet_authority_discovery: kusama::AuthorityDiscoveryConfig { keys: vec![] },
......@@ -1309,7 +1327,10 @@ pub fn westend_testnet_genesis(
slash_reward_fraction: Perbill::from_percent(10),
..Default::default()
},
pallet_babe: Default::default(),
pallet_babe: westend::BabeConfig {
authorities: Default::default(),
epoch_config: Some(westend::BABE_GENESIS_EPOCH_CONFIG),
},
pallet_grandpa: Default::default(),
pallet_im_online: Default::default(),
pallet_authority_discovery: westend::AuthorityDiscoveryConfig { keys: vec![] },
......@@ -1363,7 +1384,10 @@ pub fn rococo_testnet_genesis(
),
)).collect::<Vec<_>>(),
},
pallet_babe: Default::default(),
pallet_babe: rococo_runtime::BabeConfig {
authorities: Default::default(),
epoch_config: Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG),
},
pallet_grandpa: Default::default(),
pallet_im_online: Default::default(),
pallet_authority_discovery: rococo_runtime::AuthorityDiscoveryConfig {
......
......@@ -22,7 +22,7 @@ use grandpa::AuthorityId as GrandpaId;
use pallet_staking::Forcing;
use polkadot_primitives::v1::{ValidatorId, AccountId, AssignmentId};
use polkadot_service::chain_spec::{get_account_id_from_seed, get_from_seed, Extensions};
use polkadot_test_runtime::constants::currency::DOTS;
use polkadot_test_runtime::{constants::currency::DOTS, BABE_GENESIS_EPOCH_CONFIG};
use sc_chain_spec::{ChainSpec, ChainType};
use sp_core::sr25519;
use sp_runtime::Perbill;
......@@ -162,7 +162,10 @@ fn polkadot_testnet_genesis(
slash_reward_fraction: Perbill::from_percent(10),
..Default::default()
},
pallet_babe: Default::default(),
pallet_babe: runtime::BabeConfig {
authorities: vec![],
epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG),
},
pallet_grandpa: Default::default(),
pallet_authority_discovery: runtime::AuthorityDiscoveryConfig { keys: vec![] },
claims: runtime::ClaimsConfig {
......
......@@ -99,6 +99,13 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
transaction_version: 4,
};
/// The BABE epoch configuration at genesis.
pub const BABE_GENESIS_EPOCH_CONFIG: babe_primitives::BabeEpochConfiguration =
babe_primitives::BabeEpochConfiguration {
c: PRIMARY_PROBABILITY,
allowed_slots: babe_primitives::AllowedSlots::PrimaryAndSecondaryVRFSlots
};
/// Native version.
#[cfg(any(feature = "std", test))]
pub fn native_version() -> NativeVersion {
......@@ -1036,6 +1043,24 @@ construct_runtime! {
}
}
impl pallet_babe::migrations::BabePalletPrefix for Runtime {
fn pallet_prefix() -> &'static str {
"Babe"
}
}
pub struct BabeEpochConfigMigrations;
impl frame_support::traits::OnRuntimeUpgrade for BabeEpochConfigMigrations {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
pallet_babe::migrations::add_epoch_configuration::<Runtime>(
babe_primitives::BabeEpochConfiguration {
allowed_slots: babe_primitives::AllowedSlots::PrimaryAndSecondaryPlainSlots,
..BABE_GENESIS_EPOCH_CONFIG
}
)
}
}
/// The address format for describing accounts.
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
/// Block header type as expected by this runtime.
......@@ -1067,6 +1092,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllModules,
BabeEpochConfigMigrations,
>;
/// The payload being signed in the transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
......@@ -1236,10 +1262,10 @@ sp_api::impl_runtime_apis! {
babe_primitives::BabeGenesisConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
c: PRIMARY_PROBABILITY,
c: BABE_GENESIS_EPOCH_CONFIG.c,
genesis_authorities: Babe::authorities(),
randomness: Babe::randomness(),
allowed_slots: babe_primitives::AllowedSlots::PrimaryAndSecondaryVRFSlots,
allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots,
}
}
......
......@@ -101,6 +101,13 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
transaction_version: 6,
};
/// The BABE epoch configuration at genesis.
pub const BABE_GENESIS_EPOCH_CONFIG: babe_primitives::BabeEpochConfiguration =
babe_primitives::BabeEpochConfiguration {
c: PRIMARY_PROBABILITY,
allowed_slots: babe_primitives::AllowedSlots::PrimaryAndSecondaryVRFSlots
};
/// Native version.
#[cfg(any(feature = "std", test))]
pub fn native_version() -> NativeVersion {
......@@ -1031,6 +1038,21 @@ construct_runtime! {
}
}
impl pallet_babe::migrations::BabePalletPrefix for Runtime {
fn pallet_prefix() -> &'static str {
"Babe"
}
}
pub struct BabeEpochConfigMigrations;
impl frame_support::traits::OnRuntimeUpgrade for BabeEpochConfigMigrations {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
pallet_babe::migrations::add_epoch_configuration::<Runtime>(
BABE_GENESIS_EPOCH_CONFIG,
)
}
}
/// The address format for describing accounts.
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
/// Block header type as expected by this runtime.
......@@ -1063,7 +1085,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllModules,
()
BabeEpochConfigMigrations,
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
......@@ -1232,10 +1254,10 @@ sp_api::impl_runtime_apis! {
babe_primitives::BabeGenesisConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
c: PRIMARY_PROBABILITY,
c: BABE_GENESIS_EPOCH_CONFIG.c,
genesis_authorities: Babe::authorities(),
randomness: Babe::randomness(),
allowed_slots: babe_primitives::AllowedSlots::PrimaryAndSecondaryVRFSlots,
allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots,
}
}
......
......@@ -110,6 +110,13 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
transaction_version: 0,
};
/// The BABE epoch configuration at genesis.
pub const BABE_GENESIS_EPOCH_CONFIG: babe_primitives::BabeEpochConfiguration =
babe_primitives::BabeEpochConfiguration {
c: PRIMARY_PROBABILITY,
allowed_slots: babe_primitives::AllowedSlots::PrimaryAndSecondaryVRFSlots
};
/// Native version.
#[cfg(any(feature = "std", test))]
pub fn native_version() -> NativeVersion {
......@@ -805,10 +812,10 @@ sp_api::impl_runtime_apis! {
babe_primitives::BabeGenesisConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDurationInBlocks::get().into(),
c: PRIMARY_PROBABILITY,
c: BABE_GENESIS_EPOCH_CONFIG.c,
genesis_authorities: Babe::authorities(),
randomness: Babe::randomness(),
allowed_slots: babe_primitives::AllowedSlots::PrimaryAndSecondaryVRFSlots,
allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots,
}
}
......
......@@ -100,6 +100,13 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
transaction_version: 1,
};
/// The BABE epoch configuration at genesis.
pub const BABE_GENESIS_EPOCH_CONFIG: babe_primitives::BabeEpochConfiguration =
babe_primitives::BabeEpochConfiguration {
c: PRIMARY_PROBABILITY,
allowed_slots: babe_primitives::AllowedSlots::PrimaryAndSecondaryVRFSlots
};
/// Native version.
#[cfg(any(feature = "std", test))]
pub fn native_version() -> NativeVersion {
......@@ -737,10 +744,10 @@ sp_api::impl_runtime_apis! {
babe_primitives::BabeGenesisConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
c: PRIMARY_PROBABILITY,
c: BABE_GENESIS_EPOCH_CONFIG.c,
genesis_authorities: Babe::authorities(),
randomness: Babe::randomness(),
allowed_slots: babe_primitives::AllowedSlots::PrimaryAndSecondaryVRFSlots,
allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots,
}
}
......
......@@ -96,6 +96,13 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
transaction_version: 4,
};
/// The BABE epoch configuration at genesis.
pub const BABE_GENESIS_EPOCH_CONFIG: babe_primitives::BabeEpochConfiguration =
babe_primitives::BabeEpochConfiguration {
c: PRIMARY_PROBABILITY,
allowed_slots: babe_primitives::AllowedSlots::PrimaryAndSecondaryVRFSlots
};
/// Native version.
#[cfg(any(feature = "std", test))]
pub fn native_version() -> NativeVersion {
......@@ -743,6 +750,21 @@ construct_runtime! {
}
}
impl pallet_babe::migrations::BabePalletPrefix for Runtime {
fn pallet_prefix() -> &'static str {
"Babe"
}
}
pub struct BabeEpochConfigMigrations;
impl frame_support::traits::OnRuntimeUpgrade for BabeEpochConfigMigrations {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
pallet_babe::migrations::add_epoch_configuration::<Runtime>(
BABE_GENESIS_EPOCH_CONFIG,
)
}
}
/// The address format for describing accounts.
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
/// Block header type as expected by this runtime.
......@@ -774,6 +796,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllModules,
BabeEpochConfigMigrations,
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
......@@ -951,10 +974,10 @@ sp_api::impl_runtime_apis! {
babe_primitives::BabeGenesisConfiguration {
slot_duration: Babe::slot_duration(),
epoch_length: EpochDuration::get(),
c: PRIMARY_PROBABILITY,
c: BABE_GENESIS_EPOCH_CONFIG.c,
genesis_authorities: Babe::authorities(),
randomness: Babe::randomness(),
allowed_slots: babe_primitives::AllowedSlots::PrimaryAndSecondaryVRFSlots,
allowed_slots: BABE_GENESIS_EPOCH_CONFIG.allowed_slots,
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment