Skip to content

Commit 3591add

Browse files
authored
chore: log message id if send queue full instead of full raw message
Fixes #6252 Reduce log size for "Send Queue full" warnings by avoiding printing large message data. Previously, when the send queue was full, the warning log would print the entire `RpcOut` using its `Debug` implementation, which included the complete `RawMessage` with potentially massive byte arrays (`data`, `signature`, `key` fields). In high-traffic scenarios, this resulted in extremely large log files and unnecessary disk I/O. This PR introduces a `RpcLog` wrapper struct with a custom `Debug` implementation that: - For `Publish` and `Forward` variants: logs only the essential debugging information (`message_id`, `topic`, `source`, `sequence_number`, `validated`) while omitting the large byte arrays (`data`, `signature`, `key`, and `timeout`) - For other variants (`Subscribe`, `Unsubscribe`, `Graft`, `Prune`, `IHave`, `IWant`, `IDontWant`): logs normally as they don't contain large data This change significantly reduces log file sizes in high-load scenarios while maintaining all useful debugging information for troubleshooting. Pull-Request: #6263.
1 parent 55e775a commit 3591add

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

protocols/gossipsub/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
## 0.50.0
2+
3+
- Reduce log size by implementing custom Debug for RawMessage that logs data length instead of full byte arrays.
4+
See [PR 6263](https://github.com/libp2p/rust-libp2p/pull/6263)
5+
26
- Log when sending and receiving messages.
37
See [PR 6234](https://github.com/libp2p/rust-libp2p/pull/6234)
48

protocols/gossipsub/src/types.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub enum PeerKind {
123123
}
124124

125125
/// A message received by the gossipsub system and stored locally in caches..
126-
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
126+
#[derive(Clone, PartialEq, Eq, Hash)]
127127
pub struct RawMessage {
128128
/// Id of the peer that published this message.
129129
pub source: Option<PeerId>,
@@ -147,6 +147,20 @@ pub struct RawMessage {
147147
pub validated: bool,
148148
}
149149

150+
impl fmt::Debug for RawMessage {
151+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
152+
f.debug_struct("RawMessage")
153+
.field("source", &self.source)
154+
.field("data length", &self.data.len())
155+
.field("sequence_number", &self.sequence_number)
156+
.field("topic", &self.topic)
157+
.field("signature", &self.signature)
158+
.field("key", &self.key)
159+
.field("validated", &self.validated)
160+
.finish()
161+
}
162+
}
163+
150164
impl PeerKind {
151165
/// Returns true if peer speaks any gossipsub version.
152166
pub(crate) fn is_gossipsub(&self) -> bool {

0 commit comments

Comments
 (0)