From 7c23c1772c8dd3653d4117b23f6288aa90445c7f Mon Sep 17 00:00:00 2001 From: Mykhailo Kremniov Date: Fri, 26 Jan 2024 19:22:21 +0200 Subject: [PATCH] Only reset the mempool in handle_new_tip if in ibd --- mempool/src/pool/reorg.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mempool/src/pool/reorg.rs b/mempool/src/pool/reorg.rs index 82a76e20f3..81026630fa 100644 --- a/mempool/src/pool/reorg.rs +++ b/mempool/src/pool/reorg.rs @@ -162,10 +162,17 @@ pub fn handle_new_tip( if is_ibd || new_tip != actual_tip { log::debug!("Not updating mempool: is_ibd = {is_ibd}, new_tip = {new_tip:?}, actual_tip = {actual_tip:?}"); - // We still need to update the current tx_verifier tip - let mut old_transactions = mempool.reset(); - if old_transactions.next().is_some() { - log::warn!("Discarding mempool transactions during IBD or because the tip has changed"); + if is_ibd { + // Note: mempool.reset() will also re-create the tx verifier from the current chainstate, + // which will also change its "best block for utxos". This is not really needed here, + // but some existing functional tests, namely blockprod_ibd.py and mempool_ibd.py, + // use this fact to detect that the corresponding new tip event has already reached + // the mempool. TODO: refactor the tests, remove this call of "mempool.reset()". + let mut old_transactions = mempool.reset(); + if old_transactions.next().is_some() { + // Note: actually, this should never happen during ibd. + log::warn!("Discarding mempool transactions during IBD"); + } } return Ok(()); }