From 8222119308b3af90fd603d6b78c1a4e45d78e161 Mon Sep 17 00:00:00 2001 From: MrishoLukamba Date: Sun, 16 Feb 2025 19:50:05 +0300 Subject: [PATCH 1/6] feat(collator) add export pov on slot base collator --- .../consensus/aura/src/collators/lookahead.rs | 2 +- .../collators/slot_based/collation_task.rs | 32 +++++++++++- .../aura/src/collators/slot_based/mod.rs | 52 ++++++++++++------- .../polkadot-omni-node/lib/src/nodes/aura.rs | 15 ++++-- cumulus/test/service/src/lib.rs | 9 ++-- 5 files changed, 80 insertions(+), 30 deletions(-) diff --git a/cumulus/client/consensus/aura/src/collators/lookahead.rs b/cumulus/client/consensus/aura/src/collators/lookahead.rs index 8427a40419986..c55c2e1d8ff30 100644 --- a/cumulus/client/consensus/aura/src/collators/lookahead.rs +++ b/cumulus/client/consensus/aura/src/collators/lookahead.rs @@ -74,7 +74,7 @@ use crate::{collator as collator_util, LOG_TARGET}; /// /// The `parent_header`, `relay_parent_storage_root` and `relay_parent_number` will also be /// stored in the file alongside the `pov`. This enables stateless validation of the `pov`. -fn export_pov_to_path( +pub fn export_pov_to_path( path: PathBuf, pov: PoV, block_hash: Block::Hash, diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs b/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs index eb48494cf6dcd..7394c756837f2 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs @@ -15,6 +15,7 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . +use std::path::PathBuf; use codec::Encode; use cumulus_client_collator::service::ServiceInterface as CollatorServiceInterface; @@ -26,9 +27,11 @@ use polkadot_overseer::Handle as OverseerHandle; use polkadot_primitives::{CollatorPair, Id as ParaId}; use futures::prelude::*; +use cumulus_primitives_core::relay_chain::BlockId; use sc_utils::mpsc::TracingUnboundedReceiver; use sp_runtime::traits::{Block as BlockT, Header}; +use crate::collators::lookahead::export_pov_to_path; use super::CollatorMessage; @@ -68,6 +71,7 @@ pub async fn run_collation_task( mut collator_receiver, mut block_import_handle, }: Params, + export_pov: Option ) where Block: BlockT, CS: CollatorServiceInterface + Send + Sync + 'static, @@ -93,7 +97,7 @@ pub async fn run_collation_task( return; }; - handle_collation_message(message, &collator_service, &mut overseer_handle).await; + handle_collation_message(message, &collator_service, &mut overseer_handle,relay_client.clone(),export_pov.clone()).await; }, block_import_msg = block_import_handle.next().fuse() => { // TODO: Implement me. @@ -107,10 +111,12 @@ pub async fn run_collation_task( /// Handle an incoming collation message from the block builder task. /// This builds the collation from the [`CollatorMessage`] and submits it to /// the collation-generation subsystem of the relay chain. -async fn handle_collation_message( +async fn handle_collation_message( message: CollatorMessage, collator_service: &impl CollatorServiceInterface, overseer_handle: &mut OverseerHandle, + relay_client: RClient, + export_pov: Option ) { let CollatorMessage { parent_header, @@ -140,6 +146,28 @@ async fn handle_collation_message( ); if let MaybeCompressedPoV::Compressed(ref pov) = collation.proof_of_validity { + + if let Ok(relay_parent_header) = relay_client.header(BlockId::Hash(relay_parent)).await { + + if let Some(relay_parent_header) = relay_parent_header { + if let Some(pov_path) = export_pov { + export_pov_to_path::( + pov_path.clone(), + pov.clone(), + block_data.header().hash(), + *block_data.header().number(), + parent_header.clone(), + relay_parent_header.state_root, + relay_parent_header.number + ); + } + }else{ + tracing::error!(target: LOG_TARGET, "relay parent header from hash: {relay_parent} not found"); + } + }else { + tracing::error!(target: LOG_TARGET, "Failed to get relay parent header from hash: {relay_parent}."); + } + tracing::info!( target: LOG_TARGET, "Compressed PoV size: {}kb", diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs b/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs index f72960fe4c2e1..42ff82acc8364 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs @@ -55,6 +55,7 @@ use sp_inherents::CreateInherentDataProviders; use sp_keystore::KeystorePtr; use sp_runtime::traits::{Block as BlockT, Member, NumberFor, One}; use std::{sync::Arc, time::Duration}; +use std::path::PathBuf; pub use block_import::{SlotBasedBlockImport, SlotBasedBlockImportHandle}; @@ -102,26 +103,17 @@ pub struct Params { + /// Parameters + pub params: Params, + /// When set, the collator will export every produced `POV` to this folder. + pub export_pov: Option, +} + /// Run aura-based block building and collation task. pub fn run( - Params { - create_inherent_data_providers, - block_import, - para_client, - para_backend, - relay_client, - code_hash_provider, - keystore, - collator_key, - para_id, - proposer, - collator_service, - authoring_duration, - reinitialize, - slot_drift, - block_import_handle, - spawner, - }: Params, + params_with_export: ParamsWithExport ) where Block: BlockT, Client: ProvideRuntimeApi @@ -148,6 +140,28 @@ pub fn run> + Member + Codec, Spawner: SpawnNamed, { + let ParamsWithExport { + params: Params { + create_inherent_data_providers, + block_import, + para_client, + para_backend, + relay_client, + code_hash_provider, + keystore, + collator_key, + para_id, + proposer, + collator_service, + authoring_duration, + reinitialize, + slot_drift, + block_import_handle, + spawner, + }, + export_pov + } = params_with_export; + let (tx, rx) = tracing_unbounded("mpsc_builder_to_collator", 100); let collator_task_params = collation_task::Params { relay_client: relay_client.clone(), @@ -159,7 +173,7 @@ pub fn run(collator_task_params); + let collation_task_fut = run_collation_task::(collator_task_params,export_pov); let block_builder_params = block_builder_task::BuilderTaskParams { create_inherent_data_providers, diff --git a/cumulus/polkadot-omni-node/lib/src/nodes/aura.rs b/cumulus/polkadot-omni-node/lib/src/nodes/aura.rs index 0d526b09834e9..771b8cb060cbe 100644 --- a/cumulus/polkadot-omni-node/lib/src/nodes/aura.rs +++ b/cumulus/polkadot-omni-node/lib/src/nodes/aura.rs @@ -35,7 +35,7 @@ use cumulus_client_collator::service::{ }; #[docify::export(slot_based_colator_import)] use cumulus_client_consensus_aura::collators::slot_based::{ - self as slot_based, Params as SlotBasedParams, + self as slot_based, Params as SlotBasedParams, ParamsWithExport as SlotBasedParamsWithExport }; use cumulus_client_consensus_aura::{ collators::{ @@ -250,7 +250,7 @@ where { #[docify::export_content] fn launch_slot_based_collator( - params: SlotBasedParams< + params_with_export: SlotBasedParamsWithExport< Block, ParachainBlockImport< Block, @@ -277,7 +277,7 @@ where CS: CollatorServiceInterface + Send + Sync + Clone + 'static, Spawner: SpawnNamed, { - slot_based::run::::Pair, _, _, _, _, _, _, _, _, _>(params); + slot_based::run::::Pair, _, _, _, _, _, _, _, _, _>(params_with_export); } } @@ -319,7 +319,7 @@ where _overseer_handle: OverseerHandle, announce_block: Arc>) + Send + Sync>, backend: Arc>, - _node_extra_args: NodeExtraArgs, + node_extra_args: NodeExtraArgs, block_import_handle: SlotBasedBlockImportHandle, ) -> Result<(), Error> { let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( @@ -362,7 +362,12 @@ where // We have a separate function only to be able to use `docify::export` on this piece of // code. - Self::launch_slot_based_collator(params); + let params_with_export = SlotBasedParamsWithExport { + params, + export_pov: node_extra_args.export_pov + }; + + Self::launch_slot_based_collator(params_with_export); Ok(()) } diff --git a/cumulus/test/service/src/lib.rs b/cumulus/test/service/src/lib.rs index f3f04cbb63835..36c4fbd0627eb 100644 --- a/cumulus/test/service/src/lib.rs +++ b/cumulus/test/service/src/lib.rs @@ -29,7 +29,7 @@ use cumulus_client_consensus_aura::{ lookahead::{self as aura, Params as AuraParams}, slot_based::{ self as slot_based, Params as SlotBasedParams, SlotBasedBlockImport, - SlotBasedBlockImportHandle, + SlotBasedBlockImportHandle, ParamsWithExport as SlotBasedParamsWithExport }, }, ImportQueueParams, @@ -507,8 +507,11 @@ where block_import_handle: slot_based_handle, spawner: task_manager.spawn_handle(), }; - - slot_based::run::(params); + let params_with_export = SlotBasedParamsWithExport { + params, + None + }; + slot_based::run::(params_with_export); } else { tracing::info!(target: LOG_TARGET, "Starting block authoring with lookahead collator."); let params = AuraParams { From 05922612036215d0368e56621f586dfa6c28239e Mon Sep 17 00:00:00 2001 From: MrishoLukamba Date: Wed, 19 Feb 2025 16:54:09 +0300 Subject: [PATCH 2/6] refactored and checking export_pov before fetching relay header --- .../consensus/aura/src/collators/lookahead.rs | 45 ++-------------- .../collators/slot_based/collation_task.rs | 33 +++++------- .../aura/src/collators/slot_based/mod.rs | 2 + cumulus/client/consensus/aura/src/lib.rs | 53 +++++++++++++++---- prdoc/pr_7585.prdoc | 11 ++++ 5 files changed, 76 insertions(+), 68 deletions(-) create mode 100644 prdoc/pr_7585.prdoc diff --git a/cumulus/client/consensus/aura/src/collators/lookahead.rs b/cumulus/client/consensus/aura/src/collators/lookahead.rs index c55c2e1d8ff30..9ba568f0d9719 100644 --- a/cumulus/client/consensus/aura/src/collators/lookahead.rs +++ b/cumulus/client/consensus/aura/src/collators/lookahead.rs @@ -40,12 +40,12 @@ use cumulus_primitives_aura::AuraUnincludedSegmentApi; use cumulus_primitives_core::{ClaimQueueOffset, CollectCollationInfo, PersistedValidationData}; use cumulus_relay_chain_interface::RelayChainInterface; -use polkadot_node_primitives::{PoV, SubmitCollationParams}; +use polkadot_node_primitives::SubmitCollationParams; use polkadot_node_subsystem::messages::CollationGenerationMessage; use polkadot_overseer::Handle as OverseerHandle; use polkadot_primitives::{ - vstaging::DEFAULT_CLAIM_QUEUE_OFFSET, BlockNumber as RBlockNumber, CollatorPair, Hash as RHash, - HeadData, Id as ParaId, OccupiedCoreAssumption, + vstaging::DEFAULT_CLAIM_QUEUE_OFFSET, CollatorPair, + Id as ParaId, OccupiedCoreAssumption, }; use futures::prelude::*; @@ -58,49 +58,14 @@ use sp_consensus_aura::{AuraApi, Slot}; use sp_core::crypto::Pair; use sp_inherents::CreateInherentDataProviders; use sp_keystore::KeystorePtr; -use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member, NumberFor}; +use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member}; use std::{ - fs::{self, File}, path::PathBuf, sync::Arc, time::Duration, }; +use crate::{collator as collator_util, export_pov_to_path}; -use crate::{collator as collator_util, LOG_TARGET}; - -/// Export the given `pov` to the file system at `path`. -/// -/// The file will be named `block_hash_block_number.pov`. -/// -/// The `parent_header`, `relay_parent_storage_root` and `relay_parent_number` will also be -/// stored in the file alongside the `pov`. This enables stateless validation of the `pov`. -pub fn export_pov_to_path( - path: PathBuf, - pov: PoV, - block_hash: Block::Hash, - block_number: NumberFor, - parent_header: Block::Header, - relay_parent_storage_root: RHash, - relay_parent_number: RBlockNumber, -) { - 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); - HeadData(parent_header.encode()).encode_to(&mut file); - relay_parent_storage_root.encode_to(&mut file); - relay_parent_number.encode_to(&mut file); -} /// Parameters for [`run`]. pub struct Params { diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs b/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs index 7394c756837f2..1bdd194e5af4b 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs @@ -31,7 +31,7 @@ use cumulus_primitives_core::relay_chain::BlockId; use sc_utils::mpsc::TracingUnboundedReceiver; use sp_runtime::traits::{Block as BlockT, Header}; -use crate::collators::lookahead::export_pov_to_path; +use crate::export_pov_to_path; use super::CollatorMessage; @@ -147,25 +147,20 @@ async fn handle_collation_message( - pov_path.clone(), - pov.clone(), - block_data.header().hash(), - *block_data.header().number(), - parent_header.clone(), - relay_parent_header.state_root, - relay_parent_header.number - ); - } - }else{ - tracing::error!(target: LOG_TARGET, "relay parent header from hash: {relay_parent} not found"); + if let Some(pov_path) = export_pov { + if let Ok(Some(relay_parent_header)) = relay_client.header(BlockId::Hash(relay_parent)).await { + export_pov_to_path::( + pov_path.clone(), + pov.clone(), + block_data.header().hash(), + *block_data.header().number(), + parent_header.clone(), + relay_parent_header.state_root, + relay_parent_header.number + ); + }else { + tracing::error!(target: LOG_TARGET, "Failed to get relay parent header from hash: {relay_parent}"); } - }else { - tracing::error!(target: LOG_TARGET, "Failed to get relay parent header from hash: {relay_parent}."); } tracing::info!( diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs b/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs index 42ff82acc8364..6ef5442c60c65 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs @@ -173,6 +173,8 @@ pub fn run(collator_task_params,export_pov); let block_builder_params = block_builder_task::BuilderTaskParams { diff --git a/cumulus/client/consensus/aura/src/lib.rs b/cumulus/client/consensus/aura/src/lib.rs index 0e404541ab9a6..175e409f53f2e 100644 --- a/cumulus/client/consensus/aura/src/lib.rs +++ b/cumulus/client/consensus/aura/src/lib.rs @@ -23,7 +23,7 @@ //! //! For more information about AuRa, the Substrate crate should be checked. -use codec::Codec; +use codec::{Codec, Encode}; use cumulus_client_consensus_common::{ ParachainBlockImportMarker, ParachainCandidate, ParachainConsensus, }; @@ -43,18 +43,19 @@ use sp_core::crypto::Pair; use sp_inherents::CreateInherentDataProviders; use sp_keystore::KeystorePtr; use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member, NumberFor}; -use std::{ - convert::TryFrom, - marker::PhantomData, - sync::{ - atomic::{AtomicU64, Ordering}, - Arc, - }, -}; +use std::{convert::TryFrom, fs, marker::PhantomData, sync::{ + atomic::{AtomicU64, Ordering}, + Arc, +}}; +use std::fs::File; +use std::path::PathBuf; +use cumulus_primitives_core::relay_chain::HeadData; +use polkadot_primitives::{BlockNumber as RBlockNumber, Hash as RHash}; 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, @@ -252,3 +253,37 @@ where Some(ParachainCandidate { block: res.block, proof: res.storage_proof }) } } + +/// Export the given `pov` to the file system at `path`. +/// +/// The file will be named `block_hash_block_number.pov`. +/// +/// The `parent_header`, `relay_parent_storage_root` and `relay_parent_number` will also be +/// stored in the file alongside the `pov`. This enables stateless validation of the `pov`. +pub fn export_pov_to_path( + path: PathBuf, + pov: PoV, + block_hash: Block::Hash, + block_number: NumberFor, + parent_header: Block::Header, + relay_parent_storage_root: RHash, + relay_parent_number: RBlockNumber, +) { + 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); + HeadData(parent_header.encode()).encode_to(&mut file); + relay_parent_storage_root.encode_to(&mut file); + relay_parent_number.encode_to(&mut file); +} diff --git a/prdoc/pr_7585.prdoc b/prdoc/pr_7585.prdoc new file mode 100644 index 0000000000000..839e493a95522 --- /dev/null +++ b/prdoc/pr_7585.prdoc @@ -0,0 +1,11 @@ +title: 'Add export PoV on slot base collator' +doc: +- audience: [Node Dev, Node Operator] + description: Add functionality to export Proof of Validity (PoV) based on collator slots. +crates: +- name: cumulus-test-service + bump: patch +- name: cumulus-client-consensus-aura + bump: patch +- name: polkadot-omni-node + bump: patch \ No newline at end of file From 2d4b3e47146896b4e765ecb561a4cbcf757f467f Mon Sep 17 00:00:00 2001 From: MrishoLukamba Date: Fri, 21 Feb 2025 02:51:51 +0300 Subject: [PATCH 3/6] refactored params --- .../collators/slot_based/collation_task.rs | 4 +- .../aura/src/collators/slot_based/mod.rs | 52 ++++++++----------- cumulus/client/consensus/aura/src/lib.rs | 2 +- .../polkadot-omni-node/lib/src/nodes/aura.rs | 11 ++-- cumulus/test/service/src/lib.rs | 10 ++-- prdoc/pr_7585.prdoc | 8 +-- 6 files changed, 38 insertions(+), 49 deletions(-) diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs b/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs index 1bdd194e5af4b..b10d721e42689 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs @@ -53,6 +53,8 @@ pub struct Params { pub collator_receiver: TracingUnboundedReceiver>, /// The handle from the special slot based block import. pub block_import_handle: super::SlotBasedBlockImportHandle, + /// When set, the collator will export every produced `POV` to this folder. + pub export_pov: Option } /// Asynchronously executes the collation task for a parachain. @@ -70,8 +72,8 @@ pub async fn run_collation_task( collator_service, mut collator_receiver, mut block_import_handle, + export_pov }: Params, - export_pov: Option ) where Block: BlockT, CS: CollatorServiceInterface + Send + Sync + 'static, diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs b/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs index 6ef5442c60c65..a4564ad863488 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/mod.rs @@ -101,19 +101,14 @@ pub struct Params, /// Spawner for spawning futures. pub spawner: Spawner, -} - -/// Parameters for slot based aura with export_pov option -pub struct ParamsWithExport { - /// Parameters - pub params: Params, /// When set, the collator will export every produced `POV` to this folder. pub export_pov: Option, } + /// Run aura-based block building and collation task. pub fn run( - params_with_export: ParamsWithExport + params: Params ) where Block: BlockT, Client: ProvideRuntimeApi @@ -140,27 +135,25 @@ pub fn run> + Member + Codec, Spawner: SpawnNamed, { - let ParamsWithExport { - params: Params { - create_inherent_data_providers, - block_import, - para_client, - para_backend, - relay_client, - code_hash_provider, - keystore, - collator_key, - para_id, - proposer, - collator_service, - authoring_duration, - reinitialize, - slot_drift, - block_import_handle, - spawner, - }, + let Params { + create_inherent_data_providers, + block_import, + para_client, + para_backend, + relay_client, + code_hash_provider, + keystore, + collator_key, + para_id, + proposer, + collator_service, + authoring_duration, + reinitialize, + slot_drift, + block_import_handle, + spawner, export_pov - } = params_with_export; + } = params; let (tx, rx) = tracing_unbounded("mpsc_builder_to_collator", 100); let collator_task_params = collation_task::Params { @@ -171,11 +164,10 @@ pub fn run(collator_task_params,export_pov); + let collation_task_fut = run_collation_task::(collator_task_params); let block_builder_params = block_builder_task::BuilderTaskParams { create_inherent_data_providers, diff --git a/cumulus/client/consensus/aura/src/lib.rs b/cumulus/client/consensus/aura/src/lib.rs index 175e409f53f2e..a748406c53373 100644 --- a/cumulus/client/consensus/aura/src/lib.rs +++ b/cumulus/client/consensus/aura/src/lib.rs @@ -260,7 +260,7 @@ where /// /// The `parent_header`, `relay_parent_storage_root` and `relay_parent_number` will also be /// stored in the file alongside the `pov`. This enables stateless validation of the `pov`. -pub fn export_pov_to_path( +pub(crate) fn export_pov_to_path( path: PathBuf, pov: PoV, block_hash: Block::Hash, diff --git a/cumulus/polkadot-omni-node/lib/src/nodes/aura.rs b/cumulus/polkadot-omni-node/lib/src/nodes/aura.rs index 771b8cb060cbe..478cf92a75b6c 100644 --- a/cumulus/polkadot-omni-node/lib/src/nodes/aura.rs +++ b/cumulus/polkadot-omni-node/lib/src/nodes/aura.rs @@ -35,7 +35,7 @@ use cumulus_client_collator::service::{ }; #[docify::export(slot_based_colator_import)] use cumulus_client_consensus_aura::collators::slot_based::{ - self as slot_based, Params as SlotBasedParams, ParamsWithExport as SlotBasedParamsWithExport + self as slot_based, Params as SlotBasedParams }; use cumulus_client_consensus_aura::{ collators::{ @@ -250,7 +250,7 @@ where { #[docify::export_content] fn launch_slot_based_collator( - params_with_export: SlotBasedParamsWithExport< + params_with_export: SlotBasedParams< Block, ParachainBlockImport< Block, @@ -358,16 +358,13 @@ where slot_drift: Duration::from_secs(1), block_import_handle, spawner: task_manager.spawn_handle(), + export_pov: node_extra_args.export_pov }; // We have a separate function only to be able to use `docify::export` on this piece of // code. - let params_with_export = SlotBasedParamsWithExport { - params, - export_pov: node_extra_args.export_pov - }; - Self::launch_slot_based_collator(params_with_export); + Self::launch_slot_based_collator(params); Ok(()) } diff --git a/cumulus/test/service/src/lib.rs b/cumulus/test/service/src/lib.rs index 36c4fbd0627eb..524aa79fd2353 100644 --- a/cumulus/test/service/src/lib.rs +++ b/cumulus/test/service/src/lib.rs @@ -29,7 +29,7 @@ use cumulus_client_consensus_aura::{ lookahead::{self as aura, Params as AuraParams}, slot_based::{ self as slot_based, Params as SlotBasedParams, SlotBasedBlockImport, - SlotBasedBlockImportHandle, ParamsWithExport as SlotBasedParamsWithExport + SlotBasedBlockImportHandle }, }, ImportQueueParams, @@ -506,12 +506,10 @@ where slot_drift: Duration::from_secs(1), block_import_handle: slot_based_handle, spawner: task_manager.spawn_handle(), + export_pov: None }; - let params_with_export = SlotBasedParamsWithExport { - params, - None - }; - slot_based::run::(params_with_export); + + slot_based::run::(params); } else { tracing::info!(target: LOG_TARGET, "Starting block authoring with lookahead collator."); let params = AuraParams { diff --git a/prdoc/pr_7585.prdoc b/prdoc/pr_7585.prdoc index 839e493a95522..7edc9025dff75 100644 --- a/prdoc/pr_7585.prdoc +++ b/prdoc/pr_7585.prdoc @@ -1,11 +1,11 @@ title: 'Add export PoV on slot base collator' doc: - audience: [Node Dev, Node Operator] - description: Add functionality to export Proof of Validity (PoV) based on collator slots. + description: Add functionality to export the Proof of Validity (PoV) when the slot-based collator is used. crates: - name: cumulus-test-service - bump: patch + bump: major - name: cumulus-client-consensus-aura - bump: patch + bump: major - name: polkadot-omni-node - bump: patch \ No newline at end of file + bump: major \ No newline at end of file From 9bcc0f4d857237c494b69499ea99e9d1f81ffa12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 21 Feb 2025 18:24:13 +0100 Subject: [PATCH 4/6] Update cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs --- .../consensus/aura/src/collators/slot_based/collation_task.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs b/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs index b10d721e42689..f4304fcede99e 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs @@ -161,7 +161,7 @@ async fn handle_collation_message Date: Fri, 21 Feb 2025 17:27:35 +0000 Subject: [PATCH 5/6] Update from bkchr running command 'fmt' --- .../consensus/aura/src/collators/lookahead.rs | 12 +++-------- .../collators/slot_based/collation_task.rs | 21 ++++++++++--------- .../aura/src/collators/slot_based/mod.rs | 10 ++++----- cumulus/client/consensus/aura/src/lib.rs | 21 ++++++++++++------- .../polkadot-omni-node/lib/src/nodes/aura.rs | 8 ++++--- cumulus/test/service/src/lib.rs | 4 ++-- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/cumulus/client/consensus/aura/src/collators/lookahead.rs b/cumulus/client/consensus/aura/src/collators/lookahead.rs index 9ba568f0d9719..17c4059b11466 100644 --- a/cumulus/client/consensus/aura/src/collators/lookahead.rs +++ b/cumulus/client/consensus/aura/src/collators/lookahead.rs @@ -44,10 +44,10 @@ use polkadot_node_primitives::SubmitCollationParams; use polkadot_node_subsystem::messages::CollationGenerationMessage; use polkadot_overseer::Handle as OverseerHandle; use polkadot_primitives::{ - vstaging::DEFAULT_CLAIM_QUEUE_OFFSET, CollatorPair, - Id as ParaId, OccupiedCoreAssumption, + vstaging::DEFAULT_CLAIM_QUEUE_OFFSET, CollatorPair, Id as ParaId, OccupiedCoreAssumption, }; +use crate::{collator as collator_util, export_pov_to_path}; use futures::prelude::*; use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf}; use sc_consensus::BlockImport; @@ -59,13 +59,7 @@ use sp_core::crypto::Pair; use sp_inherents::CreateInherentDataProviders; use sp_keystore::KeystorePtr; use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member}; -use std::{ - path::PathBuf, - sync::Arc, - time::Duration, -}; -use crate::{collator as collator_util, export_pov_to_path}; - +use std::{path::PathBuf, sync::Arc, time::Duration}; /// Parameters for [`run`]. pub struct Params { diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs b/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs index f4304fcede99e..17019a105c241 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs @@ -15,8 +15,8 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . -use std::path::PathBuf; use codec::Encode; +use std::path::PathBuf; use cumulus_client_collator::service::ServiceInterface as CollatorServiceInterface; use cumulus_relay_chain_interface::RelayChainInterface; @@ -26,12 +26,12 @@ use polkadot_node_subsystem::messages::CollationGenerationMessage; use polkadot_overseer::Handle as OverseerHandle; use polkadot_primitives::{CollatorPair, Id as ParaId}; -use futures::prelude::*; use cumulus_primitives_core::relay_chain::BlockId; +use futures::prelude::*; +use crate::export_pov_to_path; use sc_utils::mpsc::TracingUnboundedReceiver; use sp_runtime::traits::{Block as BlockT, Header}; -use crate::export_pov_to_path; use super::CollatorMessage; @@ -54,7 +54,7 @@ pub struct Params { /// The handle from the special slot based block import. pub block_import_handle: super::SlotBasedBlockImportHandle, /// When set, the collator will export every produced `POV` to this folder. - pub export_pov: Option + pub export_pov: Option, } /// Asynchronously executes the collation task for a parachain. @@ -72,7 +72,7 @@ pub async fn run_collation_task( collator_service, mut collator_receiver, mut block_import_handle, - export_pov + export_pov, }: Params, ) where Block: BlockT, @@ -118,7 +118,7 @@ async fn handle_collation_message, overseer_handle: &mut OverseerHandle, relay_client: RClient, - export_pov: Option + export_pov: Option, ) { let CollatorMessage { parent_header, @@ -148,9 +148,10 @@ async fn handle_collation_message( pov_path.clone(), pov.clone(), @@ -158,9 +159,9 @@ async fn handle_collation_message, } - /// Run aura-based block building and collation task. pub fn run( - params: Params + params: Params, ) where Block: BlockT, Client: ProvideRuntimeApi @@ -152,7 +150,7 @@ pub fn run(collator_task_params); diff --git a/cumulus/client/consensus/aura/src/lib.rs b/cumulus/client/consensus/aura/src/lib.rs index a748406c53373..2e9b4b702344b 100644 --- a/cumulus/client/consensus/aura/src/lib.rs +++ b/cumulus/client/consensus/aura/src/lib.rs @@ -29,7 +29,9 @@ use cumulus_client_consensus_common::{ }; use cumulus_primitives_core::{relay_chain::Hash as PHash, PersistedValidationData}; +use cumulus_primitives_core::relay_chain::HeadData; use futures::lock::Mutex; +use polkadot_primitives::{BlockNumber as RBlockNumber, Hash as RHash}; use sc_client_api::{backend::AuxStore, BlockOf}; use sc_consensus::BlockImport; use sc_consensus_slots::{BackoffAuthoringBlocksStrategy, SimpleSlotWorker, SlotInfo}; @@ -43,14 +45,17 @@ use sp_core::crypto::Pair; use sp_inherents::CreateInherentDataProviders; use sp_keystore::KeystorePtr; use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member, NumberFor}; -use std::{convert::TryFrom, fs, marker::PhantomData, sync::{ - atomic::{AtomicU64, Ordering}, - Arc, -}}; -use std::fs::File; -use std::path::PathBuf; -use cumulus_primitives_core::relay_chain::HeadData; -use polkadot_primitives::{BlockNumber as RBlockNumber, Hash as RHash}; +use std::{ + convert::TryFrom, + fs, + fs::File, + marker::PhantomData, + path::PathBuf, + sync::{ + atomic::{AtomicU64, Ordering}, + Arc, + }, +}; mod import_queue; diff --git a/cumulus/polkadot-omni-node/lib/src/nodes/aura.rs b/cumulus/polkadot-omni-node/lib/src/nodes/aura.rs index 478cf92a75b6c..60c75464ae3ec 100644 --- a/cumulus/polkadot-omni-node/lib/src/nodes/aura.rs +++ b/cumulus/polkadot-omni-node/lib/src/nodes/aura.rs @@ -35,7 +35,7 @@ use cumulus_client_collator::service::{ }; #[docify::export(slot_based_colator_import)] use cumulus_client_consensus_aura::collators::slot_based::{ - self as slot_based, Params as SlotBasedParams + self as slot_based, Params as SlotBasedParams, }; use cumulus_client_consensus_aura::{ collators::{ @@ -277,7 +277,9 @@ where CS: CollatorServiceInterface + Send + Sync + Clone + 'static, Spawner: SpawnNamed, { - slot_based::run::::Pair, _, _, _, _, _, _, _, _, _>(params_with_export); + slot_based::run::::Pair, _, _, _, _, _, _, _, _, _>( + params_with_export, + ); } } @@ -358,7 +360,7 @@ where slot_drift: Duration::from_secs(1), block_import_handle, spawner: task_manager.spawn_handle(), - export_pov: node_extra_args.export_pov + export_pov: node_extra_args.export_pov, }; // We have a separate function only to be able to use `docify::export` on this piece of diff --git a/cumulus/test/service/src/lib.rs b/cumulus/test/service/src/lib.rs index 524aa79fd2353..075258fe25b98 100644 --- a/cumulus/test/service/src/lib.rs +++ b/cumulus/test/service/src/lib.rs @@ -29,7 +29,7 @@ use cumulus_client_consensus_aura::{ lookahead::{self as aura, Params as AuraParams}, slot_based::{ self as slot_based, Params as SlotBasedParams, SlotBasedBlockImport, - SlotBasedBlockImportHandle + SlotBasedBlockImportHandle, }, }, ImportQueueParams, @@ -506,7 +506,7 @@ where slot_drift: Duration::from_secs(1), block_import_handle: slot_based_handle, spawner: task_manager.spawn_handle(), - export_pov: None + export_pov: None, }; slot_based::run::(params); From ac16055bd06d12f22a93e10c05dcf1a341fe0d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Sat, 22 Feb 2025 17:22:13 +0100 Subject: [PATCH 6/6] Apply suggestions from code review --- .../consensus/aura/src/collators/slot_based/collation_task.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs b/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs index 17019a105c241..d92cfb044b836 100644 --- a/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs +++ b/cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs @@ -162,7 +162,7 @@ async fn handle_collation_message