Skip to content

Commit 866c805

Browse files
committed
Interrupt orphan processing after every transaction
This makes orphan processing work like handling getdata messages: After every actual transaction validation attempt, interrupt processing to deal with messages arriving from other peers.
1 parent 6e051f3 commit 866c805

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,8 @@ class CNode
739739
CAmount lastSentFeeFilter{0};
740740
int64_t nextSendTimeFeeFilter{0};
741741

742+
std::set<uint256> orphan_work_set;
743+
742744
CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress &addrBindIn, const std::string &addrNameIn = "", bool fInboundIn = false);
743745
~CNode();
744746
CNode(const CNode&) = delete;

src/net_processing.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,8 @@ void static ProcessOrphanTx(CConnman* connman, std::set<uint256>& orphan_work_se
17181718
AssertLockHeld(cs_main);
17191719
AssertLockHeld(g_cs_orphans);
17201720
std::set<NodeId> setMisbehaving;
1721-
while (!orphan_work_set.empty()) {
1721+
bool done = false;
1722+
while (!done && !orphan_work_set.empty()) {
17221723
const uint256 orphanHash = *orphan_work_set.begin();
17231724
orphan_work_set.erase(orphan_work_set.begin());
17241725

@@ -1747,6 +1748,7 @@ void static ProcessOrphanTx(CConnman* connman, std::set<uint256>& orphan_work_se
17471748
}
17481749
}
17491750
EraseOrphanTx(orphanHash);
1751+
done = true;
17501752
} else if (!fMissingInputs2) {
17511753
int nDos = 0;
17521754
if (stateDummy.IsInvalid(nDos) && nDos > 0) {
@@ -1766,6 +1768,7 @@ void static ProcessOrphanTx(CConnman* connman, std::set<uint256>& orphan_work_se
17661768
recentRejects->insert(orphanHash);
17671769
}
17681770
EraseOrphanTx(orphanHash);
1771+
done = true;
17691772
}
17701773
mempool.check(pcoinsTip.get());
17711774
}
@@ -2400,8 +2403,6 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
24002403
return true;
24012404
}
24022405

2403-
std::set<uint256> orphan_work_set;
2404-
24052406
CTransactionRef ptx;
24062407
vRecv >> ptx;
24072408
const CTransaction& tx = *ptx;
@@ -2429,7 +2430,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
24292430
auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(inv.hash, i));
24302431
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
24312432
for (const auto& elem : it_by_prev->second) {
2432-
orphan_work_set.insert(elem->first);
2433+
pfrom->orphan_work_set.insert(elem->first);
24332434
}
24342435
}
24352436
}
@@ -2442,7 +2443,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
24422443
mempool.size(), mempool.DynamicMemoryUsage() / 1000);
24432444

24442445
// Recursively process any orphan transactions that depended on this one
2445-
ProcessOrphanTx(connman, orphan_work_set, lRemovedTxn);
2446+
ProcessOrphanTx(connman, pfrom->orphan_work_set, lRemovedTxn);
24462447
}
24472448
else if (fMissingInputs)
24482449
{
@@ -3174,11 +3175,21 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& inter
31743175
if (!pfrom->vRecvGetData.empty())
31753176
ProcessGetData(pfrom, chainparams, connman, interruptMsgProc);
31763177

3178+
if (!pfrom->orphan_work_set.empty()) {
3179+
std::list<CTransactionRef> removed_txn;
3180+
LOCK2(cs_main, g_cs_orphans);
3181+
ProcessOrphanTx(connman, pfrom->orphan_work_set, removed_txn);
3182+
for (const CTransactionRef& removedTx : removed_txn) {
3183+
AddToCompactExtraTransactions(removedTx);
3184+
}
3185+
}
3186+
31773187
if (pfrom->fDisconnect)
31783188
return false;
31793189

31803190
// this maintains the order of responses
31813191
if (!pfrom->vRecvGetData.empty()) return true;
3192+
if (!pfrom->orphan_work_set.empty()) return true;
31823193

31833194
// Don't bother if send buffer is too full to respond anyway
31843195
if (pfrom->fPauseSend)

0 commit comments

Comments
 (0)