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
+5 -1
View File
@@ -111,7 +111,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to 0. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 260,
spec_version: 261,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
@@ -1141,6 +1141,10 @@ impl_runtime_apis! {
Babe::current_epoch_start()
}
fn current_epoch() -> sp_consensus_babe::Epoch {
Babe::current_epoch()
}
fn generate_key_ownership_proof(
_slot_number: sp_consensus_babe::SlotNumber,
authority_id: sp_consensus_babe::AuthorityId,
+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())
@@ -350,6 +350,21 @@ impl OpaqueKeyOwnershipProof {
}
}
/// BABE epoch information
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)]
pub struct Epoch {
/// The epoch index.
pub epoch_index: u64,
/// The starting slot of the epoch.
pub start_slot: SlotNumber,
/// The duration of this epoch.
pub duration: SlotNumber,
/// The authorities and their weights.
pub authorities: Vec<(AuthorityId, BabeAuthorityWeight)>,
/// Randomness for this epoch.
pub randomness: [u8; VRF_OUTPUT_LENGTH],
}
sp_api::decl_runtime_apis! {
/// API necessary for block authorship with BABE.
#[api_version(2)]
@@ -364,6 +379,9 @@ sp_api::decl_runtime_apis! {
/// Returns the slot number that started the current epoch.
fn current_epoch_start() -> SlotNumber;
/// Returns information regarding the current epoch.
fn current_epoch() -> Epoch;
/// Generates a proof of key ownership for the given authority in the
/// current epoch. An example usage of this module is coupled with the
/// session historical module to prove that a given authority key is
+10 -2
View File
@@ -732,10 +732,14 @@ cfg_if! {
}
}
fn current_epoch_start() -> SlotNumber {
fn current_epoch_start() -> sp_consensus_babe::SlotNumber {
<pallet_babe::Module<Runtime>>::current_epoch_start()
}
fn current_epoch() -> sp_consensus_babe::Epoch {
<pallet_babe::Module<Runtime>>::current_epoch()
}
fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: sp_consensus_babe::EquivocationProof<
<Block as BlockT>::Header,
@@ -983,10 +987,14 @@ cfg_if! {
}
}
fn current_epoch_start() -> SlotNumber {
fn current_epoch_start() -> sp_consensus_babe::SlotNumber {
<pallet_babe::Module<Runtime>>::current_epoch_start()
}
fn current_epoch() -> sp_consensus_babe::Epoch {
<pallet_babe::Module<Runtime>>::current_epoch()
}
fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: sp_consensus_babe::EquivocationProof<
<Block as BlockT>::Header,