Skip to content

Commit b447416

Browse files
committed
Public mempool removal methods Assume() no changeset is outstanding
While a changeset is outstanding, removing transaction directly from the mempool will invalidate the changeset state, so this is not permitted.
1 parent 2b30f4d commit b447416

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/txmempool.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ void CTxMemPool::removeRecursive(const CTransaction &origTx, MemPoolRemovalReaso
606606
{
607607
// Remove transaction from memory pool
608608
AssertLockHeld(cs);
609+
Assume(!m_have_changeset);
609610
setEntries txToRemove;
610611
txiter origit = mapTx.find(origTx.GetHash());
611612
if (origit != mapTx.end()) {
@@ -637,6 +638,7 @@ void CTxMemPool::removeForReorg(CChain& chain, std::function<bool(txiter)> check
637638
// Remove transactions spending a coinbase which are now immature and no-longer-final transactions
638639
AssertLockHeld(cs);
639640
AssertLockHeld(::cs_main);
641+
Assume(!m_have_changeset);
640642

641643
setEntries txToRemove;
642644
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
@@ -675,6 +677,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx)
675677
void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight)
676678
{
677679
AssertLockHeld(cs);
680+
Assume(!m_have_changeset);
678681
std::vector<RemovedMempoolTransactionInfo> txs_removed_for_block;
679682
txs_removed_for_block.reserve(vtx.size());
680683
for (const auto& tx : vtx)
@@ -1093,6 +1096,7 @@ void CTxMemPool::RemoveStaged(setEntries &stage, bool updateDescendants, MemPool
10931096
int CTxMemPool::Expire(std::chrono::seconds time)
10941097
{
10951098
AssertLockHeld(cs);
1099+
Assume(!m_have_changeset);
10961100
indexed_transaction_set::index<entry_time>::type::iterator it = mapTx.get<entry_time>().begin();
10971101
setEntries toremove;
10981102
while (it != mapTx.get<entry_time>().end() && it->GetTime() < time) {
@@ -1163,6 +1167,7 @@ void CTxMemPool::trackPackageRemoved(const CFeeRate& rate) {
11631167

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

11671172
unsigned nTxnRemoved = 0;
11681173
CFeeRate maxFeeRateRemoved(0);

src/validation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,11 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptPackage(const Package& package,
18201820
AcceptSubPackage(txns_package_eval, args);
18211821
PackageValidationState& package_state_final = multi_submission_result.m_state;
18221822

1823+
// This is invoked by AcceptSubPackage() already, so this is just here for
1824+
// clarity (since it's not permitted to invoke LimitMempoolSize() while a
1825+
// changeset is outstanding).
1826+
ClearSubPackageState();
1827+
18231828
// Make sure we haven't exceeded max mempool size.
18241829
// Package transactions that were submitted to mempool or already in mempool may be evicted.
18251830
LimitMempoolSize(m_pool, m_active_chainstate.CoinsTip());

0 commit comments

Comments
 (0)