aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2023-05-08 15:37:11 +1000
committerfanquake <fanquake@gmail.com>2023-05-11 14:24:19 +0100
commita9a861af2b4b1c0a17b8abda34cb741170e12d7d (patch)
tree0310605776bc3fa2e18fde8348cd550f25d8cc57
parentec7cd33c9c70af5903bf5dbf1056d42868de6f43 (diff)
txmempool: have CompareDepthAndScore sort missing txs first
We use CompareDepthAndScore to choose an order of txs to inv. Rather than sorting txs that have been evicted from the mempool at the end of the list, sort them at the beginning so they are removed from the queue immediately. Github-Pull: #27610 Rebased-From: 228e9201efb5574b1b96bb924de1d2e8dd1317f3
-rw-r--r--src/txmempool.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/txmempool.cpp b/src/txmempool.cpp
index e1288b7346..d03ab75546 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -805,11 +805,16 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei
bool CTxMemPool::CompareDepthAndScore(const uint256& hasha, const uint256& hashb, bool wtxid)
{
+ /* Return `true` if hasha should be considered sooner than hashb. Namely when:
+ * a is not in the mempool, but b is
+ * both are in the mempool and a has fewer ancestors than b
+ * both are in the mempool and a has a higher score than b
+ */
LOCK(cs);
- indexed_transaction_set::const_iterator i = wtxid ? get_iter_from_wtxid(hasha) : mapTx.find(hasha);
- if (i == mapTx.end()) return false;
indexed_transaction_set::const_iterator j = wtxid ? get_iter_from_wtxid(hashb) : mapTx.find(hashb);
- if (j == mapTx.end()) return true;
+ if (j == mapTx.end()) return false;
+ indexed_transaction_set::const_iterator i = wtxid ? get_iter_from_wtxid(hasha) : mapTx.find(hasha);
+ if (i == mapTx.end()) return true;
uint64_t counta = i->GetCountWithAncestors();
uint64_t countb = j->GetCountWithAncestors();
if (counta == countb) {