Skip to main content

anvil_polkadot/substrate_node/service/
consensus.rs

1use polkadot_sdk::{
2    sc_consensus::BlockImportParams,
3    sc_consensus_aura::CompatibleDigestItem,
4    sc_consensus_manual_seal::{ConsensusDataProvider, Error},
5    sp_api::StorageProof,
6    sp_consensus_aura::ed25519::AuthoritySignature,
7    sp_consensus_babe::Slot,
8    sp_inherents::InherentData,
9    sp_runtime::{Digest, DigestItem, traits::Block as BlockT},
10};
11use std::marker::PhantomData;
12
13/// Consensus data provider for Aura. This will always use slot 0 (used to determine the
14/// index of the AURA authority from the authorities set by AURA runtimes) for the aura
15/// digest since anvil-polkadot node will be the sole block author and AURA will pick
16/// only its configured address, residing at index 0 in the AURA authorities set. When
17/// forking from an assethub chain, we expect an assethub runtime based on AURA,
18/// which will pick the author based on the slot given through the digest, which will
19/// also result in picking the AURA authority from index 0.
20pub struct SameSlotConsensusDataProvider<B> {
21    _phantom: PhantomData<B>,
22}
23
24impl<B> SameSlotConsensusDataProvider<B> {
25    pub fn new() -> Self {
26        Self { _phantom: PhantomData }
27    }
28}
29
30impl<B> ConsensusDataProvider<B> for SameSlotConsensusDataProvider<B>
31where
32    B: BlockT,
33{
34    fn create_digest(
35        &self,
36        _parent: &B::Header,
37        _inherents: &InherentData,
38    ) -> Result<Digest, Error> {
39        let digest_item = <DigestItem as CompatibleDigestItem<AuthoritySignature>>::aura_pre_digest(
40            Slot::default(),
41        );
42
43        Ok(Digest { logs: vec![digest_item] })
44    }
45
46    fn append_block_import(
47        &self,
48        _parent: &B::Header,
49        _params: &mut BlockImportParams<B>,
50        _inherents: &InherentData,
51        _proof: StorageProof,
52    ) -> Result<(), Error> {
53        Ok(())
54    }
55}