mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
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.
This commit is contained in:
parent
b9ef21dd72
commit
46847d69d2
2 changed files with 13 additions and 1 deletions
|
@ -1055,11 +1055,22 @@ void CTxMemPool::TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpends
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t CTxMemPool::CalculateDescendantMaximum(txiter entry) const {
|
||||||
|
// find top parent
|
||||||
|
txiter top = entry;
|
||||||
|
for (;;) {
|
||||||
|
const setEntries& parents = GetMemPoolParents(top);
|
||||||
|
if (parents.size() == 0) break;
|
||||||
|
top = *parents.begin();
|
||||||
|
}
|
||||||
|
return top->GetCountWithDescendants();
|
||||||
|
}
|
||||||
|
|
||||||
bool CTxMemPool::TransactionWithinChainLimit(const uint256& txid, size_t ancestor_limit, size_t descendant_limit) const {
|
bool CTxMemPool::TransactionWithinChainLimit(const uint256& txid, size_t ancestor_limit, size_t descendant_limit) const {
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
auto it = mapTx.find(txid);
|
auto it = mapTx.find(txid);
|
||||||
return it == mapTx.end() || (it->GetCountWithAncestors() < ancestor_limit &&
|
return it == mapTx.end() || (it->GetCountWithAncestors() < ancestor_limit &&
|
||||||
it->GetCountWithDescendants() < descendant_limit);
|
CalculateDescendantMaximum(it) < descendant_limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
SaltedTxidHasher::SaltedTxidHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
|
SaltedTxidHasher::SaltedTxidHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
|
||||||
|
|
|
@ -498,6 +498,7 @@ public:
|
||||||
|
|
||||||
const setEntries & GetMemPoolParents(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
const setEntries & GetMemPoolParents(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
const setEntries & GetMemPoolChildren(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
const setEntries & GetMemPoolChildren(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
private:
|
private:
|
||||||
typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
|
typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue