Merge #10557: Make check to distinguish between orphan txs and old txs more efficient.
18bacec6c
Make check to distinguish between orphan txs and old txs more efficient. (Alex Morcos)
Tree-SHA512: b6b4bad89aa561975dce7b68b2fdad5623af5ebcb9c38fd6a72b5f6d0544ed441df4865591ac018f7ae0df9b5c60820cb4d9e55664f5667c9268458df70fd554
This commit is contained in:
commit
66270a416e
1 changed files with 8 additions and 12 deletions
|
@ -532,24 +532,20 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
|
|||
CCoinsViewMemPool viewMemPool(pcoinsTip, pool);
|
||||
view.SetBackend(viewMemPool);
|
||||
|
||||
// do we already have it?
|
||||
for (size_t out = 0; out < tx.vout.size(); out++) {
|
||||
COutPoint outpoint(hash, out);
|
||||
bool had_coin_in_cache = pcoinsTip->HaveCoinInCache(outpoint);
|
||||
if (view.HaveCoin(outpoint)) {
|
||||
if (!had_coin_in_cache) {
|
||||
coins_to_uncache.push_back(outpoint);
|
||||
}
|
||||
return state.Invalid(false, REJECT_DUPLICATE, "txn-already-known");
|
||||
}
|
||||
}
|
||||
|
||||
// do all inputs exist?
|
||||
for (const CTxIn txin : tx.vin) {
|
||||
if (!pcoinsTip->HaveCoinInCache(txin.prevout)) {
|
||||
coins_to_uncache.push_back(txin.prevout);
|
||||
}
|
||||
if (!view.HaveCoin(txin.prevout)) {
|
||||
// Are inputs missing because we already have the tx?
|
||||
for (size_t out = 0; out < tx.vout.size(); out++) {
|
||||
// Optimistically just do efficient check of cache for outputs
|
||||
if (pcoinsTip->HaveCoinInCache(COutPoint(hash, out))) {
|
||||
return state.Invalid(false, REJECT_DUPLICATE, "txn-already-known");
|
||||
}
|
||||
}
|
||||
// Otherwise assume this might be an orphan tx for which we just haven't seen parents yet
|
||||
if (pfMissingInputs) {
|
||||
*pfMissingInputs = true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue