Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion polkadot/parachain/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,19 @@ pub struct BlockData(#[cfg_attr(feature = "std", serde(with = "bytes"))] pub Vec
Ord,
PartialEq,
PartialOrd,
Debug,
serde::Serialize,
serde::Deserialize,
TypeInfo,
)]
#[cfg_attr(feature = "std", derive(derive_more::Display))]
pub struct Id(u32);

impl core::fmt::Debug for Id {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.0.fmt(f)
}
}

impl codec::EncodeLike<u32> for Id {}
impl codec::EncodeLike<Id> for u32 {}

Expand Down Expand Up @@ -473,3 +478,14 @@ pub struct ValidationResult {
/// processed.
pub hrmp_watermark: RelayChainBlockNumber,
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn para_id_debug() {
let id = Id::new(42);
assert_eq!(format!("{:?}", id), "42");
}
}
14 changes: 14 additions & 0 deletions prdoc/pr_9920.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
title: '[debug]: change impl of Debug of (para)Id to be just "<ID>".'
doc:
- audience: Node Dev
description: |-
The std::fmt::Debug impl (derived) of Id results in "Id(42)" instead of "42", this causes discrepancies in logs.
Sometimes we log "para_id=Id(3392)" but sometimes we log "para_id=3392" (without the "Id()").

This makes e.g. Grafana PromQL queries harder to do, and logs harder to search in general.

This PR changes the impl of Debug to be just "<ID>".

crates:
- name: polkadot-parachain-primitives
bump: patch
Loading