Skip to content

Commit ee135c8

Browse files
committed
txorphanage: Extract AddChildrenToWorkSet
Extract some common code into AddChildrenToWorkSet function. (It's a hard knock life)
1 parent 38a11c3 commit ee135c8

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/net_processing.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,14 +2121,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
21212121
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
21222122
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
21232123
RelayTransaction(orphanHash, porphanTx->GetWitnessHash(), m_connman);
2124-
for (unsigned int i = 0; i < porphanTx->vout.size(); i++) {
2125-
auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(orphanHash, i));
2126-
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
2127-
for (const auto& elem : it_by_prev->second) {
2128-
orphan_work_set.insert(elem->first);
2129-
}
2130-
}
2131-
}
2124+
AddChildrenToWorkSet(*porphanTx, orphan_work_set);
21322125
EraseOrphanTx(orphanHash);
21332126
for (const CTransactionRef& removedTx : result.m_replaced_transactions.value()) {
21342127
AddToCompactExtraTransactions(removedTx);
@@ -3147,14 +3140,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
31473140
m_txrequest.ForgetTxHash(tx.GetHash());
31483141
m_txrequest.ForgetTxHash(tx.GetWitnessHash());
31493142
RelayTransaction(tx.GetHash(), tx.GetWitnessHash(), m_connman);
3150-
for (unsigned int i = 0; i < tx.vout.size(); i++) {
3151-
auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(txid, i));
3152-
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
3153-
for (const auto& elem : it_by_prev->second) {
3154-
peer->m_orphan_work_set.insert(elem->first);
3155-
}
3156-
}
3157-
}
3143+
AddChildrenToWorkSet(tx, peer->m_orphan_work_set);
31583144

31593145
pfrom.nLastTXTime = GetTime();
31603146

src/txorphanage.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,16 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
106106
return nEvicted;
107107
}
108108

109+
void AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work_set)
110+
{
111+
AssertLockHeld(g_cs_orphans);
112+
for (unsigned int i = 0; i < tx.vout.size(); i++) {
113+
const auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(tx.GetHash(), i));
114+
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
115+
for (const auto& elem : it_by_prev->second) {
116+
orphan_work_set.insert(elem->first);
117+
}
118+
}
119+
}
120+
}
121+

src/txorphanage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct COrphanTx {
2626
int EraseOrphanTx(const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
2727
void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
2828
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
29+
void AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
2930

3031
/** Map from txid to orphan transaction record. Limited by
3132
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */

0 commit comments

Comments
 (0)