From d0cbf3111a9569eef28be5277dc7b8d5883a00fd Mon Sep 17 00:00:00 2001 From: divma Date: Sun, 22 Nov 2020 23:58:23 +0000 Subject: [PATCH] move sync state to the chains KV (#1940) ## Issue Addressed we have a log saying we add a peer to a chain, and an another one in case the chain is not syncing. To avoid needing to peer there two (and reduce log entries) simply log the chain's syncing state in the chain's KV --- .../network/src/sync/range_sync/chain.rs | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/beacon_node/network/src/sync/range_sync/chain.rs b/beacon_node/network/src/sync/range_sync/chain.rs index d850c3d1c..c1b374f67 100644 --- a/beacon_node/network/src/sync/range_sync/chain.rs +++ b/beacon_node/network/src/sync/range_sync/chain.rs @@ -31,6 +31,7 @@ const BATCH_BUFFER_SIZE: u8 = 5; pub type ProcessingResult = Result; /// Reasons for removing a chain +#[derive(Debug)] pub enum RemoveChain { EmptyPeerPool, ChainCompleted, @@ -101,7 +102,7 @@ pub struct SyncingChain { log: slog::Logger, } -#[derive(PartialEq)] +#[derive(PartialEq, Debug)] pub enum ChainSyncingState { /// The chain is not being synced. Stopped, @@ -764,9 +765,6 @@ impl SyncingChain { network: &mut SyncNetworkContext, peer_id: PeerId, ) -> ProcessingResult { - if let ChainSyncingState::Stopped = self.state { - debug!(self.log, "Peer added to non-syncing chain"; "peer" => %peer_id) - } // add the peer without overwriting its active requests if self.peers.entry(peer_id).or_default().is_empty() { // Either new or not, this peer is idle, try to request more batches @@ -1041,6 +1039,7 @@ impl slog::KV for SyncingChain { serializer.emit_usize("batches", self.batches.len())?; serializer.emit_usize("peers", self.peers.len())?; serializer.emit_u8("validated_batches", self.validated_batches)?; + serializer.emit_arguments("state", &format_args!("{:?}", self.state))?; slog::Result::Ok(()) } } @@ -1052,19 +1051,6 @@ impl From for RemoveChain { } } -impl std::fmt::Debug for RemoveChain { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - // needed to avoid Debugging Strings - match self { - RemoveChain::ChainCompleted => f.write_str("ChainCompleted"), - RemoveChain::EmptyPeerPool => f.write_str("EmptyPeerPool"), - RemoveChain::ChainFailed(batch) => write!(f, "ChainFailed(batch: {} )", batch), - RemoveChain::WrongBatchState(reason) => write!(f, "WrongBatchState: {}", reason), - RemoveChain::WrongChainState(reason) => write!(f, "WrongChainState: {}", reason), - } - } -} - impl RemoveChain { pub fn is_critical(&self) -> bool { matches!(