MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / CheckInputsFromMempoolAndCache

Function CheckInputsFromMempoolAndCache

src/validation.cpp:551–583  ·  view source on GitHub ↗

Used to avoid mempool polluting consensus critical paths if CCoinsViewMempool were somehow broken and returning the wrong scriptPubKeys

Source from the content-addressed store, hash-verified

549// Used to avoid mempool polluting consensus critical paths if CCoinsViewMempool
550// were somehow broken and returning the wrong scriptPubKeys
551static bool CheckInputsFromMempoolAndCache(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& view, const CTxMemPool& pool,
552 unsigned int flags, bool cacheSigStore, PrecomputedTransactionData& txdata) {
553 AssertLockHeld(cs_main);
554
555 // pool.cs should be locked already, but go ahead and re-take the lock here
556 // to enforce that mempool doesn't change between when we check the view
557 // and when we actually call through to CheckInputs
558 LOCK(pool.cs);
559
560 assert(!tx.IsCoinBase());
561 for (const CTxIn& txin : tx.vin) {
562 const Coin& coin = view.AccessCoin(txin.prevout);
563
564 // At this point we haven't actually checked if the coins are all
565 // available (or shouldn't assume we have, since CheckInputs does).
566 // So we just return failure if the inputs are not available here,
567 // and then only have to check equivalence for available inputs.
568 if (coin.IsSpent()) return false;
569
570 const CTransactionRef& txFrom = pool.get(txin.prevout.hash);
571 if (txFrom) {
572 assert(txFrom->GetHash() == txin.prevout.hash);
573 assert(txFrom->vout.size() > txin.prevout.n);
574 assert(txFrom->vout[txin.prevout.n] == coin.out);
575 } else {
576 const Coin& coinFromDisk = pcoinsTip->AccessCoin(txin.prevout);
577 assert(!coinFromDisk.IsSpent());
578 assert(coinFromDisk.out == coin.out);
579 }
580 }
581
582 return CheckInputs(tx, state, view, true, flags, cacheSigStore, true, txdata);
583}
584
585static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool& pool, CValidationState& state, const CTransactionRef& ptx,
586 bool* pfMissingInputs, int64_t nAcceptTime, std::list<CTransactionRef>* plTxnReplaced,

Callers 1

AcceptToMemoryPoolWorkerFunction · 0.85

Calls 6

CheckInputsFunction · 0.85
getMethod · 0.80
IsCoinBaseMethod · 0.45
IsSpentMethod · 0.45
GetHashMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected