From a5e41db4b1f98ebfe65a542f210fe74911cb94fc Mon Sep 17 00:00:00 2001 From: Philippe McLean Date: Thu, 5 Dec 2024 10:39:47 -0800 Subject: [PATCH] report mempool fetched and missing counts to prometheus --- src/new_index/mempool.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/new_index/mempool.rs b/src/new_index/mempool.rs index 4ccd4cd59..dfd642848 100644 --- a/src/new_index/mempool.rs +++ b/src/new_index/mempool.rs @@ -497,6 +497,7 @@ impl Mempool { // Continuously attempt to fetch mempool transactions until we're able to get them in full let mut fetched_txs = HashMap::::new(); let mut indexed_txids = mempool.read().unwrap().txids_set(); + loop { // Get bitcoind's current list of mempool txids let all_txids = daemon @@ -520,12 +521,24 @@ impl Mempool { if new_txids.is_empty() { break; } + + let all_txs_count = all_txids.len(); + let fetched_txs_count = indexed_txids.len() + fetched_txs.len(); + let new_txs_count = new_txids.len(); + debug!( "mempool with total {} txs, {} fetched, {} missing", - all_txids.len(), - indexed_txids.len() + fetched_txs.len(), - new_txids.len() + all_txs_count, + fetched_txs_count, + new_txs_count ); + + let counter = &mempool.write().unwrap().count; + + counter.with_label_values(&["txs"]).set(all_txs_count as f64); + counter.with_label_values(&["fetched"]).set(fetched_txs_count as f64); + counter.with_label_values(&["missing"]).set(new_txs_count as f64); + let new_txs = daemon.gettransactions_available(&new_txids)?; // Abort if the chain tip moved while fetching transactions @@ -554,11 +567,6 @@ impl Mempool { mempool.add(fetched_txs)?; - mempool - .count - .with_label_values(&["txs"]) - .set(mempool.txstore.len() as f64); - // Update cached backlog stats (if expired) if mempool.backlog_stats.1.elapsed() > Duration::from_secs(BACKLOG_STATS_TTL) { mempool.update_backlog_stats();