Skip to content

Commit f294da7

Browse files
committed
txorphanage: Extract GetOrphanTx
Extract orphan lookup code into GetOrphanTx function.
1 parent 83679ff commit f294da7

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/net_processing.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,10 +2104,9 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
21042104
const uint256 orphanHash = *orphan_work_set.begin();
21052105
orphan_work_set.erase(orphan_work_set.begin());
21062106

2107-
auto orphan_it = mapOrphanTransactions.find(orphanHash);
2108-
if (orphan_it == mapOrphanTransactions.end()) continue;
2107+
const auto [porphanTx, from_peer] = GetOrphanTx(orphanHash);
2108+
if (porphanTx == nullptr) continue;
21092109

2110-
const CTransactionRef porphanTx = orphan_it->second.tx;
21112110
const MempoolAcceptResult result = AcceptToMemoryPool(::ChainstateActive(), m_mempool, porphanTx, false /* bypass_limits */);
21122111
const TxValidationState& state = result.m_state;
21132112

@@ -2124,10 +2123,10 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
21242123
if (state.IsInvalid()) {
21252124
LogPrint(BCLog::MEMPOOL, " invalid orphan tx %s from peer=%d. %s\n",
21262125
orphanHash.ToString(),
2127-
orphan_it->second.fromPeer,
2126+
from_peer,
21282127
state.ToString());
21292128
// Maybe punish peer that gave us an invalid orphan tx
2130-
MaybePunishNodeForTx(orphan_it->second.fromPeer, state);
2129+
MaybePunishNodeForTx(from_peer, state);
21312130
}
21322131
// Has inputs but not accepted to mempool
21332132
// Probably non-standard or insufficient fee

src/txorphanage.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,11 @@ bool HaveOrphanTx(const GenTxid& gtxid)
129129
}
130130
}
131131

132+
std::pair<CTransactionRef, NodeId> GetOrphanTx(const uint256& txid)
133+
{
134+
AssertLockHeld(g_cs_orphans);
135+
136+
const auto it = mapOrphanTransactions.find(txid);
137+
if (it == mapOrphanTransactions.end()) return {nullptr, -1};
138+
return {it->second.tx, it->second.fromPeer};
139+
}

src/txorphanage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
2828
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
2929
void AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
3030
bool HaveOrphanTx(const GenTxid& gtxid) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans);
31+
std::pair<CTransactionRef, NodeId> GetOrphanTx(const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
3132

3233
/** Map from txid to orphan transaction record. Limited by
3334
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */

0 commit comments

Comments
 (0)