aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2021-01-31 21:59:57 +1000
committerAnthony Towns <aj@erisian.com.au>2021-02-26 23:55:10 +1000
commitf294da727413210fda279afdc206a4dd12046d56 (patch)
tree2fa630f333aae50b5122e8796151300df0cd03c2
parent83679ffc600305ec0926fd195ee31c11de2ed613 (diff)
downloadbitcoin-f294da727413210fda279afdc206a4dd12046d56.tar.xz
txorphanage: Extract GetOrphanTx
Extract orphan lookup code into GetOrphanTx function.
-rw-r--r--src/net_processing.cpp9
-rw-r--r--src/txorphanage.cpp8
-rw-r--r--src/txorphanage.h1
3 files changed, 13 insertions, 5 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index cda177dfe3..4ac50dc1f0 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -2104,10 +2104,9 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
const uint256 orphanHash = *orphan_work_set.begin();
orphan_work_set.erase(orphan_work_set.begin());
- auto orphan_it = mapOrphanTransactions.find(orphanHash);
- if (orphan_it == mapOrphanTransactions.end()) continue;
+ const auto [porphanTx, from_peer] = GetOrphanTx(orphanHash);
+ if (porphanTx == nullptr) continue;
- const CTransactionRef porphanTx = orphan_it->second.tx;
const MempoolAcceptResult result = AcceptToMemoryPool(::ChainstateActive(), m_mempool, porphanTx, false /* bypass_limits */);
const TxValidationState& state = result.m_state;
@@ -2124,10 +2123,10 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
if (state.IsInvalid()) {
LogPrint(BCLog::MEMPOOL, " invalid orphan tx %s from peer=%d. %s\n",
orphanHash.ToString(),
- orphan_it->second.fromPeer,
+ from_peer,
state.ToString());
// Maybe 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.cpp b/src/txorphanage.cpp
index 473abd5044..6baea9f69e 100644
--- a/src/txorphanage.cpp
+++ b/src/txorphanage.cpp
@@ -129,3 +129,11 @@ bool HaveOrphanTx(const GenTxid& gtxid)
}
}
+std::pair<CTransactionRef, NodeId> GetOrphanTx(const uint256& 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};
+}
diff --git a/src/txorphanage.h b/src/txorphanage.h
index ab4960be69..1adc6f1d6c 100644
--- a/src/txorphanage.h
+++ b/src/txorphanage.h
@@ -28,6 +28,7 @@ void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
void AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
bool HaveOrphanTx(const GenTxid& gtxid) EXCLUSIVE_LOCKS_REQUIRED(!g_cs_orphans);
+std::pair<CTransactionRef, NodeId> GetOrphanTx(const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
/** Map from txid to orphan transaction record. Limited by
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */