From 1a41e7962db364b7abf1eb37901c3455ddc3e2bb Mon Sep 17 00:00:00 2001 From: glozow Date: Fri, 27 Jun 2025 14:40:11 -0400 Subject: [PATCH] [refactor] create aliases for TxOrphanage Count and Usage --- src/node/txorphanage.cpp | 18 +++++++++--------- src/node/txorphanage.h | 11 +++++++---- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/node/txorphanage.cpp b/src/node/txorphanage.cpp index f4fe22e480d..d7262ce6996 100644 --- a/src/node/txorphanage.cpp +++ b/src/node/txorphanage.cpp @@ -22,11 +22,11 @@ private: }; /** Total usage (weight) of all entries in m_orphans. */ - int64_t m_total_orphan_usage{0}; + TxOrphanage::Usage m_total_orphan_usage{0}; /** Total number of pairs. Can be larger than m_orphans.size() because multiple peers * may have announced the same orphan. */ - unsigned int m_total_announcements{0}; + TxOrphanage::Count m_total_announcements{0}; /** Map from wtxid to orphan transaction record. Limited by * DEFAULT_MAX_ORPHAN_TRANSACTIONS */ @@ -44,7 +44,7 @@ private: * PeerOrphanInfo, so the total of all peers' m_total_usage may be larger than * m_total_orphan_size. If a peer is removed as an announcer, even if the orphan still * remains in the orphanage, this number will be decremented. */ - int64_t m_total_usage{0}; + TxOrphanage::Usage m_total_usage{0}; }; std::map m_peer_orphanage_info; @@ -85,8 +85,8 @@ public: std::vector GetChildrenFromSamePeer(const CTransactionRef& parent, NodeId nodeid) const override; size_t Size() const override { return m_orphans.size(); } std::vector GetOrphanTransactions() const override; - int64_t TotalOrphanUsage() const override { return m_total_orphan_usage; } - int64_t UsageByPeer(NodeId peer) const override; + TxOrphanage::Usage TotalOrphanUsage() const override { return m_total_orphan_usage; } + TxOrphanage::Usage UsageByPeer(NodeId peer) const override; void SanityCheck() const override; }; @@ -401,7 +401,7 @@ std::vector TxOrphanageImpl::GetOrphanTransactions() return ret; } -int64_t TxOrphanageImpl::UsageByPeer(NodeId peer) const +TxOrphanage::Usage TxOrphanageImpl::UsageByPeer(NodeId peer) const { auto peer_it = m_peer_orphanage_info.find(peer); return peer_it == m_peer_orphanage_info.end() ? 0 : peer_it->second.m_total_usage; @@ -410,12 +410,12 @@ int64_t TxOrphanageImpl::UsageByPeer(NodeId peer) const void TxOrphanageImpl::SanityCheck() const { // Check that cached m_total_announcements is correct - unsigned int counted_total_announcements{0}; + TxOrphanage::Count counted_total_announcements{0}; // Check that m_total_orphan_usage is correct - int64_t counted_total_usage{0}; + TxOrphanage::Usage counted_total_usage{0}; // Check that cached PeerOrphanInfo::m_total_size is correct - std::map counted_size_per_peer; + std::map counted_size_per_peer; for (const auto& [wtxid, orphan] : m_orphans) { counted_total_announcements += orphan.announcers.size(); diff --git a/src/node/txorphanage.h b/src/node/txorphanage.h index 8567b178dd4..b21d323c2c3 100644 --- a/src/node/txorphanage.h +++ b/src/node/txorphanage.h @@ -31,6 +31,9 @@ static const uint32_t DEFAULT_MAX_ORPHAN_TRANSACTIONS{100}; */ class TxOrphanage { public: + using Usage = int64_t; + using Count = unsigned int; + /** Allows providing orphan information externally */ struct OrphanTxBase { CTransactionRef tx; @@ -38,7 +41,7 @@ public: std::set announcers; /** Get the weight of this transaction, an approximation of its memory usage. */ - unsigned int GetUsage() const { + TxOrphanage::Usage GetUsage() const { return GetTransactionWeight(*tx); } }; @@ -99,12 +102,12 @@ public: /** Get the total usage (weight) of all orphans. If an orphan has multiple announcers, its usage is * only counted once within this total. */ - virtual int64_t TotalOrphanUsage() const = 0; + virtual Usage TotalOrphanUsage() const = 0; /** Total usage (weight) of orphans for which this peer is an announcer. If an orphan has multiple * announcers, its weight will be accounted for in each PeerOrphanInfo, so the total of all - * peers' UsageByPeer() may be larger than TotalOrphanBytes(). */ - virtual int64_t UsageByPeer(NodeId peer) const = 0; + * peers' UsageByPeer() may be larger than TotalOrphanUsage(). */ + virtual Usage UsageByPeer(NodeId peer) const = 0; /** Check consistency between PeerOrphanInfo and m_orphans. Recalculate counters and ensure they * match what is cached. */