diff --git a/zebra-network/src/peer/client.rs b/zebra-network/src/peer/client.rs index bf26a2b5..668fcd62 100644 --- a/zebra-network/src/peer/client.rs +++ b/zebra-network/src/peer/client.rs @@ -87,6 +87,15 @@ pub(super) struct MustUseOneshotSender { pub tx: Option>, } +impl std::fmt::Debug for Client { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + // skip the channels, they don't tell us anything useful + f.debug_struct("Client") + .field("error_slot", &self.error_slot) + .finish() + } +} + impl From for InProgressClientRequest { fn from(client_request: ClientRequest) -> Self { let ClientRequest { request, tx, span } = client_request; diff --git a/zebra-network/src/peer/error.rs b/zebra-network/src/peer/error.rs index 5311e677..ab1c36db 100644 --- a/zebra-network/src/peer/error.rs +++ b/zebra-network/src/peer/error.rs @@ -74,6 +74,16 @@ pub enum PeerError { #[derive(Default, Clone)] pub(super) struct ErrorSlot(Arc>>); +impl std::fmt::Debug for ErrorSlot { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + // don't hang if the mutex is locked + // show the panic if the mutex was poisoned + f.debug_struct("ErrorSlot") + .field("error", &self.0.try_lock()) + .finish() + } +} + impl ErrorSlot { /// Read the current error in the slot. /// diff --git a/zebra-network/src/peer_set/initialize.rs b/zebra-network/src/peer_set/initialize.rs index f8020444..d36f253f 100644 --- a/zebra-network/src/peer_set/initialize.rs +++ b/zebra-network/src/peer_set/initialize.rs @@ -195,7 +195,16 @@ where S: Service, Error = BoxError> + Clone, S::Future: Send + 'static, { - info!(?initial_peers, "connecting to initial peer set"); + let initial_peer_count = initial_peers.len(); + let mut handshake_success_total: usize = 0; + let mut handshake_error_total: usize = 0; + + info!( + ?initial_peer_count, + ?initial_peers, + "connecting to initial peer set" + ); + // # Security // // TODO: rate-limit initial seed peer connections (#2326) @@ -217,13 +226,38 @@ where .collect(); while let Some(handshake_result) = handshakes.next().await { - // this is verbose, but it's better than just hanging with no output - if let Err((addr, ref e)) = handshake_result { - info!(?addr, ?e, "an initial peer connection failed"); + match handshake_result { + Ok(ref change) => { + handshake_success_total += 1; + debug!( + ?handshake_success_total, + ?handshake_error_total, + ?change, + "an initial peer handshake succeeded" + ); + } + Err((addr, ref e)) => { + // this is verbose, but it's better than just hanging with no output when there are errors + handshake_error_total += 1; + info!( + ?handshake_success_total, + ?handshake_error_total, + ?addr, + ?e, + "an initial peer connection failed" + ); + } } + tx.send(handshake_result.map_err(|(_addr, e)| e)).await?; } + info!( + ?handshake_success_total, + ?handshake_error_total, + "finished connecting to initial seed peers" + ); + Ok(()) }