From bdcefb8a8b0667539744eae63e9eb5b7dc1c51da Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Tue, 3 Oct 2023 11:19:15 -0400 Subject: [PATCH] Use mempool/txgraph to determine if a tx has descendants Remove a reference to GetCountWithDescendants() in preparation for removing this function and the associated cached state from the mempool. --- src/node/interfaces.cpp | 5 +---- src/txmempool.cpp | 8 ++++++++ src/txmempool.h | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 8e38ae126ff..c3e57291794 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -665,10 +665,7 @@ public: bool hasDescendantsInMempool(const Txid& txid) override { if (!m_node.mempool) return false; - LOCK(m_node.mempool->cs); - const auto entry{m_node.mempool->GetEntry(txid)}; - if (entry == nullptr) return false; - return entry->GetCountWithDescendants() > 1; + return m_node.mempool->HasDescendants(txid); } bool broadcastTransaction(const CTransactionRef& tx, const CAmount& max_tx_fee, diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 7fd5a470053..f7bdbf94e3c 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -229,6 +229,14 @@ util::Result CTxMemPool::CheckPackageLimits(const Package& package, return {}; } +bool CTxMemPool::HasDescendants(const Txid& txid) const +{ + LOCK(cs); + auto entry = GetEntry(txid); + if (!entry) return false; + return m_txgraph->GetDescendants(*entry, TxGraph::Level::MAIN).size() > 1; +} + util::Result CTxMemPool::CalculateMemPoolAncestors( const CTxMemPoolEntry &entry, const Limits& limits, diff --git a/src/txmempool.h b/src/txmempool.h index 475a39966d8..b65333cc3b3 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -467,6 +467,8 @@ public: const Limits& limits, bool fSearchForParents = true) const EXCLUSIVE_LOCKS_REQUIRED(cs); + bool HasDescendants(const Txid& txid) const; + /** Collect the entire cluster of connected transactions for each transaction in txids. * All txids must correspond to transaction entries in the mempool, otherwise this returns an * empty vector. This call will also exit early and return an empty vector if it collects 500 or