From 1f5ee85f8702129d4e89a61566fcbd6485bf5f20 Mon Sep 17 00:00:00 2001 From: Yiannis Marangos Date: Mon, 10 Jun 2024 13:50:50 +0300 Subject: [PATCH 1/2] feat: Change all error/warn logs to debug --- src/cid_prefix.rs | 6 +++--- src/client.rs | 4 ++-- src/incoming_stream.rs | 23 ++++++++++++++++------- src/server.rs | 6 +++--- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/cid_prefix.rs b/src/cid_prefix.rs index 99acdec..3c292fd 100644 --- a/src/cid_prefix.rs +++ b/src/cid_prefix.rs @@ -1,5 +1,5 @@ use cid::{CidGeneric, Version}; -use tracing::error; +use tracing::debug; use crate::multihasher::{MultihasherError, MultihasherTable}; @@ -89,8 +89,8 @@ impl CidPrefix { data: &[u8], ) -> Result, MultihasherError> { if self.multihash_size > S { - error!( - "Multihash<{}> can not hold multihash of size {}", + debug!( + "beetswap error: Multihash<{}> can not hold multihash of size {}", S, self.multihash_size ); return Err(MultihasherError::InvalidMultihashSize); diff --git a/src/client.rs b/src/client.rs index d655d04..58e0c37 100644 --- a/src/client.rs +++ b/src/client.rs @@ -20,7 +20,7 @@ use libp2p_swarm::{ ConnectionHandlerEvent, ConnectionId, NotifyHandler, StreamProtocol, SubstreamProtocol, ToSwarm, }; use smallvec::SmallVec; -use tracing::warn; +use tracing::debug; use crate::incoming_stream::ClientMessage; use crate::message::Codec; @@ -570,7 +570,7 @@ impl ClientConnectionHandler { } fn close_sink_on_error(&mut self, location: &str) { - warn!("sink operation failed, closing: {location}"); + debug!("beetswap error: sink operation failed, closing: {location}"); self.sink_state = SinkState::None; } diff --git a/src/incoming_stream.rs b/src/incoming_stream.rs index 28b458e..8695857 100644 --- a/src/incoming_stream.rs +++ b/src/incoming_stream.rs @@ -8,7 +8,7 @@ use cid::CidGeneric; use fnv::FnvHashMap; use futures_util::future::{BoxFuture, Fuse, FusedFuture, FutureExt}; use futures_util::stream::StreamExt; -use tracing::error; +use tracing::debug; use crate::cid_prefix::CidPrefix; use crate::message::Codec; @@ -87,7 +87,7 @@ impl futures_core::stream::Stream for IncomingStream { let msg = match self.stream.poll_next_unpin(cx) { Poll::Ready(Some(Ok(msg))) => msg, Poll::Ready(Some(Err(e))) => { - error!("Message decoding failed: {e}"); + debug!("beetswap error: Message decoding failed: {e}"); return Poll::Ready(None); } Poll::Ready(None) => return Poll::Ready(None), @@ -116,7 +116,10 @@ async fn process_message( let cid = match CidGeneric::try_from(&block_presence.cid[..]) { Ok(cid) => cid, Err(e) => { - error!("Invalid CID bytes: {}: {:?}", e, block_presence.cid); + debug!( + "beetswap error: Invalid CID bytes: {}: {:?}", + e, block_presence.cid + ); return None; } }; @@ -130,23 +133,29 @@ async fn process_message( for payload in msg.payload { let Some(cid_prefix) = CidPrefix::from_bytes(&payload.prefix) else { - error!("block.prefix not decodable: {:?}", payload.prefix); + debug!( + "beeswap error: block.prefix not decodable: {:?}", + payload.prefix + ); return None; }; let cid = match cid_prefix.to_cid(&multihasher, &payload.data).await { Ok(cid) => cid, Err(MultihasherError::UnknownMultihashCode) => { - error!("Unknown multihash code: {}", cid_prefix.multihash_code()); + debug!( + "beetswap error: Multihasher non-fatal error: Unknown multihash code: {}", + cid_prefix.multihash_code() + ); continue; } Err(MultihasherError::Custom(e)) => { - error!("{e}"); + debug!("beetswap error: Multihasher non-fatal error: {e}"); continue; } // Any other error is fatal and we need to close the stream. Err(e) => { - error!("{e}"); + debug!("beetswap error: Multihasher fatal error: {e}"); return None; } }; diff --git a/src/server.rs b/src/server.rs index e778bdf..96cadc8 100644 --- a/src/server.rs +++ b/src/server.rs @@ -16,7 +16,7 @@ use libp2p_swarm::{ ConnectionHandlerEvent, NotifyHandler, StreamProtocol, SubstreamProtocol, ToSwarm, }; use smallvec::SmallVec; -use tracing::{debug, trace, warn}; +use tracing::{debug, trace}; use crate::incoming_stream::ServerMessage; use crate::message::Codec; @@ -271,7 +271,7 @@ where self.outgoing_queue.push_back((cid, data)); } Err(e) => { - warn!("Fetching {cid} from blockstore failed: {e}"); + debug!("beetswap error: Fetching {cid} from blockstore failed: {e}"); } } } @@ -393,7 +393,7 @@ impl ServerConnectionHandler { } fn close_sink_on_error(&mut self, location: &str) { - warn!("sink operation failed, closing: {location}"); + debug!("beetswap error: sink operation failed, closing: {location}"); self.sink = SinkState::None; } From 1dc2c17fff9d58434aed31a200da0665b3935209 Mon Sep 17 00:00:00 2001 From: Yiannis Marangos Date: Tue, 11 Jun 2024 11:18:56 +0300 Subject: [PATCH 2/2] remove `beetswap error` prefix in messages --- src/cid_prefix.rs | 2 +- src/client.rs | 2 +- src/incoming_stream.rs | 18 ++++++------------ src/server.rs | 4 ++-- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/cid_prefix.rs b/src/cid_prefix.rs index 3c292fd..3a0dfa7 100644 --- a/src/cid_prefix.rs +++ b/src/cid_prefix.rs @@ -90,7 +90,7 @@ impl CidPrefix { ) -> Result, MultihasherError> { if self.multihash_size > S { debug!( - "beetswap error: Multihash<{}> can not hold multihash of size {}", + "Multihash<{}> can not hold multihash of size {}", S, self.multihash_size ); return Err(MultihasherError::InvalidMultihashSize); diff --git a/src/client.rs b/src/client.rs index 58e0c37..e84670f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -570,7 +570,7 @@ impl ClientConnectionHandler { } fn close_sink_on_error(&mut self, location: &str) { - debug!("beetswap error: sink operation failed, closing: {location}"); + debug!("sink operation failed, closing: {location}"); self.sink_state = SinkState::None; } diff --git a/src/incoming_stream.rs b/src/incoming_stream.rs index 8695857..5cb199a 100644 --- a/src/incoming_stream.rs +++ b/src/incoming_stream.rs @@ -87,7 +87,7 @@ impl futures_core::stream::Stream for IncomingStream { let msg = match self.stream.poll_next_unpin(cx) { Poll::Ready(Some(Ok(msg))) => msg, Poll::Ready(Some(Err(e))) => { - debug!("beetswap error: Message decoding failed: {e}"); + debug!("Message decoding failed: {e}"); return Poll::Ready(None); } Poll::Ready(None) => return Poll::Ready(None), @@ -116,10 +116,7 @@ async fn process_message( let cid = match CidGeneric::try_from(&block_presence.cid[..]) { Ok(cid) => cid, Err(e) => { - debug!( - "beetswap error: Invalid CID bytes: {}: {:?}", - e, block_presence.cid - ); + debug!("Invalid CID bytes: {}: {:?}", e, block_presence.cid); return None; } }; @@ -133,10 +130,7 @@ async fn process_message( for payload in msg.payload { let Some(cid_prefix) = CidPrefix::from_bytes(&payload.prefix) else { - debug!( - "beeswap error: block.prefix not decodable: {:?}", - payload.prefix - ); + debug!("block.prefix not decodable: {:?}", payload.prefix); return None; }; @@ -144,18 +138,18 @@ async fn process_message( Ok(cid) => cid, Err(MultihasherError::UnknownMultihashCode) => { debug!( - "beetswap error: Multihasher non-fatal error: Unknown multihash code: {}", + "Multihasher non-fatal error: Unknown multihash code: {}", cid_prefix.multihash_code() ); continue; } Err(MultihasherError::Custom(e)) => { - debug!("beetswap error: Multihasher non-fatal error: {e}"); + debug!("Multihasher non-fatal error: {e}"); continue; } // Any other error is fatal and we need to close the stream. Err(e) => { - debug!("beetswap error: Multihasher fatal error: {e}"); + debug!("Multihasher fatal error: {e}"); return None; } }; diff --git a/src/server.rs b/src/server.rs index 96cadc8..71b45a0 100644 --- a/src/server.rs +++ b/src/server.rs @@ -271,7 +271,7 @@ where self.outgoing_queue.push_back((cid, data)); } Err(e) => { - debug!("beetswap error: Fetching {cid} from blockstore failed: {e}"); + debug!("Fetching {cid} from blockstore failed: {e}"); } } } @@ -393,7 +393,7 @@ impl ServerConnectionHandler { } fn close_sink_on_error(&mut self, location: &str) { - debug!("beetswap error: sink operation failed, closing: {location}"); + debug!("sink operation failed, closing: {location}"); self.sink = SinkState::None; }