20#include <xrpld/app/main/Application.h>
21#include <xrpld/app/rdb/Vacuum.h>
22#include <xrpld/core/Config.h>
23#include <xrpld/core/ConfigSections.h>
24#include <xrpld/core/TimeKeeper.h>
25#include <xrpld/net/RPCCall.h>
26#include <xrpl/basics/Log.h>
27#include <xrpl/beast/core/CurrentThreadName.h>
28#include <xrpl/protocol/BuildInfo.h>
31#include <test/unit_test/multi_runner.h>
32#include <xrpl/beast/unit_test/match.h>
35#include <boost/process.hpp>
36#include <boost/program_options.hpp>
37#include <google/protobuf/stubs/common.h>
51#if !BOOST_OS_LINUX && !BOOST_OS_WINDOWS && !BOOST_OS_MACOS
52#error Supported platforms are: Linux, Windows and MacOS
56#if (BOOST_OS_LINUX && (BOOST_OS_WINDOWS || BOOST_OS_MACOS)) || \
57 (BOOST_OS_MACOS && (BOOST_OS_WINDOWS || BOOST_OS_LINUX)) || \
58 (BOOST_OS_WINDOWS && (BOOST_OS_LINUX || BOOST_OS_MACOS))
59#error Multiple supported platforms appear active at once
63#include "antithesis_instrumentation.h"
66namespace po = boost::program_options;
79 if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
82 if (rl.rlim_cur == RLIM_INFINITY)
94 if (setrlimit(RLIMIT_NOFILE, &rl) == 0)
101 j.
fatal() <<
"Insufficient number of file descriptors: " << needed
102 <<
" are needed, but only " <<
available <<
" are available.";
104 std::cerr <<
"Insufficient number of file descriptors: " << needed
106 <<
" are available.\n";
119 <<
systemName() <<
"d [options] <command> <params>\n"
122 " account_currencies <account> [<ledger>]\n"
123 " account_info <account>|<key> [<ledger>]\n"
124 " account_lines <account> <account>|\"\" [<ledger>]\n"
125 " account_channels <account> <account>|\"\" [<ledger>]\n"
126 " account_objects <account> [<ledger>]\n"
127 " account_offers <account>|<account_public_key> [<ledger>]\n"
128 " account_tx accountID [ledger_index_min [ledger_index_max "
131 " book_changes [<ledger hash|id>]\n"
132 " book_offers <taker_pays> <taker_gets> [<taker [<ledger> "
133 "[<limit> [<proof> [<marker>]]]]]\n"
134 " can_delete [<ledgerid>|<ledgerhash>|now|always|never]\n"
135 " channel_authorize <private_key> <channel_id> <drops>\n"
136 " channel_verify <public_key> <channel_id> <drops> <signature>\n"
137 " connect <ip> [<port>]\n"
139 " deposit_authorized <source_account> <destination_account> "
140 "[<ledger> [<credentials>, ...]]\n"
141 " feature [<feature> [accept|reject]]\n"
142 " fetch_info [clear]\n"
143 " gateway_balances [<ledger>] <issuer_account> [ <hotwallet> [ "
146 " json <method> <json>\n"
147 " ledger [<id>|current|closed|validated] [full]\n"
152 " ledger_request <ledger>\n"
153 " log_level [[<partition>] <severity>]\n"
155 " manifest <public_key>\n"
159 " peer_reservations_add <public_key> [<description>]\n"
160 " peer_reservations_del <public_key>\n"
161 " peer_reservations_list\n"
163 " ripple_path_find <json> [<ledger>]\n"
164 " server_definitions [<hash>]\n"
165 " server_info [counters]\n"
166 " server_state [counters]\n"
167 " sign <private_key> <tx_json> [offline]\n"
168 " sign_for <signer_address> <signer_private_key> <tx_json> "
171 " simulate [<tx_blob>|<tx_json>] [<binary>]\n"
172 " submit <tx_blob>|[<private_key> <tx_json>]\n"
173 " submit_multisigned <tx_json>\n"
175 " validation_create [<seed>|<pass_phrase>|<key>]\n"
178 " validator_list_sites\n"
180 " wallet_propose [<passphrase>]\n";
195 explicit multi_selector(
std::string const& patterns =
"")
198 boost::split(v, patterns, boost::algorithm::is_any_of(
","));
202 if (selectors_.empty() || !s.empty())
203 selectors_.emplace_back(
204 beast::unit_test::selector::automatch, s);
211 for (
auto& sel : selectors_)
220 return selectors_.size();
228template <
class Runner>
230anyMissing(Runner& runner, multi_selector
const& pred)
232 if (runner.tests() == 0)
234 runner.add_failures(1);
238 if (runner.suites() < pred.size())
240 auto const missing = pred.size() - runner.suites();
241 runner.add_failures(missing);
243 <<
" filters did not match any existing test suites"
267 if (!child && num_jobs == 1)
272 child_runner.arg(argument);
273 multi_selector pred(pattern);
274 auto const any_failed =
275 child_runner.run_multi(pred) || anyMissing(child_runner, pred);
290 for (
int i = 1; i < argc; ++i)
297 boost::process::exe = exe_name, boost::process::args = args);
299 int bad_child_exits = 0;
300 int terminated_child_exits = 0;
301 for (
auto& c : children)
313 ++terminated_child_exits;
318 anyMissing(parent_runner, multi_selector(pattern));
320 if (parent_runner.
any_failed() || bad_child_exits)
329 auto const anyFailed =
runner.run_multi(multi_selector(pattern));
348 po::variables_map vm;
352 importText +=
"Import an existing node database (specified in the [";
354 importText +=
"] configuration file section) into the current ";
355 importText +=
"node database (specified in the [";
357 importText +=
"] configuration file section).";
362 po::options_description gen(
"General Options");
364 "conf", po::value<std::string>(),
"Specify the configuration file.")(
365 "debug",
"Enable normally suppressed debug logging")(
366 "help,h",
"Display this message.")(
367 "newnodeid",
"Generate a new node identity for this server.")(
369 po::value<std::string>(),
370 "Specify the node identity for this server.")(
372 po::value<std::size_t>(),
373 "Override the minimum validation quorum.")(
374 "silent",
"No output to the console after startup.")(
375 "standalone,a",
"Run with no peers.")(
"verbose,v",
"Verbose logging.")
377 (
"force_ledger_present_range",
378 po::value<std::string>(),
379 "Specify the range of present ledgers for testing purposes. Min and "
380 "max values are comma separated.")(
381 "version",
"Display the build version.");
383 po::options_description data(
"Ledger/Data Options");
384 data.add_options()(
"import", importText.
c_str())(
386 po::value<std::string>(),
387 "Load the specified ledger and start from the value given.")(
389 po::value<std::string>(),
390 "Load the specified ledger file.")(
391 "load",
"Load the current ledger from the local DB.")(
392 "net",
"Get the initial ledger from the network.")(
393 "replay",
"Replay a ledger close.")(
395 po::value<std::string>(),
396 "Trap a specific transaction during replay.")(
397 "start",
"Start from a fresh Ledger.")(
398 "vacuum",
"VACUUM the transaction db.")(
399 "valid",
"Consider the initial ledger a valid network ledger.");
401 po::options_description
rpc(
"RPC Client Options");
404 "Perform rpc command - see below for available commands. "
405 "This is assumed if any positional parameters are provided.")(
407 po::value<std::string>(),
408 "Specify the IP address for RPC command. "
409 "Format: <ip-address>[':'<port-number>]")(
411 po::value<std::uint16_t>(),
412 "DEPRECATED: include with rpc_ip instead. "
413 "Specify the port number for RPC command.");
416 po::options_description test(
"Unit Test Options");
419 "Suppress test suite messages, "
420 "including suite/case name (at start) and test log messages.")(
422 po::value<std::string>()->implicit_value(
""),
423 "Perform unit tests. The optional argument specifies one or "
424 "more comma-separated selectors. Each selector specifies a suite name, "
425 "suite name prefix, full-name (lib.module.suite), module, or library "
426 "(checked in that order).")(
428 po::value<std::string>()->implicit_value(
""),
429 "Supplies an argument string to unit tests. If provided, this argument "
430 "is made available to each suite that runs. Interpretation of the "
431 "argument is handled individually by any suite that accesses it -- "
432 "as such, it typically only make sense to provide this when running "
435 "Use IPv6 localhost when running unittests (default is IPv4).")(
437 "Force unit test log message output. Only useful in combination with "
438 "--quiet, in which case log messages will print but suite/case names "
441 po::value<std::size_t>(),
442 "Number of unittest jobs to run in parallel (child processes).");
447 po::options_description hidden(
"Hidden Options");
448 hidden.add_options()(
450 po::value<vector<string>>(),
451 "Specify rpc command and parameters. This option must be repeated "
452 "for each command/param. Positional parameters also serve this "
454 "so this option is not needed for users")
457 "For internal use only when spawning child unit test processes.")
459 (
"unittest",
"Disabled in this build.")(
460 "unittest-child",
"Disabled in this build.")
462 (
"fg",
"Deprecated: server always in foreground mode.");
465 po::positional_options_description p;
466 p.add(
"parameters", -1);
468 po::options_description
all;
477 po::options_description desc;
490 po::command_line_parser(argc, argv)
504 if (vm.count(
"help"))
510 if (vm.count(
"version"))
514#ifdef GIT_COMMIT_HASH
524 if (vm.count(
"unittest") || vm.count(
"unittest-child"))
534 if (vm.count(
"unittest"))
538 if (vm.count(
"unittest-arg"))
542 bool unittestChild =
false;
543 if (vm.count(
"unittest-jobs"))
544 numJobs =
std::max(numJobs, vm[
"unittest-jobs"].as<std::size_t>());
545 unittestChild = bool(vm.count(
"unittest-child"));
548 vm[
"unittest"].as<std::string>(),
550 bool(vm.count(
"quiet")),
551 bool(vm.count(
"unittest-log")),
553 bool(vm.count(
"unittest-ipv6")),
561 if (vm.count(
"unittest-jobs"))
564 std::cerr <<
"rippled: '--unittest-jobs' specified without "
566 std::cerr <<
"To run the unit tests the '--unittest' option must "
573 auto config = std::make_unique<Config>();
581 bool(vm.count(
"quiet")),
582 bool(vm.count(
"silent")),
583 bool(vm.count(
"standalone")));
585 if (vm.count(
"vacuum"))
587 if (config->standalone())
589 std::cerr <<
"vacuum not applicable in standalone mode.\n";
601 std::cerr <<
"exception " << e.
what() <<
" in function " << __func__
609 if (vm.contains(
"force_ledger_present_range"))
617 vm[
"force_ledger_present_range"].as<std::string>(),
618 boost::algorithm::is_any_of(
","));
620 for (
auto& s : strVec)
634 "Invalid force_ledger_present_range parameter");
636 config->FORCED_LEDGER_RANGE_PRESENT.emplace(r[0], r[1]);
641 "Invalid force_ledger_present_range parameter");
646 std::cerr <<
"invalid 'force_ledger_present_range' parameter. The "
647 "parameter must be two numbers separated by a comma. "
648 "The first number must be <= the second."
654 if (vm.count(
"start"))
659 if (vm.count(
"import"))
660 config->doImport =
true;
662 if (vm.count(
"ledger"))
664 config->START_LEDGER = vm[
"ledger"].as<
std::string>();
665 if (vm.count(
"replay"))
668 if (vm.count(
"trap_tx_hash"))
674 config->TRAP_TX_HASH = tmp;
678 std::cerr <<
"Trap parameter was ill-formed, expected "
679 "valid transaction hash but received: "
688 else if (vm.count(
"ledgerfile"))
690 config->START_LEDGER = vm[
"ledgerfile"].as<
std::string>();
693 else if (vm.count(
"load") || config->FAST_LOAD)
698 if (vm.count(
"trap_tx_hash") && vm.count(
"replay") == 0)
700 std::cerr <<
"Cannot use trap option without replay option"
705 if (vm.count(
"net") && !config->FAST_LOAD)
710 std::cerr <<
"Net and load/replay options are incompatible"
718 if (vm.count(
"valid"))
720 config->START_VALID =
true;
725 if (vm.count(
"rpc_ip"))
728 vm[
"rpc_ip"].as<std::string>());
736 if (endpoint->port() == 0)
738 std::cerr <<
"No port specified in rpc_ip.\n";
739 if (vm.count(
"rpc_port"))
741 std::cerr <<
"WARNING: using deprecated rpc_port param.\n";
745 endpoint->at_port(vm[
"rpc_port"].as<std::uint16_t>());
746 if (endpoint->port() == 0)
759 config->rpc_ip = std::move(*endpoint);
762 if (vm.count(
"quorum"))
766 config->VALIDATION_QUORUM = vm[
"quorum"].as<
std::size_t>();
774 std::cerr <<
"Invalid value specified for --quorum (" << e.
what()
784 if (vm.count(
"quiet"))
786 else if (vm.count(
"verbose"))
789 auto logs = std::make_unique<Logs>(thresh);
792 if (!vm.count(
"parameters"))
796 if (config->had_trailing_comments())
798 JLOG(logs->journal(
"Application").warn())
799 <<
"Trailing comments were seen in your config file. "
800 <<
"The treatment of inline/trailing comments has changed "
802 <<
"Any `#` characters NOT intended to delimit comments should "
804 <<
"preceded by a \\";
812 if (vm.count(
"debug"))
816 std::move(config), std::move(logs), std::make_unique<TimeKeeper>());
824 app->fdRequired(), app->logs().journal(
"Application")))
846main(
int argc,
char** argv)
866 atexit(&google::protobuf::ShutdownProtobufLibrary);
static std::optional< Endpoint > from_string_checked(std::string const &s)
Create an Endpoint from a string.
A generic endpoint for log messages.
Unit test runner interface.
void arg(std::string const &s)
Set the argument string.
Associates a unit test type with metadata.
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Set the expected result code for a JTx The test will fail if the code doesn't match.
A class to run a subset of unit tests.
Manager for children running unit tests.
void add_failures(std::size_t failures)
T emplace_back(T... args)
A namespace for easy access to logging severity values.
Severity
Severity level / threshold of a Journal message.
void setCurrentThreadName(std::string_view newThreadName)
Changes the name of the caller thread.
std::string const & getVersionString()
Server version.
int fromCommandLine(Config const &config, const std::vector< std::string > &vCmd, Logs &logs)
std::atomic< bool > envUseIPv4
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static std::string const & systemName()
DatabaseCon::Setup setup_DatabaseCon(Config const &c, std::optional< beast::Journal > j=std::nullopt)
void printHelp(const po::options_description &desc)
std::unique_ptr< Application > make_Application(std::unique_ptr< Config > config, std::unique_ptr< Logs > logs, std::unique_ptr< TimeKeeper > timeKeeper)
int run(int argc, char **argv)
bool adjustDescriptorLimit(int needed, beast::Journal j)
std::unique_ptr< beast::Journal::Sink > setDebugLogSink(std::unique_ptr< beast::Journal::Sink > sink)
Set the sink for the debug journal.
bool doVacuumDB(DatabaseCon::Setup const &setup, beast::Journal j)
doVacuumDB Creates, initialises, and performs cleanup on a database.
static std::string nodeDatabase()
static std::string importNodeDatabase()