init: cap -maxmempool to 500 MB on 32-bit systems

32-bit architecture is limited to 4GiB, so it doesn't make sense to set a too high value. 500 MB is
chosen as an arbitrary maximum value that seems reasonable.

Github-Pull: #32530
Rebased-From: 2c43b6adeb
This commit is contained in:
Antoine Poinsot
2025-05-15 17:45:44 -04:00
committed by fanquake
parent a3c1939d6e
commit eafea2393d

View File

@@ -25,6 +25,9 @@ using common::AmountErrMsg;
using kernel::MemPoolLimits;
using kernel::MemPoolOptions;
//! Maximum mempool size on 32-bit systems.
static constexpr int MAX_32BIT_MEMPOOL_MB{500};
namespace {
void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolLimits& mempool_limits)
{
@@ -42,7 +45,13 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& argsman, const CChainP
{
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")) {
constexpr bool is_32bit{sizeof(void*) == 4};
if (is_32bit && *mb > MAX_32BIT_MEMPOOL_MB) {
return util::Error{Untranslated(strprintf("-maxmempool is set to %i but can't be over %i MB on 32-bit systems", *mb, MAX_32BIT_MEMPOOL_MB))};
}
mempool_opts.max_size_bytes = *mb * 1'000'000;
}
if (auto hours = argsman.GetIntArg("-mempoolexpiry")) mempool_opts.expiry = std::chrono::hours{*hours};