mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-09 22:28:51 +02:00
Reimplement GetTransactionAncestry() to not rely on cached data
In preparation for removing ancestor data from CTxMemPoolEntry, recalculate the ancestor statistics on demand wherever needed.
This commit is contained in:
@@ -1217,15 +1217,31 @@ uint64_t CTxMemPool::CalculateDescendantMaximum(txiter entry) const {
|
||||
return maximum;
|
||||
}
|
||||
|
||||
std::tuple<size_t, size_t, CAmount> 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<const CTxMemPoolEntry&>(*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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -285,6 +285,9 @@ public:
|
||||
using Limits = kernel::MemPoolLimits;
|
||||
|
||||
uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
std::tuple<size_t, size_t, CAmount> CalculateAncestorData(const CTxMemPoolEntry& entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||
|
||||
private:
|
||||
typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user