Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions core/consensus/babe/primitives/src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ impl<Hash> CompatibleDigestItem for DigestItem<Hash> where

fn as_next_epoch_descriptor(&self) -> Option<NextEpochDescriptor> {
self.try_to(OpaqueDigestItemId::Consensus(&BABE_ENGINE_ID))
.and_then(|x: super::ConsensusLog| match x {
super::ConsensusLog::NextEpochData(n) => Some(n),
_ => None,
})
}
}

Expand Down
6 changes: 6 additions & 0 deletions core/consensus/babe/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ impl Epoch {
randomness: descriptor.randomness,
}
}

/// Produce the "end slot" of the epoch. This is NOT inclusive to the epoch,
// i.e. the slots covered by the epoch are `self.start_slot .. self.end_slot()`.
pub fn end_slot(&self) -> SlotNumber {
self.start_slot + self.duration
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a proof that this cannot overflow?

}
}

/// An consensus log item for BABE.
Expand Down
6 changes: 3 additions & 3 deletions core/consensus/babe/src/aux_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use client::error::{Result as ClientResult, Error as ClientError};
use sr_primitives::traits::Block as BlockT;
use babe_primitives::BabeBlockWeight;

use super::{EpochChanges, SharedEpochChanges};
use super::{epoch_changes::EpochChangesFor, SharedEpochChanges};

const BABE_EPOCH_CHANGES: &[u8] = b"babe_epoch_changes";

Expand All @@ -50,7 +50,7 @@ fn load_decode<B, T>(backend: &B, key: &[u8]) -> ClientResult<Option<T>>
pub(crate) fn load_epoch_changes<Block: BlockT, B: AuxStore>(
backend: &B,
) -> ClientResult<SharedEpochChanges<Block>> {
let epoch_changes = load_decode::<_, EpochChanges<Block>>(backend, BABE_EPOCH_CHANGES)?
let epoch_changes = load_decode::<_, EpochChangesFor<Block>>(backend, BABE_EPOCH_CHANGES)?
.map(Into::into)
.unwrap_or_else(|| {
info!(target: "babe",
Expand All @@ -64,7 +64,7 @@ pub(crate) fn load_epoch_changes<Block: BlockT, B: AuxStore>(

/// Update the epoch changes on disk after a change.
pub(crate) fn write_epoch_changes<Block: BlockT, F, R>(
epoch_changes: &EpochChanges<Block>,
epoch_changes: &EpochChangesFor<Block>,
write_aux: F,
) -> R where
F: FnOnce(&[(&'static [u8], &[u8])]) -> R,
Expand Down
Loading