Skip to content

Commit 66270a4

Browse files
committed
Merge #10557: Make check to distinguish between orphan txs and old txs more efficient.
18bacec Make check to distinguish between orphan txs and old txs more efficient. (Alex Morcos) Tree-SHA512: b6b4bad89aa561975dce7b68b2fdad5623af5ebcb9c38fd6a72b5f6d0544ed441df4865591ac018f7ae0df9b5c60820cb4d9e55664f5667c9268458df70fd554
2 parents db825d2 + 18bacec commit 66270a4

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/validation.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -532,24 +532,20 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
532532
CCoinsViewMemPool viewMemPool(pcoinsTip, pool);
533533
view.SetBackend(viewMemPool);
534534

535-
// do we already have it?
536-
for (size_t out = 0; out < tx.vout.size(); out++) {
537-
COutPoint outpoint(hash, out);
538-
bool had_coin_in_cache = pcoinsTip->HaveCoinInCache(outpoint);
539-
if (view.HaveCoin(outpoint)) {
540-
if (!had_coin_in_cache) {
541-
coins_to_uncache.push_back(outpoint);
542-
}
543-
return state.Invalid(false, REJECT_DUPLICATE, "txn-already-known");
544-
}
545-
}
546-
547535
// do all inputs exist?
548536
for (const CTxIn txin : tx.vin) {
549537
if (!pcoinsTip->HaveCoinInCache(txin.prevout)) {
550538
coins_to_uncache.push_back(txin.prevout);
551539
}
552540
if (!view.HaveCoin(txin.prevout)) {
541+
// Are inputs missing because we already have the tx?
542+
for (size_t out = 0; out < tx.vout.size(); out++) {
543+
// Optimistically just do efficient check of cache for outputs
544+
if (pcoinsTip->HaveCoinInCache(COutPoint(hash, out))) {
545+
return state.Invalid(false, REJECT_DUPLICATE, "txn-already-known");
546+
}
547+
}
548+
// Otherwise assume this might be an orphan tx for which we just haven't seen parents yet
553549
if (pfMissingInputs) {
554550
*pfMissingInputs = true;
555551
}

0 commit comments

Comments
 (0)