From acc05bb8c2a3c73749b8b2fffd35508b9d4eeb77 Mon Sep 17 00:00:00 2001 From: James Dorfman Date: Wed, 27 Mar 2024 22:03:53 +0000 Subject: [PATCH] remove stale mempool txs before fetching new ones (and possibly failing) --- src/new_index/mempool.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/new_index/mempool.rs b/src/new_index/mempool.rs index 3b71db603..491404b9e 100644 --- a/src/new_index/mempool.rs +++ b/src/new_index/mempool.rs @@ -510,6 +510,10 @@ impl Mempool { .chain_err(|| "failed to update mempool from daemon")?; let to_remove: HashSet<&Txid> = old_txids.difference(&new_txids).collect(); + // 2. Remove missing transactions. Even if we are unable to download new transactions from + // the daemon, we still want to remove the transactions that are no longer in the mempool. + mempool.write().unwrap().remove(to_remove); + // 2. Download the new transactions from the daemon's mempool let to_add = Mempool::download_new_mempool_txs(&daemon, &old_txids, &new_txids)?; @@ -518,8 +522,6 @@ impl Mempool { let mut mempool = mempool.write().unwrap(); // Add new transactions mempool.add(to_add); - // Remove missing transactions - mempool.remove(to_remove); mempool.count .with_label_values(&["txs"])