cumulus_client_consensus_relay_chain/
import_queue.rs1use std::{marker::PhantomData, sync::Arc};
19
20use sc_consensus::{import_queue::Verifier as VerifierT, BlockImportParams};
21use sp_api::ProvideRuntimeApi;
22use sp_block_builder::BlockBuilder as BlockBuilderApi;
23use sp_inherents::CreateInherentDataProviders;
24use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
25
26pub struct Verifier<Client, Block, CIDP> {
28 client: Arc<Client>,
29 create_inherent_data_providers: CIDP,
30 _marker: PhantomData<Block>,
31}
32
33impl<Client, Block, CIDP> Verifier<Client, Block, CIDP> {
34 pub fn new(client: Arc<Client>, create_inherent_data_providers: CIDP) -> Self {
36 Self { client, create_inherent_data_providers, _marker: PhantomData }
37 }
38}
39
40#[async_trait::async_trait]
41impl<Client, Block, CIDP> VerifierT<Block> for Verifier<Client, Block, CIDP>
42where
43 Block: BlockT,
44 Client: ProvideRuntimeApi<Block> + Send + Sync,
45 <Client as ProvideRuntimeApi<Block>>::Api: BlockBuilderApi<Block>,
46 CIDP: CreateInherentDataProviders<Block, ()>,
47{
48 async fn verify(
49 &self,
50 mut block_params: BlockImportParams<Block>,
51 ) -> Result<BlockImportParams<Block>, String> {
52 block_params.fork_choice = Some(sc_consensus::ForkChoiceStrategy::Custom(
53 block_params.origin == sp_consensus::BlockOrigin::NetworkInitialSync,
54 ));
55
56 if block_params.state_action.skip_execution_checks() || block_params.with_state() {
61 return Ok(block_params)
62 }
63
64 if let Some(inner_body) = block_params.body.take() {
65 let inherent_data_providers = self
66 .create_inherent_data_providers
67 .create_inherent_data_providers(*block_params.header.parent_hash(), ())
68 .await
69 .map_err(|e| e.to_string())?;
70
71 let block = Block::new(block_params.header.clone(), inner_body);
72 sp_block_builder::check_inherents(
73 self.client.clone(),
74 *block.header().parent_hash(),
75 block.clone(),
76 &inherent_data_providers,
77 )
78 .await
79 .map_err(|e| format!("Error checking block inherents {:?}", e))?;
80
81 let (_, inner_body) = block.deconstruct();
82 block_params.body = Some(inner_body);
83 }
84
85 block_params.post_hash = Some(block_params.header.hash());
86 Ok(block_params)
87 }
88}