Skip to content

Commit

Permalink
Return mempool queries in dependency order
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa authored and furszy committed Jan 18, 2021
1 parent 23c9f3e commit 191c62e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,16 @@ bool CTxMemPool::CompareDepthAndScore(const uint256& hasha, const uint256& hashb
return counta < countb;
}

namespace {
class DepthAndScoreComparator
{
CTxMemPool *mp;
public:
DepthAndScoreComparator(CTxMemPool *mempool) : mp(mempool) {}
bool operator()(const uint256& a, const uint256& b) { return mp->CompareDepthAndScore(a, b); }
};
}

void CTxMemPool::queryHashes(std::vector<uint256>& vtxid)
{
vtxid.clear();
Expand All @@ -838,6 +848,8 @@ void CTxMemPool::queryHashes(std::vector<uint256>& vtxid)
vtxid.reserve(mapTx.size());
for (indexed_transaction_set::iterator mi = mapTx.begin(); mi != mapTx.end(); ++mi)
vtxid.push_back(mi->GetTx().GetHash());

std::sort(vtxid.begin(), vtxid.end(), DepthAndScoreComparator(this));
}

void CTxMemPool::getTransactions(std::set<uint256>& setTxid)
Expand Down

0 comments on commit 191c62e

Please sign in to comment.