| 318 | } |
| 319 | |
| 320 | bool CTxMemPool::CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, |
| 321 | setEntries &setAncestors, |
| 322 | uint64_t limitAncestorCount, |
| 323 | uint64_t limitAncestorSize, |
| 324 | uint64_t limitDescendantCount, |
| 325 | uint64_t limitDescendantSize, |
| 326 | std::string &errString, |
| 327 | bool fSearchForParents /* = true */) const |
| 328 | { |
| 329 | CTxMemPoolEntry::Parents staged_ancestors; |
| 330 | const CTransaction &tx = entry.GetTx(); |
| 331 | |
| 332 | if (fSearchForParents) { |
| 333 | // Get parents of this transaction that are in the mempool |
| 334 | // GetMemPoolParents() is only valid for entries in the mempool, so we |
| 335 | // iterate mapTx to find parents. |
| 336 | for (unsigned int i = 0; i < tx.vin.size(); i++) { |
| 337 | std::optional<txiter> piter = GetIter(tx.vin[i].prevout.hash); |
| 338 | if (piter) { |
| 339 | staged_ancestors.insert(**piter); |
| 340 | if (staged_ancestors.size() + 1 > limitAncestorCount) { |
| 341 | errString = strprintf("too many unconfirmed parents [limit: %u]", limitAncestorCount); |
| 342 | return false; |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | } else { |
| 347 | // If we're not searching for parents, we require this to already be an |
| 348 | // entry in the mempool and use the entry's cached parents. |
| 349 | txiter it = mapTx.iterator_to(entry); |
| 350 | staged_ancestors = it->GetMemPoolParentsConst(); |
| 351 | } |
| 352 | |
| 353 | return CalculateAncestorsAndCheckLimits(entry.GetTxSize(), /* entry_count */ 1, |
| 354 | setAncestors, staged_ancestors, |
| 355 | limitAncestorCount, limitAncestorSize, |
| 356 | limitDescendantCount, limitDescendantSize, errString); |
| 357 | } |
| 358 | |
| 359 | void CTxMemPool::UpdateAncestorsOf(bool add, txiter it, setEntries &setAncestors) |
| 360 | { |