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

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

Merged
25 commits merged into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
37d0af2
Add a config field to babe epochs
expenses Feb 17, 2021
6aff871
Merge remote-tracking branch 'origin/master' into ashley-change-babe-…
expenses Feb 18, 2021
e20860a
Fix test
expenses Feb 18, 2021
e99e958
Merge remote-tracking branch 'origin/master' into ashley-change-babe-…
expenses Feb 22, 2021
e752f11
Add BABE_GENESIS_EPOCH_CONFIG consts
expenses Feb 22, 2021
9f53c73
Use PrimaryAndSecondaryVRFSlots and remove newlines
expenses Feb 24, 2021
ca36203
Merge remote-tracking branch 'origin/master' into ashley-change-babe-…
expenses Feb 24, 2021
60e7e3f
Merge remote-tracking branch 'origin/master' into ashley-change-babe-…
expenses Feb 25, 2021
316f242
Make epoch_configs Some
expenses Feb 25, 2021
9a436d8
Fix tests
expenses Feb 25, 2021
9ea0f71
Fix test service tests
expenses Feb 26, 2021
93fdc59
Add a BabeEpochConfigMigrations OnRuntimeUpgrade
expenses Mar 1, 2021
ad5c7d8
Merge remote-tracking branch 'origin/master' into ashley-change-babe-…
expenses Mar 3, 2021
8399429
Apply suggestions
expenses Mar 3, 2021
30dd81c
Merge remote-tracking branch 'origin/master' into ashley-change-babe-…
expenses Mar 3, 2021
3c78c7a
Use PrimaryAndSecondaryPlainSlots in kusama
expenses Mar 3, 2021
a9550e6
Remove migration from test runtime and rococo
expenses Mar 5, 2021
a467317
Merge remote-tracking branch 'origin/master' into ashley-change-babe-…
expenses Mar 9, 2021
1fdd426
Add HasPalletPrefix
expenses Mar 9, 2021
8cf8910
Rename to BabePalletPrefix and change BabeApi -> Babe
expenses Mar 9, 2021
c21ae7d
"Update Substrate"
Mar 10, 2021
0072f6c
Update substrate
expenses Mar 10, 2021
deea094
Merge branch 'ashley-change-babe-epoch' of github.com:paritytech/polk…
expenses Mar 10, 2021
c3a4fd3
Merge remote-tracking branch 'origin/master' into ashley-change-babe-…
expenses Mar 10, 2021
c5a6cfb
Resolve parantheses errors
expenses Mar 10, 2021
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
16 changes: 15 additions & 1 deletion node/core/approval-voting/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,9 @@ mod tests {
use polkadot_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;
Expand Down Expand Up @@ -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,
},
}));
}
);
Expand Down Expand Up @@ -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,
},
}));
}
);
Expand Down Expand Up @@ -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,
},
}));
}
);
Expand Down
8 changes: 7 additions & 1 deletion node/core/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion node/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
40 changes: 32 additions & 8 deletions node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ fn polkadot_staging_testnet_config_genesis(wasm_binary: &[u8]) -> polkadot::Gene
phantom: Default::default(),
}),
pallet_membership_Instance1: Some(Default::default()),
pallet_babe: Some(Default::default()),
pallet_babe: Some(polkadot::BabeConfig {
authorities: Default::default(),
epoch_config: Some(polkadot::BABE_GENESIS_EPOCH_CONFIG),
}),
pallet_grandpa: Some(Default::default()),
pallet_im_online: Some(Default::default()),
pallet_authority_discovery: Some(polkadot::AuthorityDiscoveryConfig { keys: vec![] }),
Expand Down Expand Up @@ -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: Some(Default::default()),
pallet_babe: Some(westend::BabeConfig {
authorities: Default::default(),
epoch_config: Some(westend::BABE_GENESIS_EPOCH_CONFIG),
}),
pallet_grandpa: Some(Default::default()),
pallet_im_online: Some(Default::default()),
pallet_authority_discovery: Some(westend::AuthorityDiscoveryConfig { keys: vec![] }),
Expand Down Expand Up @@ -644,7 +650,10 @@ fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::GenesisC
phantom: Default::default(),
}),
pallet_membership_Instance1: Some(Default::default()),
pallet_babe: Some(Default::default()),
pallet_babe: Some(kusama::BabeConfig {
authorities: Default::default(),
epoch_config: Some(kusama::BABE_GENESIS_EPOCH_CONFIG),
}),
pallet_grandpa: Some(Default::default()),
pallet_im_online: Some(Default::default()),
pallet_authority_discovery: Some(kusama::AuthorityDiscoveryConfig { keys: vec![] }),
Expand Down Expand Up @@ -850,7 +859,10 @@ fn rococo_staging_testnet_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::
),
)).collect::<Vec<_>>(),
}),
pallet_babe: Some(Default::default()),
pallet_babe: Some(rococo_runtime::BabeConfig {
authorities: Default::default(),
epoch_config: Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG),
}),
pallet_grandpa: Some(Default::default()),
pallet_im_online: Some(Default::default()),
pallet_authority_discovery: Some(rococo_runtime::AuthorityDiscoveryConfig {
Expand Down Expand Up @@ -1130,7 +1142,10 @@ pub fn polkadot_testnet_genesis(
phantom: Default::default(),
}),
pallet_membership_Instance1: Some(Default::default()),
pallet_babe: Some(Default::default()),
pallet_babe: Some(polkadot::BabeConfig {
authorities: Default::default(),
epoch_config: Some(polkadot::BABE_GENESIS_EPOCH_CONFIG),
}),
pallet_grandpa: Some(Default::default()),
pallet_im_online: Some(Default::default()),
pallet_authority_discovery: Some(polkadot::AuthorityDiscoveryConfig { keys: vec![] }),
Expand Down Expand Up @@ -1225,7 +1240,10 @@ pub fn kusama_testnet_genesis(
phantom: Default::default(),
}),
pallet_membership_Instance1: Some(Default::default()),
pallet_babe: Some(Default::default()),
pallet_babe: Some(kusama::BabeConfig {
authorities: Default::default(),
epoch_config: Some(kusama::BABE_GENESIS_EPOCH_CONFIG),
}),
pallet_grandpa: Some(Default::default()),
pallet_im_online: Some(Default::default()),
pallet_authority_discovery: Some(kusama::AuthorityDiscoveryConfig { keys: vec![] }),
Expand Down Expand Up @@ -1309,7 +1327,10 @@ pub fn westend_testnet_genesis(
slash_reward_fraction: Perbill::from_percent(10),
..Default::default()
}),
pallet_babe: Some(Default::default()),
pallet_babe: Some(westend::BabeConfig {
authorities: Default::default(),
epoch_config: Some(westend::BABE_GENESIS_EPOCH_CONFIG),
}),
pallet_grandpa: Some(Default::default()),
pallet_im_online: Some(Default::default()),
pallet_authority_discovery: Some(westend::AuthorityDiscoveryConfig { keys: vec![] }),
Expand Down Expand Up @@ -1363,7 +1384,10 @@ pub fn rococo_testnet_genesis(
),
)).collect::<Vec<_>>(),
}),
pallet_babe: Some(Default::default()),
pallet_babe: Some(rococo_runtime::BabeConfig {
authorities: Default::default(),
epoch_config: Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG),
}),
pallet_grandpa: Some(Default::default()),
pallet_im_online: Some(Default::default()),
pallet_authority_discovery: Some(rococo_runtime::AuthorityDiscoveryConfig {
Expand Down
7 changes: 5 additions & 2 deletions node/test/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -162,7 +162,10 @@ fn polkadot_testnet_genesis(
slash_reward_fraction: Perbill::from_percent(10),
..Default::default()
}),
pallet_babe: Some(Default::default()),
pallet_babe: Some(runtime::BabeConfig {
authorities: vec![],
epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG),
}),
pallet_grandpa: Some(Default::default()),
pallet_authority_discovery: Some(runtime::AuthorityDiscoveryConfig { keys: vec![] }),
claims: Some(runtime::ClaimsConfig {
Expand Down
24 changes: 22 additions & 2 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
expenses marked this conversation as resolved.
Show resolved Hide resolved
};

/// Native version.
#[cfg(any(feature = "std", test))]
pub fn native_version() -> NativeVersion {
Expand Down Expand Up @@ -1036,6 +1043,18 @@ construct_runtime! {
}
}

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.
Expand Down Expand Up @@ -1067,6 +1086,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>;
Expand Down Expand Up @@ -1236,10 +1256,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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is only called at genesis?

@andresilva ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's fine. The migration has the correct value PrimaryAndSecondaryPlainSlots.

}
}

Expand Down
22 changes: 19 additions & 3 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1031,6 +1038,15 @@ construct_runtime! {
}
}

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.
Expand Down Expand Up @@ -1063,7 +1079,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>;
Expand Down Expand Up @@ -1232,10 +1248,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,
}
}

Expand Down
29 changes: 26 additions & 3 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
expenses marked this conversation as resolved.
Show resolved Hide resolved
babe_primitives::BabeEpochConfiguration {
c: PRIMARY_PROBABILITY,
allowed_slots: babe_primitives::AllowedSlots::PrimaryAndSecondaryVRFSlots
};

/// Native version.
#[cfg(any(feature = "std", test))]
pub fn native_version() -> NativeVersion {
Expand All @@ -119,6 +126,15 @@ pub fn native_version() -> NativeVersion {
}
}

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.
Expand All @@ -145,7 +161,14 @@ pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signatu
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Nonce, Call>;
/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<Runtime, Block, frame_system::ChainContext<Runtime>, Runtime, AllModules>;
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllModules,
(BabeEpochConfigMigrations),
>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;

Expand Down Expand Up @@ -805,10 +828,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,
}
}

Expand Down
Loading