Skip to content

Commit

Permalink
Allow initializing babe pallet after genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwhit committed Jun 28, 2023
1 parent 1b1b67e commit ee4ee95
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,23 @@ impl EpochChangeTrigger for SameAuthoritiesForever {

const UNDER_CONSTRUCTION_SEGMENT_LENGTH: u32 = 256;

#[derive(Default)]
pub struct InitConfig {
pub authorities: Vec<(AuthorityId, BabeAuthorityWeight)>,
pub epoch_config: Option<BabeEpochConfiguration>,
}

#[cfg(feature = "std")]
impl From<&pallet::GenesisConfig> for InitConfig {
fn from(genesis: &pallet::GenesisConfig) -> Self {
Self {
authorities: genesis.authorities.clone(),
epoch_config: genesis.epoch_config.clone(),
}
}
}


#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down Expand Up @@ -325,11 +342,7 @@ pub mod pallet {
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {
SegmentIndex::<T>::put(0);
Pallet::<T>::initialize_genesis_authorities(&self.authorities);
EpochConfig::<T>::put(
self.epoch_config.clone().expect("epoch_config must not be None"),
);
Pallet::<T>::genesis_init(self.into())
}
}

Expand Down Expand Up @@ -888,6 +901,14 @@ impl<T: Config> Pallet<T> {
) -> Option<()> {
T::EquivocationReportSystem::publish_evidence((equivocation_proof, key_owner_proof)).ok()
}

pub fn genesis_init(config: crate::InitConfig) {
SegmentIndex::<T>::put(0);
Pallet::<T>::initialize_genesis_authorities(&config.authorities);
EpochConfig::<T>::put(
config.epoch_config.clone().expect("epoch_config must not be None"),
);
}
}

impl<T: Config> OnTimestampSet<T::Moment> for Pallet<T> {
Expand Down

0 comments on commit ee4ee95

Please sign in to comment.