Skip to content

Commit d1f932b

Browse files
committed
validation: Pass in coins cache to ::LimitMempoolSize
1 parent b805dbb commit d1f932b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/validation.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ bool CheckSequenceLocks(const CTxMemPool& pool, const CTransaction& tx, int flag
329329
// Returns the script flags which should be checked for a given block
330330
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& chainparams);
331331

332-
static void LimitMempoolSize(CTxMemPool& pool, size_t limit, std::chrono::seconds age)
332+
static void LimitMempoolSize(CTxMemPool& pool, CCoinsViewCache& coins_cache, size_t limit, std::chrono::seconds age)
333333
EXCLUSIVE_LOCKS_REQUIRED(pool.cs, ::cs_main)
334334
{
335335
int expired = pool.Expire(GetTime<std::chrono::seconds>() - age);
@@ -339,8 +339,9 @@ static void LimitMempoolSize(CTxMemPool& pool, size_t limit, std::chrono::second
339339

340340
std::vector<COutPoint> vNoSpendsRemaining;
341341
pool.TrimToSize(limit, &vNoSpendsRemaining);
342+
assert(std::addressof(::ChainstateActive().CoinsTip()) == std::addressof(coins_cache));
342343
for (const COutPoint& removed : vNoSpendsRemaining)
343-
::ChainstateActive().CoinsTip().Uncache(removed);
344+
coins_cache.Uncache(removed);
344345
}
345346

346347
static bool IsCurrentForFeeEstimation() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
@@ -403,7 +404,7 @@ static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransact
403404
// We also need to remove any now-immature transactions
404405
mempool.removeForReorg(&::ChainstateActive().CoinsTip(), ::ChainActive().Tip()->nHeight + 1, STANDARD_LOCKTIME_VERIFY_FLAGS);
405406
// Re-limit mempool size, in case we added any transactions
406-
LimitMempoolSize(mempool, gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, std::chrono::hours{gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
407+
LimitMempoolSize(mempool, ::ChainstateActive().CoinsTip(), gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, std::chrono::hours{gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
407408
}
408409

409410
/**
@@ -1015,7 +1016,7 @@ bool MemPoolAccept::Finalize(const ATMPArgs& args, Workspace& ws)
10151016

10161017
// trim mempool and check if tx was trimmed
10171018
if (!bypass_limits) {
1018-
LimitMempoolSize(m_pool, gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, std::chrono::hours{gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
1019+
LimitMempoolSize(m_pool, ::ChainstateActive().CoinsTip(), gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, std::chrono::hours{gArgs.GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
10191020
if (!m_pool.exists(hash))
10201021
return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "mempool full");
10211022
}

0 commit comments

Comments
 (0)