referrerpolicy=no-referrer-when-downgrade

cumulus_client_consensus_aura/
lib.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//! The AuRa consensus algorithm for parachains.
19//!
20//! This extends the Substrate provided AuRa consensus implementation to make it compatible for
21//! parachains.
22//!
23//! For more information about AuRa, the Substrate crate should be checked.
24
25use codec::Encode;
26use cumulus_primitives_core::{relay_chain::HeadData, PersistedValidationData};
27use polkadot_node_primitives::PoV;
28use polkadot_primitives::{BlockNumber as RBlockNumber, Hash as RHash};
29use sp_runtime::traits::{Block as BlockT, NumberFor};
30use std::{fs, fs::File, path::Path};
31
32mod import_queue;
33
34pub use import_queue::{build_verifier, import_queue, BuildVerifierParams, ImportQueueParams};
35pub use sc_consensus_aura::{
36	slot_duration, standalone::slot_duration_at, AuraVerifier, BuildAuraWorkerParams,
37	SlotProportion,
38};
39pub use sc_consensus_slots::InherentDataProviderExt;
40
41pub mod collator;
42pub mod collators;
43pub mod equivocation_import_queue;
44
45const LOG_TARGET: &str = "aura::cumulus";
46
47/// Export the given `pov` to the file system at `path`.
48///
49/// The file will be named `block_hash_block_number.pov`.
50///
51/// The `parent_header`, `relay_parent_storage_root` and `relay_parent_number` will also be
52/// stored in the file alongside the `pov`. This enables stateless validation of the `pov`.
53pub(crate) fn export_pov_to_path<Block: BlockT>(
54	path: &Path,
55	pov: PoV,
56	block_hash: Block::Hash,
57	block_number: NumberFor<Block>,
58	parent_header: Block::Header,
59	relay_parent_storage_root: RHash,
60	relay_parent_number: RBlockNumber,
61	max_pov_size: u32,
62) {
63	if let Err(error) = fs::create_dir_all(&path) {
64		tracing::error!(target: LOG_TARGET, %error, path = %path.display(), "Failed to create PoV export directory");
65		return;
66	}
67
68	let mut file = match File::create(path.join(format!("{block_hash:?}_{block_number}.pov"))) {
69		Ok(f) => f,
70		Err(error) => {
71			tracing::error!(target: LOG_TARGET, %error, "Failed to export PoV.");
72			return;
73		},
74	};
75
76	pov.encode_to(&mut file);
77	PersistedValidationData {
78		parent_head: HeadData(parent_header.encode()),
79		relay_parent_number,
80		relay_parent_storage_root,
81		max_pov_size,
82	}
83	.encode_to(&mut file);
84}