Fetch Babe configuration from runtime state (#11760)

* Fetch babe config data from runtime state

* Some renaming

* More renaming

* Final nits

* Fix tests and benches

* Rename  to  in BabeConfiguration

* Remove duplicate babe parameter description

Already specified over the 'PRIMARY_PROBABILITY' constant value

* trigger pipeline

* trigger pipeline
This commit is contained in:
Davide Galassi
2022-09-05 19:41:32 +02:00
committed by GitHub
parent f919894c84
commit 83aec6f93a
14 changed files with 125 additions and 155 deletions
@@ -39,7 +39,7 @@ pub trait ConsensusDataProvider<B: BlockT>: Send + Sync {
/// Attempt to create a consensus digest.
fn create_digest(&self, parent: &B::Header, inherents: &InherentData) -> Result<Digest, Error>;
/// set up the neccessary import params.
/// Set up the necessary import params.
fn append_block_import(
&self,
parent: &B::Header,
@@ -24,8 +24,7 @@ use crate::Error;
use codec::Encode;
use sc_client_api::{AuxStore, UsageProvider};
use sc_consensus_babe::{
authorship, find_pre_digest, BabeIntermediate, CompatibleDigestItem, Config, Epoch,
INTERMEDIATE_KEY,
authorship, find_pre_digest, BabeIntermediate, CompatibleDigestItem, Epoch, INTERMEDIATE_KEY,
};
use sc_consensus_epochs::{
descendent_query, EpochHeader, SharedEpochChanges, ViableEpochDescriptor,
@@ -40,7 +39,7 @@ use sp_consensus::CacheKeyId;
use sp_consensus_babe::{
digests::{NextEpochDescriptor, PreDigest, SecondaryPlainPreDigest},
inherents::BabeInherentData,
AuthorityId, BabeApi, BabeAuthorityWeight, ConsensusLog, BABE_ENGINE_ID,
AuthorityId, BabeApi, BabeAuthorityWeight, BabeConfiguration, ConsensusLog, BABE_ENGINE_ID,
};
use sp_consensus_slots::Slot;
use sp_inherents::InherentData;
@@ -64,7 +63,10 @@ pub struct BabeConsensusDataProvider<B: BlockT, C, P> {
epoch_changes: SharedEpochChanges<B, Epoch>,
/// BABE config, gotten from the runtime.
config: Config,
/// NOTE: This is used to fetch `slot_duration` and `epoch_length` in the
/// `ConsensusDataProvider` implementation. Correct as far as these values
/// are not changed during an epoch change.
config: BabeConfiguration,
/// Authorities to be used for this babe chain.
authorities: Vec<(AuthorityId, BabeAuthorityWeight)>,
@@ -152,7 +154,7 @@ where
return Err(Error::StringError("Cannot supply empty authority set!".into()))
}
let config = Config::get(&*client)?;
let config = sc_consensus_babe::configuration(&*client)?;
Ok(Self {
config,
@@ -177,9 +179,7 @@ where
.ok_or(sp_consensus::Error::InvalidAuthoritiesSet)?;
let epoch = epoch_changes
.viable_epoch(&epoch_descriptor, |slot| {
Epoch::genesis(self.config.genesis_config(), slot)
})
.viable_epoch(&epoch_descriptor, |slot| Epoch::genesis(&self.config, slot))
.ok_or_else(|| {
log::info!(target: "babe", "create_digest: no viable_epoch :(");
sp_consensus::Error::InvalidAuthoritiesSet
@@ -306,7 +306,7 @@ where
identifier,
EpochHeader {
start_slot: slot,
end_slot: (*slot * self.config.genesis_config().epoch_length).into(),
end_slot: (*slot * self.config.epoch_length).into(),
},
),
_ => unreachable!(
@@ -63,7 +63,7 @@ impl SlotTimestampProvider {
C: AuxStore + HeaderBackend<B> + ProvideRuntimeApi<B> + UsageProvider<B>,
C::Api: BabeApi<B>,
{
let slot_duration = sc_consensus_babe::Config::get(&*client)?.slot_duration();
let slot_duration = sc_consensus_babe::configuration(&*client)?.slot_duration();
let time = Self::with_header(&client, slot_duration, |header| {
let slot_number = *sc_consensus_babe::find_pre_digest::<B>(&header)