@@ -457,11 +457,12 @@ class PeerManagerImpl final : public PeerManager
457
457
/* * Number of peers from which we're downloading blocks. */
458
458
int nPeersWithValidatedDownloads GUARDED_BY (cs_main) = 0;
459
459
460
+ /* * Storage for orphan information */
461
+ TxOrphanage m_orphanage;
460
462
};
461
463
} // namespace
462
464
463
465
namespace {
464
-
465
466
/* * Number of preferable block download peers. */
466
467
int nPreferredDownload GUARDED_BY (cs_main) = 0;
467
468
@@ -1003,7 +1004,7 @@ void PeerManagerImpl::FinalizeNode(const CNode& node, bool& fUpdateConnectionTim
1003
1004
for (const QueuedBlock& entry : state->vBlocksInFlight ) {
1004
1005
mapBlocksInFlight.erase (entry.hash );
1005
1006
}
1006
- WITH_LOCK (g_cs_orphans, EraseOrphansFor (nodeid));
1007
+ WITH_LOCK (g_cs_orphans, m_orphanage. EraseForPeer (nodeid));
1007
1008
m_txrequest.DisconnectedPeer (nodeid);
1008
1009
nPreferredDownload -= state->fPreferredDownload ;
1009
1010
nPeersWithValidatedDownloads -= (state->nBlocksInFlightValidHeaders != 0 );
@@ -1080,11 +1081,6 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats)
1080
1081
return true ;
1081
1082
}
1082
1083
1083
- // ////////////////////////////////////////////////////////////////////////////
1084
- //
1085
- // mapOrphanTransactions
1086
- //
1087
-
1088
1084
static void AddToCompactExtraTransactions (const CTransactionRef& tx) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
1089
1085
{
1090
1086
size_t max_extra_txn = gArgs .GetArg (" -blockreconstructionextratxn" , DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN);
@@ -1255,13 +1251,13 @@ PeerManagerImpl::PeerManagerImpl(const CChainParams& chainparams, CConnman& conn
1255
1251
}
1256
1252
1257
1253
/* *
1258
- * Evict orphan txn pool entries (EraseOrphanTx) based on a newly connected
1254
+ * Evict orphan txn pool entries based on a newly connected
1259
1255
* block, remember the recently confirmed transactions, and delete tracked
1260
1256
* announcements for them. Also save the time of the last tip update.
1261
1257
*/
1262
1258
void PeerManagerImpl::BlockConnected (const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
1263
1259
{
1264
- EraseOrphansForBlock (*pblock);
1260
+ m_orphanage. EraseForBlock (*pblock);
1265
1261
m_last_tip_update = GetTime ();
1266
1262
1267
1263
{
@@ -1445,7 +1441,7 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid)
1445
1441
1446
1442
const uint256& hash = gtxid.GetHash ();
1447
1443
1448
- if (HaveOrphanTx (gtxid)) return true ;
1444
+ if (m_orphanage. HaveTx (gtxid)) return true ;
1449
1445
1450
1446
{
1451
1447
LOCK (m_recent_confirmed_transactions_mutex);
@@ -2040,7 +2036,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
2040
2036
const uint256 orphanHash = *orphan_work_set.begin ();
2041
2037
orphan_work_set.erase (orphan_work_set.begin ());
2042
2038
2043
- const auto [porphanTx, from_peer] = GetOrphanTx (orphanHash);
2039
+ const auto [porphanTx, from_peer] = m_orphanage. GetTx (orphanHash);
2044
2040
if (porphanTx == nullptr ) continue ;
2045
2041
2046
2042
const MempoolAcceptResult result = AcceptToMemoryPool (::ChainstateActive (), m_mempool, porphanTx, false /* bypass_limits */ );
@@ -2049,8 +2045,8 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
2049
2045
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
2050
2046
LogPrint (BCLog::MEMPOOL, " accepted orphan tx %s\n " , orphanHash.ToString ());
2051
2047
RelayTransaction (orphanHash, porphanTx->GetWitnessHash (), m_connman);
2052
- AddChildrenToWorkSet (*porphanTx, orphan_work_set);
2053
- EraseOrphanTx (orphanHash);
2048
+ m_orphanage. AddChildrenToWorkSet (*porphanTx, orphan_work_set);
2049
+ m_orphanage. EraseTx (orphanHash);
2054
2050
for (const CTransactionRef& removedTx : result.m_replaced_transactions .value ()) {
2055
2051
AddToCompactExtraTransactions (removedTx);
2056
2052
}
@@ -2097,7 +2093,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
2097
2093
recentRejects->insert (porphanTx->GetHash ());
2098
2094
}
2099
2095
}
2100
- EraseOrphanTx (orphanHash);
2096
+ m_orphanage. EraseTx (orphanHash);
2101
2097
break ;
2102
2098
}
2103
2099
}
@@ -3068,7 +3064,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3068
3064
m_txrequest.ForgetTxHash (tx.GetHash ());
3069
3065
m_txrequest.ForgetTxHash (tx.GetWitnessHash ());
3070
3066
RelayTransaction (tx.GetHash (), tx.GetWitnessHash (), m_connman);
3071
- AddChildrenToWorkSet (tx, peer->m_orphan_work_set );
3067
+ m_orphanage. AddChildrenToWorkSet (tx, peer->m_orphan_work_set );
3072
3068
3073
3069
pfrom.nLastTXTime = GetTime ();
3074
3070
@@ -3118,19 +3114,19 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3118
3114
if (!AlreadyHaveTx (gtxid)) AddTxAnnouncement (pfrom, gtxid, current_time);
3119
3115
}
3120
3116
3121
- if (OrphanageAddTx (ptx, pfrom.GetId ())) {
3117
+ if (m_orphanage. AddTx (ptx, pfrom.GetId ())) {
3122
3118
AddToCompactExtraTransactions (ptx);
3123
3119
}
3124
3120
3125
3121
// Once added to the orphan pool, a tx is considered AlreadyHave, and we shouldn't request it anymore.
3126
3122
m_txrequest.ForgetTxHash (tx.GetHash ());
3127
3123
m_txrequest.ForgetTxHash (tx.GetWitnessHash ());
3128
3124
3129
- // DoS prevention: do not allow mapOrphanTransactions to grow unbounded (see CVE-2012-3789)
3125
+ // DoS prevention: do not allow m_orphanage to grow unbounded (see CVE-2012-3789)
3130
3126
unsigned int nMaxOrphanTx = (unsigned int )std::max ((int64_t )0 , gArgs .GetArg (" -maxorphantx" , DEFAULT_MAX_ORPHAN_TRANSACTIONS));
3131
- unsigned int nEvicted = LimitOrphanTxSize (nMaxOrphanTx);
3127
+ unsigned int nEvicted = m_orphanage. LimitOrphans (nMaxOrphanTx);
3132
3128
if (nEvicted > 0 ) {
3133
- LogPrint (BCLog::MEMPOOL, " mapOrphan overflow, removed %u tx\n " , nEvicted);
3129
+ LogPrint (BCLog::MEMPOOL, " orphanage overflow, removed %u tx\n " , nEvicted);
3134
3130
}
3135
3131
} else {
3136
3132
LogPrint (BCLog::MEMPOOL, " not keeping orphan with rejected parents %s\n " ,tx.GetHash ().ToString ());
@@ -4744,15 +4740,3 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
4744
4740
return true ;
4745
4741
}
4746
4742
4747
- class CNetProcessingCleanup
4748
- {
4749
- public:
4750
- CNetProcessingCleanup () {}
4751
- ~CNetProcessingCleanup () {
4752
- // orphan transactions
4753
- mapOrphanTransactions.clear ();
4754
- mapOrphanTransactionsByPrev.clear ();
4755
- g_orphans_by_wtxid.clear ();
4756
- }
4757
- };
4758
- static CNetProcessingCleanup instance_of_cnetprocessingcleanup;
0 commit comments