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 <>
This commit is contained in:
Ashley
2021-03-10 10:39:08 +01:00
committed by GitHub
parent 287604cf7e
commit 956be35dd4
11 changed files with 328 additions and 183 deletions
+25 -2
View File
@@ -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,
}
}