mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 15:32:34 +02:00
Merge 21780 via rpc_maxmempool
This commit is contained in:
commit
c433f09bab
@ -1494,7 +1494,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
|||||||
}
|
}
|
||||||
mempool_opts.check_ratio = std::clamp<int>(mempool_opts.check_ratio, 0, 1'000'000);
|
mempool_opts.check_ratio = std::clamp<int>(mempool_opts.check_ratio, 0, 1'000'000);
|
||||||
|
|
||||||
int64_t descendant_limit_bytes = mempool_opts.limits.descendant_size_vbytes * 40;
|
int64_t descendant_limit_bytes = maxmempoolMinimumBytes(mempool_opts.limits.descendant_size_vbytes);
|
||||||
if (mempool_opts.max_size_bytes < 0 || mempool_opts.max_size_bytes < descendant_limit_bytes) {
|
if (mempool_opts.max_size_bytes < 0 || mempool_opts.max_size_bytes < descendant_limit_bytes) {
|
||||||
return InitError(strprintf(_("-maxmempool must be at least %d MB"), std::ceil(descendant_limit_bytes / 1'000'000.0)));
|
return InitError(strprintf(_("-maxmempool must be at least %d MB"), std::ceil(descendant_limit_bytes / 1'000'000.0)));
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
|||||||
{ "getbalance", 3, "avoid_reuse" },
|
{ "getbalance", 3, "avoid_reuse" },
|
||||||
{ "getblockfrompeer", 1, "peer_id" },
|
{ "getblockfrompeer", 1, "peer_id" },
|
||||||
{ "getblockhash", 0, "height" },
|
{ "getblockhash", 0, "height" },
|
||||||
|
{ "maxmempool", 0, "megabytes" },
|
||||||
{ "waitforblockheight", 0, "height" },
|
{ "waitforblockheight", 0, "height" },
|
||||||
{ "waitforblockheight", 1, "timeout" },
|
{ "waitforblockheight", 1, "timeout" },
|
||||||
{ "waitforblock", 1, "timeout" },
|
{ "waitforblock", 1, "timeout" },
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <chainparams.h>
|
#include <chainparams.h>
|
||||||
#include <core_io.h>
|
#include <core_io.h>
|
||||||
#include <kernel/mempool_entry.h>
|
#include <kernel/mempool_entry.h>
|
||||||
|
#include <node/context.h>
|
||||||
#include <node/mempool_persist_args.h>
|
#include <node/mempool_persist_args.h>
|
||||||
#include <policy/rbf.h>
|
#include <policy/rbf.h>
|
||||||
#include <policy/settings.h>
|
#include <policy/settings.h>
|
||||||
@ -23,6 +24,7 @@
|
|||||||
#include <univalue.h>
|
#include <univalue.h>
|
||||||
#include <util/fs.h>
|
#include <util/fs.h>
|
||||||
#include <util/moneystr.h>
|
#include <util/moneystr.h>
|
||||||
|
#include <util/system.h>
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@ -378,6 +380,42 @@ UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose, bool include_mempoo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static RPCHelpMan maxmempool()
|
||||||
|
{
|
||||||
|
return RPCHelpMan{"maxmempool",
|
||||||
|
"\nSets the allocated memory for the memory pool.\n",
|
||||||
|
{
|
||||||
|
{"megabytes", RPCArg::Type::NUM, RPCArg::Optional::NO, "The memory allocated in MB"},
|
||||||
|
},
|
||||||
|
RPCResult{
|
||||||
|
RPCResult::Type::NONE, "", ""},
|
||||||
|
RPCExamples{
|
||||||
|
HelpExampleCli("maxmempool", "150") + HelpExampleRpc("maxmempool", "150")
|
||||||
|
},
|
||||||
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
|
{
|
||||||
|
int64_t nSize = request.params[0].getInt<int32_t>();
|
||||||
|
int64_t nMempoolSizeMax = nSize * 1000000;
|
||||||
|
|
||||||
|
CTxMemPool& mempool = EnsureAnyMemPool(request.context);
|
||||||
|
LOCK2(cs_main, mempool.cs);
|
||||||
|
|
||||||
|
int64_t nMempoolSizeMin = maxmempoolMinimumBytes(mempool.m_limits.descendant_size_vbytes);
|
||||||
|
if (nMempoolSizeMax < 0 || nMempoolSizeMax < nMempoolSizeMin)
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("MaxMempool size %d is too small", nSize));
|
||||||
|
mempool.m_max_size_bytes = nSize;
|
||||||
|
|
||||||
|
auto node_context = util::AnyPtr<NodeContext>(request.context);
|
||||||
|
if (node_context && node_context->chainman) {
|
||||||
|
Chainstate& active_chainstate = node_context->chainman->ActiveChainstate();
|
||||||
|
LimitMempoolSize(mempool, active_chainstate.CoinsTip());
|
||||||
|
}
|
||||||
|
|
||||||
|
return NullUniValue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
static RPCHelpMan getrawmempool()
|
static RPCHelpMan getrawmempool()
|
||||||
{
|
{
|
||||||
return RPCHelpMan{"getrawmempool",
|
return RPCHelpMan{"getrawmempool",
|
||||||
@ -1025,6 +1063,7 @@ void RegisterMempoolRPCCommands(CRPCTable& t)
|
|||||||
{"blockchain", &getmempoolinfo},
|
{"blockchain", &getmempoolinfo},
|
||||||
{"blockchain", &getrawmempool},
|
{"blockchain", &getrawmempool},
|
||||||
{"blockchain", &savemempool},
|
{"blockchain", &savemempool},
|
||||||
|
{"blockchain", &maxmempool},
|
||||||
{"hidden", &submitpackage},
|
{"hidden", &submitpackage},
|
||||||
};
|
};
|
||||||
for (const auto& c : commands) {
|
for (const auto& c : commands) {
|
||||||
|
@ -151,6 +151,7 @@ const std::vector<std::string> RPC_COMMANDS_SAFE_FOR_FUZZING{
|
|||||||
"listbanned",
|
"listbanned",
|
||||||
"listprunelocks",
|
"listprunelocks",
|
||||||
"logging",
|
"logging",
|
||||||
|
"maxmempool",
|
||||||
"mockscheduler",
|
"mockscheduler",
|
||||||
"ping",
|
"ping",
|
||||||
"preciousblock",
|
"preciousblock",
|
||||||
|
@ -44,6 +44,10 @@ class Chainstate;
|
|||||||
/** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
|
/** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
|
||||||
static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
|
static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
|
||||||
|
|
||||||
|
inline int64_t maxmempoolMinimumBytes(const int64_t descendant_size_vbytes) {
|
||||||
|
return descendant_size_vbytes * 40;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether the LockPoints height and time are still valid on the current chain
|
* Test whether the LockPoints height and time are still valid on the current chain
|
||||||
*/
|
*/
|
||||||
@ -451,7 +455,7 @@ public:
|
|||||||
|
|
||||||
using Options = kernel::MemPoolOptions;
|
using Options = kernel::MemPoolOptions;
|
||||||
|
|
||||||
const int64_t m_max_size_bytes;
|
int64_t m_max_size_bytes;
|
||||||
const std::chrono::seconds m_expiry;
|
const std::chrono::seconds m_expiry;
|
||||||
const CFeeRate m_incremental_relay_feerate;
|
const CFeeRate m_incremental_relay_feerate;
|
||||||
const CFeeRate m_min_relay_feerate;
|
const CFeeRate m_min_relay_feerate;
|
||||||
|
@ -254,7 +254,7 @@ 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)
|
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);
|
||||||
|
@ -303,6 +303,8 @@ std::optional<LockPoints> CalculateLockPointsAtTip(
|
|||||||
bool CheckSequenceLocksAtTip(CBlockIndex* tip,
|
bool CheckSequenceLocksAtTip(CBlockIndex* tip,
|
||||||
const LockPoints& lock_points);
|
const LockPoints& lock_points);
|
||||||
|
|
||||||
|
void LimitMempoolSize(CTxMemPool&, CCoinsViewCache&);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closure representing one script verification
|
* Closure representing one script verification
|
||||||
* Note that this stores references to the spending transaction
|
* Note that this stores references to the spending transaction
|
||||||
|
Loading…
Reference in New Issue
Block a user