From 8b81a2f806bd91baced8ded84ef8f4f2c2b4b3ff Mon Sep 17 00:00:00 2001 From: Simon B Date: Mon, 11 Dec 2017 15:38:46 +0100 Subject: [PATCH] Seed debug outputs cleanup (#460) * DRY up * iterate 66% less * clarify debug! outputs * less verbose peer queuing Rationale: debug outputs that happen _a lot_ is nice if they're short and distinct, making them easier to pattern match / willfully ignore while reading through logs * update comment to mention last weeks' added usecases * .push() less --- grin/src/seed.rs | 32 ++++++++++++++------------------ p2p/src/store.rs | 13 +++++-------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/grin/src/seed.rs b/grin/src/seed.rs index 80578e723..4e6cca914 100644 --- a/grin/src/seed.rs +++ b/grin/src/seed.rs @@ -84,32 +84,28 @@ impl Seeder { let mon_loop = Timer::default() .interval(time::Duration::from_secs(30)) .for_each(move |_| { + let total_count = p2p_server.all_peers().len(); debug!( LOGGER, - "monitor_peers: {} / {} / {}", + "monitor_peers: {} most_work_peers, {} connected, {} total known", p2p_server.most_work_peers().len(), p2p_server.connected_peers().len(), - p2p_server.all_peers().len(), + total_count, ); - let all_peers = p2p_server.all_peers(); - let healthy_count = all_peers - .iter() - .filter(|x| x.flags == p2p::State::Healthy) - .count(); - let banned_count = all_peers - .iter() - .filter(|x| x.flags == p2p::State::Banned) - .count(); - let defunct_count = all_peers - .iter() - .filter(|x| x.flags == p2p::State::Defunct) - .count(); + let mut healthy_count = 0; + let mut banned_count = 0; + let mut defunct_count = 0; + for x in p2p_server.all_peers() { + if x.flags == p2p::State::Healthy { healthy_count += 1 } + else if x.flags == p2p::State::Banned { banned_count += 1 } + else if x.flags == p2p::State::Defunct { defunct_count += 1 }; + } debug!( LOGGER, - "monitor_peers: all - {}, healthy - {}, banned - {}, defunct - {}", - all_peers.len(), + "monitor_peers: all {} = {} healthy + {} banned + {} defunct", + total_count, healthy_count, banned_count, defunct_count, @@ -150,7 +146,7 @@ impl Seeder { for p in peers { debug!( LOGGER, - "monitor_peers: queueing up {} for connection (may be already connected)", + "monitor_peers: queue to soon try {}", p.addr, ); tx.unbounded_send(p.addr).unwrap(); diff --git a/p2p/src/store.rs b/p2p/src/store.rs index cf03e391b..4cb77c111 100644 --- a/p2p/src/store.rs +++ b/p2p/src/store.rs @@ -122,15 +122,12 @@ impl PeerStore { peers.iter().take(count).cloned().collect() } - /// List all known peers (for the /v1/peers api endpoint) + /// List all known peers + /// Used for /v1/peers, for seed / sync (debug & if too few peers connected) pub fn all_peers(&self) -> Vec { - let peers_iter = self.db - .iter::(&to_key(PEER_PREFIX, &mut "".to_string().into_bytes())); - let mut peers = vec![]; - for p in peers_iter { - peers.push(p); - } - peers + self.db + .iter::(&to_key(PEER_PREFIX, &mut "".to_string().into_bytes())) + .collect::>() } /// Convenience method to load a peer data, update its status and save it