From 176923a7713e4a2d0d3a59f7075b81dd21adde72 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 26 Nov 2020 17:26:10 +1000 Subject: [PATCH] Add an info-level log when UTXO requests are pruned (#1396) And a debug-level log when no requests are pruned. I'm seeing some hangs during the initial sync, these logs might help identify the cause. --- zebra-state/src/service.rs | 19 +++++++++++++++++++ zebra-state/src/service/pending_utxos.rs | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/zebra-state/src/service.rs b/zebra-state/src/service.rs index 07daf6c23..bb368eaf7 100644 --- a/zebra-state/src/service.rs +++ b/zebra-state/src/service.rs @@ -374,8 +374,27 @@ impl Service for StateService { let now = Instant::now(); if self.last_prune + Self::PRUNE_INTERVAL < now { + let tip = self.tip(); + let old_len = self.pending_utxos.len(); + self.pending_utxos.prune(); self.last_prune = now; + + let new_len = self.pending_utxos.len(); + let prune_count = old_len + .checked_sub(new_len) + .expect("prune does not add any utxo requests"); + if prune_count > 0 { + tracing::info!( + ?old_len, + ?new_len, + ?prune_count, + ?tip, + "pruned utxo requests" + ); + } else { + tracing::debug!(len = ?old_len, ?tip, "no utxo requests needed pruning"); + } } Poll::Ready(Ok(())) diff --git a/zebra-state/src/service/pending_utxos.rs b/zebra-state/src/service/pending_utxos.rs index 4ad38c2b0..277173f7b 100644 --- a/zebra-state/src/service/pending_utxos.rs +++ b/zebra-state/src/service/pending_utxos.rs @@ -61,4 +61,9 @@ impl PendingUtxos { pub fn prune(&mut self) { self.0.retain(|_, chan| chan.receiver_count() > 0); } + + /// Returns the number of utxos that are being waited on. + pub fn len(&self) -> usize { + self.0.len() + } }