@@ -699,23 +699,23 @@ void CTxMemPool::check(CChainState& active_chainstate) const
699699 CCoinsViewCache mempoolDuplicate (const_cast <CCoinsViewCache*>(&active_coins_tip));
700700 const int64_t spendheight = active_chainstate.m_chain .Height () + 1 ;
701701
702- std::list<const CTxMemPoolEntry*> waitingOnDependants;
703702 for (const auto & it : GetSortedDepthAndScore ()) {
704- unsigned int i = 0 ;
705703 checkTotal += it->GetTxSize ();
706704 check_total_fee += it->GetFee ();
707705 innerUsage += it->DynamicMemoryUsage ();
708706 const CTransaction& tx = it->GetTx ();
709707 innerUsage += memusage::DynamicUsage (it->GetMemPoolParentsConst ()) + memusage::DynamicUsage (it->GetMemPoolChildrenConst ());
710- bool fDependsWait = false ;
711708 CTxMemPoolEntry::Parents setParentCheck;
712709 for (const CTxIn &txin : tx.vin ) {
713710 // Check that every mempool transaction's inputs refer to available coins, or other mempool tx's.
714711 indexed_transaction_set::const_iterator it2 = mapTx.find (txin.prevout .hash );
715712 if (it2 != mapTx.end ()) {
716713 const CTransaction& tx2 = it2->GetTx ();
717714 assert (tx2.vout .size () > txin.prevout .n && !tx2.vout [txin.prevout .n ].IsNull ());
718- if (!mempoolDuplicate.HaveCoin (txin.prevout )) fDependsWait = true ;
715+ // We are iterating through the mempool entries sorted in order by ancestor count.
716+ // All parents must have been checked before their children and their coins added to
717+ // the mempoolDuplicate coins cache.
718+ assert (mempoolDuplicate.HaveCoin (txin.prevout ));
719719 setParentCheck.insert (*it2);
720720 } else {
721721 assert (active_coins_tip.HaveCoin (txin.prevout ));
@@ -725,7 +725,6 @@ void CTxMemPool::check(CChainState& active_chainstate) const
725725 assert (it3 != mapNextTx.end ());
726726 assert (it3->first == &txin.prevout );
727727 assert (it3->second == &tx);
728- i++;
729728 }
730729 auto comp = [](const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) -> bool {
731730 return a.GetTx ().GetHash () == b.GetTx ().GetHash ();
@@ -773,24 +772,7 @@ void CTxMemPool::check(CChainState& active_chainstate) const
773772 // just a sanity check, not definitive that this calc is correct...
774773 assert (it->GetSizeWithDescendants () >= child_sizes + it->GetTxSize ());
775774
776- if (fDependsWait )
777- waitingOnDependants.push_back (&(*it));
778- else {
779- CheckInputsAndUpdateCoins (tx, mempoolDuplicate, spendheight);
780- }
781- }
782- unsigned int stepsSinceLastRemove = 0 ;
783- while (!waitingOnDependants.empty ()) {
784- const CTxMemPoolEntry* entry = waitingOnDependants.front ();
785- waitingOnDependants.pop_front ();
786- if (!mempoolDuplicate.HaveInputs (entry->GetTx ())) {
787- waitingOnDependants.push_back (entry);
788- stepsSinceLastRemove++;
789- assert (stepsSinceLastRemove < waitingOnDependants.size ());
790- } else {
791- CheckInputsAndUpdateCoins (entry->GetTx (), mempoolDuplicate, spendheight);
792- stepsSinceLastRemove = 0 ;
793- }
775+ CheckInputsAndUpdateCoins (tx, mempoolDuplicate, spendheight);
794776 }
795777 for (auto it = mapNextTx.cbegin (); it != mapNextTx.cend (); it++) {
796778 uint256 hash = it->second ->GetHash ();
0 commit comments