sc_consensus_manual_seal/consensus/
aura.rs1use crate::{ConsensusDataProvider, Error};
23use sc_client_api::{AuxStore, UsageProvider};
24use sc_consensus::BlockImportParams;
25use sp_api::ProvideRuntimeApi;
26use sp_blockchain::{HeaderBackend, HeaderMetadata};
27use sp_consensus_aura::{
28 digests::CompatibleDigestItem,
29 sr25519::{AuthorityId, AuthoritySignature},
30 AuraApi, Slot, SlotDuration,
31};
32use sp_inherents::InherentData;
33use sp_runtime::{traits::Block as BlockT, Digest, DigestItem};
34use sp_timestamp::TimestampInherentData;
35use std::{marker::PhantomData, sync::Arc};
36
37pub struct AuraConsensusDataProvider<B, C, P> {
39 slot_duration: SlotDuration,
41 _phantom: PhantomData<(B, C, P)>,
43}
44
45impl<B, C, P> AuraConsensusDataProvider<B, C, P>
46where
47 B: BlockT,
48 C: AuxStore + ProvideRuntimeApi<B> + UsageProvider<B>,
49 C::Api: AuraApi<B, AuthorityId>,
50{
51 pub fn new(client: Arc<C>) -> Self {
54 let slot_duration = sc_consensus_aura::slot_duration(&*client)
55 .expect("slot_duration is always present; qed.");
56
57 Self { slot_duration, _phantom: PhantomData }
58 }
59}
60
61impl<B, C, P> ConsensusDataProvider<B> for AuraConsensusDataProvider<B, C, P>
62where
63 B: BlockT,
64 C: AuxStore
65 + HeaderBackend<B>
66 + HeaderMetadata<B, Error = sp_blockchain::Error>
67 + UsageProvider<B>
68 + ProvideRuntimeApi<B>,
69 C::Api: AuraApi<B, AuthorityId>,
70 P: Send + Sync,
71{
72 type Proof = P;
73
74 fn create_digest(
75 &self,
76 _parent: &B::Header,
77 inherents: &InherentData,
78 ) -> Result<Digest, Error> {
79 let timestamp =
80 inherents.timestamp_inherent_data()?.expect("Timestamp is always present; qed");
81
82 let digest_item = <DigestItem as CompatibleDigestItem<AuthoritySignature>>::aura_pre_digest(
85 Slot::from_timestamp(timestamp, self.slot_duration),
86 );
87
88 Ok(Digest { logs: vec![digest_item] })
89 }
90
91 fn append_block_import(
92 &self,
93 _parent: &B::Header,
94 _params: &mut BlockImportParams<B>,
95 _inherents: &InherentData,
96 _proof: Self::Proof,
97 ) -> Result<(), Error> {
98 Ok(())
99 }
100}