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

Commit

Permalink
Versioned NextConfigDescriptor for BABE (#5789)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorpaas authored Apr 28, 2020
1 parent 15e49f7 commit 72a3d3b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ impl<Block, Client, Inner> BlockImport<Block> for BabeBlockImport<Block, Client,
ConsensusError::ClientImport(Error::<Block>::FetchEpoch(parent_hash).into())
})?;

let epoch_config = next_config_digest.unwrap_or_else(
let epoch_config = next_config_digest.map(Into::into).unwrap_or_else(
|| viable_epoch.as_ref().config.clone()
);

Expand Down
23 changes: 21 additions & 2 deletions primitives/consensus/babe/src/digests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#[cfg(feature = "std")]
use super::{BABE_ENGINE_ID, AuthoritySignature};
use super::{AuthorityId, AuthorityIndex, SlotNumber, BabeAuthorityWeight, BabeEpochConfiguration};
use super::{AuthorityId, AuthorityIndex, SlotNumber, BabeAuthorityWeight, BabeEpochConfiguration, AllowedSlots};
#[cfg(feature = "std")]
use sp_runtime::{DigestItem, generic::OpaqueDigestItemId};
#[cfg(feature = "std")]
Expand Down Expand Up @@ -183,7 +183,26 @@ pub struct NextEpochDescriptor {

/// Information about the next epoch config, if changed. This is broadcast in the first
/// block of the epoch, and applies using the same rules as `NextEpochDescriptor`.
pub type NextConfigDescriptor = BabeEpochConfiguration;
#[derive(Decode, Encode, PartialEq, Eq, Clone, RuntimeDebug)]
pub enum NextConfigDescriptor {
/// Version 1.
#[codec(index = "1")]
V1 {
/// Value of `c` in `BabeEpochConfiguration`.
c: (u64, u64),
/// Value of `allowed_slots` in `BabeEpochConfiguration`.
allowed_slots: AllowedSlots,
}
}

impl From<NextConfigDescriptor> for BabeEpochConfiguration {
fn from(desc: NextConfigDescriptor) -> Self {
match desc {
NextConfigDescriptor::V1 { c, allowed_slots } =>
Self { c, allowed_slots },
}
}
}

/// A digest item which is usable with BABE consensus.
#[cfg(feature = "std")]
Expand Down

0 comments on commit 72a3d3b

Please sign in to comment.