@@ -699,23 +699,23 @@ void CTxMemPool::check(CChainState& active_chainstate) const
699
699
CCoinsViewCache mempoolDuplicate (const_cast <CCoinsViewCache*>(&active_coins_tip));
700
700
const int64_t spendheight = active_chainstate.m_chain .Height () + 1 ;
701
701
702
- std::list<const CTxMemPoolEntry*> waitingOnDependants;
703
702
for (const auto & it : GetSortedDepthAndScore ()) {
704
- unsigned int i = 0 ;
705
703
checkTotal += it->GetTxSize ();
706
704
check_total_fee += it->GetFee ();
707
705
innerUsage += it->DynamicMemoryUsage ();
708
706
const CTransaction& tx = it->GetTx ();
709
707
innerUsage += memusage::DynamicUsage (it->GetMemPoolParentsConst ()) + memusage::DynamicUsage (it->GetMemPoolChildrenConst ());
710
- bool fDependsWait = false ;
711
708
CTxMemPoolEntry::Parents setParentCheck;
712
709
for (const CTxIn &txin : tx.vin ) {
713
710
// Check that every mempool transaction's inputs refer to available coins, or other mempool tx's.
714
711
indexed_transaction_set::const_iterator it2 = mapTx.find (txin.prevout .hash );
715
712
if (it2 != mapTx.end ()) {
716
713
const CTransaction& tx2 = it2->GetTx ();
717
714
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 ));
719
719
setParentCheck.insert (*it2);
720
720
} else {
721
721
assert (active_coins_tip.HaveCoin (txin.prevout ));
@@ -725,7 +725,6 @@ void CTxMemPool::check(CChainState& active_chainstate) const
725
725
assert (it3 != mapNextTx.end ());
726
726
assert (it3->first == &txin.prevout );
727
727
assert (it3->second == &tx);
728
- i++;
729
728
}
730
729
auto comp = [](const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) -> bool {
731
730
return a.GetTx ().GetHash () == b.GetTx ().GetHash ();
@@ -773,24 +772,7 @@ void CTxMemPool::check(CChainState& active_chainstate) const
773
772
// just a sanity check, not definitive that this calc is correct...
774
773
assert (it->GetSizeWithDescendants () >= child_sizes + it->GetTxSize ());
775
774
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);
794
776
}
795
777
for (auto it = mapNextTx.cbegin (); it != mapNextTx.cend (); it++) {
796
778
uint256 hash = it->second ->GetHash ();
0 commit comments