mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-06 14:19:59 -05:00
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)}
This commit is contained in:
parent
51c7a41a5e
commit
aa9141cd81
6 changed files with 15 additions and 13 deletions
|
@ -4,12 +4,15 @@
|
||||||
#ifndef BITCOIN_KERNEL_MEMPOOL_OPTIONS_H
|
#ifndef BITCOIN_KERNEL_MEMPOOL_OPTIONS_H
|
||||||
#define BITCOIN_KERNEL_MEMPOOL_OPTIONS_H
|
#define BITCOIN_KERNEL_MEMPOOL_OPTIONS_H
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
class CBlockPolicyEstimator;
|
class CBlockPolicyEstimator;
|
||||||
|
|
||||||
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
|
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
|
||||||
static constexpr unsigned int DEFAULT_MAX_MEMPOOL_SIZE_MB{300};
|
static constexpr unsigned int DEFAULT_MAX_MEMPOOL_SIZE_MB{300};
|
||||||
|
/** Default for -mempoolexpiry, expiration time for mempool transactions in hours */
|
||||||
|
static constexpr unsigned int DEFAULT_MEMPOOL_EXPIRY{336};
|
||||||
|
|
||||||
namespace kernel {
|
namespace kernel {
|
||||||
/**
|
/**
|
||||||
|
@ -25,6 +28,7 @@ struct MemPoolOptions {
|
||||||
/* The ratio used to determine how often sanity checks will run. */
|
/* The ratio used to determine how often sanity checks will run. */
|
||||||
int check_ratio{0};
|
int check_ratio{0};
|
||||||
int64_t max_size_bytes{DEFAULT_MAX_MEMPOOL_SIZE_MB * 1'000'000};
|
int64_t max_size_bytes{DEFAULT_MAX_MEMPOOL_SIZE_MB * 1'000'000};
|
||||||
|
std::chrono::seconds expiry{std::chrono::hours{DEFAULT_MEMPOOL_EXPIRY}};
|
||||||
};
|
};
|
||||||
} // namespace kernel
|
} // namespace kernel
|
||||||
|
|
||||||
|
|
|
@ -15,4 +15,6 @@ void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolOptions& mempool_opt
|
||||||
mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio);
|
mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio);
|
||||||
|
|
||||||
if (auto mb = argsman.GetIntArg("-maxmempool")) mempool_opts.max_size_bytes = *mb * 1'000'000;
|
if (auto mb = argsman.GetIntArg("-maxmempool")) mempool_opts.max_size_bytes = *mb * 1'000'000;
|
||||||
|
|
||||||
|
if (auto hours = argsman.GetIntArg("-mempoolexpiry")) mempool_opts.expiry = std::chrono::hours{*hours};
|
||||||
}
|
}
|
||||||
|
|
|
@ -454,7 +454,8 @@ void CTxMemPoolEntry::UpdateAncestorState(int64_t modifySize, CAmount modifyFee,
|
||||||
CTxMemPool::CTxMemPool(const Options& opts)
|
CTxMemPool::CTxMemPool(const Options& opts)
|
||||||
: m_check_ratio{opts.check_ratio},
|
: m_check_ratio{opts.check_ratio},
|
||||||
minerPolicyEstimator{opts.estimator},
|
minerPolicyEstimator{opts.estimator},
|
||||||
m_max_size_bytes{opts.max_size_bytes}
|
m_max_size_bytes{opts.max_size_bytes},
|
||||||
|
m_expiry{opts.expiry}
|
||||||
{
|
{
|
||||||
_clear(); //lock free clear
|
_clear(); //lock free clear
|
||||||
}
|
}
|
||||||
|
|
|
@ -567,6 +567,7 @@ public:
|
||||||
using Options = kernel::MemPoolOptions;
|
using Options = kernel::MemPoolOptions;
|
||||||
|
|
||||||
const int64_t m_max_size_bytes;
|
const int64_t m_max_size_bytes;
|
||||||
|
const std::chrono::seconds m_expiry;
|
||||||
|
|
||||||
/** Create a new CTxMemPool.
|
/** Create a new CTxMemPool.
|
||||||
* Sanity checks will be off by default for performance, because otherwise
|
* Sanity checks will be off by default for performance, because otherwise
|
||||||
|
|
|
@ -255,12 +255,12 @@ bool CheckSequenceLocksAtTip(CBlockIndex* tip,
|
||||||
// Returns the script flags which should be checked for a given block
|
// Returns the script flags which should be checked for a given block
|
||||||
static unsigned int GetBlockScriptFlags(const CBlockIndex& block_index, const ChainstateManager& chainman);
|
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)
|
EXCLUSIVE_LOCKS_REQUIRED(::cs_main, pool.cs)
|
||||||
{
|
{
|
||||||
AssertLockHeld(::cs_main);
|
AssertLockHeld(::cs_main);
|
||||||
AssertLockHeld(pool.cs);
|
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) {
|
if (expired != 0) {
|
||||||
LogPrint(BCLog::MEMPOOL, "Expired %i transactions from the memory pool\n", expired);
|
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
|
// We also need to remove any now-immature transactions
|
||||||
m_mempool->removeForReorg(m_chain, filter_final_and_mature);
|
m_mempool->removeForReorg(m_chain, filter_final_and_mature);
|
||||||
// Re-limit mempool size, in case we added any transactions
|
// Re-limit mempool size, in case we added any transactions
|
||||||
LimitMempoolSize(
|
LimitMempoolSize(*m_mempool, this->CoinsTip());
|
||||||
*m_mempool,
|
|
||||||
this->CoinsTip(),
|
|
||||||
std::chrono::hours{gArgs.GetIntArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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
|
// 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.
|
// is still within limits and package submission happens atomically.
|
||||||
if (!args.m_package_submission && !bypass_limits) {
|
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)))
|
if (!m_pool.exists(GenTxid::Txid(hash)))
|
||||||
return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "mempool full");
|
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,
|
// 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.
|
// make sure we haven't exceeded max mempool size.
|
||||||
LimitMempoolSize(m_pool, m_active_chainstate.CoinsTip(),
|
LimitMempoolSize(m_pool, m_active_chainstate.CoinsTip());
|
||||||
std::chrono::hours{gArgs.GetIntArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY)});
|
|
||||||
|
|
||||||
// Find the wtxids of the transactions that made it into the mempool. Allow partial submission,
|
// 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.
|
// 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)
|
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")};
|
FILE* filestr{mockable_fopen_function(gArgs.GetDataDirNet() / "mempool.dat", "rb")};
|
||||||
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
|
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
|
||||||
if (file.IsNull()) {
|
if (file.IsNull()) {
|
||||||
|
|
|
@ -59,8 +59,6 @@ namespace Consensus {
|
||||||
struct Params;
|
struct Params;
|
||||||
} // namespace Consensus
|
} // namespace Consensus
|
||||||
|
|
||||||
/** Default for -mempoolexpiry, expiration time for mempool transactions in hours */
|
|
||||||
static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336;
|
|
||||||
/** Maximum number of dedicated script-checking threads allowed */
|
/** Maximum number of dedicated script-checking threads allowed */
|
||||||
static const int MAX_SCRIPTCHECK_THREADS = 15;
|
static const int MAX_SCRIPTCHECK_THREADS = 15;
|
||||||
/** -par default (number of script-checking threads, 0 = auto) */
|
/** -par default (number of script-checking threads, 0 = auto) */
|
||||||
|
|
Loading…
Add table
Reference in a new issue