From aa93aa29c7e4a2a50ac71f9e7d86c2253f86d228 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Tue, 14 May 2024 05:58:56 -0400 Subject: [PATCH] remove custom debugs --- .../network/src/sync/block_lookups/mod.rs | 2 +- .../sync/block_lookups/single_block_lookup.rs | 52 +++---------------- 2 files changed, 9 insertions(+), 45 deletions(-) diff --git a/beacon_node/network/src/sync/block_lookups/mod.rs b/beacon_node/network/src/sync/block_lookups/mod.rs index 54120dd9600..22693172755 100644 --- a/beacon_node/network/src/sync/block_lookups/mod.rs +++ b/beacon_node/network/src/sync/block_lookups/mod.rs @@ -683,7 +683,7 @@ impl BlockLookups { if lookup.elapsed_since_created() > Duration::from_secs(LOOKUP_MAX_DURATION_SECS) { debug!(self.log, "Lookup maybe stuck"; // Fields id and block_root are also part of the summary. However, logging them - // here allows log parsers o index them and have better search + // here allows log parsers to index them and have better search "id" => lookup.id, "block_root" => ?lookup.block_root(), "summary" => ?lookup, diff --git a/beacon_node/network/src/sync/block_lookups/single_block_lookup.rs b/beacon_node/network/src/sync/block_lookups/single_block_lookup.rs index 027a8fee9b2..4ce7ac24841 100644 --- a/beacon_node/network/src/sync/block_lookups/single_block_lookup.rs +++ b/beacon_node/network/src/sync/block_lookups/single_block_lookup.rs @@ -4,6 +4,7 @@ use crate::sync::block_lookups::common::RequestState; use crate::sync::block_lookups::Id; use crate::sync::network_context::{LookupRequestResult, SyncNetworkContext}; use beacon_chain::BeaconChainTypes; +use derivative::Derivative; use itertools::Itertools; use rand::seq::IteratorRandom; use std::collections::HashSet; @@ -43,6 +44,8 @@ pub enum LookupRequestError { UnknownLookup, } +#[derive(Derivative)] +#[derivative(Debug(bound = "T: BeaconChainTypes"))] pub struct SingleBlockLookup { pub id: Id, pub block_request_state: BlockRequestState, @@ -270,15 +273,17 @@ impl BlockRequestState { } } -#[derive(Debug, PartialEq, Eq, Clone)] +#[derive(PartialEq, Eq, Clone, Derivative)] +#[derivative(Debug)] pub struct DownloadResult { + #[derivative(Debug = "ignore")] pub value: T, pub block_root: Hash256, pub seen_timestamp: Duration, pub peer_id: PeerId, } -#[derive(PartialEq, Eq, IntoStaticStr)] +#[derive(Debug, PartialEq, Eq, IntoStaticStr)] pub enum State { AwaitingDownload, Downloading, @@ -292,7 +297,7 @@ pub enum State { } /// Object representing the state of a single block or blob lookup request. -#[derive(PartialEq, Eq)] +#[derive(PartialEq, Eq, Debug)] pub struct SingleLookupRequestState { /// State of this request. state: State, @@ -537,44 +542,3 @@ impl std::fmt::Display for State { write!(f, "{}", Into::<&'static str>::into(self)) } } - -// Debug is used in the log_stuck_lookups print to include some more info. Implements custom Debug -// to not dump an entire block or blob to terminal which don't add valuable data. -impl std::fmt::Debug for State { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::AwaitingDownload => write!(f, "AwaitingDownload"), - Self::Downloading => write!(f, "Downloading"), - Self::AwaitingProcess(d) => write!(f, "AwaitingProcess({:?})", d.peer_id), - Self::Processing(d) => write!(f, "Processing({:?})", d.peer_id), - Self::Processed(_) => write!(f, "Processed"), - } - } -} - -// TODO: Manual implementation of Debug, otherwise T must be bounded by Debug -impl std::fmt::Debug for SingleBlockLookup { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("SingleBlockLookup") - .field("id", &self.id) - .field("block_root", &self.block_root) - .field("awaiting_parent", &self.awaiting_parent) - .field("created", &self.created) - .field("block_request_state", &self.block_request_state) - .field("blob_request_state", &self.blob_request_state) - // Log peers once for block and blob requests as are identical - .field("peers", &self.block_request_state.state.available_peers) - .finish() - } -} - -impl std::fmt::Debug for SingleLookupRequestState { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("State") - .field("state", &self.state) - .field("failed_downloading", &self.failed_downloading) - .field("failed_processing", &self.failed_processing) - // Do not log available peers here, do it once in SingleBlockLookup - .finish() - } -}