mirror of
https://github.com/Xahau/xahaud.git
synced 2026-04-29 15:37:46 +00:00
* Add jss fields used by Clio `nft_info`: (#4320) Add Clio-specific JSS constants to ensure a common vocabulary of keywords in Clio and this project. By providing visibility of the full API keyword namespace, it reduces the likelihood of developers introducing minor variations on names used by Clio, or unknowingly claiming a keyword that Clio has already claimed. This change moves this project slightly away from having only the code necessary for running the core server, but it is a step toward the goal of keeping this server's and Clio's APIs similar. The added JSS constants are annotated to indicate their relevance to Clio. Clio can be found here: https://github.com/XRPLF/clio Signed-off-by: ledhed2222 <ledhed2222@users.noreply.github.com> * Introduce support for a slabbed allocator: (#4218) When instantiating a large amount of fixed-sized objects on the heap the overhead that dynamic memory allocation APIs impose will quickly become significant. In some cases, allocating a large amount of memory at once and using a slabbing allocator to carve the large block into fixed-sized units that are used to service requests for memory out will help to reduce memory fragmentation significantly and, potentially, improve overall performance. This commit introduces a new `SlabAllocator<>` class that exposes an API that is _similar_ to the C++ concept of an `Allocator` but it is not meant to be a general-purpose allocator. It should not be used unless profiling and analysis of specific memory allocation patterns indicates that the additional complexity introduced will improve the performance of the system overall, and subsequent profiling proves it. A helper class, `SlabAllocatorSet<>` simplifies handling of variably sized objects that benefit from slab allocations. This commit incorporates improvements suggested by Greg Popovitch (@greg7mdp). Commit 1 of 3 in #4218. * Optimize `SHAMapItem` and leverage new slab allocator: (#4218) The `SHAMapItem` class contains a variable-sized buffer that holds the serialized data associated with a particular item inside a `SHAMap`. Prior to this commit, the buffer for the serialized data was allocated separately. Coupled with the fact that most instances of `SHAMapItem` were wrapped around a `std::shared_ptr` meant that an instantiation might result in up to three separate memory allocations. This commit switches away from `std::shared_ptr` for `SHAMapItem` and uses `boost::intrusive_ptr` instead, allowing the reference count for an instance to live inside the instance itself. Coupled with using a slab-based allocator to optimize memory allocation for the most commonly sized buffers, the net result is significant memory savings. In testing, the reduction in memory usage hovers between 400MB and 650MB. Other scenarios might result in larger savings. In performance testing with NFTs, this commit reduces memory size by about 15% sustained over long duration. Commit 2 of 3 in #4218. * Avoid using std::shared_ptr when not necessary: (#4218) The `Ledger` class contains two `SHAMap` instances: the state and transaction maps. Previously, the maps were dynamically allocated using `std::make_shared` despite the fact that they did not require lifetime management separate from the lifetime of the `Ledger` instance to which they belong. The two `SHAMap` instances are now regular member variables. Some smart pointers and dynamic memory allocation was avoided by using stack-based alternatives. Commit 3 of 3 in #4218. * Prevent replay attacks with NetworkID field: (#4370) Add a `NetworkID` field to help prevent replay attacks on and from side-chains. The new field must be used when the server is using a network id > 1024. To preserve legacy behavior, all chains with a network ID less than 1025 retain the existing behavior. This includes Mainnet, Testnet, Devnet, and hooks-testnet. If `sfNetworkID` is present in any transaction submitted to any of the nodes on one of these chains, then `telNETWORK_ID_MAKES_TX_NON_CANONICAL` is returned. Since chains with a network ID less than 1025, including Mainnet, retain the existing behavior, there is no need for an amendment. The `NetworkID` helps to prevent replay attacks because users specify a `NetworkID` field in every transaction for that chain. This change introduces a new UINT32 field, `sfNetworkID` ("NetworkID"). There are also three new local error codes for transaction results: - `telNETWORK_ID_MAKES_TX_NON_CANONICAL` - `telREQUIRES_NETWORK_ID` - `telWRONG_NETWORK` To learn about the other transaction result codes, see: https://xrpl.org/transaction-results.html Local error codes were chosen because a transaction is not necessarily malformed if it is submitted to a node running on the incorrect chain. This is a local error specific to that node and could be corrected by switching to a different node or by changing the `network_id` on that node. See: https://xrpl.org/connect-your-rippled-to-the-xrp-test-net.html In addition to using `NetworkID`, it is still generally recommended to use different accounts and keys on side-chains. However, people will undoubtedly use the same keys on multiple chains; for example, this is common practice on other blockchain networks. There are also some legitimate use cases for this. A `app.NetworkID` test suite has been added, and `core.Config` was updated to include some network_id tests. * Fix the fix for std::result_of (#4496) Newer compilers, such as Apple Clang 15.0, have removed `std::result_of` as part of C++20. The build instructions provided a fix for this (by adding a preprocessor definition), but the fix was broken. This fixes the fix by: * Adding the `conf` prefix for tool configurations (which had been forgotten). * Passing `extra_b2_flags` to `boost` package to fix its build. * Define `BOOST_ASIO_HAS_STD_INVOKE_RESULT` in order to build boost 1.77 with a newer compiler. * Use quorum specified via command line: (#4489) If `--quorum` setting is present on the command line, use the specified value as the minimum quorum. This allows for the use of a potentially fork-unsafe quorum, but it is sometimes necessary for small and test networks. Fix #4488. --------- Co-authored-by: RichardAH <richard.holland@starstone.co.nz> * Fix errors for Clang 16: (#4501) Address issues related to the removal of `std::{u,bi}nary_function` in C++17 and some warnings with Clang 16. Some warnings appeared with the upgrade to Apple clang version 14.0.3 (clang-1403.0.22.14.1). - `std::{u,bi}nary_function` were removed in C++17. They were empty classes with a few associated types. We already have conditional code to define the types. Just make it unconditional. - libc++ checks a cast in an unevaluated context to see if a type inherits from a binary function class in the standard library, e.g. `std::equal_to`, and this causes an error when the type privately inherits from such a class. Change these instances to public inheritance. - We don't need a middle-man for the empty base optimization. Prefer to inherit directly from an empty class than from `beast::detail::empty_base_optimization`. - Clang warns when all the uses of a variable are removed by conditional compilation of assertions. Add a `[[maybe_unused]]` annotation to suppress it. - As a drive-by clean-up, remove commented code. See related work in #4486. * Fix typo (#4508) * fix!: Prevent API from accepting seed or public key for account (#4404) The API would allow seeds (and public keys) to be used in place of accounts at several locations in the API. For example, when calling account_info, you could pass `"account": "foo"`. The string "foo" is treated like a seed, so the method returns `actNotFound` (instead of `actMalformed`, as most developers would expect). In the early days, this was a convenience to make testing easier. However, it allows for poor security practices, so it is no longer a good idea. Allowing a secret or passphrase is now considered a bug. Previously, it was controlled by the `strict` option on some methods. With this commit, since the API does not interpret `account` as `seed`, the option `strict` is no longer needed and is removed. Removing this behavior from the API is a [breaking change](https://xrpl.org/request-formatting.html#breaking-changes). One could argue that it shouldn't be done without bumping the API version; however, in this instance, there is no evidence that anyone is using the API in the "legacy" way. Furthermore, it is a potential security hole, as it allows users to send secrets to places where they are not needed, where they could end up in logs, error messages, etc. There's no reason to take such a risk with a seed/secret, since only the public address is needed. Resolves: #3329, #3330, #4337 BREAKING CHANGE: Remove non-strict account parsing (#3330) * Add nftoken_id, nftoken_ids, offer_id fields for NFTokens (#4447) Three new fields are added to the `Tx` responses for NFTs: 1. `nftoken_id`: This field is included in the `Tx` responses for `NFTokenMint` and `NFTokenAcceptOffer`. This field indicates the `NFTokenID` for the `NFToken` that was modified on the ledger by the transaction. 2. `nftoken_ids`: This array is included in the `Tx` response for `NFTokenCancelOffer`. This field provides a list of all the `NFTokenID`s for the `NFToken`s that were modified on the ledger by the transaction. 3. `offer_id`: This field is included in the `Tx` response for `NFTokenCreateOffer` transactions and shows the OfferID of the `NFTokenOffer` created. The fields make it easier to track specific tokens and offers. The implementation includes code (by @ledhed2222) from the Clio project to extract NFTokenIDs from mint transactions. * Ensure that switchover vars are initialized before use: (#4527) Global variables in different TUs are initialized in an undefined order. At least one global variable was accessing a global switchover variable. This caused the switchover variable to be accessed in an uninitialized state. Since the switchover is always explicitly set before transaction processing, this bug can not effect transaction processing, but could effect unit tests (and potentially the value of some global variables). Note: at the time of this patch the offending bug is not yet in production. * Move faulty assert (#4533) This assert was put in the wrong place, but it only triggers if shards are configured. This change moves the assert to the right place and updates it to ensure correctness. The assert could be hit after the server downloads some shards. It may be necessary to restart after the shards are downloaded. Note that asserts are normally checked only in debug builds, so release packages should not be affected. Introduced in: #4319 (66627b26cf) * Fix unaligned load and stores: (#4528) (#4531) Misaligned load and store operations are supported by both Intel and ARM CPUs. However, in C++, these operations are undefined behavior (UB). Substituting these operations with a `memcpy` fixes this UB. The compiled assembly code is equivalent to the original, so there is no performance penalty to using memcpy. For context: The unaligned load and store operations fixed here were originally introduced in the slab allocator (#4218). * Add missing includes for gcc 13.1: (#4555) gcc 13.1 failed to compile due to missing headers. This patch adds the needed headers. * Trivial: add comments for NFToken-related invariants (#4558) * fix node size estimation (#4536) Fix a bug in the `NODE_SIZE` auto-detection feature in `Config.cpp`. Specifically, this patch corrects the calculation for the total amount of RAM available, which was previously returned in bytes, but is now being returned in units of the system's memory unit. Additionally, the patch adjusts the node size based on the number of available hardware threads of execution. * fix: remove redundant moves (#4565) - Resolve gcc compiler warning: AccountObjects.cpp:182:47: warning: redundant move in initialization [-Wredundant-move] - The std::move() operation on trivially copyable types may generate a compile warning in newer versions of gcc. - Remove extraneous header (unused imports) from a unit test file. * Revert "Fix the fix for std::result_of (#4496)" This reverts commitcee8409d60. * Revert "Fix typo (#4508)" This reverts commit2956f14de8. * clang * [fold] bad merge * [fold] fix bad merge - add back filter for ripple state on account_channels - add back network id test (env auto adds network id in xahau) * [fold] fix build error --------- Signed-off-by: ledhed2222 <ledhed2222@users.noreply.github.com> Co-authored-by: ledhed2222 <ledhed2222@users.noreply.github.com> Co-authored-by: Nik Bougalis <nikb@bougalis.net> Co-authored-by: RichardAH <richard.holland@starstone.co.nz> Co-authored-by: John Freeman <jfreeman08@gmail.com> Co-authored-by: Mark Travis <mtrippled@users.noreply.github.com> Co-authored-by: solmsted <steven.olm@gmail.com> Co-authored-by: drlongle <drlongle@gmail.com> Co-authored-by: Shawn Xie <35279399+shawnxie999@users.noreply.github.com> Co-authored-by: Scott Determan <scott.determan@yahoo.com> Co-authored-by: Ed Hennis <ed@ripple.com> Co-authored-by: Scott Schurr <scott@ripple.com> Co-authored-by: Chenna Keshava B S <21219765+ckeshava@users.noreply.github.com>
811 lines
25 KiB
C++
811 lines
25 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of rippled: https://github.com/ripple/rippled
|
|
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
#include <ripple/app/main/Application.h>
|
|
#include <ripple/app/main/DBInit.h>
|
|
#include <ripple/app/rdb/Vacuum.h>
|
|
#include <ripple/basics/Log.h>
|
|
#include <ripple/basics/StringUtilities.h>
|
|
#include <ripple/basics/contract.h>
|
|
#include <ripple/beast/clock/basic_seconds_clock.h>
|
|
#include <ripple/beast/core/CurrentThreadName.h>
|
|
#include <ripple/core/Config.h>
|
|
#include <ripple/core/ConfigSections.h>
|
|
#include <ripple/core/TimeKeeper.h>
|
|
#include <ripple/json/to_string.h>
|
|
#include <ripple/net/RPCCall.h>
|
|
#include <ripple/protocol/BuildInfo.h>
|
|
#include <ripple/resource/Fees.h>
|
|
#include <ripple/rpc/RPCHandler.h>
|
|
|
|
#ifdef ENABLE_TESTS
|
|
#include <ripple/beast/unit_test/match.hpp>
|
|
#include <test/unit_test/multi_runner.h>
|
|
#endif // ENABLE_TESTS
|
|
|
|
#include <google/protobuf/stubs/common.h>
|
|
|
|
#include <boost/filesystem.hpp>
|
|
#include <boost/predef.h>
|
|
#include <boost/process.hpp>
|
|
#include <boost/program_options.hpp>
|
|
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <utility>
|
|
|
|
#if BOOST_OS_WINDOWS
|
|
#include <sys/timeb.h>
|
|
#include <sys/types.h>
|
|
#endif
|
|
|
|
// Do we know the plaform we're compiling on? If you're adding new platforms
|
|
// modify this check accordingly.
|
|
#if !BOOST_OS_LINUX && !BOOST_OS_WINDOWS && !BOOST_OS_MACOS
|
|
#error Supported platforms are: Linux, Windows and MacOS
|
|
#endif
|
|
|
|
// Ensure that precisely one platform is detected.
|
|
#if (BOOST_OS_LINUX && (BOOST_OS_WINDOWS || BOOST_OS_MACOS)) || \
|
|
(BOOST_OS_MACOS && (BOOST_OS_WINDOWS || BOOST_OS_LINUX)) || \
|
|
(BOOST_OS_WINDOWS && (BOOST_OS_LINUX || BOOST_OS_MACOS))
|
|
#error Multiple supported platforms appear active at once
|
|
#endif
|
|
|
|
namespace po = boost::program_options;
|
|
|
|
namespace ripple {
|
|
|
|
bool
|
|
adjustDescriptorLimit(int needed, beast::Journal j)
|
|
{
|
|
#ifdef RLIMIT_NOFILE
|
|
// Get the current limit, then adjust it to what we need.
|
|
struct rlimit rl;
|
|
|
|
int available = 0;
|
|
|
|
if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
|
|
{
|
|
// If the limit is infinite, then we are good.
|
|
if (rl.rlim_cur == RLIM_INFINITY)
|
|
available = needed;
|
|
else
|
|
available = rl.rlim_cur;
|
|
|
|
if (available < needed)
|
|
{
|
|
// Ignore the rlim_max, as the process may
|
|
// be configured to override it anyways. We
|
|
// ask for the number descriptors we need.
|
|
rl.rlim_cur = needed;
|
|
|
|
if (setrlimit(RLIMIT_NOFILE, &rl) == 0)
|
|
available = rl.rlim_cur;
|
|
}
|
|
}
|
|
|
|
if (needed > available)
|
|
{
|
|
j.fatal() << "Insufficient number of file descriptors: " << needed
|
|
<< " are needed, but only " << available << " are available.";
|
|
|
|
std::cerr << "Insufficient number of file descriptors: " << needed
|
|
<< " are needed, but only " << available
|
|
<< " are available.\n";
|
|
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
return true;
|
|
}
|
|
|
|
void
|
|
printHelp(const po::options_description& desc)
|
|
{
|
|
std::cerr
|
|
<< systemName() << "d [options] <command> <params>\n"
|
|
<< desc << std::endl
|
|
<< "Commands: \n"
|
|
" account_currencies <account> [<ledger>]\n"
|
|
" account_info <account>|<key> [<ledger>]\n"
|
|
" account_lines <account> <account>|\"\" [<ledger>]\n"
|
|
" account_channels <account> <account>|\"\" [<ledger>]\n"
|
|
" account_objects <account> [<ledger>]\n"
|
|
" account_offers <account>|<account_public_key> [<ledger>]\n"
|
|
" account_tx accountID [ledger_index_min [ledger_index_max "
|
|
"[limit "
|
|
"]]] [binary]\n"
|
|
" book_changes [<ledger hash|id>]\n"
|
|
" book_offers <taker_pays> <taker_gets> [<taker [<ledger> "
|
|
"[<limit> [<proof> [<marker>]]]]]\n"
|
|
" can_delete [<ledgerid>|<ledgerhash>|now|always|never]\n"
|
|
" channel_authorize <private_key> <channel_id> <drops>\n"
|
|
" channel_verify <public_key> <channel_id> <drops> <signature>\n"
|
|
" connect <ip> [<port>]\n"
|
|
" consensus_info\n"
|
|
" deposit_authorized <source_account> <destination_account> "
|
|
"[<ledger>]\n"
|
|
" download_shard [[<index> <url>]]\n"
|
|
" feature [<feature> [accept|reject]]\n"
|
|
" fetch_info [clear]\n"
|
|
" gateway_balances [<ledger>] <issuer_account> [ <hotwallet> [ "
|
|
"<hotwallet> ]]\n"
|
|
" get_counts\n"
|
|
" json <method> <json>\n"
|
|
" ledger [<id>|current|closed|validated] [full]\n"
|
|
" ledger_accept\n"
|
|
" ledger_cleaner\n"
|
|
" ledger_closed\n"
|
|
" ledger_current\n"
|
|
" ledger_request <ledger>\n"
|
|
" log_level [[<partition>] <severity>]\n"
|
|
" logrotate\n"
|
|
" manifest <public_key>\n"
|
|
" node_to_shard [status|start|stop]\n"
|
|
" peers\n"
|
|
" ping\n"
|
|
" random\n"
|
|
" peer_reservations_add <public_key> [<description>]\n"
|
|
" peer_reservations_del <public_key>\n"
|
|
" peer_reservations_list\n"
|
|
" ripple ...\n"
|
|
" ripple_path_find <json> [<ledger>]\n"
|
|
" server_info [counters]\n"
|
|
" server_state [counters]\n"
|
|
" sign <private_key> <tx_json> [offline]\n"
|
|
" sign_for <signer_address> <signer_private_key> <tx_json> "
|
|
"[offline]\n"
|
|
" stop\n"
|
|
" submit <tx_blob>|[<private_key> <tx_json>]\n"
|
|
" submit_multisigned <tx_json>\n"
|
|
" tx <id>\n"
|
|
" validation_create [<seed>|<pass_phrase>|<key>]\n"
|
|
" validator_info\n"
|
|
" validators\n"
|
|
" validator_list_sites\n"
|
|
" version\n"
|
|
" wallet_propose [<passphrase>]\n";
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
#ifdef ENABLE_TESTS
|
|
/* simple unit test selector that allows a comma separated list
|
|
* of selectors
|
|
*/
|
|
class multi_selector
|
|
{
|
|
private:
|
|
std::vector<beast::unit_test::selector> selectors_;
|
|
|
|
public:
|
|
explicit multi_selector(std::string const& patterns = "")
|
|
{
|
|
std::vector<std::string> v;
|
|
boost::split(v, patterns, boost::algorithm::is_any_of(","));
|
|
selectors_.reserve(v.size());
|
|
std::for_each(v.begin(), v.end(), [this](std::string s) {
|
|
boost::trim(s);
|
|
if (selectors_.empty() || !s.empty())
|
|
selectors_.emplace_back(
|
|
beast::unit_test::selector::automatch, s);
|
|
});
|
|
}
|
|
|
|
bool
|
|
operator()(beast::unit_test::suite_info const& s)
|
|
{
|
|
for (auto& sel : selectors_)
|
|
if (sel(s))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
std::size_t
|
|
size() const
|
|
{
|
|
return selectors_.size();
|
|
}
|
|
};
|
|
|
|
namespace test {
|
|
extern std::atomic<bool> envUseIPv4;
|
|
}
|
|
|
|
template <class Runner>
|
|
static bool
|
|
anyMissing(Runner& runner, multi_selector const& pred)
|
|
{
|
|
if (runner.tests() == 0)
|
|
{
|
|
runner.add_failures(1);
|
|
std::cout << "Failed: No tests run" << std::endl;
|
|
return true;
|
|
}
|
|
if (runner.suites() < pred.size())
|
|
{
|
|
auto const missing = pred.size() - runner.suites();
|
|
runner.add_failures(missing);
|
|
std::cout << "Failed: " << missing
|
|
<< " filters did not match any existing test suites"
|
|
<< std::endl;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static int
|
|
runUnitTests(
|
|
std::string const& pattern,
|
|
std::string const& argument,
|
|
bool quiet,
|
|
bool log,
|
|
bool child,
|
|
bool ipv6,
|
|
std::size_t num_jobs,
|
|
int argc,
|
|
char** argv)
|
|
{
|
|
using namespace beast::unit_test;
|
|
using namespace ripple::test;
|
|
|
|
ripple::test::envUseIPv4 = (!ipv6);
|
|
|
|
if (!child && num_jobs == 1)
|
|
{
|
|
multi_runner_parent parent_runner;
|
|
|
|
multi_runner_child child_runner{num_jobs, quiet, log};
|
|
child_runner.arg(argument);
|
|
multi_selector pred(pattern);
|
|
auto const any_failed =
|
|
child_runner.run_multi(pred) || anyMissing(child_runner, pred);
|
|
|
|
if (any_failed)
|
|
return EXIT_FAILURE;
|
|
return EXIT_SUCCESS;
|
|
}
|
|
if (!child)
|
|
{
|
|
multi_runner_parent parent_runner;
|
|
std::vector<boost::process::child> children;
|
|
|
|
std::string const exe_name = argv[0];
|
|
std::vector<std::string> args;
|
|
{
|
|
args.reserve(argc);
|
|
for (int i = 1; i < argc; ++i)
|
|
args.emplace_back(argv[i]);
|
|
args.emplace_back("--unittest-child");
|
|
}
|
|
|
|
for (std::size_t i = 0; i < num_jobs; ++i)
|
|
children.emplace_back(
|
|
boost::process::exe = exe_name, boost::process::args = args);
|
|
|
|
int bad_child_exits = 0;
|
|
int terminated_child_exits = 0;
|
|
for (auto& c : children)
|
|
{
|
|
try
|
|
{
|
|
c.wait();
|
|
if (c.exit_code())
|
|
++bad_child_exits;
|
|
}
|
|
catch (...)
|
|
{
|
|
// wait throws if process was terminated with a signal
|
|
++bad_child_exits;
|
|
++terminated_child_exits;
|
|
}
|
|
}
|
|
|
|
parent_runner.add_failures(terminated_child_exits);
|
|
anyMissing(parent_runner, multi_selector(pattern));
|
|
|
|
if (parent_runner.any_failed() || bad_child_exits)
|
|
return EXIT_FAILURE;
|
|
return EXIT_SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
// child
|
|
multi_runner_child runner{num_jobs, quiet, log};
|
|
runner.arg(argument);
|
|
auto const anyFailed = runner.run_multi(multi_selector(pattern));
|
|
|
|
if (anyFailed)
|
|
return EXIT_FAILURE;
|
|
return EXIT_SUCCESS;
|
|
}
|
|
}
|
|
|
|
#endif // ENABLE_TESTS
|
|
//------------------------------------------------------------------------------
|
|
|
|
int
|
|
run(int argc, char** argv)
|
|
{
|
|
using namespace std;
|
|
|
|
beast::setCurrentThreadName(
|
|
"xahaud: main " + BuildInfo::getVersionString());
|
|
|
|
po::variables_map vm;
|
|
|
|
std::string importText;
|
|
{
|
|
importText += "Import an existing node database (specified in the [";
|
|
importText += ConfigSection::importNodeDatabase();
|
|
importText += "] configuration file section) into the current ";
|
|
importText += "node database (specified in the [";
|
|
importText += ConfigSection::nodeDatabase();
|
|
importText += "] configuration file section).";
|
|
}
|
|
|
|
// Set up option parsing.
|
|
//
|
|
po::options_description gen("General Options");
|
|
gen.add_options()(
|
|
"conf", po::value<std::string>(), "Specify the configuration file.")(
|
|
"debug", "Enable normally suppressed debug logging")(
|
|
"help,h", "Display this message.")(
|
|
"newnodeid", "Generate a new node identity for this server.")(
|
|
"nodeid",
|
|
po::value<std::string>(),
|
|
"Specify the node identity for this server.")(
|
|
"quorum",
|
|
po::value<std::size_t>(),
|
|
"Override the minimum validation quorum.")(
|
|
"reportingReadOnly", "Run in read-only reporting mode")(
|
|
"silent", "No output to the console after startup.")(
|
|
"standalone,a", "Run with no peers.")("verbose,v", "Verbose logging.")(
|
|
"version", "Display the build version.");
|
|
|
|
po::options_description data("Ledger/Data Options");
|
|
data.add_options()("import", importText.c_str())(
|
|
"ledger",
|
|
po::value<std::string>(),
|
|
"Load the specified ledger and start from the value given.")(
|
|
"ledgerfile",
|
|
po::value<std::string>(),
|
|
"Load the specified ledger file.")(
|
|
"load", "Load the current ledger from the local DB.")(
|
|
"net", "Get the initial ledger from the network.")(
|
|
"nodetoshard", "Import node store into shards")(
|
|
"replay", "Replay a ledger close.")(
|
|
"start", "Start from a fresh Ledger.")(
|
|
"startReporting",
|
|
po::value<std::string>(),
|
|
"Start reporting from a fresh Ledger.")(
|
|
"vacuum", "VACUUM the transaction db.")(
|
|
"valid", "Consider the initial ledger a valid network ledger.");
|
|
|
|
po::options_description rpc("RPC Client Options");
|
|
rpc.add_options()(
|
|
"rpc",
|
|
"Perform rpc command - see below for available commands. "
|
|
"This is assumed if any positional parameters are provided.")(
|
|
"rpc_ip",
|
|
po::value<std::string>(),
|
|
"Specify the IP address for RPC command. "
|
|
"Format: <ip-address>[':'<port-number>]")(
|
|
"rpc_port",
|
|
po::value<std::uint16_t>(),
|
|
"DEPRECATED: include with rpc_ip instead. "
|
|
"Specify the port number for RPC command.");
|
|
|
|
#ifdef ENABLE_TESTS
|
|
po::options_description test("Unit Test Options");
|
|
test.add_options()(
|
|
"quiet,q",
|
|
"Suppress test suite messages, "
|
|
"including suite/case name (at start) and test log messages.")(
|
|
"unittest,u",
|
|
po::value<std::string>()->implicit_value(""),
|
|
"Perform unit tests. The optional argument specifies one or "
|
|
"more comma-separated selectors. Each selector specifies a suite name, "
|
|
"full-name (lib.module.suite), module, or library "
|
|
"(checked in that "
|
|
"order).")(
|
|
"unittest-arg",
|
|
po::value<std::string>()->implicit_value(""),
|
|
"Supplies an argument string to unit tests. If provided, this argument "
|
|
"is made available to each suite that runs. Interpretation of the "
|
|
"argument is handled individually by any suite that accesses it -- "
|
|
"as such, it typically only make sense to provide this when running "
|
|
"a single suite.")(
|
|
"unittest-ipv6",
|
|
"Use IPv6 localhost when running unittests (default is IPv4).")(
|
|
"unittest-log",
|
|
"Force unit test log message output. Only useful in combination with "
|
|
"--quiet, in which case log messages will print but suite/case names "
|
|
"will not.")(
|
|
"unittest-jobs",
|
|
po::value<std::size_t>(),
|
|
"Number of unittest jobs to run in parallel (child processes).");
|
|
#endif // ENABLE_TESTS
|
|
|
|
// These are hidden options, not intended to be shown in the usage/help
|
|
// message
|
|
po::options_description hidden("Hidden Options");
|
|
hidden.add_options()(
|
|
"parameters",
|
|
po::value<vector<string>>(),
|
|
"Specify rpc command and parameters. This option must be repeated "
|
|
"for each command/param. Positional parameters also serve this "
|
|
"purpose, "
|
|
"so this option is not needed for users")
|
|
#ifdef ENABLE_TESTS
|
|
("unittest-child",
|
|
"For internal use only when spawning child unit test processes.")
|
|
#else
|
|
("unittest", "Disabled in this build.")(
|
|
"unittest-child", "Disabled in this build.")
|
|
#endif // ENABLE_TESTS
|
|
("fg", "Deprecated: server always in foreground mode.");
|
|
|
|
// Interpret positional arguments as --parameters.
|
|
po::positional_options_description p;
|
|
p.add("parameters", -1);
|
|
|
|
po::options_description all;
|
|
all.add(gen)
|
|
.add(rpc)
|
|
.add(data)
|
|
#ifdef ENABLE_TESTS
|
|
.add(test)
|
|
#endif // ENABLE_TESTS
|
|
.add(hidden);
|
|
|
|
po::options_description desc;
|
|
desc.add(gen)
|
|
.add(rpc)
|
|
.add(data)
|
|
#ifdef ENABLE_TESTS
|
|
.add(test)
|
|
#endif // ENABLE_TESTS
|
|
;
|
|
|
|
// Parse options, if no error.
|
|
try
|
|
{
|
|
po::store(
|
|
po::command_line_parser(argc, argv)
|
|
.options(all) // Parse options.
|
|
.positional(p) // Remainder as --parameters.
|
|
.run(),
|
|
vm);
|
|
po::notify(vm); // Invoke option notify functions.
|
|
}
|
|
catch (std::exception const& ex)
|
|
{
|
|
std::cerr << "xahaud: " << ex.what() << std::endl;
|
|
std::cerr << "Try 'rippled --help' for a list of options." << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
if (vm.count("help"))
|
|
{
|
|
printHelp(desc);
|
|
return 0;
|
|
}
|
|
|
|
if (vm.count("version"))
|
|
{
|
|
std::cout << "xahaud version " << BuildInfo::getVersionString()
|
|
<< std::endl;
|
|
return 0;
|
|
}
|
|
|
|
#ifndef ENABLE_TESTS
|
|
if (vm.count("unittest") || vm.count("unittest-child"))
|
|
{
|
|
std::cerr << "xahaud: Tests disabled in this build." << std::endl;
|
|
std::cerr << "Try 'rippled --help' for a list of options." << std::endl;
|
|
return 1;
|
|
}
|
|
#else
|
|
// Run the unit tests if requested.
|
|
// The unit tests will exit the application with an appropriate return code.
|
|
//
|
|
if (vm.count("unittest"))
|
|
{
|
|
std::string argument;
|
|
|
|
if (vm.count("unittest-arg"))
|
|
argument = vm["unittest-arg"].as<std::string>();
|
|
|
|
std::size_t numJobs = 1;
|
|
bool unittestChild = false;
|
|
if (vm.count("unittest-jobs"))
|
|
numJobs = std::max(numJobs, vm["unittest-jobs"].as<std::size_t>());
|
|
unittestChild = bool(vm.count("unittest-child"));
|
|
|
|
return runUnitTests(
|
|
vm["unittest"].as<std::string>(),
|
|
argument,
|
|
bool(vm.count("quiet")),
|
|
bool(vm.count("unittest-log")),
|
|
unittestChild,
|
|
bool(vm.count("unittest-ipv6")),
|
|
numJobs,
|
|
argc,
|
|
argv);
|
|
}
|
|
else
|
|
{
|
|
if (vm.count("unittest-jobs"))
|
|
{
|
|
// unittest jobs only makes sense with `unittest`
|
|
std::cerr << "xahaud: '--unittest-jobs' specified without "
|
|
"'--unittest'.\n";
|
|
std::cerr << "To run the unit tests the '--unittest' option must "
|
|
"be present.\n";
|
|
return 1;
|
|
}
|
|
}
|
|
#endif // ENABLE_TESTS
|
|
|
|
auto config = std::make_unique<Config>();
|
|
|
|
auto configFile =
|
|
vm.count("conf") ? vm["conf"].as<std::string>() : std::string();
|
|
|
|
// config file, quiet flag.
|
|
config->setup(
|
|
configFile,
|
|
bool(vm.count("quiet")),
|
|
bool(vm.count("silent")),
|
|
bool(vm.count("standalone")));
|
|
|
|
if (vm.count("vacuum"))
|
|
{
|
|
if (config->standalone())
|
|
{
|
|
std::cerr << "vacuum not applicable in standalone mode.\n";
|
|
return -1;
|
|
}
|
|
|
|
try
|
|
{
|
|
auto setup = setup_DatabaseCon(*config);
|
|
if (!doVacuumDB(setup))
|
|
return -1;
|
|
}
|
|
catch (std::exception const& e)
|
|
{
|
|
std::cerr << "exception " << e.what() << " in function " << __func__
|
|
<< std::endl;
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
if (vm.count("start"))
|
|
{
|
|
config->START_UP = Config::FRESH;
|
|
}
|
|
|
|
if (vm.count("startReporting"))
|
|
{
|
|
config->START_UP = Config::FRESH;
|
|
config->START_LEDGER = vm["startReporting"].as<std::string>();
|
|
}
|
|
|
|
if (vm.count("reportingReadOnly"))
|
|
{
|
|
config->setReportingReadOnly(true);
|
|
}
|
|
|
|
if (vm.count("import"))
|
|
config->doImport = true;
|
|
|
|
if (vm.count("nodetoshard"))
|
|
config->nodeToShard = true;
|
|
|
|
if (vm.count("ledger"))
|
|
{
|
|
config->START_LEDGER = vm["ledger"].as<std::string>();
|
|
if (vm.count("replay"))
|
|
config->START_UP = Config::REPLAY;
|
|
else
|
|
config->START_UP = Config::LOAD;
|
|
}
|
|
else if (vm.count("ledgerfile"))
|
|
{
|
|
config->START_LEDGER = vm["ledgerfile"].as<std::string>();
|
|
config->START_UP = Config::LOAD_FILE;
|
|
}
|
|
else if (vm.count("load") || config->FAST_LOAD)
|
|
{
|
|
config->START_UP = Config::LOAD;
|
|
}
|
|
|
|
if (vm.count("net") && !config->FAST_LOAD)
|
|
{
|
|
if ((config->START_UP == Config::LOAD) ||
|
|
(config->START_UP == Config::REPLAY))
|
|
{
|
|
std::cerr << "Net and load/replay options are incompatible"
|
|
<< std::endl;
|
|
return -1;
|
|
}
|
|
|
|
config->START_UP = Config::NETWORK;
|
|
}
|
|
|
|
if (vm.count("valid"))
|
|
{
|
|
config->START_VALID = true;
|
|
}
|
|
|
|
// Override the RPC destination IP address. This must
|
|
// happen after the config file is loaded.
|
|
if (vm.count("rpc_ip"))
|
|
{
|
|
auto endpoint = beast::IP::Endpoint::from_string_checked(
|
|
vm["rpc_ip"].as<std::string>());
|
|
if (!endpoint)
|
|
{
|
|
std::cerr << "Invalid rpc_ip = " << vm["rpc_ip"].as<std::string>()
|
|
<< "\n";
|
|
return -1;
|
|
}
|
|
|
|
if (endpoint->port() == 0)
|
|
{
|
|
std::cerr << "No port specified in rpc_ip.\n";
|
|
if (vm.count("rpc_port"))
|
|
{
|
|
std::cerr << "WARNING: using deprecated rpc_port param.\n";
|
|
try
|
|
{
|
|
endpoint =
|
|
endpoint->at_port(vm["rpc_port"].as<std::uint16_t>());
|
|
if (endpoint->port() == 0)
|
|
throw std::domain_error("0");
|
|
}
|
|
catch (std::exception const& e)
|
|
{
|
|
std::cerr << "Invalid rpc_port = " << e.what() << "\n";
|
|
return -1;
|
|
}
|
|
}
|
|
else
|
|
return -1;
|
|
}
|
|
|
|
config->rpc_ip = std::move(*endpoint);
|
|
}
|
|
|
|
if (vm.count("quorum"))
|
|
{
|
|
try
|
|
{
|
|
config->VALIDATION_QUORUM = vm["quorum"].as<std::size_t>();
|
|
if (config->VALIDATION_QUORUM == std::size_t{})
|
|
{
|
|
throw std::domain_error("0");
|
|
}
|
|
}
|
|
catch (std::exception const& e)
|
|
{
|
|
std::cerr << "Invalid value specified for --quorum (" << e.what()
|
|
<< ")\n";
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
// Construct the logs object at the configured severity
|
|
using namespace beast::severities;
|
|
Severity thresh = kInfo;
|
|
|
|
if (vm.count("quiet"))
|
|
thresh = kFatal;
|
|
else if (vm.count("verbose"))
|
|
thresh = kTrace;
|
|
|
|
auto logs = std::make_unique<Logs>(thresh);
|
|
|
|
// No arguments. Run server.
|
|
if (!vm.count("parameters"))
|
|
{
|
|
// TODO: this comment can be removed in a future release -
|
|
// say 1.7 or higher
|
|
if (config->had_trailing_comments())
|
|
{
|
|
JLOG(logs->journal("Application").warn())
|
|
<< "Trailing comments were seen in your config file. "
|
|
<< "The treatment of inline/trailing comments has changed "
|
|
"recently. "
|
|
<< "Any `#` characters NOT intended to delimit comments should "
|
|
"be "
|
|
<< "preceded by a \\";
|
|
}
|
|
|
|
// We want at least 1024 file descriptors. We'll
|
|
// tweak this further.
|
|
if (!adjustDescriptorLimit(1024, logs->journal("Application")))
|
|
return -1;
|
|
|
|
if (vm.count("debug"))
|
|
setDebugLogSink(logs->makeSink("Debug", beast::severities::kTrace));
|
|
|
|
auto timeKeeper = make_TimeKeeper(logs->journal("TimeKeeper"));
|
|
|
|
auto app = make_Application(
|
|
std::move(config), std::move(logs), std::move(timeKeeper));
|
|
|
|
if (!app->setup(vm))
|
|
return -1;
|
|
|
|
// With our configuration parsed, ensure we have
|
|
// enough file descriptors available:
|
|
if (!adjustDescriptorLimit(
|
|
app->fdRequired(), app->logs().journal("Application")))
|
|
return -1;
|
|
|
|
// Start the server
|
|
app->start(true /*start timers*/);
|
|
|
|
// Block until we get a stop RPC.
|
|
app->run();
|
|
|
|
return 0;
|
|
}
|
|
|
|
// We have an RPC command to process:
|
|
beast::setCurrentThreadName("xahaud: rpc");
|
|
return RPCCall::fromCommandLine(
|
|
*config, vm["parameters"].as<std::vector<std::string>>(), *logs);
|
|
}
|
|
|
|
} // namespace ripple
|
|
|
|
int
|
|
main(int argc, char** argv)
|
|
{
|
|
#if BOOST_OS_WINDOWS
|
|
{
|
|
// Work around for https://svn.boost.org/trac/boost/ticket/10657
|
|
// Reported against boost version 1.56.0. If an application's
|
|
// first call to GetTimeZoneInformation is from a coroutine, an
|
|
// unhandled exception is generated. A workaround is to call
|
|
// GetTimeZoneInformation at least once before launching any
|
|
// coroutines. At the time of this writing the _ftime call is
|
|
// used to initialize the timezone information.
|
|
struct _timeb t;
|
|
#ifdef _INC_TIME_INL
|
|
_ftime_s(&t);
|
|
#else
|
|
_ftime(&t);
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
atexit(&google::protobuf::ShutdownProtobufLibrary);
|
|
|
|
return ripple::run(argc, argv);
|
|
}
|