Skip to content

Commit

Permalink
report mempool fetched and missing counts to prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
philippem committed Dec 5, 2024
1 parent dca8c59 commit a5e41db
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/new_index/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Txid, Transaction>::new();
let mut indexed_txids = mempool.read().unwrap().txids_set();

loop {
// Get bitcoind's current list of mempool txids
let all_txids = daemon
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a5e41db

Please sign in to comment.