Skip to content

Commit d2418fc

Browse files
jamesdorfmanshesek
authored andcommitted
remove stale mempool txs before fetching new ones (and possibly failing)
1 parent 206fba8 commit d2418fc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/new_index/mempool.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,19 +499,21 @@ impl Mempool {
499499
.chain_err(|| "failed to update mempool from daemon")?;
500500
let txids_to_remove: HashSet<&Txid> = old_txids.difference(&all_txids).collect();
501501

502-
// 2. Download the new transactions from the daemon's mempool
502+
// 2. Remove missing transactions. Even if we are unable to download new transactions from
503+
// the daemon, we still want to remove the transactions that are no longer in the mempool.
504+
mempool.write().unwrap().remove(txids_to_remove);
505+
506+
// 3. Download the new transactions from the daemon's mempool
503507
let new_txids: Vec<&Txid> = all_txids.difference(&old_txids).collect();
504508
let txs_to_add = daemon
505509
.gettransactions(&new_txids)
506510
.chain_err(|| format!("failed to get {} transactions", new_txids.len()))?;
507511

508-
// 3. Update local mempool to match daemon's state
512+
// 4. Update local mempool to match daemon's state
509513
{
510514
let mut mempool = mempool.write().unwrap();
511515
// Add new transactions
512516
mempool.add(txs_to_add);
513-
// Remove missing transactions
514-
mempool.remove(txids_to_remove);
515517

516518
mempool
517519
.count

0 commit comments

Comments
 (0)