1#include <xrpld/app/main/Application.h>
2#include <xrpld/core/Config.h>
3#include <xrpld/core/ConfigSections.h>
4#include <xrpld/core/TimeKeeper.h>
5#include <xrpld/rpc/RPCCall.h>
7#include <xrpl/basics/Log.h>
8#include <xrpl/beast/core/CurrentThreadName.h>
9#include <xrpl/git/Git.h>
10#include <xrpl/protocol/BuildInfo.h>
11#include <xrpl/server/Vacuum.h>
13#include <boost/asio/io_context.hpp>
14#include <boost/process/v1/args.hpp>
15#include <boost/process/v1/child.hpp>
16#include <boost/process/v1/exe.hpp>
19#include <test/unit_test/multi_runner.h>
21#include <xrpl/beast/unit_test/match.h>
23#include <boost/algorithm/string.hpp>
24#include <boost/program_options.hpp>
26#include <google/protobuf/stubs/common.h>
40#if !BOOST_OS_LINUX && !BOOST_OS_WINDOWS && !BOOST_OS_MACOS
41#error Supported platforms are: Linux, Windows and MacOS
45#if (BOOST_OS_LINUX && (BOOST_OS_WINDOWS || BOOST_OS_MACOS)) || \
46 (BOOST_OS_MACOS && (BOOST_OS_WINDOWS || BOOST_OS_LINUX)) || \
47 (BOOST_OS_WINDOWS && (BOOST_OS_LINUX || BOOST_OS_MACOS))
48#error Multiple supported platforms appear active at once
52#include "antithesis_instrumentation.h"
55namespace po = boost::program_options;
68 if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
71 if (rl.rlim_cur == RLIM_INFINITY)
87 if (setrlimit(RLIMIT_NOFILE, &rl) == 0)
94 j.
fatal() <<
"Insufficient number of file descriptors: " << needed
95 <<
" are needed, but only " <<
available <<
" are available.";
97 std::cerr <<
"Insufficient number of file descriptors: " << needed
98 <<
" are needed, but only " <<
available <<
" are available.\n";
113 " account_currencies <account> [<ledger>]\n"
114 " account_info <account>|<key> [<ledger>]\n"
115 " account_lines <account> <account>|\"\" [<ledger>]\n"
116 " account_channels <account> <account>|\"\" [<ledger>]\n"
117 " account_objects <account> [<ledger>]\n"
118 " account_offers <account>|<account_public_key> [<ledger>]\n"
119 " account_tx accountID [ledger_index_min [ledger_index_max "
122 " book_changes [<ledger hash|id>]\n"
123 " book_offers <taker_pays> <taker_gets> [<taker [<ledger> "
124 "[<limit> [<proof> [<marker>]]]]]\n"
125 " can_delete [<ledgerid>|<ledgerhash>|now|always|never]\n"
126 " channel_authorize <private_key> <channel_id> <drops>\n"
127 " channel_verify <public_key> <channel_id> <drops> <signature>\n"
128 " connect <ip> [<port>]\n"
130 " deposit_authorized <source_account> <destination_account> "
131 "[<ledger> [<credentials>, ...]]\n"
132 " feature [<feature> [accept|reject]]\n"
133 " fetch_info [clear]\n"
134 " gateway_balances [<ledger>] <issuer_account> [ <hotwallet> [ "
137 " json <method> <json>\n"
138 " ledger [<id>|current|closed|validated] [full]\n"
143 " ledger_request <ledger>\n"
144 " log_level [[<partition>] <severity>]\n"
146 " manifest <public_key>\n"
150 " peer_reservations_add <public_key> [<description>]\n"
151 " peer_reservations_del <public_key>\n"
152 " peer_reservations_list\n"
154 " ripple_path_find <json> [<ledger>]\n"
155 " server_definitions [<hash>]\n"
156 " server_info [counters]\n"
157 " server_state [counters]\n"
158 " sign <private_key> <tx_json> [offline]\n"
159 " sign_for <signer_address> <signer_private_key> <tx_json> "
160 "[offline] [<signature_field>]\n"
162 " simulate [<tx_blob>|<tx_json>] [<binary>]\n"
163 " submit <tx_blob>|[<private_key> <tx_json>]\n"
164 " submit_multisigned <tx_json>\n"
166 " validation_create [<seed>|<pass_phrase>|<key>]\n"
169 " validator_list_sites\n"
171 " wallet_propose [<passphrase>]\n";
186 explicit multi_selector(
std::string const& patterns =
"")
189 boost::split(v, patterns, boost::algorithm::is_any_of(
","));
193 if (selectors_.empty() || !s.empty())
194 selectors_.emplace_back(beast::unit_test::selector::automatch, s);
201 for (
auto& sel : selectors_)
212 return selectors_.
size();
220template <
class Runner>
222anyMissing(Runner& runner, multi_selector
const& pred)
224 if (runner.tests() == 0)
226 runner.add_failures(1);
230 if (runner.suites() < pred.size())
232 auto const missing = pred.size() - runner.suites();
233 runner.add_failures(missing);
234 std::cout <<
"Failed: " << missing <<
" filters did not match any existing test suites"
258 if (!child && num_jobs == 1)
263 child_runner.arg(argument);
264 multi_selector
const pred(pattern);
265 auto const any_failed = child_runner.run_multi(pred) || anyMissing(child_runner, pred);
280 for (
int i = 1; i < argc; ++i)
289 boost::process::v1::exe = exe_name, boost::process::v1::args = args);
292 int bad_child_exits = 0;
293 int terminated_child_exits = 0;
294 for (
auto& c : children)
299 if (c.exit_code() != 0)
306 ++terminated_child_exits;
311 anyMissing(parent_runner, multi_selector(pattern));
313 if (parent_runner.
any_failed() || (bad_child_exits != 0))
321 auto const anyFailed =
runner.run_multi(multi_selector(pattern));
338 po::variables_map vm;
342 importText +=
"Import an existing node database (specified in the [";
344 importText +=
"] configuration file section) into the current ";
345 importText +=
"node database (specified in the [";
347 importText +=
"] configuration file section).";
352 po::options_description gen(
"General Options");
353 gen.add_options()(
"conf", po::value<std::string>(),
"Specify the configuration file.")(
354 "debug",
"Enable normally suppressed debug logging")(
"help,h",
"Display this message.")(
355 "newnodeid",
"Generate a new node identity for this server.")(
356 "nodeid", po::value<std::string>(),
"Specify the node identity for this server.")(
357 "quorum", po::value<std::size_t>(),
"Override the minimum validation quorum.")(
358 "silent",
"No output to the console after startup.")(
"standalone,a",
"Run with no peers.")(
359 "verbose,v",
"Verbose logging.")
361 (
"force_ledger_present_range",
362 po::value<std::string>(),
363 "Specify the range of present ledgers for testing purposes. Min and "
364 "max values are comma separated.")(
"version",
"Display the build version.");
366 po::options_description data(
"Ledger/Data Options");
367 data.add_options()(
"import", importText.
c_str())(
369 po::value<std::string>(),
370 "Load the specified ledger and start from the value given.")(
371 "ledgerfile", po::value<std::string>(),
"Load the specified ledger file.")(
372 "load",
"Load the current ledger from the local DB.")(
373 "net",
"Get the initial ledger from the network.")(
"replay",
"Replay a ledger close.")(
374 "trap_tx_hash", po::value<std::string>(),
"Trap a specific transaction during replay.")(
375 "start",
"Start from a fresh Ledger.")(
"vacuum",
"VACUUM the transaction db.")(
376 "valid",
"Consider the initial ledger a valid network ledger.");
378 po::options_description
rpc(
"RPC Client Options");
381 "Perform rpc command - see below for available commands. "
382 "This is assumed if any positional parameters are provided.")(
384 po::value<std::string>(),
385 "Specify the IP address for RPC command. "
386 "Format: <ip-address>[':'<port-number>]")(
388 po::value<std::uint16_t>(),
389 "DEPRECATED: include with rpc_ip instead. "
390 "Specify the port number for RPC command.");
393 po::options_description test(
"Unit Test Options");
396 "Suppress test suite messages, "
397 "including suite/case name (at start) and test log messages.")(
399 po::value<std::string>()->implicit_value(
""),
400 "Perform unit tests. The optional argument specifies one or "
401 "more comma-separated selectors. Each selector specifies a suite name, "
402 "suite name prefix, full-name (lib.module.suite), module, or library "
403 "(checked in that order).")(
405 po::value<std::string>()->implicit_value(
""),
406 "Supplies an argument string to unit tests. If provided, this argument "
407 "is made available to each suite that runs. Interpretation of the "
408 "argument is handled individually by any suite that accesses it -- "
409 "as such, it typically only make sense to provide this when running "
411 "unittest-ipv6",
"Use IPv6 localhost when running unittests (default is IPv4).")(
413 "Force unit test log message output. Only useful in combination with "
414 "--quiet, in which case log messages will print but suite/case names "
417 po::value<std::size_t>(),
418 "Number of unittest jobs to run in parallel (child processes).");
423 po::options_description hidden(
"Hidden Options");
424 hidden.add_options()(
426 po::value<vector<string>>(),
427 "Specify rpc command and parameters. This option must be repeated "
428 "for each command/param. Positional parameters also serve this "
430 "so this option is not needed for users")
432 (
"unittest-child",
"For internal use only when spawning child unit test processes.")
434 (
"unittest",
"Disabled in this build.")(
"unittest-child",
"Disabled in this build.")
436 (
"fg",
"Deprecated: server always in foreground mode.");
439 po::positional_options_description p;
440 p.add(
"parameters", -1);
442 po::options_description all;
451 po::options_description desc;
464 po::command_line_parser(argc, argv)
478 if (vm.contains(
"help"))
484 if (vm.contains(
"version"))
493 if (vm.count(
"unittest") || vm.count(
"unittest-child"))
503 if (vm.contains(
"unittest"))
507 if (vm.contains(
"unittest-arg"))
511 bool unittestChild =
false;
512 if (vm.contains(
"unittest-jobs"))
513 numJobs =
std::max(numJobs, vm[
"unittest-jobs"].as<std::size_t>());
514 unittestChild = vm.contains(
"unittest-child");
517 vm[
"unittest"].as<std::string>(),
519 vm.contains(
"quiet"),
520 vm.contains(
"unittest-log"),
522 vm.contains(
"unittest-ipv6"),
529 if (vm.contains(
"unittest-jobs"))
532 std::cerr <<
"rippled: '--unittest-jobs' specified without "
534 std::cerr <<
"To run the unit tests the '--unittest' option must "
547 configFile, vm.contains(
"quiet"), vm.contains(
"silent"), vm.contains(
"standalone"));
549 if (vm.contains(
"vacuum"))
551 if (config->standalone())
553 std::cerr <<
"vacuum not applicable in standalone mode.\n";
572 if (vm.contains(
"force_ledger_present_range"))
580 vm[
"force_ledger_present_range"].as<std::string>(),
581 boost::algorithm::is_any_of(
","));
583 for (
auto& s : strVec)
598 config->FORCED_LEDGER_RANGE_PRESENT.emplace(r[0], r[1]);
607 std::cerr <<
"invalid 'force_ledger_present_range' parameter. The "
608 "parameter must be two numbers separated by a comma. "
609 "The first number must be <= the second."
615 if (vm.contains(
"start"))
620 if (vm.contains(
"import"))
621 config->doImport =
true;
623 if (vm.contains(
"ledger"))
625 config->START_LEDGER = vm[
"ledger"].as<
std::string>();
626 if (vm.contains(
"replay"))
629 if (vm.contains(
"trap_tx_hash"))
635 config->TRAP_TX_HASH = tmp;
639 std::cerr <<
"Trap parameter was ill-formed, expected "
640 "valid transaction hash but received: "
651 else if (vm.contains(
"ledgerfile"))
653 config->START_LEDGER = vm[
"ledgerfile"].as<
std::string>();
656 else if (vm.contains(
"load") || config->FAST_LOAD)
661 if (vm.contains(
"trap_tx_hash") && !vm.contains(
"replay"))
667 if (vm.contains(
"net") && !config->FAST_LOAD)
678 if (vm.contains(
"valid"))
680 config->START_VALID =
true;
685 if (vm.contains(
"rpc_ip"))
694 if (endpoint->port() == 0)
696 std::cerr <<
"No port specified in rpc_ip.\n";
697 if (vm.contains(
"rpc_port"))
699 std::cerr <<
"WARNING: using deprecated rpc_port param.\n";
702 endpoint = endpoint->at_port(vm[
"rpc_port"].as<std::uint16_t>());
703 if (endpoint->port() == 0)
718 config->rpc_ip = std::move(*endpoint);
721 if (vm.contains(
"quorum"))
725 config->VALIDATION_QUORUM = vm[
"quorum"].as<
std::size_t>();
733 std::cerr <<
"Invalid value specified for --quorum (" << e.
what() <<
")\n";
742 if (vm.contains(
"quiet"))
746 else if (vm.contains(
"verbose"))
754 if (!vm.contains(
"parameters"))
756 if (config->had_trailing_comments())
758 JLOG(logs->journal(
"Application").warn())
759 <<
"Trailing comments were seen in your config file. "
760 <<
"The treatment of inline/trailing comments has changed "
762 <<
"Any `#` characters NOT intended to delimit comments should "
764 <<
"preceded by a \\";
772 if (vm.contains(
"debug"))
805main(
int argc,
char** argv)
825 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::string const & getCommitHash()
std::string const & getBuildBranch()
std::atomic< bool > envUseIPv4
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
int run(int argc, char **argv)
bool doVacuumDB(DatabaseCon::Setup const &setup, beast::Journal j)
doVacuumDB Creates, initialises, and performs cleanup on a database.
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()
void printHelp(po::options_description const &desc)
static std::string nodeDatabase()
static std::string importNodeDatabase()