20#include <xrpld/app/main/Application.h>
21#include <xrpld/app/main/DBInit.h>
22#include <xrpld/app/rdb/Vacuum.h>
23#include <xrpld/core/Config.h>
24#include <xrpld/core/ConfigSections.h>
25#include <xrpld/core/TimeKeeper.h>
26#include <xrpld/net/RPCCall.h>
27#include <xrpld/rpc/RPCHandler.h>
28#include <xrpl/basics/Log.h>
29#include <xrpl/basics/StringUtilities.h>
30#include <xrpl/basics/contract.h>
31#include <xrpl/beast/clock/basic_seconds_clock.h>
32#include <xrpl/beast/core/CurrentThreadName.h>
33#include <xrpl/json/to_string.h>
34#include <xrpl/protocol/BuildInfo.h>
35#include <xrpl/resource/Fees.h>
38#include <test/unit_test/multi_runner.h>
39#include <xrpl/beast/unit_test/match.h>
42#include <google/protobuf/stubs/common.h>
44#include <boost/filesystem.hpp>
45#include <boost/predef.h>
46#include <boost/process.hpp>
47#include <boost/program_options.hpp>
61#if !BOOST_OS_LINUX && !BOOST_OS_WINDOWS && !BOOST_OS_MACOS
62#error Supported platforms are: Linux, Windows and MacOS
66#if (BOOST_OS_LINUX && (BOOST_OS_WINDOWS || BOOST_OS_MACOS)) || \
67 (BOOST_OS_MACOS && (BOOST_OS_WINDOWS || BOOST_OS_LINUX)) || \
68 (BOOST_OS_WINDOWS && (BOOST_OS_LINUX || BOOST_OS_MACOS))
69#error Multiple supported platforms appear active at once
73#include "antithesis_instrumentation.h"
76namespace po = boost::program_options;
89 if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
92 if (rl.rlim_cur == RLIM_INFINITY)
102 rl.rlim_cur = needed;
104 if (setrlimit(RLIMIT_NOFILE, &rl) == 0)
111 j.
fatal() <<
"Insufficient number of file descriptors: " << needed
112 <<
" are needed, but only " <<
available <<
" are available.";
114 std::cerr <<
"Insufficient number of file descriptors: " << needed
116 <<
" are available.\n";
129 <<
systemName() <<
"d [options] <command> <params>\n"
132 " account_currencies <account> [<ledger>]\n"
133 " account_info <account>|<key> [<ledger>]\n"
134 " account_lines <account> <account>|\"\" [<ledger>]\n"
135 " account_channels <account> <account>|\"\" [<ledger>]\n"
136 " account_objects <account> [<ledger>]\n"
137 " account_offers <account>|<account_public_key> [<ledger>]\n"
138 " account_tx accountID [ledger_index_min [ledger_index_max "
141 " book_changes [<ledger hash|id>]\n"
142 " book_offers <taker_pays> <taker_gets> [<taker [<ledger> "
143 "[<limit> [<proof> [<marker>]]]]]\n"
144 " can_delete [<ledgerid>|<ledgerhash>|now|always|never]\n"
145 " channel_authorize <private_key> <channel_id> <drops>\n"
146 " channel_verify <public_key> <channel_id> <drops> <signature>\n"
147 " connect <ip> [<port>]\n"
149 " deposit_authorized <source_account> <destination_account> "
150 "[<ledger> [<credentials>, ...]]\n"
151 " feature [<feature> [accept|reject]]\n"
152 " fetch_info [clear]\n"
153 " gateway_balances [<ledger>] <issuer_account> [ <hotwallet> [ "
156 " json <method> <json>\n"
157 " ledger [<id>|current|closed|validated] [full]\n"
162 " ledger_request <ledger>\n"
163 " log_level [[<partition>] <severity>]\n"
165 " manifest <public_key>\n"
169 " peer_reservations_add <public_key> [<description>]\n"
170 " peer_reservations_del <public_key>\n"
171 " peer_reservations_list\n"
173 " ripple_path_find <json> [<ledger>]\n"
174 " server_definitions [<hash>]\n"
175 " server_info [counters]\n"
176 " server_state [counters]\n"
177 " sign <private_key> <tx_json> [offline]\n"
178 " sign_for <signer_address> <signer_private_key> <tx_json> "
181 " submit <tx_blob>|[<private_key> <tx_json>]\n"
182 " submit_multisigned <tx_json>\n"
184 " validation_create [<seed>|<pass_phrase>|<key>]\n"
187 " validator_list_sites\n"
189 " wallet_propose [<passphrase>]\n";
204 explicit multi_selector(
std::string const& patterns =
"")
207 boost::split(v, patterns, boost::algorithm::is_any_of(
","));
211 if (selectors_.empty() || !s.empty())
212 selectors_.emplace_back(
213 beast::unit_test::selector::automatch, s);
220 for (
auto& sel : selectors_)
229 return selectors_.size();
237template <
class Runner>
239anyMissing(Runner& runner, multi_selector
const& pred)
241 if (runner.tests() == 0)
243 runner.add_failures(1);
247 if (runner.suites() < pred.size())
249 auto const missing = pred.size() - runner.suites();
250 runner.add_failures(missing);
252 <<
" filters did not match any existing test suites"
276 if (!child && num_jobs == 1)
281 child_runner.arg(argument);
282 multi_selector pred(pattern);
283 auto const any_failed =
284 child_runner.run_multi(pred) || anyMissing(child_runner, pred);
299 for (
int i = 1; i < argc; ++i)
306 boost::process::exe = exe_name, boost::process::args = args);
308 int bad_child_exits = 0;
309 int terminated_child_exits = 0;
310 for (
auto& c : children)
322 ++terminated_child_exits;
327 anyMissing(parent_runner, multi_selector(pattern));
329 if (parent_runner.
any_failed() || bad_child_exits)
338 auto const anyFailed =
runner.run_multi(multi_selector(pattern));
357 po::variables_map vm;
361 importText +=
"Import an existing node database (specified in the [";
363 importText +=
"] configuration file section) into the current ";
364 importText +=
"node database (specified in the [";
366 importText +=
"] configuration file section).";
371 po::options_description gen(
"General Options");
373 "conf", po::value<std::string>(),
"Specify the configuration file.")(
374 "debug",
"Enable normally suppressed debug logging")(
375 "help,h",
"Display this message.")(
376 "newnodeid",
"Generate a new node identity for this server.")(
378 po::value<std::string>(),
379 "Specify the node identity for this server.")(
381 po::value<std::size_t>(),
382 "Override the minimum validation quorum.")(
383 "silent",
"No output to the console after startup.")(
384 "standalone,a",
"Run with no peers.")(
"verbose,v",
"Verbose logging.")
386 (
"force_ledger_present_range",
387 po::value<std::string>(),
388 "Specify the range of present ledgers for testing purposes. Min and "
389 "max values are comma separated.")(
390 "version",
"Display the build version.");
392 po::options_description data(
"Ledger/Data Options");
393 data.add_options()(
"import", importText.
c_str())(
395 po::value<std::string>(),
396 "Load the specified ledger and start from the value given.")(
398 po::value<std::string>(),
399 "Load the specified ledger file.")(
400 "load",
"Load the current ledger from the local DB.")(
401 "net",
"Get the initial ledger from the network.")(
402 "replay",
"Replay a ledger close.")(
404 po::value<std::string>(),
405 "Trap a specific transaction during replay.")(
406 "start",
"Start from a fresh Ledger.")(
407 "vacuum",
"VACUUM the transaction db.")(
408 "valid",
"Consider the initial ledger a valid network ledger.");
410 po::options_description
rpc(
"RPC Client Options");
413 "Perform rpc command - see below for available commands. "
414 "This is assumed if any positional parameters are provided.")(
416 po::value<std::string>(),
417 "Specify the IP address for RPC command. "
418 "Format: <ip-address>[':'<port-number>]")(
420 po::value<std::uint16_t>(),
421 "DEPRECATED: include with rpc_ip instead. "
422 "Specify the port number for RPC command.");
425 po::options_description test(
"Unit Test Options");
428 "Suppress test suite messages, "
429 "including suite/case name (at start) and test log messages.")(
431 po::value<std::string>()->implicit_value(
""),
432 "Perform unit tests. The optional argument specifies one or "
433 "more comma-separated selectors. Each selector specifies a suite name, "
434 "suite name prefix, full-name (lib.module.suite), module, or library "
435 "(checked in that order).")(
437 po::value<std::string>()->implicit_value(
""),
438 "Supplies an argument string to unit tests. If provided, this argument "
439 "is made available to each suite that runs. Interpretation of the "
440 "argument is handled individually by any suite that accesses it -- "
441 "as such, it typically only make sense to provide this when running "
444 "Use IPv6 localhost when running unittests (default is IPv4).")(
446 "Force unit test log message output. Only useful in combination with "
447 "--quiet, in which case log messages will print but suite/case names "
450 po::value<std::size_t>(),
451 "Number of unittest jobs to run in parallel (child processes).");
456 po::options_description hidden(
"Hidden Options");
457 hidden.add_options()(
459 po::value<vector<string>>(),
460 "Specify rpc command and parameters. This option must be repeated "
461 "for each command/param. Positional parameters also serve this "
463 "so this option is not needed for users")
466 "For internal use only when spawning child unit test processes.")
468 (
"unittest",
"Disabled in this build.")(
469 "unittest-child",
"Disabled in this build.")
471 (
"fg",
"Deprecated: server always in foreground mode.");
474 po::positional_options_description p;
475 p.add(
"parameters", -1);
477 po::options_description
all;
486 po::options_description desc;
499 po::command_line_parser(argc, argv)
513 if (vm.count(
"help"))
519 if (vm.count(
"version"))
527 if (vm.count(
"unittest") || vm.count(
"unittest-child"))
537 if (vm.count(
"unittest"))
541 if (vm.count(
"unittest-arg"))
545 bool unittestChild =
false;
546 if (vm.count(
"unittest-jobs"))
547 numJobs =
std::max(numJobs, vm[
"unittest-jobs"].as<std::size_t>());
548 unittestChild = bool(vm.count(
"unittest-child"));
551 vm[
"unittest"].as<std::string>(),
553 bool(vm.count(
"quiet")),
554 bool(vm.count(
"unittest-log")),
556 bool(vm.count(
"unittest-ipv6")),
564 if (vm.count(
"unittest-jobs"))
567 std::cerr <<
"rippled: '--unittest-jobs' specified without "
569 std::cerr <<
"To run the unit tests the '--unittest' option must "
576 auto config = std::make_unique<Config>();
584 bool(vm.count(
"quiet")),
585 bool(vm.count(
"silent")),
586 bool(vm.count(
"standalone")));
588 if (vm.count(
"vacuum"))
590 if (config->standalone())
592 std::cerr <<
"vacuum not applicable in standalone mode.\n";
604 std::cerr <<
"exception " << e.
what() <<
" in function " << __func__
612 if (vm.contains(
"force_ledger_present_range"))
620 vm[
"force_ledger_present_range"].as<std::string>(),
621 boost::algorithm::is_any_of(
","));
623 for (
auto& s : strVec)
637 "Invalid force_ledger_present_range parameter");
639 config->FORCED_LEDGER_RANGE_PRESENT.emplace(r[0], r[1]);
644 "Invalid force_ledger_present_range parameter");
649 std::cerr <<
"invalid 'force_ledger_present_range' parameter. The "
650 "parameter must be two numbers separated by a comma. "
651 "The first number must be <= the second."
657 if (vm.count(
"start"))
662 if (vm.count(
"import"))
663 config->doImport =
true;
665 if (vm.count(
"ledger"))
667 config->START_LEDGER = vm[
"ledger"].as<
std::string>();
668 if (vm.count(
"replay"))
671 if (vm.count(
"trap_tx_hash"))
677 config->TRAP_TX_HASH = tmp;
681 std::cerr <<
"Trap parameter was ill-formed, expected "
682 "valid transaction hash but received: "
691 else if (vm.count(
"ledgerfile"))
693 config->START_LEDGER = vm[
"ledgerfile"].as<
std::string>();
696 else if (vm.count(
"load") || config->FAST_LOAD)
701 if (vm.count(
"trap_tx_hash") && vm.count(
"replay") == 0)
703 std::cerr <<
"Cannot use trap option without replay option"
708 if (vm.count(
"net") && !config->FAST_LOAD)
713 std::cerr <<
"Net and load/replay options are incompatible"
721 if (vm.count(
"valid"))
723 config->START_VALID =
true;
728 if (vm.count(
"rpc_ip"))
731 vm[
"rpc_ip"].as<std::string>());
739 if (endpoint->port() == 0)
741 std::cerr <<
"No port specified in rpc_ip.\n";
742 if (vm.count(
"rpc_port"))
744 std::cerr <<
"WARNING: using deprecated rpc_port param.\n";
748 endpoint->at_port(vm[
"rpc_port"].as<std::uint16_t>());
749 if (endpoint->port() == 0)
762 config->rpc_ip = std::move(*endpoint);
765 if (vm.count(
"quorum"))
769 config->VALIDATION_QUORUM = vm[
"quorum"].as<
std::size_t>();
777 std::cerr <<
"Invalid value specified for --quorum (" << e.
what()
787 if (vm.count(
"quiet"))
789 else if (vm.count(
"verbose"))
792 auto logs = std::make_unique<Logs>(thresh);
795 if (!vm.count(
"parameters"))
799 if (config->had_trailing_comments())
801 JLOG(logs->journal(
"Application").warn())
802 <<
"Trailing comments were seen in your config file. "
803 <<
"The treatment of inline/trailing comments has changed "
805 <<
"Any `#` characters NOT intended to delimit comments should "
807 <<
"preceded by a \\";
815 if (vm.count(
"debug"))
819 std::move(config), std::move(logs), std::make_unique<TimeKeeper>());
827 app->fdRequired(), app->logs().journal(
"Application")))
849main(
int argc,
char** argv)
869 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()