diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 326ff79f3ef..85feb8b29c0 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -1217,15 +1217,31 @@ uint64_t CTxMemPool::CalculateDescendantMaximum(txiter entry) const { return maximum; } +std::tuple CTxMemPool::CalculateAncestorData(const CTxMemPoolEntry& entry) const +{ + auto ancestors = m_txgraph->GetAncestors(entry, TxGraph::Level::MAIN); + + size_t ancestor_count = ancestors.size(); + size_t ancestor_size = 0; + CAmount ancestor_fees = 0; + for (auto tx: ancestors) { + const CTxMemPoolEntry& anc = static_cast(*tx); + ancestor_size += anc.GetTxSize(); + ancestor_fees += anc.GetModifiedFee(); + } + return {ancestor_count, ancestor_size, ancestor_fees}; +} + void CTxMemPool::GetTransactionAncestry(const Txid& txid, size_t& ancestors, size_t& descendants, size_t* const ancestorsize, CAmount* const ancestorfees) const { LOCK(cs); auto it = mapTx.find(txid); ancestors = descendants = 0; if (it != mapTx.end()) { - ancestors = it->GetCountWithAncestors(); - if (ancestorsize) *ancestorsize = it->GetSizeWithAncestors(); - if (ancestorfees) *ancestorfees = it->GetModFeesWithAncestors(); + auto [ancestor_count, ancestor_size, ancestor_fees] = CalculateAncestorData(*it); descendants = CalculateDescendantMaximum(it); + ancestors = ancestor_count; + if (ancestorsize) *ancestorsize = ancestor_size; + if (ancestorfees) *ancestorfees = ancestor_fees; } } diff --git a/src/txmempool.h b/src/txmempool.h index fb2a4669bae..df4d50a4e67 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -285,6 +285,9 @@ public: using Limits = kernel::MemPoolLimits; uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs); + + std::tuple CalculateAncestorData(const CTxMemPoolEntry& entry) const EXCLUSIVE_LOCKS_REQUIRED(cs); + private: typedef std::map cacheMap;