From 88672e205ba1570fc92449b557fd32d836618781 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Tue, 16 Apr 2024 11:10:07 -0400 Subject: [PATCH] Rewrite GatherClusters to use the txgraph implementation --- src/txmempool.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 921765de732..53d92b8d9ea 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -977,28 +977,24 @@ void CTxMemPool::SetLoadTried(bool load_tried) std::vector CTxMemPool::GatherClusters(const std::vector& txids) const { AssertLockHeld(cs); - std::vector clustered_txs{GetIterVec(txids)}; - // Use epoch: visiting an entry means we have added it to the clustered_txs vector. It does not - // necessarily mean the entry has been processed. - WITH_FRESH_EPOCH(m_epoch); - for (const auto& it : clustered_txs) { - visited(it); - } - // i = index of where the list of entries to process starts - for (size_t i{0}; i < clustered_txs.size(); ++i) { - // DoS protection: if there are 500 or more entries to process, just quit. - if (clustered_txs.size() > 500) return {}; - const txiter& tx_iter = clustered_txs.at(i); - for (const auto& entries : {tx_iter->GetMemPoolParentsConst(), tx_iter->GetMemPoolChildrenConst()}) { - for (const CTxMemPoolEntry& entry : entries) { - const auto entry_it = mapTx.iterator_to(entry); - if (!visited(entry_it)) { - clustered_txs.push_back(entry_it); + + std::vector ret; + std::set unique_cluster_representatives; + for (auto txid : txids) { + auto it = mapTx.find(txid); + if (it != mapTx.end()) { + auto cluster = m_txgraph->GetCluster(*it, TxGraph::Level::MAIN); + if (unique_cluster_representatives.insert(static_cast(&(**cluster.begin()))).second) { + for (auto tx : cluster) { + ret.emplace_back(mapTx.iterator_to(static_cast(*tx))); } } } } - return clustered_txs; + if (ret.size() > 500) { + return {}; + } + return ret; } util::Result, std::vector>> CTxMemPool::ChangeSet::CalculateChunksForRBF()