Skip to content

Commit 1a41e79

Browse files
committed
[refactor] create aliases for TxOrphanage Count and Usage
1 parent b50bd72 commit 1a41e79

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/node/txorphanage.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ class TxOrphanageImpl final : public TxOrphanage {
2222
};
2323

2424
/** Total usage (weight) of all entries in m_orphans. */
25-
int64_t m_total_orphan_usage{0};
25+
TxOrphanage::Usage m_total_orphan_usage{0};
2626

2727
/** Total number of <peer, tx> pairs. Can be larger than m_orphans.size() because multiple peers
2828
* may have announced the same orphan. */
29-
unsigned int m_total_announcements{0};
29+
TxOrphanage::Count m_total_announcements{0};
3030

3131
/** Map from wtxid to orphan transaction record. Limited by
3232
* DEFAULT_MAX_ORPHAN_TRANSACTIONS */
@@ -44,7 +44,7 @@ class TxOrphanageImpl final : public TxOrphanage {
4444
* PeerOrphanInfo, so the total of all peers' m_total_usage may be larger than
4545
* m_total_orphan_size. If a peer is removed as an announcer, even if the orphan still
4646
* remains in the orphanage, this number will be decremented. */
47-
int64_t m_total_usage{0};
47+
TxOrphanage::Usage m_total_usage{0};
4848
};
4949
std::map<NodeId, PeerOrphanInfo> m_peer_orphanage_info;
5050

@@ -85,8 +85,8 @@ class TxOrphanageImpl final : public TxOrphanage {
8585
std::vector<CTransactionRef> GetChildrenFromSamePeer(const CTransactionRef& parent, NodeId nodeid) const override;
8686
size_t Size() const override { return m_orphans.size(); }
8787
std::vector<OrphanTxBase> GetOrphanTransactions() const override;
88-
int64_t TotalOrphanUsage() const override { return m_total_orphan_usage; }
89-
int64_t UsageByPeer(NodeId peer) const override;
88+
TxOrphanage::Usage TotalOrphanUsage() const override { return m_total_orphan_usage; }
89+
TxOrphanage::Usage UsageByPeer(NodeId peer) const override;
9090
void SanityCheck() const override;
9191
};
9292

@@ -401,7 +401,7 @@ std::vector<TxOrphanage::OrphanTxBase> TxOrphanageImpl::GetOrphanTransactions()
401401
return ret;
402402
}
403403

404-
int64_t TxOrphanageImpl::UsageByPeer(NodeId peer) const
404+
TxOrphanage::Usage TxOrphanageImpl::UsageByPeer(NodeId peer) const
405405
{
406406
auto peer_it = m_peer_orphanage_info.find(peer);
407407
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
410410
void TxOrphanageImpl::SanityCheck() const
411411
{
412412
// Check that cached m_total_announcements is correct
413-
unsigned int counted_total_announcements{0};
413+
TxOrphanage::Count counted_total_announcements{0};
414414
// Check that m_total_orphan_usage is correct
415-
int64_t counted_total_usage{0};
415+
TxOrphanage::Usage counted_total_usage{0};
416416

417417
// Check that cached PeerOrphanInfo::m_total_size is correct
418-
std::map<NodeId, int64_t> counted_size_per_peer;
418+
std::map<NodeId, TxOrphanage::Usage> counted_size_per_peer;
419419

420420
for (const auto& [wtxid, orphan] : m_orphans) {
421421
counted_total_announcements += orphan.announcers.size();

src/node/txorphanage.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@ static const uint32_t DEFAULT_MAX_ORPHAN_TRANSACTIONS{100};
3131
*/
3232
class TxOrphanage {
3333
public:
34+
using Usage = int64_t;
35+
using Count = unsigned int;
36+
3437
/** Allows providing orphan information externally */
3538
struct OrphanTxBase {
3639
CTransactionRef tx;
3740
/** Peers added with AddTx or AddAnnouncer. */
3841
std::set<NodeId> announcers;
3942

4043
/** Get the weight of this transaction, an approximation of its memory usage. */
41-
unsigned int GetUsage() const {
44+
TxOrphanage::Usage GetUsage() const {
4245
return GetTransactionWeight(*tx);
4346
}
4447
};
@@ -99,12 +102,12 @@ class TxOrphanage {
99102

100103
/** Get the total usage (weight) of all orphans. If an orphan has multiple announcers, its usage is
101104
* only counted once within this total. */
102-
virtual int64_t TotalOrphanUsage() const = 0;
105+
virtual Usage TotalOrphanUsage() const = 0;
103106

104107
/** Total usage (weight) of orphans for which this peer is an announcer. If an orphan has multiple
105108
* announcers, its weight will be accounted for in each PeerOrphanInfo, so the total of all
106-
* peers' UsageByPeer() may be larger than TotalOrphanBytes(). */
107-
virtual int64_t UsageByPeer(NodeId peer) const = 0;
109+
* peers' UsageByPeer() may be larger than TotalOrphanUsage(). */
110+
virtual Usage UsageByPeer(NodeId peer) const = 0;
108111

109112
/** Check consistency between PeerOrphanInfo and m_orphans. Recalculate counters and ensure they
110113
* match what is cached. */

0 commit comments

Comments
 (0)