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>
27#include <xrpl/basics/Log.h>
28#include <xrpl/beast/core/CurrentThreadName.h>
29#include <xrpl/protocol/BuildInfo.h>
32#include <test/unit_test/multi_runner.h>
34#include <xrpl/beast/unit_test/match.h>
36#include <boost/process.hpp>
37#include <boost/program_options.hpp>
39#include <google/protobuf/stubs/common.h>
53#if !BOOST_OS_LINUX && !BOOST_OS_WINDOWS && !BOOST_OS_MACOS
54#error Supported platforms are: Linux, Windows and MacOS
58#if (BOOST_OS_LINUX && (BOOST_OS_WINDOWS || BOOST_OS_MACOS)) || \
59 (BOOST_OS_MACOS && (BOOST_OS_WINDOWS || BOOST_OS_LINUX)) || \
60 (BOOST_OS_WINDOWS && (BOOST_OS_LINUX || BOOST_OS_MACOS))
61#error Multiple supported platforms appear active at once
65#include "antithesis_instrumentation.h"
68namespace po = boost::program_options;
81 if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
84 if (rl.rlim_cur == RLIM_INFINITY)
96 if (setrlimit(RLIMIT_NOFILE, &rl) == 0)
103 j.
fatal() <<
"Insufficient number of file descriptors: " << needed
104 <<
" are needed, but only " <<
available <<
" are available.";
106 std::cerr <<
"Insufficient number of file descriptors: " << needed
108 <<
" are available.\n";
121 <<
systemName() <<
"d [options] <command> <params>\n"
124 " account_currencies <account> [<ledger>]\n"
125 " account_info <account>|<key> [<ledger>]\n"
126 " account_lines <account> <account>|\"\" [<ledger>]\n"
127 " account_channels <account> <account>|\"\" [<ledger>]\n"
128 " account_objects <account> [<ledger>]\n"
129 " account_offers <account>|<account_public_key> [<ledger>]\n"
130 " account_tx accountID [ledger_index_min [ledger_index_max "
133 " book_changes [<ledger hash|id>]\n"
134 " book_offers <taker_pays> <taker_gets> [<taker [<ledger> "
135 "[<limit> [<proof> [<marker>]]]]]\n"
136 " can_delete [<ledgerid>|<ledgerhash>|now|always|never]\n"
137 " channel_authorize <private_key> <channel_id> <drops>\n"
138 " channel_verify <public_key> <channel_id> <drops> <signature>\n"
139 " connect <ip> [<port>]\n"
141 " deposit_authorized <source_account> <destination_account> "
142 "[<ledger> [<credentials>, ...]]\n"
143 " feature [<feature> [accept|reject]]\n"
144 " fetch_info [clear]\n"
145 " gateway_balances [<ledger>] <issuer_account> [ <hotwallet> [ "
148 " json <method> <json>\n"
149 " ledger [<id>|current|closed|validated] [full]\n"
154 " ledger_request <ledger>\n"
155 " log_level [[<partition>] <severity>]\n"
157 " manifest <public_key>\n"
161 " peer_reservations_add <public_key> [<description>]\n"
162 " peer_reservations_del <public_key>\n"
163 " peer_reservations_list\n"
165 " ripple_path_find <json> [<ledger>]\n"
166 " server_definitions [<hash>]\n"
167 " server_info [counters]\n"
168 " server_state [counters]\n"
169 " sign <private_key> <tx_json> [offline]\n"
170 " sign_for <signer_address> <signer_private_key> <tx_json> "
173 " simulate [<tx_blob>|<tx_json>] [<binary>]\n"
174 " submit <tx_blob>|[<private_key> <tx_json>]\n"
175 " submit_multisigned <tx_json>\n"
177 " validation_create [<seed>|<pass_phrase>|<key>]\n"
180 " validator_list_sites\n"
182 " wallet_propose [<passphrase>]\n";
197 explicit multi_selector(
std::string const& patterns =
"")
200 boost::split(v, patterns, boost::algorithm::is_any_of(
","));
204 if (selectors_.empty() || !s.empty())
205 selectors_.emplace_back(
206 beast::unit_test::selector::automatch, s);
213 for (
auto& sel : selectors_)
222 return selectors_.size();
230template <
class Runner>
232anyMissing(Runner& runner, multi_selector
const& pred)
234 if (runner.tests() == 0)
236 runner.add_failures(1);
240 if (runner.suites() < pred.size())
242 auto const missing = pred.size() - runner.suites();
243 runner.add_failures(missing);
245 <<
" filters did not match any existing test suites"
269 if (!child && num_jobs == 1)
274 child_runner.arg(argument);
275 multi_selector pred(pattern);
276 auto const any_failed =
277 child_runner.run_multi(pred) || anyMissing(child_runner, pred);
292 for (
int i = 1; i < argc; ++i)
299 boost::process::exe = exe_name, boost::process::args = args);
301 int bad_child_exits = 0;
302 int terminated_child_exits = 0;
303 for (
auto& c : children)
315 ++terminated_child_exits;
320 anyMissing(parent_runner, multi_selector(pattern));
322 if (parent_runner.
any_failed() || bad_child_exits)
331 auto const anyFailed =
runner.run_multi(multi_selector(pattern));
350 po::variables_map vm;
354 importText +=
"Import an existing node database (specified in the [";
356 importText +=
"] configuration file section) into the current ";
357 importText +=
"node database (specified in the [";
359 importText +=
"] configuration file section).";
364 po::options_description gen(
"General Options");
366 "conf", po::value<std::string>(),
"Specify the configuration file.")(
367 "debug",
"Enable normally suppressed debug logging")(
368 "help,h",
"Display this message.")(
369 "newnodeid",
"Generate a new node identity for this server.")(
371 po::value<std::string>(),
372 "Specify the node identity for this server.")(
374 po::value<std::size_t>(),
375 "Override the minimum validation quorum.")(
376 "silent",
"No output to the console after startup.")(
377 "standalone,a",
"Run with no peers.")(
"verbose,v",
"Verbose logging.")
379 (
"force_ledger_present_range",
380 po::value<std::string>(),
381 "Specify the range of present ledgers for testing purposes. Min and "
382 "max values are comma separated.")(
383 "version",
"Display the build version.");
385 po::options_description data(
"Ledger/Data Options");
386 data.add_options()(
"import", importText.
c_str())(
388 po::value<std::string>(),
389 "Load the specified ledger and start from the value given.")(
391 po::value<std::string>(),
392 "Load the specified ledger file.")(
393 "load",
"Load the current ledger from the local DB.")(
394 "net",
"Get the initial ledger from the network.")(
395 "replay",
"Replay a ledger close.")(
397 po::value<std::string>(),
398 "Trap a specific transaction during replay.")(
399 "start",
"Start from a fresh Ledger.")(
400 "vacuum",
"VACUUM the transaction db.")(
401 "valid",
"Consider the initial ledger a valid network ledger.");
403 po::options_description
rpc(
"RPC Client Options");
406 "Perform rpc command - see below for available commands. "
407 "This is assumed if any positional parameters are provided.")(
409 po::value<std::string>(),
410 "Specify the IP address for RPC command. "
411 "Format: <ip-address>[':'<port-number>]")(
413 po::value<std::uint16_t>(),
414 "DEPRECATED: include with rpc_ip instead. "
415 "Specify the port number for RPC command.");
418 po::options_description test(
"Unit Test Options");
421 "Suppress test suite messages, "
422 "including suite/case name (at start) and test log messages.")(
424 po::value<std::string>()->implicit_value(
""),
425 "Perform unit tests. The optional argument specifies one or "
426 "more comma-separated selectors. Each selector specifies a suite name, "
427 "suite name prefix, full-name (lib.module.suite), module, or library "
428 "(checked in that order).")(
430 po::value<std::string>()->implicit_value(
""),
431 "Supplies an argument string to unit tests. If provided, this argument "
432 "is made available to each suite that runs. Interpretation of the "
433 "argument is handled individually by any suite that accesses it -- "
434 "as such, it typically only make sense to provide this when running "
437 "Use IPv6 localhost when running unittests (default is IPv4).")(
439 "Force unit test log message output. Only useful in combination with "
440 "--quiet, in which case log messages will print but suite/case names "
443 po::value<std::size_t>(),
444 "Number of unittest jobs to run in parallel (child processes).");
449 po::options_description hidden(
"Hidden Options");
450 hidden.add_options()(
452 po::value<vector<string>>(),
453 "Specify rpc command and parameters. This option must be repeated "
454 "for each command/param. Positional parameters also serve this "
456 "so this option is not needed for users")
459 "For internal use only when spawning child unit test processes.")
461 (
"unittest",
"Disabled in this build.")(
462 "unittest-child",
"Disabled in this build.")
464 (
"fg",
"Deprecated: server always in foreground mode.");
467 po::positional_options_description p;
468 p.add(
"parameters", -1);
470 po::options_description
all;
479 po::options_description desc;
492 po::command_line_parser(argc, argv)
506 if (vm.count(
"help"))
512 if (vm.count(
"version"))
516#ifdef GIT_COMMIT_HASH
526 if (vm.count(
"unittest") || vm.count(
"unittest-child"))
536 if (vm.count(
"unittest"))
540 if (vm.count(
"unittest-arg"))
544 bool unittestChild =
false;
545 if (vm.count(
"unittest-jobs"))
546 numJobs =
std::max(numJobs, vm[
"unittest-jobs"].as<std::size_t>());
547 unittestChild = bool(vm.count(
"unittest-child"));
550 vm[
"unittest"].as<std::string>(),
552 bool(vm.count(
"quiet")),
553 bool(vm.count(
"unittest-log")),
555 bool(vm.count(
"unittest-ipv6")),
563 if (vm.count(
"unittest-jobs"))
566 std::cerr <<
"rippled: '--unittest-jobs' specified without "
568 std::cerr <<
"To run the unit tests the '--unittest' option must "
575 auto config = std::make_unique<Config>();
583 bool(vm.count(
"quiet")),
584 bool(vm.count(
"silent")),
585 bool(vm.count(
"standalone")));
587 if (vm.count(
"vacuum"))
589 if (config->standalone())
591 std::cerr <<
"vacuum not applicable in standalone mode.\n";
603 std::cerr <<
"exception " << e.
what() <<
" in function " << __func__
611 if (vm.contains(
"force_ledger_present_range"))
619 vm[
"force_ledger_present_range"].as<std::string>(),
620 boost::algorithm::is_any_of(
","));
622 for (
auto& s : strVec)
636 "Invalid force_ledger_present_range parameter");
638 config->FORCED_LEDGER_RANGE_PRESENT.emplace(r[0], r[1]);
643 "Invalid force_ledger_present_range parameter");
648 std::cerr <<
"invalid 'force_ledger_present_range' parameter. The "
649 "parameter must be two numbers separated by a comma. "
650 "The first number must be <= the second."
656 if (vm.count(
"start"))
661 if (vm.count(
"import"))
662 config->doImport =
true;
664 if (vm.count(
"ledger"))
666 config->START_LEDGER = vm[
"ledger"].as<
std::string>();
667 if (vm.count(
"replay"))
670 if (vm.count(
"trap_tx_hash"))
676 config->TRAP_TX_HASH = tmp;
680 std::cerr <<
"Trap parameter was ill-formed, expected "
681 "valid transaction hash but received: "
690 else if (vm.count(
"ledgerfile"))
692 config->START_LEDGER = vm[
"ledgerfile"].as<
std::string>();
695 else if (vm.count(
"load") || config->FAST_LOAD)
700 if (vm.count(
"trap_tx_hash") && vm.count(
"replay") == 0)
702 std::cerr <<
"Cannot use trap option without replay option"
707 if (vm.count(
"net") && !config->FAST_LOAD)
712 std::cerr <<
"Net and load/replay options are incompatible"
720 if (vm.count(
"valid"))
722 config->START_VALID =
true;
727 if (vm.count(
"rpc_ip"))
730 vm[
"rpc_ip"].as<std::string>());
738 if (endpoint->port() == 0)
740 std::cerr <<
"No port specified in rpc_ip.\n";
741 if (vm.count(
"rpc_port"))
743 std::cerr <<
"WARNING: using deprecated rpc_port param.\n";
747 endpoint->at_port(vm[
"rpc_port"].as<std::uint16_t>());
748 if (endpoint->port() == 0)
761 config->rpc_ip = std::move(*endpoint);
764 if (vm.count(
"quorum"))
768 config->VALIDATION_QUORUM = vm[
"quorum"].as<
std::size_t>();
776 std::cerr <<
"Invalid value specified for --quorum (" << e.
what()
786 if (vm.count(
"quiet"))
788 else if (vm.count(
"verbose"))
791 auto logs = std::make_unique<Logs>(thresh);
794 if (!vm.count(
"parameters"))
798 if (config->had_trailing_comments())
800 JLOG(logs->journal(
"Application").warn())
801 <<
"Trailing comments were seen in your config file. "
802 <<
"The treatment of inline/trailing comments has changed "
804 <<
"Any `#` characters NOT intended to delimit comments should "
806 <<
"preceded by a \\";
814 if (vm.count(
"debug"))
818 std::move(config), std::move(logs), std::make_unique<TimeKeeper>());
826 app->fdRequired(), app->logs().journal(
"Application")))
848main(
int argc,
char** argv)
868 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, std::vector< std::string > const &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)
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.
void printHelp(po::options_description const &desc)
static std::string nodeDatabase()
static std::string importNodeDatabase()