Skip to content

Commit bb91d23

Browse files
committed
[txorphanage] change type of usage to int64_t
Since this field holds a total number of bytes, overflow is within the realm of possibility. Use int64 to be safe.
1 parent 23e15d4 commit bb91d23

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/txorphanage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,10 @@ void TxOrphanage::SanityCheck() const
327327
// Check that cached m_total_announcements is correct
328328
unsigned int counted_total_announcements{0};
329329
// Check that m_total_orphan_usage is correct
330-
unsigned int counted_total_usage{0};
330+
int64_t counted_total_usage{0};
331331

332332
// Check that cached PeerOrphanInfo::m_total_size is correct
333-
std::map<NodeId, unsigned int> counted_size_per_peer;
333+
std::map<NodeId, int64_t> counted_size_per_peer;
334334

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

src/txorphanage.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ class TxOrphanage {
9595

9696
/** Get the total usage (weight) of all orphans. If an orphan has multiple announcers, its usage is
9797
* only counted once within this total. */
98-
unsigned int TotalOrphanUsage() const { return m_total_orphan_usage; }
98+
int64_t TotalOrphanUsage() const { return m_total_orphan_usage; }
9999

100100
/** Total usage (weight) of orphans for which this peer is an announcer. If an orphan has multiple
101101
* announcers, its weight will be accounted for in each PeerOrphanInfo, so the total of all
102102
* peers' UsageByPeer() may be larger than TotalOrphanBytes(). */
103-
unsigned int UsageByPeer(NodeId peer) const {
103+
int64_t UsageByPeer(NodeId peer) const {
104104
auto peer_it = m_peer_orphanage_info.find(peer);
105105
return peer_it == m_peer_orphanage_info.end() ? 0 : peer_it->second.m_total_usage;
106106
}
@@ -115,7 +115,7 @@ class TxOrphanage {
115115
};
116116

117117
/** Total usage (weight) of all entries in m_orphans. */
118-
unsigned int m_total_orphan_usage{0};
118+
int64_t m_total_orphan_usage{0};
119119

120120
/** Total number of <peer, tx> pairs. Can be larger than m_orphans.size() because multiple peers
121121
* may have announced the same orphan. */
@@ -137,7 +137,7 @@ class TxOrphanage {
137137
* PeerOrphanInfo, so the total of all peers' m_total_usage may be larger than
138138
* m_total_orphan_size. If a peer is removed as an announcer, even if the orphan still
139139
* remains in the orphanage, this number will be decremented. */
140-
unsigned int m_total_usage{0};
140+
int64_t m_total_usage{0};
141141
};
142142
std::map<NodeId, PeerOrphanInfo> m_peer_orphanage_info;
143143

0 commit comments

Comments
 (0)