diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2991,14 +2991,12 @@ const TxId orphanTxId = *orphan_work_set.begin(); orphan_work_set.erase(orphan_work_set.begin()); - auto orphan_it = mapOrphanTransactions.find(orphanTxId); - if (orphan_it == mapOrphanTransactions.end()) { + const auto [porphanTx, from_peer] = GetOrphanTx(orphanTxId); + if (porphanTx == nullptr) { continue; } - const CTransactionRef porphanTx = orphan_it->second.tx; TxValidationState state; - if (AcceptToMemoryPool(::ChainstateActive(), config, m_mempool, state, porphanTx, false /* bypass_limits */)) { LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", @@ -3011,10 +3009,9 @@ if (state.IsInvalid()) { LogPrint(BCLog::MEMPOOL, " invalid orphan tx %s from peer=%d. %s\n", - orphanTxId.ToString(), orphan_it->second.fromPeer, - state.ToString()); + orphanTxId.ToString(), from_peer, state.ToString()); // Punish peer that gave us an invalid orphan tx - MaybePunishNodeForTx(orphan_it->second.fromPeer, state); + MaybePunishNodeForTx(from_peer, state); } // Has inputs but not accepted to mempool // Probably non-standard or insufficient fee diff --git a/src/txorphanage.h b/src/txorphanage.h --- a/src/txorphanage.h +++ b/src/txorphanage.h @@ -31,6 +31,8 @@ std::set &orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); bool HaveOrphanTx(const TxId &txid) LOCKS_EXCLUDED(g_cs_orphans); +std::pair GetOrphanTx(const TxId &txid) + EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans); /** * Map from txid to orphan transaction record. Limited by diff --git a/src/txorphanage.cpp b/src/txorphanage.cpp --- a/src/txorphanage.cpp +++ b/src/txorphanage.cpp @@ -131,3 +131,13 @@ LOCK(g_cs_orphans); return mapOrphanTransactions.count(txid); } + +std::pair GetOrphanTx(const TxId &txid) { + AssertLockHeld(g_cs_orphans); + + const auto it = mapOrphanTransactions.find(txid); + if (it == mapOrphanTransactions.end()) { + return {nullptr, -1}; + } + return {it->second.tx, it->second.fromPeer}; +}