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
This commit is contained in:
Simon B 2017-12-11 15:38:46 +01:00 committed by AntiochP
parent 18fc1384de
commit 8b81a2f806
2 changed files with 19 additions and 26 deletions

View file

@ -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();

View file

@ -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<PeerData> {
let peers_iter = self.db
.iter::<PeerData>(&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::<PeerData>(&to_key(PEER_PREFIX, &mut "".to_string().into_bytes()))
.collect::<Vec<_>>()
}
/// Convenience method to load a peer data, update its status and save it