6 #include <chainparams.h>
27 #ifdef HAVE_MALLOC_INFO
36 "\nSet the local time to given timestamp (-regtest only)\n",
39 "Pass 0 to go back to using the system time."},
46 throw std::runtime_error(
"setmocktime is for regression testing (-regtest mode) only");
56 const int64_t time{request.params[0].getInt<int64_t>()};
61 auto node_context = util::AnyPtr<NodeContext>(request.context);
63 for (
const auto& chain_client : node_context->chain_clients) {
64 chain_client->setMockTime(time);
73 #if defined(USE_SYSCALL_SANDBOX)
77 "invokedisallowedsyscall",
78 "\nInvoke a disallowed syscall to trigger a syscall sandbox violation. Used for testing purposes.\n",
85 throw std::runtime_error(
"invokedisallowedsyscall is used for testing only.");
87 TestDisallowedSandboxCall();
97 "\nBump the scheduler into the future (-regtest only)\n",
106 throw std::runtime_error(
"mockscheduler is for regression testing (-regtest mode) only");
109 int64_t delta_seconds = request.params[0].getInt<int64_t>();
110 if (delta_seconds <= 0 || delta_seconds > 3600) {
111 throw std::runtime_error(
"delta_time must be between 1 and 3600 seconds (1 hr)");
114 auto node_context =
CHECK_NONFATAL(util::AnyPtr<NodeContext>(request.context));
117 node_context->scheduler->MockForward(std::chrono::seconds(delta_seconds));
137 #ifdef HAVE_MALLOC_INFO
138 static std::string RPCMallocInfo()
142 FILE *f = open_memstream(&ptr, &size);
147 std::string rv(ptr, size);
162 "Returns an object containing information about memory usage.\n",
165 " - \"stats\" returns general statistics about memory usage in the daemon.\n"
166 " - \"mallocinfo\" returns an XML string describing low-level heap state (only available if compiled with glibc)."},
177 {
RPCResult::Type::NUM,
"locked",
"Amount of bytes that succeeded locking. If this number is smaller than total, locking pages failed at some point and key data could be swapped to disk."},
193 std::string mode = request.params[0].
isNull() ?
"stats" : request.params[0].get_str();
194 if (mode ==
"stats") {
198 }
else if (mode ==
"mallocinfo") {
199 #ifdef HAVE_MALLOC_INFO
200 return RPCMallocInfo();
213 for (
unsigned int i = 0; i < cats.
size(); ++i) {
214 std::string cat = cats[i].
get_str();
232 "Gets and sets the logging configuration.\n"
233 "When called without an argument, returns the list of categories with status that are currently being debug logged or not.\n"
234 "When called with arguments, adds or removes categories from debug logging and return the lists above.\n"
235 "The arguments are evaluated in order \"include\", \"exclude\".\n"
236 "If an item is both included and excluded, it will thus end up being excluded.\n"
238 "In addition, the following are available as category names with special meanings:\n"
239 " - \"all\", \"1\" : represent all logging categories.\n"
240 " - \"none\", \"0\" : even if other logging categories are specified, ignore all of them.\n"
265 if (request.params[0].isArray()) {
268 if (request.params[1].isArray()) {
272 uint32_t changed_log_categories = original_log_categories ^ updated_log_categories;
280 for (
const auto& logCatActive :
LogInstance().LogCategoriesList()) {
281 result.
pushKV(logCatActive.category, logCatActive.active);
292 "\nSimply echo back the input arguments. This command is for testing.\n"
293 "\nIt will return an internal bug report when arg9='trigger_internal_bug' is passed.\n"
294 "\nThe difference between echo and echojson is that echojson has argument conversion enabled in the client-side table in "
295 "bitcoin-cli and the GUI. There is no server-side difference.",
312 if (request.params[9].isStr()) {
313 CHECK_NONFATAL(request.params[9].get_str() !=
"trigger_internal_bug");
316 return request.params;
328 "\nEcho back the input argument, passing it through a spawned process in a multiprocess build.\n"
329 "This command is for testing.\n",
336 std::unique_ptr<interfaces::Echo>
echo;
346 auto init =
ipc->spawnProcess(
"bitcoin-node");
357 return echo->echo(request.params[0].get_str());
365 if (!index_name.empty() && index_name != summary.name)
return ret_summary;
368 entry.
pushKV(
"synced", summary.synced);
369 entry.
pushKV(
"best_block_height", summary.best_block_height);
370 ret_summary.
pushKV(summary.name, entry);
377 "\nReturns the status of one or all available indices currently running in the node.\n",
401 const std::string index_name = request.params[0].isNull() ?
"" : request.params[0].get_str();
431 #if defined(USE_SYSCALL_SANDBOX)
432 {
"hidden", &invokedisallowedsyscall},
435 for (
const auto& c : commands) {
436 t.appendCommand(c.name, &c);
void ForEachBlockFilterIndex(std::function< void(BlockFilterIndex &)> fn)
Iterate over all running block filter indexes, invoking fn on each.
const CChainParams & Params()
Return the currently selected parameters.
#define CHECK_NONFATAL(condition)
Identity function.
void EnableCategory(LogFlags flag)
uint32_t GetCategoryMask() const
std::string LogCategoriesString() const
Returns a string with the log categories in alphabetical order.
void DisableCategory(LogFlags flag)
IndexSummary GetSummary() const
Get a summary of the index and its state.
BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of bloc...
bool IsMockableChain() const
If this chain allows time to be mocked.
bool IsTestChain() const
If this chain is exclusively used for testing.
Stats stats() const
Get pool usage statistics.
static LockedPoolManager & Instance()
Return the current instance, or create it once.
const std::string & get_str() const
void pushKVs(UniValue obj)
const UniValue & get_array() const
void pushKV(std::string key, UniValue val)
Initial interface created when a process is first started, and used to give and get access to other i...
virtual std::unique_ptr< Echo > makeEcho()
Interface providing access to interprocess-communication (IPC) functionality.
std::unique_ptr< CoinStatsIndex > g_coin_stats_index
The global UTXO set hash object.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
void UpdateHTTPServerLogging(bool enable)
Change logging level for libevent.
BCLog::Logger & LogInstance()
static RPCHelpMan logging()
static RPCHelpMan setmocktime()
void RegisterNodeRPCCommands(CRPCTable &t)
static void EnableOrDisableLogCategories(UniValue cats, bool enable)
static UniValue RPCLockedMemoryInfo()
static RPCHelpMan mockscheduler()
static RPCHelpMan getmemoryinfo()
static RPCHelpMan echo(const std::string &name)
static UniValue SummaryToJSON(const IndexSummary &&summary, std::string index_name)
static RPCHelpMan echojson()
static RPCHelpMan echoipc()
static RPCHelpMan getindexinfo()
UniValue JSONRPCError(int code, const std::string &message)
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency.
NodeContext & EnsureAnyNodeContext(const std::any &context)
@ OMITTED
Optional argument for which the default value is omitted from help text for one of two reasons:
@ ANY
Special type to disable type checks (for testing only)
@ OBJ_DYN
Special dictionary with keys that are not literals.
NodeContext struct containing references to chain state and connection state.
interfaces::Init * init
Init interface for initializing current process and connecting to other processes.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.