aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2020-09-16 16:08:41 -0400
committerCarl Dong <contact@carldong.me>2021-02-18 14:43:28 -0500
commit3a205c43dc03cc833daba93087279402f640965b (patch)
tree6913f97b6ae61daf54df2085b9f1cbc5fbbcde8c
parentd8a816329c878b5973d28d370c0f64ebbdde716b (diff)
validation: Pass in chainstate to AcceptToMemoryPoolWithTime
-rw-r--r--src/validation.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index e658476c7f..eb0e66ee30 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -1076,6 +1076,7 @@ MempoolAcceptResult MemPoolAccept::AcceptSingleTransaction(const CTransactionRef
/** (try to) add transaction to memory pool with a specified acceptance time **/
static MempoolAcceptResult AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPool& pool,
+ CChainState& active_chainstate,
const CTransactionRef &tx, int64_t nAcceptTime,
bool bypass_limits, bool test_accept)
EXCLUSIVE_LOCKS_REQUIRED(cs_main)
@@ -1083,7 +1084,8 @@ static MempoolAcceptResult AcceptToMemoryPoolWithTime(const CChainParams& chainp
std::vector<COutPoint> coins_to_uncache;
MemPoolAccept::ATMPArgs args { chainparams, nAcceptTime, bypass_limits, coins_to_uncache, test_accept };
- const MempoolAcceptResult result = MemPoolAccept(pool, ::ChainstateActive()).AcceptSingleTransaction(tx, args);
+ assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate));
+ const MempoolAcceptResult result = MemPoolAccept(pool, active_chainstate).AcceptSingleTransaction(tx, args);
if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) {
// Remove coins that were not present in the coins cache before calling ATMPW;
// this is to prevent memory DoS in case we receive a large number of
@@ -1091,17 +1093,17 @@ static MempoolAcceptResult AcceptToMemoryPoolWithTime(const CChainParams& chainp
// (`CCoinsViewCache::cacheCoins`).
for (const COutPoint& hashTx : coins_to_uncache)
- ::ChainstateActive().CoinsTip().Uncache(hashTx);
+ active_chainstate.CoinsTip().Uncache(hashTx);
}
// After we've (potentially) uncached entries, ensure our coins cache is still within its size limits
BlockValidationState state_dummy;
- ::ChainstateActive().FlushStateToDisk(chainparams, state_dummy, FlushStateMode::PERIODIC);
+ active_chainstate.FlushStateToDisk(chainparams, state_dummy, FlushStateMode::PERIODIC);
return result;
}
MempoolAcceptResult AcceptToMemoryPool(CTxMemPool& pool, const CTransactionRef &tx, bool bypass_limits, bool test_accept)
{
- return AcceptToMemoryPoolWithTime(Params(), pool, tx, GetTime(), bypass_limits, test_accept);
+ return AcceptToMemoryPoolWithTime(Params(), pool, ::ChainstateActive(), tx, GetTime(), bypass_limits, test_accept);
}
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock)
@@ -5050,7 +5052,7 @@ bool LoadMempool(CTxMemPool& pool)
}
if (nTime > nNow - nExpiryTimeout) {
LOCK(cs_main);
- if (AcceptToMemoryPoolWithTime(chainparams, pool, tx, nTime, false /* bypass_limits */,
+ if (AcceptToMemoryPoolWithTime(chainparams, pool, ::ChainstateActive(), tx, nTime, false /* bypass_limits */,
false /* test_accept */).m_result_type == MempoolAcceptResult::ResultType::VALID) {
++count;
} else {