diff options
author | Carl Dong <contact@carldong.me> | 2021-10-28 14:13:04 -0400 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2022-06-28 15:42:23 -0400 |
commit | aa9141cd8185cb7ad532bc16feb9d302b05d9697 (patch) | |
tree | 18dad4b3fcdeb21bcfd473528e1764a78fffd2b9 /src/validation.cpp | |
parent | 51c7a41a5eb6fcb60333812c770d80227cf7b64d (diff) | |
download | bitcoin-aa9141cd8185cb7ad532bc16feb9d302b05d9697.tar.xz |
mempool: Pass in -mempoolexpiry instead of referencing gArgs
- Store the mempool expiry (-mempoolexpiry) in CTxMemPool as a
std::chrono::seconds member.
- Remove the requirement to explicitly specify a mempool expiry for
LimitMempoolSize(...), just use the newly-introduced member.
- Remove all now-unnecessary instances of:
std::chrono::hours{gArgs.GetIntArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)}
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index a14f82106f..c1ff603faa 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -255,12 +255,12 @@ bool CheckSequenceLocksAtTip(CBlockIndex* tip, // Returns the script flags which should be checked for a given block static unsigned int GetBlockScriptFlags(const CBlockIndex& block_index, const ChainstateManager& chainman); -static void LimitMempoolSize(CTxMemPool& pool, CCoinsViewCache& coins_cache, std::chrono::seconds age) +static void LimitMempoolSize(CTxMemPool& pool, CCoinsViewCache& coins_cache) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, pool.cs) { AssertLockHeld(::cs_main); AssertLockHeld(pool.cs); - int expired = pool.Expire(GetTime<std::chrono::seconds>() - age); + int expired = pool.Expire(GetTime<std::chrono::seconds>() - pool.m_expiry); if (expired != 0) { LogPrint(BCLog::MEMPOOL, "Expired %i transactions from the memory pool\n", expired); } @@ -374,10 +374,7 @@ void CChainState::MaybeUpdateMempoolForReorg( // We also need to remove any now-immature transactions m_mempool->removeForReorg(m_chain, filter_final_and_mature); // Re-limit mempool size, in case we added any transactions - LimitMempoolSize( - *m_mempool, - this->CoinsTip(), - std::chrono::hours{gArgs.GetIntArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)}); + LimitMempoolSize(*m_mempool, this->CoinsTip()); } /** @@ -1081,7 +1078,7 @@ bool MemPoolAccept::Finalize(const ATMPArgs& args, Workspace& ws) // in the package. LimitMempoolSize() should be called at the very end to make sure the mempool // is still within limits and package submission happens atomically. if (!args.m_package_submission && !bypass_limits) { - LimitMempoolSize(m_pool, m_active_chainstate.CoinsTip(), std::chrono::hours{gArgs.GetIntArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)}); + LimitMempoolSize(m_pool, m_active_chainstate.CoinsTip()); if (!m_pool.exists(GenTxid::Txid(hash))) return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "mempool full"); } @@ -1146,8 +1143,7 @@ bool MemPoolAccept::SubmitPackage(const ATMPArgs& args, std::vector<Workspace>& // It may or may not be the case that all the transactions made it into the mempool. Regardless, // make sure we haven't exceeded max mempool size. - LimitMempoolSize(m_pool, m_active_chainstate.CoinsTip(), - std::chrono::hours{gArgs.GetIntArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)}); + LimitMempoolSize(m_pool, m_active_chainstate.CoinsTip()); // Find the wtxids of the transactions that made it into the mempool. Allow partial submission, // but don't report success unless they all made it into the mempool. @@ -4645,7 +4641,7 @@ static const uint64_t MEMPOOL_DUMP_VERSION = 1; bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate, FopenFn mockable_fopen_function) { - int64_t nExpiryTimeout = gArgs.GetIntArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60; + int64_t nExpiryTimeout = std::chrono::seconds{pool.m_expiry}.count(); FILE* filestr{mockable_fopen_function(gArgs.GetDataDirNet() / "mempool.dat", "rb")}; CAutoFile file(filestr, SER_DISK, CLIENT_VERSION); if (file.IsNull()) { |