diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 2b8bec25498..8ba41e9403e 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -323,33 +323,11 @@ void CTxMemPool::removeUnchecked(txiter it, MemPoolRemovalReason reason) nTransactionsUpdated++; } -// Calculates descendants of entry that are not already in setDescendants, and adds to -// setDescendants. Assumes entryit is already a tx in the mempool and CTxMemPoolEntry::m_children -// is correct for tx and all descendants. -// Also assumes that if an entry is in setDescendants already, then all -// in-mempool descendants of it are already in setDescendants as well, so that we -// can save time by not iterating over those entries. +// Calculates descendants of given entry and adds to setDescendants. void CTxMemPool::CalculateDescendants(txiter entryit, setEntries& setDescendants) const { - setEntries stage; - if (setDescendants.count(entryit) == 0) { - stage.insert(entryit); - } - // Traverse down the children of entry, only adding children that are not - // accounted for in setDescendants already (because those children have either - // already been walked, or will be walked in this iteration). - while (!stage.empty()) { - txiter it = *stage.begin(); - setDescendants.insert(it); - stage.erase(it); - - const CTxMemPoolEntry::Children& children = it->GetMemPoolChildrenConst(); - for (const CTxMemPoolEntry& child : children) { - txiter childiter = mapTx.iterator_to(child); - if (!setDescendants.count(childiter)) { - stage.insert(childiter); - } - } + for (auto tx : m_txgraph->GetDescendants(*entryit, TxGraph::Level::MAIN)) { + setDescendants.insert(mapTx.iterator_to(static_cast(*tx))); } }