Skip to content

Commit d4a6f40

Browse files
committed
Return mempool queries in dependency order
1 parent 66a5885 commit d4a6f40

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/txmempool.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,16 @@ bool CTxMemPool::CompareDepthAndScore(const uint256& hasha, const uint256& hashb
767767
return counta < countb;
768768
}
769769

770+
namespace {
771+
class DepthAndScoreComparator
772+
{
773+
CTxMemPool *mp;
774+
public:
775+
DepthAndScoreComparator(CTxMemPool *mempool) : mp(mempool) {}
776+
bool operator()(const uint256& a, const uint256& b) { return mp->CompareDepthAndScore(a, b); }
777+
};
778+
}
779+
770780
void CTxMemPool::queryHashes(vector<uint256>& vtxid)
771781
{
772782
vtxid.clear();
@@ -775,6 +785,8 @@ void CTxMemPool::queryHashes(vector<uint256>& vtxid)
775785
vtxid.reserve(mapTx.size());
776786
for (indexed_transaction_set::iterator mi = mapTx.begin(); mi != mapTx.end(); ++mi)
777787
vtxid.push_back(mi->GetTx().GetHash());
788+
789+
std::sort(vtxid.begin(), vtxid.end(), DepthAndScoreComparator(this));
778790
}
779791

780792
bool CTxMemPool::lookup(uint256 hash, CTransaction& result) const

0 commit comments

Comments
 (0)