referrerpolicy=no-referrer-when-downgrade

cumulus_client_consensus_aura/
import_queue.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
4
5// Cumulus is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9
10// Cumulus is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14
15// You should have received a copy of the GNU General Public License
16// along with Cumulus. If not, see <https://www.gnu.org/licenses/>.
17
18//! Parachain specific wrapper for the AuRa import queue.
19
20use codec::Codec;
21use cumulus_client_consensus_common::ParachainBlockImportMarker;
22use prometheus_endpoint::Registry;
23use sc_client_api::{backend::AuxStore, BlockOf, UsageProvider};
24use sc_consensus::{import_queue::DefaultImportQueue, BlockImport};
25use sc_consensus_aura::{AuraVerifier, CompatibilityMode};
26use sc_consensus_slots::InherentDataProviderExt;
27use sc_telemetry::TelemetryHandle;
28use sp_api::{ApiExt, ProvideRuntimeApi};
29use sp_block_builder::BlockBuilder as BlockBuilderApi;
30use sp_blockchain::{HeaderBackend, HeaderMetadata};
31use sp_consensus::Error as ConsensusError;
32use sp_consensus_aura::AuraApi;
33use sp_core::crypto::Pair;
34use sp_inherents::CreateInherentDataProviders;
35use sp_runtime::traits::Block as BlockT;
36use std::{fmt::Debug, sync::Arc};
37
38/// Parameters for [`import_queue`].
39pub struct ImportQueueParams<'a, I, C, CIDP, S> {
40	/// The block import to use.
41	pub block_import: I,
42	/// The client to interact with the chain.
43	pub client: Arc<C>,
44	/// The inherent data providers, to create the inherent data.
45	pub create_inherent_data_providers: CIDP,
46	/// The spawner to spawn background tasks.
47	pub spawner: &'a S,
48	/// The prometheus registry.
49	pub registry: Option<&'a Registry>,
50	/// The telemetry handle.
51	pub telemetry: Option<TelemetryHandle>,
52}
53
54/// Start an import queue for the Aura consensus algorithm.
55pub fn import_queue<P, Block, I, C, S, CIDP>(
56	ImportQueueParams {
57		block_import,
58		client,
59		create_inherent_data_providers,
60		spawner,
61		registry,
62		telemetry,
63	}: ImportQueueParams<'_, I, C, CIDP, S>,
64) -> Result<DefaultImportQueue<Block>, sp_consensus::Error>
65where
66	Block: BlockT,
67	C::Api: BlockBuilderApi<Block> + AuraApi<Block, P::Public> + ApiExt<Block>,
68	C: 'static
69		+ ProvideRuntimeApi<Block>
70		+ BlockOf
71		+ Send
72		+ Sync
73		+ AuxStore
74		+ UsageProvider<Block>
75		+ HeaderBackend<Block>
76		+ HeaderMetadata<Block, Error = sp_blockchain::Error>,
77	I: BlockImport<Block, Error = ConsensusError>
78		+ ParachainBlockImportMarker
79		+ Send
80		+ Sync
81		+ 'static,
82	P: Pair + 'static,
83	P::Public: Debug + Codec,
84	P::Signature: Codec,
85	S: sp_core::traits::SpawnEssentialNamed,
86	CIDP: CreateInherentDataProviders<Block, ()> + Sync + Send + 'static,
87	CIDP::InherentDataProviders: InherentDataProviderExt + Send + Sync,
88{
89	sc_consensus_aura::import_queue::<P, _, _, _, _, _>(sc_consensus_aura::ImportQueueParams {
90		block_import,
91		justification_import: None,
92		client,
93		create_inherent_data_providers,
94		spawner,
95		registry,
96		check_for_equivocation: sc_consensus_aura::CheckForEquivocation::No,
97		telemetry,
98		compatibility_mode: CompatibilityMode::None,
99	})
100}
101
102/// Parameters of [`build_verifier`].
103pub struct BuildVerifierParams<C, CIDP> {
104	/// The client to interact with the chain.
105	pub client: Arc<C>,
106	/// The inherent data providers, to create the inherent data.
107	pub create_inherent_data_providers: CIDP,
108	/// The telemetry handle.
109	pub telemetry: Option<TelemetryHandle>,
110}
111
112/// Build the [`AuraVerifier`].
113pub fn build_verifier<P: Pair, C, CIDP, B: BlockT>(
114	BuildVerifierParams { client, create_inherent_data_providers, telemetry }: BuildVerifierParams<
115		C,
116		CIDP,
117	>,
118) -> AuraVerifier<C, P, CIDP, B> {
119	sc_consensus_aura::build_verifier(sc_consensus_aura::BuildVerifierParams {
120		client,
121		create_inherent_data_providers,
122		telemetry,
123		check_for_equivocation: sc_consensus_aura::CheckForEquivocation::No,
124		compatibility_mode: CompatibilityMode::None,
125	})
126}