Skip to content

Commit b961bab

Browse files
sipapatricklodder
authored andcommitted
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. Cherry-picked from: 9f2ab9e Github Pull Request: dogecoin#3575
1 parent fd72ba4 commit b961bab

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/net.h

+1
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ class CNode
696696

697697
// Counts getheaders requests sent to this peer
698698
std::atomic<int64_t> nPendingHeaderRequests;
699+
std::set<uint256> orphan_work_set;
699700

700701
CNode(NodeId id, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn, SOCKET hSocketIn, const CAddress &addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const std::string &addrNameIn = "", bool fInboundIn = false);
701702
~CNode();

src/net_processing.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,8 @@ void static ProcessOrphanTx(CConnman* connman, std::set<uint256>& orphan_work_se
13461346
{
13471347
AssertLockHeld(cs_main);
13481348
std::set<NodeId> setMisbehaving;
1349-
while (!orphan_work_set.empty()) {
1349+
bool done = false;
1350+
while (!done && !orphan_work_set.empty()) {
13501351
const uint256 orphanHash = *orphan_work_set.begin();
13511352

13521353
orphan_work_set.erase(orphan_work_set.begin());
@@ -1381,6 +1382,7 @@ void static ProcessOrphanTx(CConnman* connman, std::set<uint256>& orphan_work_se
13811382
}
13821383

13831384
EraseOrphanTx(orphanHash);
1385+
done = true;
13841386

13851387
} else if (!fMissingInputs2) {
13861388

@@ -1403,6 +1405,7 @@ void static ProcessOrphanTx(CConnman* connman, std::set<uint256>& orphan_work_se
14031405
}
14041406

14051407
EraseOrphanTx(orphanHash);
1408+
done = true;
14061409

14071410
}
14081411

@@ -2073,7 +2076,6 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
20732076
return true;
20742077
}
20752078

2076-
std::set<uint256> orphan_work_set;
20772079
CTransactionRef ptx;
20782080
vRecv >> ptx;
20792081
const CTransaction& tx = *ptx;
@@ -2100,7 +2102,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
21002102
auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(inv.hash, i));
21012103
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
21022104
for (const auto& elem : it_by_prev->second) {
2103-
orphan_work_set.insert(elem->first);
2105+
pfrom->orphan_work_set.insert(elem->first);
21042106
}
21052107
}
21062108
}
@@ -2113,7 +2115,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
21132115
mempool.size(), mempool.DynamicMemoryUsage() / 1000);
21142116

21152117
// Recursively process any orphan transactions that depended on this one
2116-
ProcessOrphanTx(&connman, orphan_work_set, lRemovedTxn);
2118+
ProcessOrphanTx(&connman, pfrom->orphan_work_set, lRemovedTxn);
21172119
}
21182120
else if (fMissingInputs)
21192121
{
@@ -2926,11 +2928,21 @@ bool ProcessMessages(CNode* pfrom, CConnman& connman, const std::atomic<bool>& i
29262928
if (!pfrom->vRecvGetData.empty())
29272929
ProcessGetData(pfrom, chainparams.GetConsensus(chainActive.Height()), connman, interruptMsgProc);
29282930

2931+
if (!pfrom->orphan_work_set.empty()) {
2932+
std::list<CTransactionRef> removed_txn;
2933+
LOCK(cs_main);
2934+
ProcessOrphanTx(&connman, pfrom->orphan_work_set, removed_txn);
2935+
for (const CTransactionRef& removedTx : removed_txn) {
2936+
AddToCompactExtraTransactions(removedTx);
2937+
}
2938+
}
2939+
29292940
if (pfrom->fDisconnect)
29302941
return false;
29312942

29322943
// this maintains the order of responses
29332944
if (!pfrom->vRecvGetData.empty()) return true;
2945+
if (!pfrom->orphan_work_set.empty()) return true;
29342946

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

0 commit comments

Comments
 (0)