@@ -43,6 +43,8 @@ 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+ auto & peer_info = m_peer_orphanage_info.try_emplace (peer).first ->second ;
47+ peer_info.m_total_usage += sz;
4648
4749 LogDebug (BCLog::TXPACKAGES, " stored orphan tx %s (wtxid=%s), weight: %u (mapsz %u outsz %u)\n " , hash.ToString (), wtxid.ToString (), sz,
4850 m_orphans.size (), m_outpoint_to_orphan_it.size ());
@@ -56,6 +58,8 @@ bool TxOrphanage::AddAnnouncer(const Wtxid& wtxid, NodeId peer)
5658 Assume (!it->second .announcers .empty ());
5759 const auto ret = it->second .announcers .insert (peer);
5860 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 ();
5963 LogDebug (BCLog::TXPACKAGES, " added peer=%d as announcer of orphan tx %s\n " , peer, wtxid.ToString ());
6064 return true ;
6165 }
@@ -80,6 +84,13 @@ int TxOrphanage::EraseTx(const Wtxid& wtxid)
8084
8185 const auto tx_size{it->second .GetUsage ()};
8286 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+ }
8394
8495 size_t old_pos = it->second .list_pos ;
8596 assert (m_orphan_list[old_pos] == it);
@@ -103,6 +114,7 @@ int TxOrphanage::EraseTx(const Wtxid& wtxid)
103114
104115void TxOrphanage::EraseForPeer (NodeId peer)
105116{
117+ // Zeroes out this peer's m_total_usage.
106118 m_peer_orphanage_info.erase (peer);
107119
108120 int nErased = 0 ;
0 commit comments