1818#include < util/moneystr.h>
1919#include < util/time.h>
2020#include < chainparams.h> // removeForBlock paklist transition
21+ #include < pegins.h>
2122
2223CTxMemPoolEntry::CTxMemPoolEntry (const CTransactionRef& _tx, const CAmount& _nFee,
2324 int64_t _nTime, unsigned int _entryHeight,
@@ -548,7 +549,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx)
548549/* *
549550 * Called when a block is connected. Removes from mempool and updates the miner fee estimator.
550551 */
551- void CTxMemPool::removeForBlock (const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight, bool pak_transition )
552+ void CTxMemPool::removeForBlock (const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight, const CBlockIndex* p_block_index_new )
552553{
553554 LOCK (cs);
554555 std::vector<const CTxMemPoolEntry*> entries;
@@ -574,6 +575,40 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
574575 ClearPrioritisation (tx->GetHash ());
575576 }
576577
578+ // Eject transactions that are invalid for *following* block due to transition
579+ // We check every epoch_length blocks due to peg-ins expiring an epoch after
580+ // being changed
581+ if (p_block_index_new) {
582+ const CChainParams& chainparams = Params ();
583+ uint32_t epoch_length = chainparams.GetConsensus ().dynamic_epoch_length ;
584+ if ((p_block_index_new->nHeight +1 ) % epoch_length == 0 ) {
585+ CPAKList enforced_paklist = GetActivePAKList (p_block_index_new, chainparams.GetConsensus ());
586+ std::vector<CTransactionRef> tx_to_remove;
587+ for (const auto & entry : mapTx) {
588+ const CTransaction& tx = entry.GetTx ();
589+ if (chainparams.GetEnforcePak () && !IsPAKValidTx (tx, enforced_paklist)) {
590+ tx_to_remove.push_back (MakeTransactionRef (tx));
591+ continue ;
592+ }
593+
594+ std::vector<CScript> fedpegscripts = GetValidFedpegScripts (p_block_index_new, chainparams.GetConsensus (), true /* nextblock_validation */ );
595+ for (size_t nIn = 0 ; nIn < tx.vin .size (); nIn++) {
596+ const CTxIn& in = tx.vin [nIn];
597+ std::string err;
598+ if (in.m_is_pegin && (!tx.HasWitness () || !IsValidPeginWitness (tx.witness .vtxinwit [nIn].m_pegin_witness , fedpegscripts, in.prevout , err, true /* check_depth */ ))) {
599+ tx_to_remove.push_back (MakeTransactionRef (tx));
600+ break ;
601+ }
602+ }
603+ }
604+ for (auto & tx : tx_to_remove) {
605+ const uint256 tx_id = tx->GetHash ();
606+ removeRecursive (*tx, MemPoolRemovalReason::BLOCK);
607+ ClearPrioritisation (tx_id);
608+ }
609+ }
610+ }
611+
577612 lastRollingFeeUpdate = GetTime ();
578613 blockSinceLastRollingFeeBump = true ;
579614}
0 commit comments