16
16
#include < util/moneystr.h>
17
17
#include < util/system.h>
18
18
#include < util/time.h>
19
- #include < validation.h>
20
19
#include < validationinterface.h>
21
20
22
21
#include < cmath>
@@ -634,43 +633,12 @@ void CTxMemPool::removeRecursive(const CTransaction &origTx, MemPoolRemovalReaso
634
633
RemoveStaged (setAllRemoves, false , reason);
635
634
}
636
635
637
- void CTxMemPool::removeForReorg (CChainState& active_chainstate, int flags )
636
+ void CTxMemPool::removeForReorg (CChain& chain, std::function< bool (txiter)> check_final_and_mature )
638
637
{
639
638
// Remove transactions spending a coinbase which are now immature and no-longer-final transactions
640
639
AssertLockHeld (cs);
641
640
AssertLockHeld (::cs_main);
642
641
643
- const auto check_final_and_mature = [this , &active_chainstate, flags](txiter it)
644
- EXCLUSIVE_LOCKS_REQUIRED (cs, ::cs_main) {
645
- bool should_remove = false ;
646
- AssertLockHeld (cs);
647
- AssertLockHeld (::cs_main);
648
- const CTransaction& tx = it->GetTx ();
649
- LockPoints lp = it->GetLockPoints ();
650
- const bool validLP = TestLockPointValidity (active_chainstate.m_chain , &lp);
651
- CCoinsViewMemPool view_mempool (&active_chainstate.CoinsTip (), *this );
652
- if (!CheckFinalTx (active_chainstate.m_chain .Tip (), tx, flags)
653
- || !CheckSequenceLocks (active_chainstate.m_chain .Tip (), view_mempool, tx, flags, &lp, validLP)) {
654
- // Note if CheckSequenceLocks fails the LockPoints may still be invalid
655
- // So it's critical that we remove the tx and not depend on the LockPoints.
656
- should_remove = true ;
657
- } else if (it->GetSpendsCoinbase ()) {
658
- for (const CTxIn& txin : tx.vin ) {
659
- indexed_transaction_set::const_iterator it2 = mapTx.find (txin.prevout .hash );
660
- if (it2 != mapTx.end ())
661
- continue ;
662
- const Coin &coin = active_chainstate.CoinsTip ().AccessCoin (txin.prevout );
663
- assert (!coin.IsSpent ());
664
- unsigned int nMemPoolHeight = active_chainstate.m_chain .Tip ()->nHeight + 1 ;
665
- if (coin.IsSpent () || (coin.IsCoinBase () && ((signed long )nMemPoolHeight) - coin.nHeight < COINBASE_MATURITY)) {
666
- should_remove = true ;
667
- break ;
668
- }
669
- }
670
- }
671
- return should_remove;
672
- };
673
-
674
642
setEntries txToRemove;
675
643
for (indexed_transaction_set::const_iterator it = mapTx.begin (); it != mapTx.end (); it++) {
676
644
if (check_final_and_mature (it)) txToRemove.insert (it);
@@ -680,7 +648,6 @@ void CTxMemPool::removeForReorg(CChainState& active_chainstate, int flags)
680
648
CalculateDescendants (it, setAllRemoves);
681
649
}
682
650
RemoveStaged (setAllRemoves, false , MemPoolRemovalReason::REORG);
683
- auto chain = active_chainstate.m_chain ;
684
651
for (indexed_transaction_set::const_iterator it = mapTx.begin (); it != mapTx.end (); it++) {
685
652
LockPoints lp = it->GetLockPoints ();
686
653
if (!TestLockPointValidity (chain, &lp)) {
0 commit comments