Skip to content

Commit 2c43b6a

Browse files
committed
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.
1 parent 725c9f7 commit 2c43b6a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/node/mempool_args.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ using common::AmountErrMsg;
2525
using kernel::MemPoolLimits;
2626
using kernel::MemPoolOptions;
2727

28+
//! Maximum mempool size on 32-bit systems.
29+
static constexpr int MAX_32BIT_MEMPOOL_MB{500};
30+
2831
namespace {
2932
void ApplyArgsManOptions(const ArgsManager& argsman, MemPoolLimits& mempool_limits)
3033
{
@@ -42,7 +45,13 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& argsman, const CChainP
4245
{
4346
mempool_opts.check_ratio = argsman.GetIntArg("-checkmempool", mempool_opts.check_ratio);
4447

45-
if (auto mb = argsman.GetIntArg("-maxmempool")) mempool_opts.max_size_bytes = *mb * 1'000'000;
48+
if (auto mb = argsman.GetIntArg("-maxmempool")) {
49+
constexpr bool is_32bit{sizeof(void*) == 4};
50+
if (is_32bit && *mb > MAX_32BIT_MEMPOOL_MB) {
51+
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))};
52+
}
53+
mempool_opts.max_size_bytes = *mb * 1'000'000;
54+
}
4655

4756
if (auto hours = argsman.GetIntArg("-mempoolexpiry")) mempool_opts.expiry = std::chrono::hours{*hours};
4857

0 commit comments

Comments
 (0)