use codec::Encode;
use cumulus_primitives_core::PersistedValidationData;
use cumulus_primitives_core::relay_chain::HeadData;
use polkadot_primitives::{BlockNumber as RBlockNumber, Hash as RHash};
use sp_runtime::traits::{Block as BlockT, NumberFor};
use std::{fs, fs::File, path::PathBuf};
mod import_queue;
pub use import_queue::{build_verifier, import_queue, BuildVerifierParams, ImportQueueParams};
use polkadot_node_primitives::PoV;
pub use sc_consensus_aura::{
slot_duration, standalone::slot_duration_at, AuraVerifier, BuildAuraWorkerParams,
SlotProportion,
};
pub use sc_consensus_slots::InherentDataProviderExt;
pub mod collator;
pub mod collators;
pub mod equivocation_import_queue;
const LOG_TARGET: &str = "aura::cumulus";
pub(crate) fn export_pov_to_path<Block: BlockT>(
path: PathBuf,
pov: PoV,
block_hash: Block::Hash,
block_number: NumberFor<Block>,
parent_header: Block::Header,
relay_parent_storage_root: RHash,
relay_parent_number: RBlockNumber,
max_pov_size: u32,
) {
if let Err(error) = fs::create_dir_all(&path) {
tracing::error!(target: LOG_TARGET, %error, path = %path.display(), "Failed to create PoV export directory");
return;
}
let mut file = match File::create(path.join(format!("{block_hash:?}_{block_number}.pov"))) {
Ok(f) => f,
Err(error) => {
tracing::error!(target: LOG_TARGET, %error, "Failed to export PoV.");
return;
},
};
pov.encode_to(&mut file);
PersistedValidationData {
parent_head: HeadData(parent_header.encode()),
relay_parent_number,
relay_parent_storage_root,
max_pov_size,
}
.encode_to(&mut file);
}