referrerpolicy=no-referrer-when-downgrade

cumulus_client_consensus_common/
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//! (unstable) Composable utilities for constructing import queues for parachains.
19//!
20//! Unlike standalone chains, parachains have the requirement that all consensus logic
21//! must be checked within the runtime. This property means that work which is normally
22//! done in the import queue per-block, such as checking signatures, quorums, and whether
23//! inherent extrinsics were constructed faithfully do not need to be done, per se.
24//!
25//! It may seem that it would be beneficial for the client to do these checks regardless,
26//! but in practice this means that clients would just reject blocks which are _valid_ according
27//! to their Parachain Validation Function, which is the ultimate source of consensus truth.
28//!
29//! However, parachain runtimes expose two different access points for executing blocks
30//! in full nodes versus executing those blocks in the parachain validation environment.
31//! At the time of writing, the inherent and consensus checks in most Cumulus runtimes
32//! are only performed during parachain validation, not full node block execution.
33//!
34//! See <https://github.com/paritytech/cumulus/issues/2436> for details.
35
36use sp_consensus::error::Error as ConsensusError;
37use sp_runtime::traits::Block as BlockT;
38
39use sc_consensus::{
40	block_import::{BlockImport, BlockImportParams},
41	import_queue::{BasicQueue, Verifier},
42};
43
44use crate::ParachainBlockImportMarker;
45
46/// A [`Verifier`] for blocks which verifies absolutely nothing.
47///
48/// This should only be used when the runtime is responsible for checking block seals and inherents.
49pub struct VerifyNothing;
50
51#[async_trait::async_trait]
52impl<Block: BlockT> Verifier<Block> for VerifyNothing {
53	async fn verify(
54		&self,
55		params: BlockImportParams<Block>,
56	) -> Result<BlockImportParams<Block>, String> {
57		Ok(params)
58	}
59}
60
61/// An import queue which does no verification.
62///
63/// This should only be used when the runtime is responsible for checking block seals and inherents.
64pub fn verify_nothing_import_queue<Block: BlockT, I>(
65	block_import: I,
66	spawner: &impl sp_core::traits::SpawnEssentialNamed,
67	registry: Option<&prometheus_endpoint::Registry>,
68) -> BasicQueue<Block>
69where
70	I: BlockImport<Block, Error = ConsensusError>
71		+ ParachainBlockImportMarker
72		+ Send
73		+ Sync
74		+ 'static,
75{
76	BasicQueue::new(VerifyNothing, Box::new(block_import), None, spawner, registry)
77}