@@ -43,6 +43,8 @@ bool TxOrphanage::AddTx(const CTransactionRef& tx, NodeId peer)
43
43
m_outpoint_to_orphan_it[txin.prevout ].insert (ret.first );
44
44
}
45
45
m_total_orphan_usage += sz;
46
+ auto & peer_info = m_peer_orphanage_info.try_emplace (peer).first ->second ;
47
+ peer_info.m_total_usage += sz;
46
48
47
49
LogDebug (BCLog::TXPACKAGES, " stored orphan tx %s (wtxid=%s), weight: %u (mapsz %u outsz %u)\n " , hash.ToString (), wtxid.ToString (), sz,
48
50
m_orphans.size (), m_outpoint_to_orphan_it.size ());
@@ -56,6 +58,8 @@ bool TxOrphanage::AddAnnouncer(const Wtxid& wtxid, NodeId peer)
56
58
Assume (!it->second .announcers .empty ());
57
59
const auto ret = it->second .announcers .insert (peer);
58
60
if (ret.second ) {
61
+ auto & peer_info = m_peer_orphanage_info.try_emplace (peer).first ->second ;
62
+ peer_info.m_total_usage += it->second .GetUsage ();
59
63
LogDebug (BCLog::TXPACKAGES, " added peer=%d as announcer of orphan tx %s\n " , peer, wtxid.ToString ());
60
64
return true ;
61
65
}
@@ -80,6 +84,13 @@ int TxOrphanage::EraseTx(const Wtxid& wtxid)
80
84
81
85
const auto tx_size{it->second .GetUsage ()};
82
86
m_total_orphan_usage -= tx_size;
87
+ // Decrement each announcer's m_total_usage
88
+ for (const auto & peer : it->second .announcers ) {
89
+ auto peer_it = m_peer_orphanage_info.find (peer);
90
+ if (Assume (peer_it != m_peer_orphanage_info.end ())) {
91
+ peer_it->second .m_total_usage -= tx_size;
92
+ }
93
+ }
83
94
84
95
size_t old_pos = it->second .list_pos ;
85
96
assert (m_orphan_list[old_pos] == it);
@@ -103,6 +114,7 @@ int TxOrphanage::EraseTx(const Wtxid& wtxid)
103
114
104
115
void TxOrphanage::EraseForPeer (NodeId peer)
105
116
{
117
+ // Zeroes out this peer's m_total_usage.
106
118
m_peer_orphanage_info.erase (peer);
107
119
108
120
int nErased = 0 ;
0 commit comments