Skip to content

Commit f06545d

Browse files
committed
Add maxmempool RPC
Github-Pull: bitcoin#21780 Rebased-From: 040b280
1 parent 250ad2d commit f06545d

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/rpc/client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
6666
{ "getbalance", 3, "avoid_reuse" },
6767
{ "getblockfrompeer", 1, "peer_id" },
6868
{ "getblockhash", 0, "height" },
69+
{ "maxmempool", 0, "megabytes" },
6970
{ "waitforblockheight", 0, "height" },
7071
{ "waitforblockheight", 1, "timeout" },
7172
{ "waitforblock", 1, "timeout" },

src/rpc/mempool.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,36 @@ UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose, bool include_mempoo
374374
}
375375
}
376376

377+
static RPCHelpMan maxmempool()
378+
{
379+
return RPCHelpMan{"maxmempool",
380+
"\nSets the allocated memory for the memory pool.\n",
381+
{
382+
{"megabytes", RPCArg::Type::NUM, RPCArg::Optional::NO, "The memory allocated in MB"},
383+
},
384+
RPCResult{
385+
RPCResult::Type::NONE, "", ""},
386+
RPCExamples{
387+
HelpExampleCli("maxmempool", "150") + HelpExampleRpc("maxmempool", "150")
388+
},
389+
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
390+
{
391+
int nSize = request.params[0].getInt<int>();
392+
int64_t nMempoolSizeMax = nSize * 1000000;
393+
394+
CTxMemPool& mempool = EnsureAnyMemPool(request.context);
395+
LOCK(mempool.cs);
396+
397+
int64_t nMempoolSizeMin = mempool.m_opts.limits.descendant_size_vbytes * 40;
398+
if (nMempoolSizeMax < 0 || nMempoolSizeMax < nMempoolSizeMin)
399+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("MaxMempool size %d is too small", nSize));
400+
mempool.m_opts.max_size_bytes = nSize;
401+
402+
return NullUniValue;
403+
}
404+
};
405+
}
406+
377407
static RPCHelpMan getrawmempool()
378408
{
379409
return RPCHelpMan{"getrawmempool",
@@ -1027,6 +1057,7 @@ void RegisterMempoolRPCCommands(CRPCTable& t)
10271057
{"blockchain", &getrawmempool},
10281058
{"blockchain", &importmempool},
10291059
{"blockchain", &savemempool},
1060+
{"blockchain", &maxmempool},
10301061
{"rawtransactions", &submitpackage},
10311062
};
10321063
for (const auto& c : commands) {

src/txmempool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ class CTxMemPool
436436

437437
using Options = kernel::MemPoolOptions;
438438

439-
const Options m_opts;
439+
Options m_opts;
440440

441441
/** Create a new CTxMemPool.
442442
* Sanity checks will be off by default for performance, because otherwise

0 commit comments

Comments
 (0)