Skip to content

Commit 8c99d1b

Browse files
committed
Treat orphans as implicit inv for parents, discard when parents rejected.
An orphan whos parents were rejected is never going to connect, so there is little utility in keeping it. Orphans also helpfully tell us what we're missing, so go ahead and treat it as INVed.
1 parent 11cc143 commit 8c99d1b

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/main.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5156,13 +5156,29 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
51565156
}
51575157
else if (fMissingInputs)
51585158
{
5159-
AddOrphanTx(tx, pfrom->GetId());
5159+
bool fRejectedParents = false; // It may be the case that the orphans parents have all been rejected
5160+
BOOST_FOREACH(const CTxIn& txin, tx.vin) {
5161+
if (recentRejects->contains(txin.prevout.hash)) {
5162+
fRejectedParents = true;
5163+
break;
5164+
}
5165+
}
5166+
if (!fRejectedParents) {
5167+
BOOST_FOREACH(const CTxIn& txin, tx.vin) {
5168+
CInv inv(MSG_TX, txin.prevout.hash);
5169+
pfrom->AddInventoryKnown(inv);
5170+
if (!AlreadyHave(inv)) pfrom->AskFor(inv);
5171+
}
5172+
AddOrphanTx(tx, pfrom->GetId());
51605173

5161-
// DoS prevention: do not allow mapOrphanTransactions to grow unbounded
5162-
unsigned int nMaxOrphanTx = (unsigned int)std::max((int64_t)0, GetArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS));
5163-
unsigned int nEvicted = LimitOrphanTxSize(nMaxOrphanTx);
5164-
if (nEvicted > 0)
5165-
LogPrint("mempool", "mapOrphan overflow, removed %u tx\n", nEvicted);
5174+
// DoS prevention: do not allow mapOrphanTransactions to grow unbounded
5175+
unsigned int nMaxOrphanTx = (unsigned int)std::max((int64_t)0, GetArg("-maxorphantx", DEFAULT_MAX_ORPHAN_TRANSACTIONS));
5176+
unsigned int nEvicted = LimitOrphanTxSize(nMaxOrphanTx);
5177+
if (nEvicted > 0)
5178+
LogPrint("mempool", "mapOrphan overflow, removed %u tx\n", nEvicted);
5179+
} else {
5180+
LogPrint("mempool", "not keeping orphan with rejected parents %s\n",tx.GetHash().ToString());
5181+
}
51665182
} else {
51675183
assert(recentRejects);
51685184
recentRejects->insert(tx.GetHash());

0 commit comments

Comments
 (0)