Skip to content

Commit 228e920

Browse files
committed
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.
1 parent fc06881 commit 228e920

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
@@ -755,11 +755,16 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei
755755

756756
bool CTxMemPool::CompareDepthAndScore(const uint256& hasha, const uint256& hashb, bool wtxid)
757757
{
758+
/* Return `true` if hasha should be considered sooner than hashb. Namely when:
759+
* a is not in the mempool, but b is
760+
* both are in the mempool and a has fewer ancestors than b
761+
* both are in the mempool and a has a higher score than b
762+
*/
758763
LOCK(cs);
759-
indexed_transaction_set::const_iterator i = wtxid ? get_iter_from_wtxid(hasha) : mapTx.find(hasha);
760-
if (i == mapTx.end()) return false;
761764
indexed_transaction_set::const_iterator j = wtxid ? get_iter_from_wtxid(hashb) : mapTx.find(hashb);
762-
if (j == mapTx.end()) return true;
765+
if (j == mapTx.end()) return false;
766+
indexed_transaction_set::const_iterator i = wtxid ? get_iter_from_wtxid(hasha) : mapTx.find(hasha);
767+
if (i == mapTx.end()) return true;
763768
uint64_t counta = i->GetCountWithAncestors();
764769
uint64_t countb = j->GetCountWithAncestors();
765770
if (counta == countb) {

0 commit comments

Comments
 (0)