From a21dd26a5ebb5879bbb2c81821520550554527b9 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 14 Oct 2021 23:19:21 +1000 Subject: [PATCH] Insert new mempool transactions, then check for rejections (#2874) Previously, we checked some rejections before inserting, so we could accept some new transactions that should be rejected. --- zebrad/src/components/mempool.rs | 37 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/zebrad/src/components/mempool.rs b/zebrad/src/components/mempool.rs index 94bcba90..01f11759 100644 --- a/zebrad/src/components/mempool.rs +++ b/zebrad/src/components/mempool.rs @@ -267,24 +267,6 @@ impl Service for Mempool { storage, tx_downloads, } => { - if let Some(tip_action) = self.chain_tip_change.last_tip_change() { - match tip_action { - // Clear the mempool and cancel downloads if there has been a chain tip reset. - TipAction::Reset { .. } => { - storage.clear(); - tx_downloads.cancel_all(); - } - // Cancel downloads/verifications/storage of transactions - // with the same mined IDs as recently mined transactions. - TipAction::Grow { block } => { - let mined_ids = block.transaction_hashes.iter().cloned().collect(); - tx_downloads.cancel(&mined_ids); - storage.remove_same_effects(&mined_ids); - storage.clear_tip_rejections(); - } - } - } - // Collect inserted transaction ids. let mut send_to_peers_ids = HashSet::<_>::new(); @@ -304,6 +286,25 @@ impl Service for Mempool { }; } + // Handle best chain tip changes + if let Some(tip_action) = self.chain_tip_change.last_tip_change() { + match tip_action { + // Clear the mempool and cancel downloads if there has been a chain tip reset. + TipAction::Reset { .. } => { + storage.clear(); + tx_downloads.cancel_all(); + } + TipAction::Grow { block } => { + // Cancel downloads/verifications/storage of transactions + // with the same mined IDs as recently mined transactions. + let mined_ids = block.transaction_hashes.iter().cloned().collect(); + tx_downloads.cancel(&mined_ids); + storage.remove_same_effects(&mined_ids); + storage.clear_tip_rejections(); + } + } + } + // Remove expired transactions from the mempool. if let Some(tip_height) = self.latest_chain_tip.best_tip_height() { let expired_transactions = remove_expired_transactions(storage, tip_height);