Skip to content

Commit 2eded09

Browse files
committed
Have removeForBlock boot transactions when required
1 parent 0cfe03b commit 2eded09

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/txmempool.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <util/moneystr.h>
1919
#include <util/time.h>
2020
#include <chainparams.h> // removeForBlock paklist transition
21+
#include <pegins.h>
2122

2223
CTxMemPoolEntry::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
}

src/validation.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,10 +2652,9 @@ bool CChainState::ConnectTip(CValidationState& state, const CChainParams& chainp
26522652
int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4;
26532653
LogPrint(BCLog::BENCH, " - Writing chainstate: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime5 - nTime4) * MILLI, nTimeChainState * MICRO, nTimeChainState * MILLI / nBlocksTotal);
26542654
// Remove conflicting transactions from the mempool.;
2655-
// ELEMENTS: We also eject now-invalid peg-outs based on block transition if not config list set
2656-
// If config is set, this means all peg-outs have been filtered for that list already and other
2657-
// functionaries aren't matching your list. Operator should restart with no list or new matching list.
2658-
mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight, (paklist && !g_paklist_config));
2655+
// ELEMENTS: We also eject peg-outs with now-invalid PAK proofs
2656+
// as well as peg-in inputs during transitional periods.
2657+
mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight, pindexNew);
26592658
disconnectpool.removeForBlock(blockConnecting.vtx);
26602659
// Update chainActive & related variables.
26612660
chainActive.SetTip(pindexNew);

0 commit comments

Comments
 (0)