add a current_epoch to BabeApi (#7789)

* add a `current_epoch` to BabeApi

* add current_epoch_start back again

* fix node-runtime

* bump spec version
This commit is contained in:
Robert Habermeier
2020-12-26 19:34:39 -05:00
committed by GitHub
parent 6dfad0921b
commit 9164cde499
4 changed files with 45 additions and 4 deletions
+12 -1
View File
@@ -43,7 +43,7 @@ use sp_timestamp::OnTimestampSet;
use sp_consensus_babe::{
digests::{NextConfigDescriptor, NextEpochDescriptor, PreDigest},
inherents::{BabeInherentData, INHERENT_IDENTIFIER},
BabeAuthorityWeight, ConsensusLog, EquivocationProof, SlotNumber, BABE_ENGINE_ID,
BabeAuthorityWeight, ConsensusLog, Epoch, EquivocationProof, SlotNumber, BABE_ENGINE_ID,
};
use sp_consensus_vrf::schnorrkel;
use sp_inherents::{InherentData, InherentIdentifier, MakeFatalError, ProvideInherent};
@@ -486,6 +486,17 @@ impl<T: Config> Module<T> {
(EpochIndex::get() * T::EpochDuration::get()) + GenesisSlot::get()
}
/// Produces information about the current epoch.
pub fn current_epoch() -> Epoch {
Epoch {
epoch_index: EpochIndex::get(),
start_slot: Self::current_epoch_start(),
duration: T::EpochDuration::get(),
authorities: Self::authorities(),
randomness: Self::randomness(),
}
}
fn deposit_consensus<U: Encode>(new: U) {
let log: DigestItem<T::Hash> = DigestItem::Consensus(BABE_ENGINE_ID, new.encode());
<frame_system::Module<T>>::deposit_log(log.into())