net_processing: Pass a Peer& to ProcessOrphanTx

This commit is contained in:
Anthony Towns committed 2022-10-07 14:40:26 +10:00
1 parent 89e2e0da0b
commit 9910ed755c
1 file changed
+9 -9
+9 -9
View File
@@ -589,7 +589,7 @@ private:
*/ */
bool MaybeDiscourageAndDisconnect(CNode& pnode, Peer& peer); bool MaybeDiscourageAndDisconnect(CNode& pnode, Peer& peer);
void ProcessOrphanTx(std::set<uint256>& orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_cs_orphans) void ProcessOrphanTx(Peer& peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_cs_orphans)
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex); EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex);
/** Process a single headers message from a peer. /** Process a single headers message from a peer.
* *
@@ -2878,20 +2878,20 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
/** /**
* Reconsider orphan transactions after a parent has been accepted to the mempool. * Reconsider orphan transactions after a parent has been accepted to the mempool.
* *
* @param[in,out] orphan_work_set The set of orphan transactions to reconsider. Generally only one * @peer[in] peer The peer whose orphan transactions we will reconsider. Generally only one
* orphan will be reconsidered on each call of this function. This set * orphan will be reconsidered on each call of this function. This set
* may be added to if accepting an orphan causes its children to be * may be added to if accepting an orphan causes its children to be
* reconsidered. * reconsidered.
*/ */
void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set) void PeerManagerImpl::ProcessOrphanTx(Peer& peer)
{ {
AssertLockHeld(g_msgproc_mutex); AssertLockHeld(g_msgproc_mutex);
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
AssertLockHeld(g_cs_orphans); AssertLockHeld(g_cs_orphans);
while (!orphan_work_set.empty()) { while (!peer.m_orphan_work_set.empty()) {
const uint256 orphanHash = *orphan_work_set.begin(); const uint256 orphanHash = *peer.m_orphan_work_set.begin();
orphan_work_set.erase(orphan_work_set.begin()); peer.m_orphan_work_set.erase(peer.m_orphan_work_set.begin());
const auto [porphanTx, from_peer] = m_orphanage.GetTx(orphanHash); const auto [porphanTx, from_peer] = m_orphanage.GetTx(orphanHash);
if (porphanTx == nullptr) continue; if (porphanTx == nullptr) continue;
@@ -2902,7 +2902,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) { if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString()); LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
RelayTransaction(orphanHash, porphanTx->GetWitnessHash()); RelayTransaction(orphanHash, porphanTx->GetWitnessHash());
m_orphanage.AddChildrenToWorkSet(*porphanTx, orphan_work_set); m_orphanage.AddChildrenToWorkSet(*porphanTx, peer.m_orphan_work_set);
m_orphanage.EraseTx(orphanHash); m_orphanage.EraseTx(orphanHash);
for (const CTransactionRef& removedTx : result.m_replaced_transactions.value()) { for (const CTransactionRef& removedTx : result.m_replaced_transactions.value()) {
AddToCompactExtraTransactions(removedTx); AddToCompactExtraTransactions(removedTx);
@@ -3959,7 +3959,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
} }
// Recursively process any orphan transactions that depended on this one // Recursively process any orphan transactions that depended on this one
ProcessOrphanTx(peer->m_orphan_work_set); ProcessOrphanTx(*peer);
} }
else if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) else if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS)
{ {
@@ -4771,7 +4771,7 @@ bool PeerManagerImpl::ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt
{ {
LOCK2(cs_main, g_cs_orphans); LOCK2(cs_main, g_cs_orphans);
if (!peer->m_orphan_work_set.empty()) { if (!peer->m_orphan_work_set.empty()) {
ProcessOrphanTx(peer->m_orphan_work_set); ProcessOrphanTx(*peer);
} }
} }