diff --git a/client/consensus/aura/src/lib.rs b/client/consensus/aura/src/lib.rs index d05c53aae8f72..ebf17deba7c73 100644 --- a/client/consensus/aura/src/lib.rs +++ b/client/consensus/aura/src/lib.rs @@ -147,7 +147,6 @@ pub fn start_aura( BS: BackoffAuthoringBlocksStrategy> + Send + 'static, IDP: CreateInherentDataProviders + Send, IDP::InherentDataProviders: InherentDataProviderExt + Send, - IDP::Error: Into, { let worker = AuraWorker { client, @@ -170,6 +169,43 @@ pub fn start_aura( )) } +/// Build and return the aura worker. +/// +/// The caller is responsible for running the returned worker. +pub fn build_aura_worker( + client: Arc, + block_import: I, + env: E, + sync_oracle: SO, + force_authoring: bool, + backoff_authoring_blocks: Option, + keystore: SyncCryptoStorePtr, +) -> impl sc_consensus_slots::SlotWorker where + B: BlockT, + C: ProvideRuntimeApi + BlockOf + ProvideCache + AuxStore + HeaderBackend + Send + Sync, + C::Api: AuraApi>, + E: Environment + Send + Sync + 'static, + E::Proposer: Proposer>, + P: Pair + Send + Sync, + P::Public: AppPublic + Hash + Member + Encode + Decode, + P::Signature: TryFrom> + Hash + Member + Encode + Decode, + I: BlockImport> + Send + Sync + 'static, + Error: std::error::Error + Send + From + 'static, + SO: SyncOracle + Send + Sync + Clone, + BS: BackoffAuthoringBlocksStrategy> + Send + 'static, +{ + AuraWorker { + client, + block_import: Arc::new(Mutex::new(block_import)), + env, + keystore, + sync_oracle, + force_authoring, + backoff_authoring_blocks, + _key_type: PhantomData::

, + } +} + struct AuraWorker { client: Arc, block_import: Arc>, @@ -498,7 +534,6 @@ impl AuraVerifier where CAW: CanAuthorWith, IDP: CreateInherentDataProviders, IDP::InherentDataProviders: InherentDataProviderExt + Send, - IDP::Error: Into, { if let Err(e) = self.can_author_with.can_author_with(&block_id) { debug!( @@ -545,7 +580,6 @@ impl Verifier for AuraVerifier whe CAW: CanAuthorWith + Send + Sync + 'static, IDP: CreateInherentDataProviders + Send + Sync, IDP::InherentDataProviders: InherentDataProviderExt + Send + Sync, - IDP::Error: Into, { async fn verify( &mut self, @@ -559,10 +593,13 @@ impl Verifier for AuraVerifier whe let authorities = authorities(self.client.as_ref(), &BlockId::Hash(parent_hash)) .map_err(|e| format!("Could not fetch authorities at {:?}: {:?}", parent_hash, e))?; - let inherent_data_providers = self.inherent_data_providers.create_inherent_data_providers( - parent_hash, - (), - ).map_err(|e| Error::::Client(sp_blockchain::Error::Consensus(e.into())))?; + let inherent_data_providers = self.inherent_data_providers + .create_inherent_data_providers( + parent_hash, + (), + ) + .await + .map_err(|e| Error::::Client(sp_blockchain::Error::Application(e)))?; let mut inherent_data = inherent_data_providers.create_inherent_data() .map_err(|e| Error::::Inherent(Box::new(e)))?; @@ -805,7 +842,6 @@ pub fn import_queue( CAW: CanAuthorWith + Send + Sync + 'static, IDP: CreateInherentDataProviders + Sync + Send + 'static, IDP::InherentDataProviders: InherentDataProviderExt + Send + Sync, - IDP::Error: Into, { initialize_authorities_cache(&*client)?; diff --git a/client/consensus/slots/src/lib.rs b/client/consensus/slots/src/lib.rs index 319f89ab4c153..6fce11b6c6ff0 100644 --- a/client/consensus/slots/src/lib.rs +++ b/client/consensus/slots/src/lib.rs @@ -71,14 +71,14 @@ pub struct SlotResult { /// The implementation should not make any assumptions of the slot being bound to the time or /// similar. The only valid assumption is that the slot number is always increasing. pub trait SlotWorker { - /// The type of the future that will be returned when a new slot is triggered. - type OnSlot: Future>>; - /// Called when a new slot is triggered. /// /// Returns a future that resolves to a [`SlotResult`] iff a block was successfully built in /// the slot. Otherwise `None` is returned. - fn on_slot(&mut self, slot_info: SlotInfo) -> Self::OnSlot; + fn on_slot( + &mut self, + slot_info: SlotInfo, + ) -> Pin>> + Send>>; } /// A skeleton implementation for `SlotWorker` which tries to claim a slot at @@ -401,9 +401,10 @@ pub trait SimpleSlotWorker { } impl> SlotWorker for T { - type OnSlot = Pin>> + Send>>; - - fn on_slot(&mut self, slot_info: SlotInfo) -> Self::OnSlot { + fn on_slot( + &mut self, + slot_info: SlotInfo, + ) -> Pin>> + Send>> { SimpleSlotWorker::on_slot(self, slot_info) } } @@ -477,7 +478,6 @@ where B: BlockT, C: SelectChain, W: SlotWorker, - W::OnSlot: Unpin, SO: SyncOracle + Send, T: SlotData + Clone, CAW: CanAuthorWith + Send,