Skip to content

Commit c289217

Browse files
committed
[txorphanage] track the total number of announcements
1 parent e5ea7da commit c289217

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/txorphanage.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
4343
m_outpoint_to_orphan_it[txin.prevout].insert(ret.first);
4444
}
4545
m_total_orphan_usage += sz;
46+
m_total_announcements += 1;
4647
auto& peer_info = m_peer_orphanage_info.try_emplace(peer).first->second;
4748
peer_info.m_total_usage += sz;
4849

@@ -60,6 +61,7 @@ bool TxOrphanage::AddAnnouncer(const Wtxid& wtxid, NodeId peer)
6061
if (ret.second) {
6162
auto& peer_info = m_peer_orphanage_info.try_emplace(peer).first->second;
6263
peer_info.m_total_usage += it->second.GetUsage();
64+
m_total_announcements += 1;
6365
LogDebug(BCLog::TXPACKAGES, "added peer=%d as announcer of orphan tx %s\n", peer, wtxid.ToString());
6466
return true;
6567
}
@@ -84,6 +86,7 @@ int TxOrphanage::EraseTx(const Wtxid& wtxid)
8486

8587
const auto tx_size{it->second.GetUsage()};
8688
m_total_orphan_usage -= tx_size;
89+
m_total_announcements -= it->second.announcers.size();
8790
// Decrement each announcer's m_total_usage
8891
for (const auto& peer : it->second.announcers) {
8992
auto peer_it = m_peer_orphanage_info.find(peer);
@@ -126,6 +129,7 @@ void TxOrphanage::EraseForPeer(NodeId peer)
126129
auto orphan_it = orphan.announcers.find(peer);
127130
if (orphan_it != orphan.announcers.end()) {
128131
orphan.announcers.erase(peer);
132+
m_total_announcements -= 1;
129133

130134
// No remaining announcers: clean up entry
131135
if (orphan.announcers.empty()) {

src/txorphanage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ class TxOrphanage {
113113
/** Total usage (weight) of all entries in m_orphans. */
114114
unsigned int m_total_orphan_usage{0};
115115

116+
/** Total number of <peer, tx> pairs. Can be larger than m_orphans.size() because multiple peers
117+
* may have announced the same orphan. */
118+
unsigned int m_total_announcements{0};
119+
116120
/** Map from wtxid to orphan transaction record. Limited by
117121
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */
118122
std::map<Wtxid, OrphanTx> m_orphans;

0 commit comments

Comments
 (0)