Skip to content

Commit 46847d6

Browse files
committed
mempool: Fix max descendants check
The chain limits check for max descendants would check the descendants of the transaction itself even though the description for -limitdescendantcount says 'any ancestor'. This commit corrects the descendant count check by finding the top parent transaction in the mempool and comparing against that.
1 parent b9ef21d commit 46847d6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/txmempool.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,11 +1055,22 @@ void CTxMemPool::TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpends
10551055
}
10561056
}
10571057

1058+
uint64_t CTxMemPool::CalculateDescendantMaximum(txiter entry) const {
1059+
// find top parent
1060+
txiter top = entry;
1061+
for (;;) {
1062+
const setEntries& parents = GetMemPoolParents(top);
1063+
if (parents.size() == 0) break;
1064+
top = *parents.begin();
1065+
}
1066+
return top->GetCountWithDescendants();
1067+
}
1068+
10581069
bool CTxMemPool::TransactionWithinChainLimit(const uint256& txid, size_t ancestor_limit, size_t descendant_limit) const {
10591070
LOCK(cs);
10601071
auto it = mapTx.find(txid);
10611072
return it == mapTx.end() || (it->GetCountWithAncestors() < ancestor_limit &&
1062-
it->GetCountWithDescendants() < descendant_limit);
1073+
CalculateDescendantMaximum(it) < descendant_limit);
10631074
}
10641075

10651076
SaltedTxidHasher::SaltedTxidHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}

src/txmempool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ class CTxMemPool
498498

499499
const setEntries & GetMemPoolParents(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
500500
const setEntries & GetMemPoolChildren(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
501+
uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
501502
private:
502503
typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
503504

0 commit comments

Comments
 (0)