diff --git a/src/txorphanage.cpp b/src/txorphanage.cpp index 06b6ab4af20..37438f54def 100644 --- a/src/txorphanage.cpp +++ b/src/txorphanage.cpp @@ -42,6 +42,7 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer) for (const CTxIn& txin : tx->vin) { m_outpoint_to_orphan_it[txin.prevout].insert(ret.first); } + m_total_orphan_usage += sz; LogDebug(BCLog::TXPACKAGES, "stored orphan tx %s (wtxid=%s), weight: %u (mapsz %u outsz %u)\n", hash.ToString(), wtxid.ToString(), sz, m_orphans.size(), m_outpoint_to_orphan_it.size()); @@ -77,6 +78,9 @@ int TxOrphanage::EraseTx(const Wtxid& wtxid) m_outpoint_to_orphan_it.erase(itPrev); } + const auto tx_size{it->second.GetUsage()}; + m_total_orphan_usage -= tx_size; + size_t old_pos = it->second.list_pos; assert(m_orphan_list[old_pos] == it); if (old_pos + 1 != m_orphan_list.size()) { diff --git a/src/txorphanage.h b/src/txorphanage.h index 4205da01994..01a9c474ff4 100644 --- a/src/txorphanage.h +++ b/src/txorphanage.h @@ -5,6 +5,7 @@ #ifndef BITCOIN_TXORPHANAGE_H #define BITCOIN_TXORPHANAGE_H +#include #include #include #include @@ -83,15 +84,27 @@ public: /** Peers added with AddTx or AddAnnouncer. */ std::set announcers; NodeSeconds nTimeExpire; + + /** Get the weight of this transaction, an approximation of its memory usage. */ + unsigned int GetUsage() const { + return GetTransactionWeight(*tx); + } }; std::vector GetOrphanTransactions() const; + /** Get the total usage (weight) of all orphans. If an orphan has multiple announcers, its usage is + * only counted once within this total. */ + unsigned int TotalOrphanUsage() const { return m_total_orphan_usage; } + protected: struct OrphanTx : public OrphanTxBase { size_t list_pos; }; + /** Total usage (weight) of all entries in m_orphans. */ + unsigned int m_total_orphan_usage{0}; + /** Map from wtxid to orphan transaction record. Limited by * -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */ std::map m_orphans;