From a4458d6c406215dccb31fd35e0968a65a3269670 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Sun, 14 Apr 2024 19:28:25 -0400 Subject: [PATCH] Use txgraph to calculate descendants --- src/txmempool.cpp | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) 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))); } }