Skip to content

Commit

Permalink
Public mempool removal methods Assume() no changeset is outstanding
Browse files Browse the repository at this point in the history
While a changeset is outstanding, removing transaction directly from the
mempool will invalidate the changeset state, so this is not permitted.
  • Loading branch information
sdaftuar committed Nov 13, 2024
1 parent 2b30f4d commit b447416
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ void CTxMemPool::removeRecursive(const CTransaction &origTx, MemPoolRemovalReaso
{
// Remove transaction from memory pool
AssertLockHeld(cs);
Assume(!m_have_changeset);
setEntries txToRemove;
txiter origit = mapTx.find(origTx.GetHash());
if (origit != mapTx.end()) {
Expand Down Expand Up @@ -637,6 +638,7 @@ void CTxMemPool::removeForReorg(CChain& chain, std::function<bool(txiter)> check
// Remove transactions spending a coinbase which are now immature and no-longer-final transactions
AssertLockHeld(cs);
AssertLockHeld(::cs_main);
Assume(!m_have_changeset);

setEntries txToRemove;
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
Expand Down Expand Up @@ -675,6 +677,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx)
void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight)
{
AssertLockHeld(cs);
Assume(!m_have_changeset);
std::vector<RemovedMempoolTransactionInfo> txs_removed_for_block;
txs_removed_for_block.reserve(vtx.size());
for (const auto& tx : vtx)
Expand Down Expand Up @@ -1093,6 +1096,7 @@ void CTxMemPool::RemoveStaged(setEntries &stage, bool updateDescendants, MemPool
int CTxMemPool::Expire(std::chrono::seconds time)
{
AssertLockHeld(cs);
Assume(!m_have_changeset);
indexed_transaction_set::index<entry_time>::type::iterator it = mapTx.get<entry_time>().begin();
setEntries toremove;
while (it != mapTx.get<entry_time>().end() && it->GetTime() < time) {
Expand Down Expand Up @@ -1163,6 +1167,7 @@ void CTxMemPool::trackPackageRemoved(const CFeeRate& rate) {

void CTxMemPool::TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining) {
AssertLockHeld(cs);
Assume(!m_have_changeset);

unsigned nTxnRemoved = 0;
CFeeRate maxFeeRateRemoved(0);
Expand Down
5 changes: 5 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,11 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
AcceptSubPackage(txns_package_eval, args);
PackageValidationState& package_state_final = multi_submission_result.m_state;

// This is invoked by AcceptSubPackage() already, so this is just here for
// clarity (since it's not permitted to invoke LimitMempoolSize() while a
// changeset is outstanding).
ClearSubPackageState();

// Make sure we haven't exceeded max mempool size.
// Package transactions that were submitted to mempool or already in mempool may be evicted.
LimitMempoolSize(m_pool, m_active_chainstate.CoinsTip());
Expand Down

0 comments on commit b447416

Please sign in to comment.