1#include <xrpld/app/main/Application.h>
2#include <xrpld/app/rdb/Vacuum.h>
3#include <xrpld/core/Config.h>
4#include <xrpld/core/ConfigSections.h>
5#include <xrpld/core/TimeKeeper.h>
6#include <xrpld/rpc/RPCCall.h>
8#include <xrpl/basics/Log.h>
9#include <xrpl/beast/core/CurrentThreadName.h>
10#include <xrpl/protocol/BuildInfo.h>
12#include <boost/asio/io_context.hpp>
13#include <boost/process/v1/args.hpp>
14#include <boost/process/v1/child.hpp>
15#include <boost/process/v1/exe.hpp>
18#include <test/unit_test/multi_runner.h>
20#include <xrpl/beast/unit_test/match.h>
22#include <boost/algorithm/string.hpp>
23#include <boost/program_options.hpp>
25#include <google/protobuf/stubs/common.h>
39#if !BOOST_OS_LINUX && !BOOST_OS_WINDOWS && !BOOST_OS_MACOS
40#error Supported platforms are: Linux, Windows and MacOS
44#if (BOOST_OS_LINUX && (BOOST_OS_WINDOWS || BOOST_OS_MACOS)) || \
45 (BOOST_OS_MACOS && (BOOST_OS_WINDOWS || BOOST_OS_LINUX)) || \
46 (BOOST_OS_WINDOWS && (BOOST_OS_LINUX || BOOST_OS_MACOS))
47#error Multiple supported platforms appear active at once
51#include "antithesis_instrumentation.h"
54namespace po = boost::program_options;
67 if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
70 if (rl.rlim_cur == RLIM_INFINITY)
82 if (setrlimit(RLIMIT_NOFILE, &rl) == 0)
89 j.
fatal() <<
"Insufficient number of file descriptors: " << needed <<
" are needed, but only " <<
available
92 std::cerr <<
"Insufficient number of file descriptors: " << needed <<
" are needed, but only " <<
available
93 <<
" are available.\n";
108 " account_currencies <account> [<ledger>]\n"
109 " account_info <account>|<key> [<ledger>]\n"
110 " account_lines <account> <account>|\"\" [<ledger>]\n"
111 " account_channels <account> <account>|\"\" [<ledger>]\n"
112 " account_objects <account> [<ledger>]\n"
113 " account_offers <account>|<account_public_key> [<ledger>]\n"
114 " account_tx accountID [ledger_index_min [ledger_index_max "
117 " book_changes [<ledger hash|id>]\n"
118 " book_offers <taker_pays> <taker_gets> [<taker [<ledger> "
119 "[<limit> [<proof> [<marker>]]]]]\n"
120 " can_delete [<ledgerid>|<ledgerhash>|now|always|never]\n"
121 " channel_authorize <private_key> <channel_id> <drops>\n"
122 " channel_verify <public_key> <channel_id> <drops> <signature>\n"
123 " connect <ip> [<port>]\n"
125 " deposit_authorized <source_account> <destination_account> "
126 "[<ledger> [<credentials>, ...]]\n"
127 " feature [<feature> [accept|reject]]\n"
128 " fetch_info [clear]\n"
129 " gateway_balances [<ledger>] <issuer_account> [ <hotwallet> [ "
132 " json <method> <json>\n"
133 " ledger [<id>|current|closed|validated] [full]\n"
138 " ledger_request <ledger>\n"
139 " log_level [[<partition>] <severity>]\n"
141 " manifest <public_key>\n"
145 " peer_reservations_add <public_key> [<description>]\n"
146 " peer_reservations_del <public_key>\n"
147 " peer_reservations_list\n"
149 " ripple_path_find <json> [<ledger>]\n"
150 " server_definitions [<hash>]\n"
151 " server_info [counters]\n"
152 " server_state [counters]\n"
153 " sign <private_key> <tx_json> [offline]\n"
154 " sign_for <signer_address> <signer_private_key> <tx_json> "
155 "[offline] [<signature_field>]\n"
157 " simulate [<tx_blob>|<tx_json>] [<binary>]\n"
158 " submit <tx_blob>|[<private_key> <tx_json>]\n"
159 " submit_multisigned <tx_json>\n"
161 " validation_create [<seed>|<pass_phrase>|<key>]\n"
164 " validator_list_sites\n"
166 " wallet_propose [<passphrase>]\n";
181 explicit multi_selector(
std::string const& patterns =
"")
184 boost::split(v, patterns, boost::algorithm::is_any_of(
","));
188 if (selectors_.empty() || !s.empty())
189 selectors_.emplace_back(beast::unit_test::selector::automatch, s);
196 for (
auto& sel : selectors_)
205 return selectors_.
size();
213template <
class Runner>
215anyMissing(Runner& runner, multi_selector
const& pred)
217 if (runner.tests() == 0)
219 runner.add_failures(1);
223 if (runner.suites() < pred.size())
225 auto const missing = pred.size() - runner.suites();
226 runner.add_failures(missing);
227 std::cout <<
"Failed: " << missing <<
" filters did not match any existing test suites" <<
std::endl;
250 if (!child && num_jobs == 1)
255 child_runner.arg(argument);
256 multi_selector pred(pattern);
257 auto const any_failed = child_runner.run_multi(pred) || anyMissing(child_runner, pred);
272 for (
int i = 1; i < argc; ++i)
278 children.
emplace_back(boost::process::v1::exe = exe_name, boost::process::v1::args = args);
280 int bad_child_exits = 0;
281 int terminated_child_exits = 0;
282 for (
auto& c : children)
294 ++terminated_child_exits;
299 anyMissing(parent_runner, multi_selector(pattern));
301 if (parent_runner.
any_failed() || bad_child_exits)
310 auto const anyFailed =
runner.run_multi(multi_selector(pattern));
328 po::variables_map vm;
332 importText +=
"Import an existing node database (specified in the [";
334 importText +=
"] configuration file section) into the current ";
335 importText +=
"node database (specified in the [";
337 importText +=
"] configuration file section).";
342 po::options_description gen(
"General Options");
343 gen.add_options()(
"conf", po::value<std::string>(),
"Specify the configuration file.")(
344 "debug",
"Enable normally suppressed debug logging")(
"help,h",
"Display this message.")(
345 "newnodeid",
"Generate a new node identity for this server.")(
346 "nodeid", po::value<std::string>(),
"Specify the node identity for this server.")(
347 "quorum", po::value<std::size_t>(),
"Override the minimum validation quorum.")(
348 "silent",
"No output to the console after startup.")(
"standalone,a",
"Run with no peers.")(
349 "verbose,v",
"Verbose logging.")
351 (
"force_ledger_present_range",
352 po::value<std::string>(),
353 "Specify the range of present ledgers for testing purposes. Min and "
354 "max values are comma separated.")(
"version",
"Display the build version.");
356 po::options_description data(
"Ledger/Data Options");
357 data.add_options()(
"import", importText.
c_str())(
358 "ledger", po::value<std::string>(),
"Load the specified ledger and start from the value given.")(
359 "ledgerfile", po::value<std::string>(),
"Load the specified ledger file.")(
360 "load",
"Load the current ledger from the local DB.")(
"net",
"Get the initial ledger from the network.")(
361 "replay",
"Replay a ledger close.")(
362 "trap_tx_hash", po::value<std::string>(),
"Trap a specific transaction during replay.")(
363 "start",
"Start from a fresh Ledger.")(
"vacuum",
"VACUUM the transaction db.")(
364 "valid",
"Consider the initial ledger a valid network ledger.");
366 po::options_description
rpc(
"RPC Client Options");
369 "Perform rpc command - see below for available commands. "
370 "This is assumed if any positional parameters are provided.")(
372 po::value<std::string>(),
373 "Specify the IP address for RPC command. "
374 "Format: <ip-address>[':'<port-number>]")(
376 po::value<std::uint16_t>(),
377 "DEPRECATED: include with rpc_ip instead. "
378 "Specify the port number for RPC command.");
381 po::options_description test(
"Unit Test Options");
384 "Suppress test suite messages, "
385 "including suite/case name (at start) and test log messages.")(
387 po::value<std::string>()->implicit_value(
""),
388 "Perform unit tests. The optional argument specifies one or "
389 "more comma-separated selectors. Each selector specifies a suite name, "
390 "suite name prefix, full-name (lib.module.suite), module, or library "
391 "(checked in that order).")(
393 po::value<std::string>()->implicit_value(
""),
394 "Supplies an argument string to unit tests. If provided, this argument "
395 "is made available to each suite that runs. Interpretation of the "
396 "argument is handled individually by any suite that accesses it -- "
397 "as such, it typically only make sense to provide this when running "
398 "a single suite.")(
"unittest-ipv6",
"Use IPv6 localhost when running unittests (default is IPv4).")(
400 "Force unit test log message output. Only useful in combination with "
401 "--quiet, in which case log messages will print but suite/case names "
403 "unittest-jobs", po::value<std::size_t>(),
"Number of unittest jobs to run in parallel (child processes).");
408 po::options_description hidden(
"Hidden Options");
409 hidden.add_options()(
411 po::value<vector<string>>(),
412 "Specify rpc command and parameters. This option must be repeated "
413 "for each command/param. Positional parameters also serve this "
415 "so this option is not needed for users")
417 (
"unittest-child",
"For internal use only when spawning child unit test processes.")
419 (
"unittest",
"Disabled in this build.")(
"unittest-child",
"Disabled in this build.")
421 (
"fg",
"Deprecated: server always in foreground mode.");
424 po::positional_options_description p;
425 p.add(
"parameters", -1);
427 po::options_description
all;
436 po::options_description desc;
449 po::command_line_parser(argc, argv)
463 if (vm.count(
"help"))
469 if (vm.count(
"version"))
472#ifdef GIT_COMMIT_HASH
482 if (vm.count(
"unittest") || vm.count(
"unittest-child"))
492 if (vm.count(
"unittest"))
496 if (vm.count(
"unittest-arg"))
500 bool unittestChild =
false;
501 if (vm.count(
"unittest-jobs"))
502 numJobs =
std::max(numJobs, vm[
"unittest-jobs"].as<std::size_t>());
503 unittestChild = bool(vm.count(
"unittest-child"));
506 vm[
"unittest"].as<std::string>(),
508 bool(vm.count(
"quiet")),
509 bool(vm.count(
"unittest-log")),
511 bool(vm.count(
"unittest-ipv6")),
519 if (vm.count(
"unittest-jobs"))
522 std::cerr <<
"rippled: '--unittest-jobs' specified without "
524 std::cerr <<
"To run the unit tests the '--unittest' option must "
536 config->setup(configFile,
bool(vm.count(
"quiet")),
bool(vm.count(
"silent")),
bool(vm.count(
"standalone")));
538 if (vm.count(
"vacuum"))
540 if (config->standalone())
542 std::cerr <<
"vacuum not applicable in standalone mode.\n";
561 if (vm.contains(
"force_ledger_present_range"))
568 strVec, vm[
"force_ledger_present_range"].as<std::string>(), boost::algorithm::is_any_of(
","));
570 for (
auto& s : strVec)
585 config->FORCED_LEDGER_RANGE_PRESENT.emplace(r[0], r[1]);
594 std::cerr <<
"invalid 'force_ledger_present_range' parameter. The "
595 "parameter must be two numbers separated by a comma. "
596 "The first number must be <= the second."
602 if (vm.count(
"start"))
607 if (vm.count(
"import"))
608 config->doImport =
true;
610 if (vm.count(
"ledger"))
612 config->START_LEDGER = vm[
"ledger"].as<
std::string>();
613 if (vm.count(
"replay"))
616 if (vm.count(
"trap_tx_hash"))
622 config->TRAP_TX_HASH = tmp;
626 std::cerr <<
"Trap parameter was ill-formed, expected "
627 "valid transaction hash but received: "
636 else if (vm.count(
"ledgerfile"))
638 config->START_LEDGER = vm[
"ledgerfile"].as<
std::string>();
641 else if (vm.count(
"load") || config->FAST_LOAD)
646 if (vm.count(
"trap_tx_hash") && vm.count(
"replay") == 0)
652 if (vm.count(
"net") && !config->FAST_LOAD)
663 if (vm.count(
"valid"))
665 config->START_VALID =
true;
670 if (vm.count(
"rpc_ip"))
679 if (endpoint->port() == 0)
681 std::cerr <<
"No port specified in rpc_ip.\n";
682 if (vm.count(
"rpc_port"))
684 std::cerr <<
"WARNING: using deprecated rpc_port param.\n";
687 endpoint = endpoint->at_port(vm[
"rpc_port"].as<std::uint16_t>());
688 if (endpoint->port() == 0)
701 config->rpc_ip = std::move(*endpoint);
704 if (vm.count(
"quorum"))
708 config->VALIDATION_QUORUM = vm[
"quorum"].as<
std::size_t>();
716 std::cerr <<
"Invalid value specified for --quorum (" << e.
what() <<
")\n";
725 if (vm.count(
"quiet"))
727 else if (vm.count(
"verbose"))
733 if (!vm.count(
"parameters"))
737 if (config->had_trailing_comments())
739 JLOG(logs->journal(
"Application").warn()) <<
"Trailing comments were seen in your config file. "
740 <<
"The treatment of inline/trailing comments has changed "
742 <<
"Any `#` characters NOT intended to delimit comments should "
744 <<
"preceded by a \\";
752 if (vm.count(
"debug"))
783main(
int argc,
char** argv)
803 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.
int run(int argc, char **argv)
std::unique_ptr< beast::Journal::Sink > setDebugLogSink(std::unique_ptr< beast::Journal::Sink > sink)
Set the sink for the debug journal.
bool adjustDescriptorLimit(int needed, beast::Journal j)
std::unique_ptr< Application > make_Application(std::unique_ptr< Config > config, std::unique_ptr< Logs > logs, std::unique_ptr< TimeKeeper > timeKeeper)
DatabaseCon::Setup setup_DatabaseCon(Config const &c, std::optional< beast::Journal > j=std::nullopt)
static std::string const & systemName()
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()