diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2017-07-14 11:54:09 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2017-07-14 11:54:50 -0700 |
commit | 66270a416edb1610f276124483feceef9cba93ff (patch) | |
tree | 71fa45b458185654114525187df5db8edfa2675d /src | |
parent | db825d293be8134505187352ec5844b70f37a43f (diff) | |
parent | 18bacec6c2c8493fd6b7011778446b3c7473bb25 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/validation.cpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index ddc8b1b964..bcc158c504 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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; } |