mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 03:01:07 +00:00
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:
@@ -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)),
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user