Skip to content

Commit a9a861a

Browse files
ajtownsfanquake
authored andcommitted
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: 228e920
1 parent ec7cd33 commit a9a861a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/txmempool.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,11 +805,16 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei
805805

806806
bool CTxMemPool::CompareDepthAndScore(const uint256& hasha, const uint256& hashb, bool wtxid)
807807
{
808+
/* Return `true` if hasha should be considered sooner than hashb. Namely when:
809+
* a is not in the mempool, but b is
810+
* both are in the mempool and a has fewer ancestors than b
811+
* both are in the mempool and a has a higher score than b
812+
*/
808813
LOCK(cs);
809-
indexed_transaction_set::const_iterator i = wtxid ? get_iter_from_wtxid(hasha) : mapTx.find(hasha);
810-
if (i == mapTx.end()) return false;
811814
indexed_transaction_set::const_iterator j = wtxid ? get_iter_from_wtxid(hashb) : mapTx.find(hashb);
812-
if (j == mapTx.end()) return true;
815+
if (j == mapTx.end()) return false;
816+
indexed_transaction_set::const_iterator i = wtxid ? get_iter_from_wtxid(hasha) : mapTx.find(hasha);
817+
if (i == mapTx.end()) return true;
813818
uint64_t counta = i->GetCountWithAncestors();
814819
uint64_t countb = j->GetCountWithAncestors();
815820
if (counta == countb) {

0 commit comments

Comments
 (0)