Skip to content

Commit 9360778

Browse files
committed
Remove AcceptToMemoryPoolWithTime
1 parent e7507f3 commit 9360778

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed

src/test/fuzz/tx_pool.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
230230
Assert(it->second.m_result_type == MempoolAcceptResult::ResultType::VALID ||
231231
it->second.m_result_type == MempoolAcceptResult::ResultType::INVALID);
232232

233-
const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(chainstate, tx_pool, tx, bypass_limits));
233+
CChainState& chainstate{node.chainman->ActiveChainstate()};
234+
const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(tx_pool, chainstate, tx, GetTime(), bypass_limits, /* test_accept= */ false));
234235
const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
235236
SyncWithValidationInterfaceQueue();
236237
UnregisterSharedValidationInterface(txr);
@@ -330,7 +331,7 @@ FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool)
330331
const auto tx = MakeTransactionRef(mut_tx);
331332
const bool bypass_limits = fuzzed_data_provider.ConsumeBool();
332333
::fRequireStandard = fuzzed_data_provider.ConsumeBool();
333-
const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(node.chainman->ActiveChainstate(), tx_pool, tx, bypass_limits));
334+
const auto res = WITH_LOCK(::cs_main, return AcceptToMemoryPool(tx_pool, chainstate, tx, GetTime(), bypass_limits, /* test_accept= */ false));
334335
const bool accepted = res.m_result_type == MempoolAcceptResult::ResultType::VALID;
335336
if (accepted) {
336337
txids.push_back(tx->GetHash());

src/validation.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ void CChainState::MaybeUpdateMempoolForReorg(
349349
while (it != disconnectpool.queuedTx.get<insertion_order>().rend()) {
350350
// ignore validation errors in resurrected transactions
351351
if (!fAddToMempool || (*it)->IsCoinBase() ||
352-
AcceptToMemoryPool(
353-
*this, *m_mempool, *it, true /* bypass_limits */).m_result_type !=
352+
AcceptToMemoryPool(*m_mempool, *this, *it, GetTime(),
353+
/* bypass_limits= */true, /* test_accept= */ false).m_result_type !=
354354
MempoolAcceptResult::ResultType::VALID) {
355355
// If the transaction doesn't make it in to the mempool, remove any
356356
// transactions that depend on it (which would now be orphans).
@@ -1078,15 +1078,13 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
10781078

10791079
} // anon namespace
10801080

1081-
/** (try to) add transaction to memory pool with a specified acceptance time **/
1082-
static MempoolAcceptResult AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPool& pool,
1083-
CChainState& active_chainstate,
1084-
const CTransactionRef &tx, int64_t nAcceptTime,
1085-
bool bypass_limits, bool test_accept)
1086-
EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1081+
MempoolAcceptResult AcceptToMemoryPool(CTxMemPool& pool, CChainState& active_chainstate, const CTransactionRef& tx,
1082+
int64_t accept_time, bool bypass_limits, bool test_accept)
1083+
EXCLUSIVE_LOCKS_REQUIRED(cs_main)
10871084
{
1085+
const CChainParams& chainparams{active_chainstate.m_params};
10881086
std::vector<COutPoint> coins_to_uncache;
1089-
auto args = MemPoolAccept::ATMPArgs::SingleAccept(chainparams, nAcceptTime, bypass_limits, coins_to_uncache, test_accept);
1087+
auto args = MemPoolAccept::ATMPArgs::SingleAccept(chainparams, accept_time, bypass_limits, coins_to_uncache, test_accept);
10901088
const MempoolAcceptResult result = MemPoolAccept(pool, active_chainstate).AcceptSingleTransaction(tx, args);
10911089
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
10921090
// Remove coins that were not present in the coins cache before calling
@@ -1103,12 +1101,6 @@ static MempoolAcceptResult AcceptToMemoryPoolWithTime(const CChainParams& chainp
11031101
return result;
11041102
}
11051103

1106-
MempoolAcceptResult AcceptToMemoryPool(CChainState& active_chainstate, CTxMemPool& pool, const CTransactionRef& tx,
1107-
bool bypass_limits, bool test_accept)
1108-
{
1109-
return AcceptToMemoryPoolWithTime(Params(), pool, active_chainstate, tx, GetTime(), bypass_limits, test_accept);
1110-
}
1111-
11121104
PackageMempoolAcceptResult ProcessNewPackage(CChainState& active_chainstate, CTxMemPool& pool,
11131105
const Package& package, bool test_accept)
11141106
{
@@ -1161,8 +1153,8 @@ CChainState::CChainState(
11611153
ChainstateManager& chainman,
11621154
std::optional<uint256> from_snapshot_blockhash)
11631155
: m_mempool(mempool),
1164-
m_params(::Params()),
11651156
m_blockman(blockman),
1157+
m_params(::Params()),
11661158
m_chainman(chainman),
11671159
m_from_snapshot_blockhash(from_snapshot_blockhash) {}
11681160

@@ -3500,7 +3492,7 @@ MempoolAcceptResult ChainstateManager::ProcessTransaction(const CTransactionRef&
35003492
state.Invalid(TxValidationResult::TX_NO_MEMPOOL, "no-mempool");
35013493
return MempoolAcceptResult::Failure(state);
35023494
}
3503-
auto result = AcceptToMemoryPool(active_chainstate, *active_chainstate.m_mempool, tx, /*bypass_limits=*/ false, test_accept);
3495+
auto result = AcceptToMemoryPool(*active_chainstate.m_mempool, active_chainstate, tx, GetTime(), /* bypass_limits= */ false, test_accept);
35043496
active_chainstate.m_mempool->check(active_chainstate.CoinsTip(), active_chainstate.m_chain.Height() + 1);
35053497
return result;
35063498
}
@@ -4530,7 +4522,6 @@ static const uint64_t MEMPOOL_DUMP_VERSION = 1;
45304522

45314523
bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate, FopenFn mockable_fopen_function)
45324524
{
4533-
const CChainParams& chainparams = Params();
45344525
int64_t nExpiryTimeout = gArgs.GetIntArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60;
45354526
FILE* filestr{mockable_fopen_function(gArgs.GetDataDirNet() / "mempool.dat", "rb")};
45364527
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
@@ -4568,8 +4559,8 @@ bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate, FopenFn mocka
45684559
}
45694560
if (nTime > nNow - nExpiryTimeout) {
45704561
LOCK(cs_main);
4571-
if (AcceptToMemoryPoolWithTime(chainparams, pool, active_chainstate, tx, nTime, false /* bypass_limits */,
4572-
false /* test_accept */).m_result_type == MempoolAcceptResult::ResultType::VALID) {
4562+
if (AcceptToMemoryPool(pool, active_chainstate, tx, nTime, /* bypass_limits= */ false,
4563+
/* test_accept= */ false).m_result_type == MempoolAcceptResult::ResultType::VALID) {
45734564
++count;
45744565
} else {
45754566
// mempool may contain the transaction already, e.g. from

src/validation.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,23 @@ struct PackageMempoolAcceptResult
208208
};
209209

210210
/**
211-
* Try to add a transaction to the mempool. This is an internal function and is
212-
* exposed only for testing. Client code should use ChainstateManager::ProcessTransaction()
211+
* Try to add a transaction to the mempool. This is an internal function and is exposed only for testing.
212+
* Client code should use ChainstateManager::ProcessTransaction()
213213
*
214-
* @param[in] active_chainstate Reference to the active chainstate.
215214
* @param[in] pool Reference to the node's mempool.
215+
* @param[in] active_chainstate Reference to the active chainstate.
216216
* @param[in] tx The transaction to submit for mempool acceptance.
217+
* @param[in] accept_time The timestamp for adding the transaction to the mempool. Usually
218+
* the current system time, but may be different.
219+
* It is also used to determine when the entry expires.
217220
* @param[in] bypass_limits When true, don't enforce mempool fee and capacity limits.
218221
* @param[in] test_accept When true, run validation checks but don't submit to mempool.
219222
*
220223
* @returns a MempoolAcceptResult indicating whether the transaction was accepted/rejected with reason.
221224
*/
222-
MempoolAcceptResult AcceptToMemoryPool(CChainState& active_chainstate, CTxMemPool& pool, const CTransactionRef& tx,
223-
bool bypass_limits, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
225+
MempoolAcceptResult AcceptToMemoryPool(CTxMemPool& pool, CChainState& active_chainstate, const CTransactionRef& tx,
226+
int64_t accept_time, bool bypass_limits, bool test_accept)
227+
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
224228

225229
/**
226230
* Atomically test acceptance of a package. If the package only contains one tx, package rules still
@@ -581,8 +585,6 @@ class CChainState
581585
//! Only the active chainstate has a mempool.
582586
CTxMemPool* m_mempool;
583587

584-
const CChainParams& m_params;
585-
586588
//! Manages the UTXO set, which is a reflection of the contents of `m_chain`.
587589
std::unique_ptr<CoinsViews> m_coins_views;
588590

@@ -591,6 +593,9 @@ class CChainState
591593
//! CChainState instances.
592594
BlockManager& m_blockman;
593595

596+
/** Chain parameters for this chainstate */
597+
const CChainParams& m_params;
598+
594599
//! The chainstate manager that owns this chainstate. The reference is
595600
//! necessary so that this instance can check whether it is the active
596601
//! chainstate within deeply nested method calls.

0 commit comments

Comments
 (0)