aura: remove unneeded SlotDuration struct and rename digest -> digests (#4958)

* aura: remove unneeded SlotDuration struct and rename digest -> digests

* aura: add alias type for SlotDuration

* aura: fix tests

* Fix missing parameters in get_or_compute

* Use special function for fetching aura slot_duration
This commit is contained in:
Wei Tang
2020-02-21 10:48:18 +01:00
committed by GitHub
parent 353e7a068f
commit 47f209a7a5
3 changed files with 19 additions and 31 deletions
@@ -57,7 +57,7 @@ macro_rules! new_full_start {
);
let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _>(
sc_consensus_aura::SlotDuration::get_or_compute(&*client)?,
sc_consensus_aura::slot_duration(&*client)?,
aura_block_import,
Some(Box::new(grandpa_block_import.clone())),
None,
@@ -115,7 +115,7 @@ pub fn new_full(config: Configuration<GenesisConfig>)
sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone());
let aura = sc_consensus_aura::start_aura::<_, _, _, _, _, AuraPair, _, _, _>(
sc_consensus_aura::SlotDuration::get_or_compute(&*client)?,
sc_consensus_aura::slot_duration(&*client)?,
client,
select_chain,
block_import,
@@ -220,7 +220,7 @@ pub fn new_light(config: Configuration<GenesisConfig>)
finality_proof_import.create_finality_proof_request_builder();
let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, ()>(
sc_consensus_aura::SlotDuration::get_or_compute(&*client)?,
sc_consensus_aura::slot_duration(&*client)?,
grandpa_block_import,
None,
Some(Box::new(finality_proof_import)),
+16 -28
View File
@@ -79,33 +79,23 @@ pub use sp_consensus_aura::{
},
};
pub use sp_consensus::SyncOracle;
pub use digest::CompatibleDigestItem;
pub use digests::CompatibleDigestItem;
mod digest;
mod digests;
type AuthorityId<P> = <P as Pair>::Public;
/// A slot duration. Create with `get_or_compute`.
#[derive(Clone, Copy, Debug, Encode, Decode, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub struct SlotDuration(sc_consensus_slots::SlotDuration<u64>);
/// Slot duration type for Aura.
pub type SlotDuration = sc_consensus_slots::SlotDuration<u64>;
impl SlotDuration {
/// Either fetch the slot duration from disk or compute it from the genesis
/// state.
pub fn get_or_compute<A, B, C>(client: &C) -> CResult<Self>
where
A: Codec,
B: BlockT,
C: AuxStore + ProvideRuntimeApi<B>,
C::Api: AuraApi<B, A, Error = sp_blockchain::Error>,
{
sc_consensus_slots::SlotDuration::get_or_compute(client, |a, b| a.slot_duration(b)).map(Self)
}
/// Get the slot duration in milliseconds.
pub fn get(&self) -> u64 {
self.0.get()
}
/// Get type of `SlotDuration` for Aura.
pub fn slot_duration<A, B, C>(client: &C) -> CResult<SlotDuration> where
A: Codec,
B: BlockT,
C: AuxStore + ProvideRuntimeApi<B>,
C::Api: AuraApi<B, A, Error = sp_blockchain::Error>,
{
SlotDuration::get_or_compute(client, |a, b| a.slot_duration(b))
}
/// Get slot author for given block along with authorities.
@@ -179,10 +169,10 @@ pub fn start_aura<B, C, SC, E, I, P, SO, CAW, Error>(
};
register_aura_inherent_data_provider(
&inherent_data_providers,
slot_duration.0.slot_duration()
slot_duration.slot_duration()
)?;
Ok(sc_consensus_slots::start_slot_worker::<_, _, _, _, _, AuraSlotCompatible, _>(
slot_duration.0,
slot_duration,
select_chain,
worker,
sync_oracle,
@@ -926,8 +916,7 @@ mod tests {
{
match client {
PeersClient::Full(client, _) => {
let slot_duration = SlotDuration::get_or_compute(&*client)
.expect("slot duration available");
let slot_duration = slot_duration(&*client).expect("slot duration available");
let inherent_data_providers = InherentDataProviders::new();
register_aura_inherent_data_provider(
&inherent_data_providers,
@@ -995,8 +984,7 @@ mod tests {
.for_each(move |_| future::ready(()))
);
let slot_duration = SlotDuration::get_or_compute(&*client)
.expect("slot duration available");
let slot_duration = slot_duration(&*client).expect("slot duration available");
let inherent_data_providers = InherentDataProviders::new();
register_aura_inherent_data_provider(