From 82a20778fdc1fcfb51db28bbc9d81955ca4eafdc Mon Sep 17 00:00:00 2001 From: Sergei Shulepov Date: Thu, 4 Feb 2021 10:02:20 +0100 Subject: [PATCH] Diagnostics quality of life improvements (#2375) * Implement `Debug` manually for CandidateHash This will make candidate hashes printed consistently without the `CandidateHash(` and `)` decorations. * Do not print CompressedPov's guts It can be overwhelming. Better just use the size. * Log when candidate is generated * Print para_id and candidate_hash upon receiving a collation --- polkadot/core-primitives/src/lib.rs | 8 +++++++- polkadot/node/collation-generation/src/lib.rs | 8 ++++++++ .../node/network/collator-protocol/src/validator_side.rs | 3 +++ polkadot/node/network/protocol/src/lib.rs | 8 +++++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/polkadot/core-primitives/src/lib.rs b/polkadot/core-primitives/src/lib.rs index 96d4c00399..e02c3f51b6 100644 --- a/polkadot/core-primitives/src/lib.rs +++ b/polkadot/core-primitives/src/lib.rs @@ -60,7 +60,7 @@ pub type Hash = sp_core::H256; /// This type is produced by [`CandidateReceipt::hash`]. /// /// This type makes it easy to enforce that a hash is a candidate hash on the type level. -#[derive(Clone, Copy, Encode, Decode, Hash, Eq, PartialEq, Debug, Default)] +#[derive(Clone, Copy, Encode, Decode, Hash, Eq, PartialEq, Default)] #[cfg_attr(feature = "std", derive(MallocSizeOf))] pub struct CandidateHash(pub Hash); @@ -71,6 +71,12 @@ impl std::fmt::Display for CandidateHash { } } +impl sp_std::fmt::Debug for CandidateHash { + fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result { + write!(f, "{:?}", self.0) + } +} + /// Index of a transaction in the relay chain. 32-bit should be plenty. pub type Nonce = u32; diff --git a/polkadot/node/collation-generation/src/lib.rs b/polkadot/node/collation-generation/src/lib.rs index a07537f244..09f3db3fd0 100644 --- a/polkadot/node/collation-generation/src/lib.rs +++ b/polkadot/node/collation-generation/src/lib.rs @@ -337,6 +337,14 @@ async fn handle_new_activations( }, }; + tracing::debug!( + target: LOG_TARGET, + candidate_hash = %ccr.hash(), + ?pov_hash, + ?relay_parent, + para_id = %scheduled_core.para_id, + "candidate is generated", + ); metrics.on_collation_generated(); if let Err(err) = task_sender.send(AllMessages::CollatorProtocol( diff --git a/polkadot/node/network/collator-protocol/src/validator_side.rs b/polkadot/node/network/collator-protocol/src/validator_side.rs index f8a90f136b..a53bdf4a17 100644 --- a/polkadot/node/network/collator-protocol/src/validator_side.rs +++ b/polkadot/node/network/collator-protocol/src/validator_side.rs @@ -387,6 +387,9 @@ where tracing::debug!( target: LOG_TARGET, %request_id, + ?para_id, + ?relay_parent, + candidate_hash = ?receipt.hash(), "Received collation", ); diff --git a/polkadot/node/network/protocol/src/lib.rs b/polkadot/node/network/protocol/src/lib.rs index 82a6f7cb04..81bd80f527 100644 --- a/polkadot/node/network/protocol/src/lib.rs +++ b/polkadot/node/network/protocol/src/lib.rs @@ -327,7 +327,7 @@ pub mod v1 { } /// SCALE and Zstd encoded [`PoV`]. - #[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)] + #[derive(Clone, Encode, Decode, PartialEq, Eq)] pub struct CompressedPoV(Vec); impl CompressedPoV { @@ -374,6 +374,12 @@ pub mod v1 { } } + impl std::fmt::Debug for CompressedPoV { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "CompressedPoV({} bytes)", self.0.len()) + } + } + /// Network messages used by the collator protocol subsystem #[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)] pub enum CollatorProtocolMessage {