Skip to content

Commit ce019bf

Browse files
committed
Check all ancestor state in CTxMemPool::check()
1 parent e2eeb5d commit ce019bf

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/txmempool.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashes
160160
}
161161
}
162162

163-
bool CTxMemPool::CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents /* = true */)
163+
bool CTxMemPool::CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents /* = true */) const
164164
{
165165
setEntries parentHashes;
166166
const CTransaction &tx = entry.GetTx();
@@ -666,10 +666,27 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
666666
i++;
667667
}
668668
assert(setParentCheck == GetMemPoolParents(it));
669-
// Also check to make sure ancestor size/sigops are >= sum with immediate
670-
// parents.
671-
assert(it->GetSizeWithAncestors() >= parentSizes + it->GetTxSize());
672-
assert(it->GetSigOpCountWithAncestors() >= parentSigOpCount + it->GetSigOpCount());
669+
// Verify ancestor state is correct.
670+
setEntries setAncestors;
671+
uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
672+
std::string dummy;
673+
CalculateMemPoolAncestors(*it, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy);
674+
uint64_t nCountCheck = setAncestors.size() + 1;
675+
uint64_t nSizeCheck = it->GetTxSize();
676+
CAmount nFeesCheck = it->GetModifiedFee();
677+
unsigned int nSigOpCheck = it->GetSigOpCount();
678+
679+
BOOST_FOREACH(txiter ancestorIt, setAncestors) {
680+
nSizeCheck += ancestorIt->GetTxSize();
681+
nFeesCheck += ancestorIt->GetModifiedFee();
682+
nSigOpCheck += ancestorIt->GetSigOpCount();
683+
}
684+
685+
assert(it->GetCountWithAncestors() == nCountCheck);
686+
assert(it->GetSizeWithAncestors() == nSizeCheck);
687+
assert(it->GetSigOpCountWithAncestors() == nSigOpCheck);
688+
assert(it->GetModFeesWithAncestors() == nFeesCheck);
689+
673690
// Check children against mapNextTx
674691
CTxMemPool::setEntries setChildrenCheck;
675692
std::map<COutPoint, CInPoint>::const_iterator iter = mapNextTx.lower_bound(COutPoint(it->GetTx().GetHash(), 0));

src/txmempool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ class CTxMemPool
527527
* fSearchForParents = whether to search a tx's vin for in-mempool parents, or
528528
* look up parents from mapLinks. Must be true for entries not in the mempool
529529
*/
530-
bool CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents = true);
530+
bool CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents = true) const;
531531

532532
/** Populate setDescendants with all in-mempool descendants of hash.
533533
* Assumes that setDescendants includes all in-mempool descendants of anything

0 commit comments

Comments
 (0)