MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / check

Method check

src/txmempool.cpp:627–740  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

625}
626
627void CTxMemPool::check(const CCoinsViewCache *pcoins) const
628{
629 if (nCheckFrequency == 0)
630 return;
631
632 if (insecure_rand() >= nCheckFrequency)
633 return;
634
635 LogPrint("mempool", "Checking mempool with %u transactions and %u inputs\n", (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size());
636
637 uint64_t checkTotal = 0;
638 uint64_t innerUsage = 0;
639
640 CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(pcoins));
641
642 LOCK(cs);
643 list<const CTxMemPoolEntry*> waitingOnDependants;
644 for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
645 unsigned int i = 0;
646 checkTotal += it->GetTxSize();
647 innerUsage += it->DynamicMemoryUsage();
648 const CTransaction& tx = it->GetTx();
649 txlinksMap::const_iterator linksiter = mapLinks.find(it);
650 assert(linksiter != mapLinks.end());
651 const TxLinks &links = linksiter->second;
652 innerUsage += memusage::DynamicUsage(links.parents) + memusage::DynamicUsage(links.children);
653 bool fDependsWait = false;
654 setEntries setParentCheck;
655 int64_t parentSizes = 0;
656 CAmount parentFees = 0;
657 BOOST_FOREACH(const CTxIn &txin, tx.vin) {
658 // Check that every mempool transaction's inputs refer to available coins, or other mempool tx's.
659 indexed_transaction_set::const_iterator it2 = mapTx.find(txin.prevout.hash);
660 if (it2 != mapTx.end()) {
661 const CTransaction& tx2 = it2->GetTx();
662 assert(tx2.vout.size() > txin.prevout.n && !tx2.vout[txin.prevout.n].IsNull());
663 fDependsWait = true;
664 if (setParentCheck.insert(it2).second) {
665 parentSizes += it2->GetTxSize();
666 parentFees += it2->GetFee();
667 }
668 } else {
669 const CCoins* coins = pcoins->AccessCoins(txin.prevout.hash);
670 assert(coins && coins->IsAvailable(txin.prevout.n));
671 }
672 // Check whether its inputs are marked in mapNextTx.
673 std::map<COutPoint, CInPoint>::const_iterator it3 = mapNextTx.find(txin.prevout);
674 assert(it3 != mapNextTx.end());
675 assert(it3->second.ptx == &tx);
676 assert(it3->second.n == i);
677 i++;
678 }
679 assert(setParentCheck == GetMemPoolParents(it));
680 // Also check to make sure ancestor size/fees are >= sum with immediate
681 // parents.
682 assert(it->GetSizeWithAncestors() >= parentSizes + it->GetTxSize());
683 assert(it->GetFeesWithAncestors() >= parentFees + it->GetFee());
684 assert(it->GetFeesWithAncestors() >= 0);

Callers

nothing calls this directly

Calls 15

insecure_randFunction · 0.85
DynamicUsageFunction · 0.85
CheckInputsFunction · 0.85
UpdateCoinsFunction · 0.85
GetTxSizeMethod · 0.80
findMethod · 0.80
GetSizeWithAncestorsMethod · 0.80
GetFeesWithAncestorsMethod · 0.80
HaveInputsMethod · 0.80
COutPointClass · 0.70

Tested by

no test coverage detected