From 001343f4bc8b22fa9e313bd2867756eb9d614fa3 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Thu, 25 Jun 2020 17:26:55 -0400 Subject: [PATCH] ProcessOrphanTx: Move AddToCompactExtraTransactions call into ProcessOrphanTx --- src/net_processing.cpp | 23 +++++++++++------------ src/net_processing.h | 3 +-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 5c3b71faa2c..c82574c4f64 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2041,10 +2041,8 @@ void PeerManager::ProcessHeadersMessage(CNode& pfrom, const std::vector& orphan_work_set, std::list& removed_txn) +void PeerManager::ProcessOrphanTx(std::set& orphan_work_set) { AssertLockHeld(cs_main); AssertLockHeld(g_cs_orphans); @@ -2058,6 +2056,7 @@ void PeerManager::ProcessOrphanTx(std::set& orphan_work_set, std::list< const CTransactionRef porphanTx = orphan_it->second.tx; TxValidationState state; + std::list removed_txn; if (AcceptToMemoryPool(m_mempool, state, porphanTx, &removed_txn, false /* bypass_limits */, 0 /* nAbsurdFee */)) { LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString()); @@ -2071,6 +2070,9 @@ void PeerManager::ProcessOrphanTx(std::set& orphan_work_set, std::list< } } EraseOrphanTx(orphanHash); + for (const CTransactionRef& removedTx : removed_txn) { + AddToCompactExtraTransactions(removedTx); + } break; } else if (state.GetResult() != TxValidationResult::TX_MISSING_INPUTS) { if (state.IsInvalid()) { @@ -3034,8 +3036,12 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat tx.GetHash().ToString(), m_mempool.size(), m_mempool.DynamicMemoryUsage() / 1000); + for (const CTransactionRef& removedTx : lRemovedTxn) { + AddToCompactExtraTransactions(removedTx); + } + // Recursively process any orphan transactions that depended on this one - ProcessOrphanTx(pfrom.orphan_work_set, lRemovedTxn); + ProcessOrphanTx(pfrom.orphan_work_set); } else if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) { @@ -3138,9 +3144,6 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat } } - for (const CTransactionRef& removedTx : lRemovedTxn) - AddToCompactExtraTransactions(removedTx); - // If a tx has been detected by recentRejects, we will have reached // this point and the tx will have been ignored. Because we haven't run // the tx through AcceptToMemoryPool, we won't have computed a DoS @@ -3853,12 +3856,8 @@ bool PeerManager::ProcessMessages(CNode* pfrom, std::atomic& interruptMsgP ProcessGetData(*pfrom, m_chainparams, m_connman, m_mempool, interruptMsgProc); if (!pfrom->orphan_work_set.empty()) { - std::list removed_txn; LOCK2(cs_main, g_cs_orphans); - ProcessOrphanTx(pfrom->orphan_work_set, removed_txn); - for (const CTransactionRef& removedTx : removed_txn) { - AddToCompactExtraTransactions(removedTx); - } + ProcessOrphanTx(pfrom->orphan_work_set); } if (pfrom->fDisconnect) diff --git a/src/net_processing.h b/src/net_processing.h index 520f7489e8f..f7afddda23a 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -121,8 +121,7 @@ private: */ bool MaybeDiscourageAndDisconnect(CNode& pnode); - void ProcessOrphanTx(std::set& orphan_work_set, std::list& removed_txn) - EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_cs_orphans); + void ProcessOrphanTx(std::set& orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_cs_orphans); /** Process a single headers message from a peer. */ void ProcessHeadersMessage(CNode& pfrom, const std::vector& headers, bool via_compact_block);