diff --git a/polkadot/node/network/collator-protocol/src/collator_side/metrics.rs b/polkadot/node/network/collator-protocol/src/collator_side/metrics.rs index 9144eafd1511e..b726a40e4b3e8 100644 --- a/polkadot/node/network/collator-protocol/src/collator_side/metrics.rs +++ b/polkadot/node/network/collator-protocol/src/collator_side/metrics.rs @@ -295,19 +295,27 @@ impl CollationTracker { receipt: CandidateReceipt, ) { let head = receipt.descriptor.para_head(); + let para_id = receipt.descriptor.para_id(); let Some(entry) = self.entries.get_mut(&head) else { gum::debug!( target: crate::LOG_TARGET_STATS, + ?para_id, ?head, "Included collation not found in tracker", ); return; }; + let pov_hash = entry.pov_hash(); + let candidate_hash = entry.candidate_hash(); + if entry.included().is_some() { gum::debug!( target: crate::LOG_TARGET_STATS, + ?para_id, ?head, + ?candidate_hash, + ?pov_hash, "Collation already included in a fork, skipping", ); return @@ -320,8 +328,10 @@ impl CollationTracker { ?latency, relay_block = ?leaf, relay_parent = ?entry.relay_parent, - para_id = ?receipt.descriptor.para_id(), - head = ?receipt.descriptor.para_head(), + ?para_id, + ?head, + ?candidate_hash, + ?pov_hash, "Collation included on relay chain", ); } @@ -412,6 +422,10 @@ pub(crate) struct CollationStats { /// The collation backing latency (seconds). Duration since collation fetched /// until the import of a relay chain block where collation is backed. backed_latency_metric: Option, + /// The Collation candidate hash + candidate_hash: Hash, + /// The Collation PoV hash + pov_hash: Hash, } impl CollationStats { @@ -421,6 +435,8 @@ impl CollationStats { relay_parent_number: BlockNumber, relay_parent: Hash, metrics: &Metrics, + candidate_hash: Hash, + pov_hash: Hash, ) -> Self { Self { pre_backing_status: CollationStatus::Created, @@ -434,6 +450,8 @@ impl CollationStats { included_at: None, fetch_latency_metric: metrics.time_collation_fetch_latency(), backed_latency_metric: None, + candidate_hash, + pov_hash, } } @@ -472,6 +490,16 @@ impl CollationStats { self.head } + /// Get candidate hash. + pub fn candidate_hash(&self) -> H256 { + self.candidate_hash + } + + /// Get candidate PoV hash. + pub fn pov_hash(&self) -> H256 { + self.pov_hash + } + /// Set the timestamp at which collation is fetched. pub fn set_fetched_at(&mut self, fetched_at: Instant) { self.fetched_at = Some(fetched_at); diff --git a/polkadot/node/network/collator-protocol/src/collator_side/mod.rs b/polkadot/node/network/collator-protocol/src/collator_side/mod.rs index d9e5c0955996c..533a771fc987f 100644 --- a/polkadot/node/network/collator-protocol/src/collator_side/mod.rs +++ b/polkadot/node/network/collator-protocol/src/collator_side/mod.rs @@ -516,6 +516,7 @@ async fn distribute_collation( } let para_head = receipt.descriptor.para_head(); + let pov_hash = pov.hash(); per_relay_parent.collations.insert( candidate_hash, CollationData { @@ -527,9 +528,16 @@ async fn distribute_collation( }, core_index, session_index, - stats: per_relay_parent - .block_number - .map(|n| CollationStats::new(para_head, n, candidate_relay_parent, &state.metrics)), + stats: per_relay_parent.block_number.map(|n| { + CollationStats::new( + para_head, + n, + candidate_relay_parent, + &state.metrics, + *candidate_hash, + pov_hash, + ) + }), }, ); @@ -1533,6 +1541,8 @@ fn process_expired_collations( for expired_collation in expired_collations { let collation_state = expired_collation.expiry_state(); let age = expired_collation.expired().unwrap_or_default(); + let candidate_hash = expired_collation.candidate_hash(); + let pov_hash = expired_collation.pov_hash(); gum::debug!( target: crate::LOG_TARGET_STATS, ?age, @@ -1540,6 +1550,8 @@ fn process_expired_collations( relay_parent = ?removed, ?para_id, head = ?expired_collation.head(), + ?candidate_hash, + ?pov_hash, "Collation expired", ); diff --git a/prdoc/pr_9927.prdoc b/prdoc/pr_9927.prdoc new file mode 100644 index 0000000000000..a1262ecd785b7 --- /dev/null +++ b/prdoc/pr_9927.prdoc @@ -0,0 +1,13 @@ +title: 'Log: log `candidate_hash` nor the `pov_hash` when collations expire' +doc: +- audience: Node Dev + description: |- + When collations expire we do not log the `candidate_hash` nor the `pov_hash`, making it hard to map the + logged entries about Candidate generated and Candidate expired together. + + This PR adds `pov_hash` and `candidate_hash` to the CollationStats struct and use these fields when we + log "Collation expired". + +crates: +- name: polkadot-collator-protocol + bump: patch