Compare commits

..

14 Commits

Author SHA1 Message Date
Denis Angell
1ac1d40d06 fix: satisfy clang-tidy include-cleaner and brace style in paychan 2026-08-03 12:26:20 -04:00
Denis Angell
fb10515cff Merge remote-tracking branch 'origin/develop' into token-paychan
# Conflicts:
#	include/xrpl/protocol/detail/features.macro
2026-08-03 11:38:43 -04:00
Denis Angell
3c85a0180f refactor: address review nits 2026-08-02 16:05:25 -04:00
Denis Angell
096fa967da fix: repair bad develop merge resolutions 2026-08-02 16:05:22 -04:00
dangell8
1ced7dc8f3 Merge branch 'develop' into token-paychan
Includes post-merge compile fixes (build-verified).
2026-07-17 15:02:03 +00:00
Denis Angell
df1458a136 test: expand token paychan transactor phase coverage 2026-07-13 19:25:43 -04:00
Denis Angell
cdd5ebf4c1 fix: validate paychan asset match in preclaim with tecWRONG_ASSET 2026-07-13 16:33:49 -04:00
Denis Angell
1a9a11fc31 style: remove includes flagged by misc-include-cleaner 2026-07-13 15:28:42 -04:00
Denis Angell
a9430d4778 style: conform doxygen comments to check-doxygen-style hook 2026-07-13 15:11:48 -04:00
Denis Angell
fed5093488 fix: adapt token paychan to develop merge helpers and sponsor reserve 2026-07-13 14:59:54 -04:00
Denis Angell
6c74fc1a7d Merge branch 'develop' into token-paychan 2026-07-13 14:05:56 -04:00
dangell8
939f8b1a49 Merge develop into token-paychan 2026-07-11 04:27:08 +00:00
Denis Angell
1f8c462c42 feat: XLS-93d Token-Enabled Payment Channels 2026-07-10 12:14:12 -04:00
Denis Angell
47df026dcc refactor: Move escrow lock/unlock helpers to EscrowHelpers.h 2026-07-10 11:55:13 -04:00
357 changed files with 18009 additions and 13698 deletions

View File

@@ -85,8 +85,6 @@ CheckOptions:
readability-braces-around-statements.ShortStatementLines: 2
readability-identifier-naming.MacroDefinitionCase: UPPER_CASE
readability-identifier-naming.NamespaceCase: lower_case
readability-identifier-naming.InlineNamespaceCase: lower_case
readability-identifier-naming.ClassCase: CamelCase
readability-identifier-naming.StructCase: CamelCase
readability-identifier-naming.UnionCase: CamelCase

2
.envrc
View File

@@ -1,3 +1 @@
watch_file nix/*.nix
use flake

View File

@@ -42,8 +42,6 @@ Our Linux CI tooling is distro-independent and uses a Nix-based environment, so
### macOS
Many `xrpld` engineers use macOS for development.
The minimum supported version is macOS 15 (Sequoia).
CI testing is done in macOS 26 (Tahoe), but the build defaults `CMAKE_OSX_DEPLOYMENT_TARGET` to 15.
### Windows

View File

@@ -13,23 +13,6 @@ if(DEFINED CMAKE_MODULE_PATH)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Must be set before project() because project() consumes it when configuring the compiler and SDK.
# A user-provided -DCMAKE_OSX_DEPLOYMENT_TARGET still takes precedence.
#
# CMAKE_SYSTEM_NAME can't be used before project(), so CMAKE_HOST_SYSTEM_NAME is used instead.
#
# When CMAKE_OSX_DEPLOYMENT_TARGET is bumped to >=26.0, FastFloat dependency won't be needed anymore
if(
CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin"
AND NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET
)
set(CMAKE_OSX_DEPLOYMENT_TARGET
"15.0"
CACHE STRING
"Minimum macOS deployment version"
)
endif()
project(xrpl)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 23)
@@ -104,7 +87,6 @@ include(deps/Boost)
add_subdirectory(external/antithesis-sdk)
find_package(date REQUIRED)
find_package(ed25519 REQUIRED)
find_package(FastFloat REQUIRED)
find_package(gRPC REQUIRED)
find_package(LibArchive REQUIRED)
find_package(lz4 REQUIRED)
@@ -120,7 +102,6 @@ target_link_libraries(
xrpl_libs
INTERFACE
ed25519::ed25519
FastFloat::fast_float
lz4::lz4
mpt-crypto::mpt-crypto
OpenSSL::Crypto

View File

@@ -20,7 +20,6 @@
"jemalloc/5.3.1#1fc58d55316041f10fbc1e8a2eae632a%1776700028.228",
"gtest/1.17.0#5224b3b3ff3b4ce1133cbdd27d53ee7d%1782392402.791979",
"grpc/1.81.1#f729f6d75992d20f9c72828e9142d62f%1783945160.094135",
"fast_float/8.2.10#f6f28d6bb22112078e7dbda611caf681%1782494504.298",
"ed25519/2015.03#ae761bdc52730a843f0809bdf6c1b1f6%1782307148.15562",
"date/3.0.4#862e11e80030356b53c2c38599ceb32b%1782392402.538492",
"c-ares/1.34.6#545240bb1c40e2cacd4362d6b8967650%1782392402.681654",
@@ -35,7 +34,7 @@
"protobuf/6.33.5#ff253ead763bd8d9904a52979cd21e81%1782392410.233933",
"nasm/2.16.01#31e26f2ee3c4346ecd347911bd126904%1782395690.33162",
"msys2/cci.latest#d22fe7b2808f5fd34d0a7923ace9c54f%1770657326.649",
"m4/1.4.19#1727f439cf74e83826ec96d0b4904eee%1784541921.659",
"m4/1.4.19#34c4bbc3eeebe98ca6edf2f52d602e7d%1777282960.259",
"cmake/4.3.3#840cf00ea09777e05c2050a50a82c722%1782392418.696091",
"b2/5.4.2#ffd6084a119587e70f11cd45d1a386e2%1782392402.624226",
"automake/1.16.5#b91b7c384c3deaa9d535be02da14d04f%1755524470.56",

View File

@@ -5,13 +5,6 @@
{% if os == "Linux" %}
{% set compiler_version = detect_api.default_compiler_version(compiler, version) %}
{% endif %}
{% if os == "Macos" %}
{# Minimum macOS the dependencies target. #}
{# Without this, Conan builds each dependency against the (possibly newer) host SDK, so the #}
{# dependency objects target a newer macOS than the binary and the linker warns. #}
{# Keep at or below CMAKE_OSX_DEPLOYMENT_TARGET in CMakeLists.txt. #}
{% set min_macos_version = "15.0" %}
{% endif %}
[settings]
os={{ os }}
@@ -25,9 +18,6 @@ compiler.runtime=static
{% else %}
compiler.libcxx={{ detect_api.detect_libcxx(compiler, version, compiler_exe) }}
{% endif %}
{% if os == "Macos" %}
os.version={{ min_macos_version }}
{% endif %}
[conf]
{# The Boost recipe builds with b2, which doesn't use Conan's toolchain files. #}
@@ -51,13 +41,3 @@ tools.build:compiler_executables={'c':'{{ cc_exe }}','cpp':'{{ cxx_exe }}'}
{# More info: https://docs.conan.io/2/reference/extensions/binary_compatibility.html #}
user.package:cppstd_version=23
tools.info.package_id:confs+=["user.package:cppstd_version"]
{% if os == "Macos" %}
[buildenv]
{# os.version adds -mmacosx-version-min to compiler command lines, #}
{# but Boost.Context's b2 assembly (.S) rule ignores it, #}
{# so those objects keep the host SDK version and still warn at link time. #}
{# clang's assembler honors this env var regardless, pinning them. #}
{# Scoped to boost/* since it is the only gap. #}
boost/*:MACOSX_DEPLOYMENT_TARGET={{ min_macos_version }}
{% endif %}

View File

@@ -29,7 +29,6 @@ class Xrpl(ConanFile):
requires = [
"ed25519/2015.03",
"fast_float/8.2.10",
"grpc/1.81.1",
"libarchive/3.8.7",
"nudb/2.0.9",
@@ -212,7 +211,6 @@ class Xrpl(ConanFile):
"boost::thread",
"date::date",
"ed25519::ed25519",
"fast_float::fast_float",
"grpc::grpc++",
"libarchive::libarchive",
"lz4::lz4",

View File

@@ -3,78 +3,6 @@
Common issues encountered when using the [Nix development shell](./nix.md), and
how to resolve them.
## `command not found: nix` after a macOS update
If a shell suddenly can't find `nix` at all:
```
$ nix develop
zsh: command not found: nix
```
then Nix is almost certainly still installed — only the shell hook that puts it
on your `PATH` is gone. Confirm that first:
```bash
ls -l /nix/var/nix/profiles/default/bin/nix
```
If that exists, the installation is fine and this is purely a `PATH` problem.
### Why it happens
The installer does not touch your dotfiles. Instead it sources a setup script
from the Nix store by editing **system-wide** rc files:
| Shell | File the installer edits |
| ----- | ------------------------------------- |
| bash | `/etc/bashrc`, `/etc/bash.bashrc` |
| zsh | `/etc/zshrc` |
| fish | `$__fish_sysconf_dir/conf.d/nix.fish` |
macOS manages `/etc/zshrc`, so an OS update can replace it with the vendor copy
and silently drop the Nix block. `/etc/bashrc` and the fish file usually survive,
which is why the breakage often shows up in zsh only. You can verify this by
diffing against the backup the installer left behind:
```bash
diff /etc/zshrc /etc/zshrc.backup-before-nix
```
If they are identical, the Nix snippet was wiped. This is upstream issue
[NixOS/nix#3616](https://github.com/NixOS/nix/issues/3616).
### Fix
To unblock the current shell:
```bash
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
```
For a permanent fix, add the snippet to your **user** rc file rather than
restoring `/etc/zshrc` — user dotfiles are not clobbered by OS updates:
```bash
cat >>~/.zshrc <<'EOF'
# Nix
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
# End Nix
EOF
```
The scripts guard against double-sourcing via `__ETC_PROFILE_NIX_SOURCED`, so
this is safe even if a system-wide hook is later restored.
> [!NOTE]
> `/etc/zshrc` and `~/.zshrc` are only read by **interactive** zsh. If the
> snippet is present but `zsh -c '…'`, a script, or an IDE terminal still can't
> find `nix`, that shell is non-interactive — put the snippet in `~/.zshenv`
> instead.
## Git worktrees
If `nix develop` fails with an error like:

View File

@@ -1,118 +0,0 @@
#pragma once
#include <functional>
#include <mutex>
#include <set>
/**
* RAII class to check if an Item is already being processed on another thread,
* as indicated by it's presence in a Collection.
*
* If the Item is not in the Collection, it will be added under lock in the
* ctor, and removed under lock in the dtor. The object will be considered
* "usable" and evaluate to `true`.
*
* If the Item is in the Collection, no changes will be made to the collection,
* and the CanProcess object will be considered "unusable".
*
* It's up to the caller to decide what "usable" and "unusable" mean. (e.g.
* Process or skip a block of code, or set a flag.)
*
* The current use is to avoid lock contention that would be involved in
* processing something associated with the Item.
*
* Examples:
*
* void IncomingLedgers::acquireAsync(LedgerHash const& hash, ...)
* {
* if (CanProcess check{acquiresMutex_, pendingAcquires_, hash})
* {
* acquire(hash, ...);
* }
* }
*
* bool
* NetworkOPsImp::recvValidation(
* std::shared_ptr<STValidation> const& val,
* std::string const& source)
* {
* CanProcess check(
* validationsMutex_, pendingValidations_, val->getLedgerHash());
* BypassAccept bypassAccept =
* check ? BypassAccept::no : BypassAccept::yes;
* handleNewValidation(app_, val, source, bypassAccept, m_journal);
* }
*
*/
class CanProcess
{
public:
template <class Mutex, class Collection, class Item>
CanProcess(Mutex& mtx, Collection& collection, Item const& item)
: cleanup_(insert(mtx, collection, item))
{
}
~CanProcess()
{
if (cleanup_)
cleanup_();
}
CanProcess(CanProcess const&) = delete;
CanProcess&
operator=(CanProcess const&) = delete;
explicit
operator bool() const
{
return static_cast<bool>(cleanup_);
}
private:
template <bool useIterator, class Mutex, class Collection, class Item>
std::function<void()>
doInsert(Mutex& mtx, Collection& collection, Item const& item)
{
std::unique_lock<Mutex> lock(mtx);
// TODO: Use structured binding once LLVM 16 is the minimum supported
// version. See also: https://github.com/llvm/llvm-project/issues/48582
// https://github.com/llvm/llvm-project/commit/127bf44385424891eb04cff8e52d3f157fc2cb7c
auto const insertResult = collection.insert(item);
auto const it = insertResult.first;
if (!insertResult.second)
return {};
if constexpr (useIterator)
return [&, it]() {
std::unique_lock<Mutex> lock(mtx);
collection.erase(it);
};
else
return [&]() {
std::unique_lock<Mutex> lock(mtx);
collection.erase(item);
};
}
// Generic insert() function doesn't use iterators because they may get
// invalidated
template <class Mutex, class Collection, class Item>
std::function<void()>
insert(Mutex& mtx, Collection& collection, Item const& item)
{
return doInsert<false>(mtx, collection, item);
}
// Specialize insert() for std::set, which does not invalidate iterators for
// insert and erase
template <class Mutex, class Item>
std::function<void()>
insert(Mutex& mtx, std::set<Item>& collection, Item const& item)
{
return doInsert<true>(mtx, collection, item);
}
// If set, then the item is "usable"
std::function<void()> cleanup_;
};

View File

@@ -11,7 +11,7 @@ namespace xrpl {
class Resolver
{
public:
using HandlerType = std::function<void(std::string, std::vector<beast::ip::Endpoint>)>;
using HandlerType = std::function<void(std::string, std::vector<beast::IP::Endpoint>)>;
virtual ~Resolver() = 0;

View File

@@ -26,7 +26,7 @@ public:
* @param journal Destination for logging output.
*/
static std::shared_ptr<StatsDCollector>
make(ip::Endpoint const& address, std::string const& prefix, Journal journal);
make(IP::Endpoint const& address, std::string const& prefix, Journal journal);
};
} // namespace beast::insight

View File

@@ -15,7 +15,7 @@
//------------------------------------------------------------------------------
namespace beast {
namespace ip {
namespace IP {
using Address = boost::asio::ip::address;
@@ -73,13 +73,13 @@ isPublic(Address const& addr)
return (addr.is_v4()) ? isPublic(addr.to_v4()) : isPublic(addr.to_v6());
}
} // namespace ip
} // namespace IP
//------------------------------------------------------------------------------
template <class Hasher>
void
hash_append(Hasher& h, beast::ip::Address const& addr) noexcept
hash_append(Hasher& h, beast::IP::Address const& addr) noexcept
{
using beast::hash_append;
if (addr.is_v4())
@@ -101,12 +101,12 @@ hash_append(Hasher& h, beast::ip::Address const& addr) noexcept
namespace boost {
template <>
struct hash<::beast::ip::Address>
struct hash<::beast::IP::Address>
{
explicit hash() = default;
std::size_t
operator()(::beast::ip::Address const& addr) const
operator()(::beast::IP::Address const& addr) const
{
return ::beast::Uhash<>{}(addr);
}

View File

@@ -4,7 +4,7 @@
#include <boost/asio.hpp>
namespace beast::ip {
namespace beast::IP {
/**
* Convert to Endpoint.
@@ -32,7 +32,7 @@ toAsioAddress(Endpoint const& endpoint);
boost::asio::ip::tcp::endpoint
toAsioEndpoint(Endpoint const& endpoint);
} // namespace beast::ip
} // namespace beast::IP
namespace beast {
@@ -41,25 +41,25 @@ struct IPAddressConversion
{
explicit IPAddressConversion() = default;
static ip::Endpoint
static IP::Endpoint
fromAsio(boost::asio::ip::address const& address)
{
return ip::fromAsio(address);
return IP::fromAsio(address);
}
static ip::Endpoint
static IP::Endpoint
fromAsio(boost::asio::ip::tcp::endpoint const& endpoint)
{
return ip::fromAsio(endpoint);
return IP::fromAsio(endpoint);
}
static boost::asio::ip::address
toAsioAddress(ip::Endpoint const& address)
toAsioAddress(IP::Endpoint const& address)
{
return ip::toAsioAddress(address);
return IP::toAsioAddress(address);
}
static boost::asio::ip::tcp::endpoint
toAsioEndpoint(ip::Endpoint const& address)
toAsioEndpoint(IP::Endpoint const& address)
{
return ip::toAsioEndpoint(address);
return IP::toAsioEndpoint(address);
}
};

View File

@@ -2,7 +2,7 @@
#include <boost/asio/ip/address_v4.hpp>
namespace beast::ip {
namespace beast::IP {
using AddressV4 = boost::asio::ip::address_v4;
@@ -25,4 +25,4 @@ isPublic(AddressV4 const& addr);
char
getClass(AddressV4 const& address);
} // namespace beast::ip
} // namespace beast::IP

View File

@@ -2,7 +2,7 @@
#include <boost/asio/ip/address_v6.hpp>
namespace beast::ip {
namespace beast::IP {
using AddressV6 = boost::asio::ip::address_v6;
@@ -18,4 +18,4 @@ isPrivate(AddressV6 const& addr);
bool
isPublic(AddressV6 const& addr);
} // namespace beast::ip
} // namespace beast::IP

View File

@@ -13,7 +13,7 @@
#include <optional>
#include <string>
namespace beast::ip {
namespace beast::IP {
using Port = std::uint16_t;
@@ -223,7 +223,7 @@ operator<<(OutputStream& os, Endpoint const& endpoint)
std::istream&
operator>>(std::istream& is, Endpoint& endpoint);
} // namespace beast::ip
} // namespace beast::IP
//------------------------------------------------------------------------------
@@ -232,12 +232,12 @@ namespace std {
* std::hash support.
*/
template <>
struct hash<::beast::ip::Endpoint>
struct hash<::beast::IP::Endpoint>
{
hash() = default;
std::size_t
operator()(::beast::ip::Endpoint const& endpoint) const
operator()(::beast::IP::Endpoint const& endpoint) const
{
return ::beast::Uhash<>{}(endpoint);
}
@@ -249,12 +249,12 @@ namespace boost {
* boost::hash support.
*/
template <>
struct hash<::beast::ip::Endpoint>
struct hash<::beast::IP::Endpoint>
{
hash() = default;
std::size_t
operator()(::beast::ip::Endpoint const& endpoint) const
operator()(::beast::IP::Endpoint const& endpoint) const
{
return ::beast::Uhash<>{}(endpoint);
}

View File

@@ -295,20 +295,6 @@ public:
return runner_->arg();
}
protected:
/**
* Lets a suite compose other suites (e.g. an aggregator that reruns a
* group of related suites under its own name) via `SuiteInfo::run`.
*
* @return The runner this suite is executing under.
*/
Runner&
runner() const
{
return *runner_;
}
public:
/**
* DEPRECATED
* @return `true` if the test condition indicates success(a false value)

View File

@@ -218,7 +218,7 @@ public:
/**
* Add a suppression peer and get message's relay status.
* Return pair:
* element 1: true if the key is added.
* element 1: true if the peer is added.
* element 2: optional is seated to the relay time point or
* is unseated if has not relayed yet.
*/

View File

@@ -18,9 +18,9 @@ namespace xrpl {
namespace node_store {
class Database;
} // namespace node_store
namespace resource {
namespace Resource {
class Manager;
} // namespace resource
} // namespace Resource
namespace perf {
class PerfLog;
} // namespace perf
@@ -160,7 +160,7 @@ public:
virtual PeerReservationTable&
getPeerReservations() = 0;
virtual resource::Manager&
virtual Resource::Manager&
getResourceManager() = 0;
// Storage services

View File

@@ -623,7 +623,6 @@ class ValueConstIterator : public ValueIteratorBase
public:
using size_t = unsigned int;
using difference_type = int;
using value_type = Value const;
using reference = Value const&;
using pointer = Value const*;
using SelfType = ValueConstIterator;
@@ -688,7 +687,6 @@ class ValueIterator : public ValueIteratorBase
public:
using size_t = unsigned int;
using difference_type = int;
using value_type = Value;
using reference = Value&;
using pointer = Value*;
using SelfType = ValueIterator;

View File

@@ -2,7 +2,9 @@
#include <xrpl/basics/Log.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/ReadView.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/MPTokenHelpers.h>
#include <xrpl/ledger/helpers/RippleStateHelpers.h>
@@ -25,6 +27,291 @@
namespace xrpl {
/**
* Validate that @p account may lock @p amount of a token for later delivery
* to @p dest.
*
* The lock-side counterpart of escrowUnlockPreclaimHelper: every issuer
* control (locking opt-in, authorization, freeze/lock, transferability,
* spendable balance) that gates locking token value lives here, so any
* transactor that locks funds applies the same rules. The signature is
* view-based rather than PreclaimContext-based so it can also run from
* doApply.
*/
template <ValidIssueType T>
TER
escrowLockPreclaimHelper(
ReadView const& view,
AccountID const& account,
AccountID const& dest,
STAmount const& amount,
beast::Journal j);
template <>
inline TER
escrowLockPreclaimHelper<Issue>(
ReadView const& view,
AccountID const& account,
AccountID const& dest,
STAmount const& amount,
beast::Journal j)
{
auto const& issue = amount.get<Issue>();
auto const& issuer = amount.getIssuer();
// If the issuer is the same as the account, return tecNO_PERMISSION
if (issuer == account)
return tecNO_PERMISSION;
// If the lsfAllowTrustLineLocking is not enabled, return tecNO_PERMISSION
auto const sleIssuer = view.read(keylet::account(issuer));
if (!sleIssuer)
return tecNO_ISSUER;
if (!sleIssuer->isFlag(lsfAllowTrustLineLocking))
return tecNO_PERMISSION;
// If the account does not have a trustline to the issuer, return tecNO_LINE
auto const sleRippleState = view.read(keylet::trustLine(account, issuer, issue.currency));
if (!sleRippleState)
return tecNO_LINE;
STAmount const balance = (*sleRippleState)[sfBalance];
// If balance is positive, issuer must have higher address than account
if (balance > beast::kZero && issuer < account)
return tecNO_PERMISSION; // LCOV_EXCL_LINE
// If balance is negative, issuer must have lower address than account
if (balance < beast::kZero && issuer > account)
return tecNO_PERMISSION; // LCOV_EXCL_LINE
// If the issuer has requireAuth set, check if the account is authorized
if (auto const ter = requireAuth(view, issue, account); !isTesSuccess(ter))
return ter;
// If the issuer has requireAuth set, check if the destination is authorized
if (auto const ter = requireAuth(view, issue, dest); !isTesSuccess(ter))
return ter;
// If the issuer has frozen the account, return tecFROZEN
if (isFrozen(view, account, issue))
return tecFROZEN;
// If the issuer has frozen the destination, return tecFROZEN
if (isFrozen(view, dest, issue))
return tecFROZEN;
STAmount const spendableAmount =
accountHolds(view, account, issue.currency, issuer, FreezeHandling::IgnoreFreeze, j);
// If the balance is less than or equal to 0, return tecINSUFFICIENT_FUNDS
if (spendableAmount <= beast::kZero)
return tecINSUFFICIENT_FUNDS;
// If the spendable amount is less than the amount, return
// tecINSUFFICIENT_FUNDS
if (spendableAmount < amount)
return tecINSUFFICIENT_FUNDS;
// If the amount is not addable to the balance, return tecPRECISION_LOSS
if (!canAdd(spendableAmount, amount))
return tecPRECISION_LOSS;
return tesSUCCESS;
}
template <>
inline TER
escrowLockPreclaimHelper<MPTIssue>(
ReadView const& view,
AccountID const& account,
AccountID const& dest,
STAmount const& amount,
beast::Journal j)
{
AccountID const issuer = amount.getIssuer();
// If the issuer is the same as the account, return tecNO_PERMISSION
if (issuer == account)
return tecNO_PERMISSION;
// If the mpt does not exist, return tecOBJECT_NOT_FOUND
auto const issuanceKey = keylet::mptokenIssuance(amount.get<MPTIssue>().getMptID());
auto const sleIssuance = view.read(issuanceKey);
if (!sleIssuance)
return tecOBJECT_NOT_FOUND;
// If the lsfMPTCanEscrow is not enabled, return tecNO_PERMISSION
if (!sleIssuance->isFlag(lsfMPTCanEscrow))
return tecNO_PERMISSION;
// If the issuer is not the same as the issuer of the mpt, return
// tecNO_PERMISSION
if (sleIssuance->getAccountID(sfIssuer) != issuer)
return tecNO_PERMISSION; // LCOV_EXCL_LINE
// If the account does not have the mpt, return tecOBJECT_NOT_FOUND
if (!view.exists(keylet::mptoken(issuanceKey.key, account)))
return tecOBJECT_NOT_FOUND;
// If the issuer has requireAuth set, check if the account is
// authorized
auto const& mptIssue = amount.get<MPTIssue>();
if (auto const ter = requireAuth(view, mptIssue, account, AuthType::WeakAuth);
!isTesSuccess(ter))
return ter;
// If the issuer has requireAuth set, check if the destination is
// authorized
if (auto const ter = requireAuth(view, mptIssue, dest, AuthType::WeakAuth); !isTesSuccess(ter))
return ter;
// If the issuer has frozen the account, return tecLOCKED
if (isFrozen(view, account, mptIssue))
return tecLOCKED;
// If the issuer has frozen the destination, return tecLOCKED
if (isFrozen(view, dest, mptIssue))
return tecLOCKED;
// If the mpt cannot be transferred, return tecNO_AUTH
if (auto const ter = canTransfer(view, mptIssue, account, dest); !isTesSuccess(ter))
return ter;
STAmount const spendableAmount = accountHolds(
view,
account,
amount.get<MPTIssue>(),
FreezeHandling::IgnoreFreeze,
AuthHandling::IgnoreAuth,
j);
// If the balance is less than or equal to 0, return tecINSUFFICIENT_FUNDS
if (spendableAmount <= beast::kZero)
return tecINSUFFICIENT_FUNDS;
// If the spendable amount is less than the amount, return
// tecINSUFFICIENT_FUNDS
if (spendableAmount < amount)
return tecINSUFFICIENT_FUNDS;
return tesSUCCESS;
}
template <ValidIssueType T>
TER
escrowLockApplyHelper(
ApplyView& view,
AccountID const& issuer,
AccountID const& sender,
STAmount const& amount,
beast::Journal journal);
template <>
inline TER
escrowLockApplyHelper<Issue>(
ApplyView& view,
AccountID const& issuer,
AccountID const& sender,
STAmount const& amount,
beast::Journal journal)
{
// Defensive: Issuer cannot create an escrow
if (issuer == sender)
return tecINTERNAL; // LCOV_EXCL_LINE
auto const ter =
directSendNoFee(view, sender, issuer, amount, !amount.holds<MPTIssue>(), journal);
if (!isTesSuccess(ter))
return ter; // LCOV_EXCL_LINE
return tesSUCCESS;
}
template <>
inline TER
escrowLockApplyHelper<MPTIssue>(
ApplyView& view,
AccountID const& issuer,
AccountID const& sender,
STAmount const& amount,
beast::Journal journal)
{
// Defensive: Issuer cannot create an escrow
if (issuer == sender)
return tecINTERNAL; // LCOV_EXCL_LINE
auto const ter = lockEscrowMPT(view, sender, amount, journal);
if (!isTesSuccess(ter))
return ter; // LCOV_EXCL_LINE
return tesSUCCESS;
}
template <ValidIssueType T>
TER
escrowUnlockPreclaimHelper(
ReadView const& view,
AccountID const& account,
STAmount const& amount,
bool checkFreeze = true);
template <>
inline TER
escrowUnlockPreclaimHelper<Issue>(
ReadView const& view,
AccountID const& account,
STAmount const& amount,
bool checkFreeze)
{
AccountID const& issuer = amount.getIssuer();
// If the issuer is the same as the account, return tesSUCCESS
if (issuer == account)
return tesSUCCESS;
// If the issuer has requireAuth set, check if the destination is authorized
if (auto const ter = requireAuth(view, amount.get<Issue>(), account); !isTesSuccess(ter))
return ter;
// If the issuer has deep frozen the destination, return tecFROZEN
if (checkFreeze &&
isDeepFrozen(view, account, amount.get<Issue>().currency, amount.getIssuer()))
return tecFROZEN;
return tesSUCCESS;
}
template <>
inline TER
escrowUnlockPreclaimHelper<MPTIssue>(
ReadView const& view,
AccountID const& account,
STAmount const& amount,
bool checkFreeze)
{
AccountID const& issuer = amount.getIssuer();
// If the issuer is the same as the account, return tesSUCCESS
if (issuer == account)
return tesSUCCESS;
// If the mpt does not exist, return tecOBJECT_NOT_FOUND
auto const issuanceKey = keylet::mptokenIssuance(amount.get<MPTIssue>().getMptID());
auto const sleIssuance = view.read(issuanceKey);
if (!sleIssuance)
return tecOBJECT_NOT_FOUND;
// If the issuer has requireAuth set, check if the account is
// authorized
auto const& mptIssue = amount.get<MPTIssue>();
if (auto const ter = requireAuth(view, mptIssue, account, AuthType::WeakAuth);
!isTesSuccess(ter))
return ter;
// If the issuer has frozen the account, return tecLOCKED
if (checkFreeze && isFrozen(view, account, mptIssue))
return tecLOCKED;
return tesSUCCESS;
}
//------------------------------------------------------------------------------
template <ValidIssueType T>
TER
escrowUnlockApplyHelper(
@@ -53,9 +340,6 @@ escrowUnlockApplyHelper<Issue>(
bool createAsset,
beast::Journal journal)
{
auto const& issue = amount.get<Issue>();
Keylet const trustLineKey = keylet::trustLine(receiver, issue);
bool const recvLow = issuer > receiver;
bool const senderIssuer = issuer == sender;
bool const receiverIssuer = issuer == receiver;
@@ -65,6 +349,10 @@ escrowUnlockApplyHelper<Issue>(
if (receiverIssuer)
return tesSUCCESS;
auto const& issue = amount.get<Issue>();
Keylet const trustLineKey = keylet::trustLine(receiver, issue);
bool const recvLow = issuer > receiver;
if (!ctx.view.exists(trustLineKey) && createAsset)
{
// Can the account cover the trust line's reserve?

View File

@@ -296,7 +296,7 @@ struct AccountingDeltas
// Whole-life (pre-LendingProtocolV1_1) recognition model: interest is
// recognized into AssetsTotal/DebtTotal up front, at origination.
namespace accrual {
namespace Accrual {
// LoanSet origination: what's added to Vault.AssetsTotal and LoanBroker.DebtTotal
AccountingDeltas
@@ -318,11 +318,11 @@ loanVaultExposure(SLE::const_ref loanSle);
AccountingDeltas
loanPaymentDeltas(LoanPaymentParts const& parts);
} // namespace accrual
} // namespace Accrual
// Cash-basis (LendingProtocolV1_1) recognition model: AssetsTotal/DebtTotal
// are principal-only, interest is recognized only as it's actually paid.
namespace cash_basis {
namespace CashBasis {
AccountingDeltas
loanOriginationDeltas(Number const& principalRequested);
@@ -333,11 +333,11 @@ loanVaultExposure(SLE::const_ref loanSle);
AccountingDeltas
loanPaymentDeltas(LoanPaymentParts const& parts);
} // namespace cash_basis
} // namespace CashBasis
// Public dispatchers: pick cash_basis:: if featureLendingProtocolV1_1 is
// Public dispatchers: pick CashBasis:: if featureLendingProtocolV1_1 is
// enabled AND the Vault's LEVersion (VaultHelpers::getVaultVersion) is
// VaultVersion::CashBasis, else accrual::. These are the only entry points
// VaultVersion::CashBasis, else Accrual::. These are the only entry points
// transactors call.
AccountingDeltas
loanOriginationDeltas(

View File

@@ -2,28 +2,85 @@
#include <xrpl/basics/base_uint.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Concepts.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/Issue.h>
#include <xrpl/protocol/MPTAmount.h>
#include <xrpl/protocol/MPTIssue.h>
#include <xrpl/protocol/Protocol.h>
#include <xrpl/protocol/Rules.h>
#include <xrpl/protocol/STAmount.h>
#include <xrpl/protocol/STLedgerEntry.h>
#include <xrpl/protocol/TER.h>
#include <xrpl/protocol/UintTypes.h>
#include <cstdint>
#include <optional>
namespace xrpl {
/**
* Validate the token amount of a PaymentChannelCreate or PaymentChannelFund
* transaction during preflight.
*
* @param rules The current ledger rules used to check amendment status.
* @param amount The channel or funding amount from the transaction.
* @return tesSUCCESS if the amount is valid; temBAD_AMOUNT, temBAD_CURRENCY,
* or temDISABLED otherwise.
*/
template <ValidIssueType T>
NotTEC
payChanAmountPreflightHelper(Rules const& rules, STAmount const& amount);
template <>
inline NotTEC
payChanAmountPreflightHelper<Issue>(Rules const&, STAmount const& amount)
{
if (amount.native() || amount <= beast::kZero)
return temBAD_AMOUNT;
if (badCurrency() == amount.get<Issue>().currency)
return temBAD_CURRENCY;
return tesSUCCESS;
}
template <>
inline NotTEC
payChanAmountPreflightHelper<MPTIssue>(Rules const& rules, STAmount const& amount)
{
if (!rules.enabled(fixCleanup3_2_0) && !rules.enabled(featureMPTokensV1))
return temDISABLED;
if (amount.native() || amount.mpt() > MPTAmount{kMaxMpTokenAmount} || amount <= beast::kZero)
return temBAD_AMOUNT;
return tesSUCCESS;
}
/**
* Close a payment channel and return its remaining funds to the channel owner.
*
* @param slep The SLE for the PayChannel object to close.
* @param view The apply view in which ledger state modifications are made.
* @param key The ledger key identifying the PayChannel entry.
* @param j Journal used for fatal-level diagnostic messages.
* @return tesSUCCESS on success; tefBAD_LEDGER if a directory removal
* fails; tefINTERNAL if the source account SLE cannot be found.
* @param slep The SLE for the PayChannel object to close.
* @param ctx The apply view context (view and transaction) in which ledger
* state modifications are made.
* @param key The ledger key identifying the PayChannel entry.
* @param txAccount The account submitting the transaction that closes the
* channel.
* @param j Journal used for fatal-level diagnostic messages.
* @return tesSUCCESS on success; tefBAD_LEDGER if a directory removal
* fails; tefINTERNAL if the source account SLE cannot be found.
*/
TER
closeChannel(SLE::ref slep, ApplyView& view, uint256 const& key, beast::Journal j);
closeChannel(
SLE::ref slep,
ApplyViewContext ctx,
uint256 const& key,
AccountID const& txAccount,
beast::Journal j);
/**
* Add two uint32_t values with saturation at UINT32_MAX.

View File

@@ -67,16 +67,16 @@ public:
return socket_->next_layer();
}
beast::ip::Endpoint
beast::IP::Endpoint
localEndpoint()
{
return beast::ip::fromAsio(lowestLayer().local_endpoint());
return beast::IP::fromAsio(lowestLayer().local_endpoint());
}
beast::ip::Endpoint
beast::IP::Endpoint
remoteEndpoint()
{
return beast::ip::fromAsio(lowestLayer().remote_endpoint());
return beast::IP::fromAsio(lowestLayer().remote_endpoint());
}
lowest_layer_type&

View File

@@ -9,7 +9,7 @@
#include <string>
#include <string_view>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
struct PeerLimitConfig
{
@@ -28,7 +28,7 @@ struct Config
* This includes both inbound and outbound, but does not include
* fixed peers.
*/
std::size_t maxPeers{tuning::kDefaultMaxPeers};
std::size_t maxPeers{Tuning::kDefaultMaxPeers};
/**
* The number of automatic outbound connections to maintain.
@@ -100,7 +100,7 @@ struct Config
onWrite(beast::PropertyStream::Map& map) const;
/**
* Make peer_finder::Config from peer limit and server mode parameters.
* Make PeerFinder::Config from peer limit and server mode parameters.
*/
static Config
makeConfig(
@@ -160,4 +160,4 @@ to_string(Result result) noexcept
return "unknown";
}
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -15,7 +15,7 @@
#include <utility>
#include <vector>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
/**
* Maintains a set of IP addresses used for getting into the network.
@@ -68,17 +68,17 @@ public:
* file, along with the set of corresponding IP addresses.
*/
virtual void
addFixedPeer(std::string_view name, std::vector<beast::ip::Endpoint> const& addresses) = 0;
addFixedPeer(std::string_view name, std::vector<beast::IP::Endpoint> const& addresses) = 0;
/**
* Add a set of strings as fallback ip::Endpoint sources.
* Add a set of strings as fallback IP::Endpoint sources.
* @param name A label used for diagnostics.
*/
virtual void
addFallbackStrings(std::string const& name, std::vector<std::string> const& strings) = 0;
/**
* Add a URL as a fallback location to obtain ip::Endpoint sources.
* Add a URL as a fallback location to obtain IP::Endpoint sources.
* @param name A label used for diagnostics.
*/
/* VFALCO NOTE Unimplemented
@@ -95,8 +95,8 @@ public:
*/
virtual std::pair<std::shared_ptr<Slot>, Result>
newInboundSlot(
beast::ip::Endpoint const& localEndpoint,
beast::ip::Endpoint const& remoteEndpoint) = 0;
beast::IP::Endpoint const& localEndpoint,
beast::IP::Endpoint const& remoteEndpoint) = 0;
/**
* Create a new outbound slot with the specified remote endpoint.
@@ -104,7 +104,7 @@ public:
* Usually this is because of a duplicate connection.
*/
virtual std::pair<std::shared_ptr<Slot>, Result>
newOutboundSlot(beast::ip::Endpoint const& remoteEndpoint) = 0;
newOutboundSlot(beast::IP::Endpoint const& remoteEndpoint) = 0;
/**
* Called when mtENDPOINTS is received.
@@ -145,7 +145,7 @@ public:
* @return `true` if the connection should be kept
*/
virtual bool
onConnected(std::shared_ptr<Slot> const& slot, beast::ip::Endpoint const& localEndpoint) = 0;
onConnected(std::shared_ptr<Slot> const& slot, beast::IP::Endpoint const& localEndpoint) = 0;
/**
* Request an active slot type.
@@ -162,7 +162,7 @@ public:
/**
* Return a set of addresses we should connect to.
*/
virtual std::vector<beast::ip::Endpoint>
virtual std::vector<beast::IP::Endpoint>
autoconnect() = 0;
virtual std::vector<std::pair<std::shared_ptr<Slot>, std::vector<Endpoint>>>
@@ -176,4 +176,4 @@ public:
oncePerSecond() = 0;
};
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -7,7 +7,7 @@
#include <memory>
#include <optional>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
/**
* Properties and state associated with a peer to peer overlay connection.
@@ -52,13 +52,13 @@ public:
/**
* The remote endpoint of socket.
*/
[[nodiscard]] virtual beast::ip::Endpoint const&
[[nodiscard]] virtual beast::IP::Endpoint const&
remoteEndpoint() const = 0;
/**
* The local endpoint of the socket, when known.
*/
[[nodiscard]] virtual std::optional<beast::ip::Endpoint> const&
[[nodiscard]] virtual std::optional<beast::IP::Endpoint> const&
localEndpoint() const = 0;
[[nodiscard]] virtual std::optional<std::uint16_t>
@@ -72,4 +72,4 @@ public:
publicKey() const = 0;
};
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -8,14 +8,14 @@
#include <cstdint>
#include <vector>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
using clock_type = beast::AbstractClock<std::chrono::steady_clock>;
/**
* Represents a set of addresses.
*/
using IPAddresses = std::vector<beast::ip::Endpoint>;
using IPAddresses = std::vector<beast::IP::Endpoint>;
//------------------------------------------------------------------------------
@@ -26,10 +26,10 @@ struct Endpoint
{
Endpoint() = default;
Endpoint(beast::ip::Endpoint ep, std::uint32_t hops);
Endpoint(beast::IP::Endpoint ep, std::uint32_t hops);
std::uint32_t hops = 0;
beast::ip::Endpoint address;
beast::IP::Endpoint address;
};
inline bool
@@ -43,4 +43,4 @@ operator<(Endpoint const& lhs, Endpoint const& rhs)
*/
using Endpoints = std::vector<Endpoint>;
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -14,7 +14,7 @@
#include <functional>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
/**
* Stores IP addresses useful for gaining initial connections.
@@ -65,7 +65,7 @@ private:
};
using left_t = boost::bimaps::
unordered_set_of<beast::ip::Endpoint, boost::hash<beast::ip::Endpoint>, std::equal_to<>>;
unordered_set_of<beast::IP::Endpoint, boost::hash<beast::IP::Endpoint>, std::equal_to<>>;
using right_t = boost::bimaps::multiset_of<Entry, std::less<>>;
using map_type = boost::bimap<left_t, right_t>;
using value_type = map_type::value_type;
@@ -73,11 +73,11 @@ private:
struct Transform
{
using first_argument_type = map_type::right_map::const_iterator::value_type const&;
using result_type = beast::ip::Endpoint const&;
using result_type = beast::IP::Endpoint const&;
explicit Transform() = default;
beast::ip::Endpoint const&
beast::IP::Endpoint const&
operator()(map_type::right_map::const_iterator::value_type const& v) const
{
return v.get_left();
@@ -121,7 +121,7 @@ public:
size() const;
/**
* ip::Endpoint iterators that traverse in decreasing valence.
* IP::Endpoint iterators that traverse in decreasing valence.
*/
/** @{ */
[[nodiscard]] const_iterator
@@ -146,25 +146,25 @@ public:
* Add a newly-learned address to the cache.
*/
bool
insert(beast::ip::Endpoint const& endpoint);
insert(beast::IP::Endpoint const& endpoint);
/**
* Add a staticallyconfigured address to the cache.
*/
bool
insertStatic(beast::ip::Endpoint const& endpoint);
insertStatic(beast::IP::Endpoint const& endpoint);
/**
* Called when an outbound connection handshake completes.
*/
void
onSuccess(beast::ip::Endpoint const& endpoint);
onSuccess(beast::IP::Endpoint const& endpoint);
/**
* Called when an outbound connection attempt fails to handshake.
*/
void
onFailure(beast::ip::Endpoint const& endpoint);
onFailure(beast::IP::Endpoint const& endpoint);
/**
* Stores the cache in the persistent database on a timer.
@@ -189,4 +189,4 @@ private:
flagForUpdate();
};
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -11,7 +11,7 @@
#include <memory>
#include <mutex>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
/**
* Tests remote listening sockets to make sure they are connectable.
@@ -104,7 +104,7 @@ public:
*/
template <class Handler>
void
asyncConnect(beast::ip::Endpoint const& endpoint, Handler&& handler);
asyncConnect(beast::IP::Endpoint const& endpoint, Handler&& handler);
private:
void
@@ -179,7 +179,7 @@ Checker<Protocol>::wait()
template <class Protocol>
template <class Handler>
void
Checker<Protocol>::asyncConnect(beast::ip::Endpoint const& endpoint, Handler&& handler)
Checker<Protocol>::asyncConnect(beast::IP::Endpoint const& endpoint, Handler&& handler)
{
auto const op =
std::make_shared<AsyncOp<Handler>>(*this, ioContext_, std::forward<Handler>(handler));
@@ -202,4 +202,4 @@ Checker<Protocol>::remove(BasicAsyncOp& op)
cond_.notify_all();
}
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -10,7 +10,7 @@
#include <sstream>
#include <string>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
/**
* Direction of a slot count adjustment.
@@ -50,7 +50,7 @@ public:
// Must be handshaked and in the right state
XRPL_ASSERT(
s.state() == Slot::State::Connected || s.state() == Slot::State::Accept,
"xrpl::peer_finder::Counts::can_activate : valid input state");
"xrpl::PeerFinder::Counts::can_activate : valid input state");
if (s.fixed() || s.reserved())
return true;
@@ -67,9 +67,9 @@ public:
[[nodiscard]] std::size_t
attemptsNeeded() const
{
if (attempts_ >= tuning::kMaxConnectAttempts)
if (attempts_ >= Tuning::kMaxConnectAttempts)
return 0;
return tuning::kMaxConnectAttempts - attempts_;
return Tuning::kMaxConnectAttempts - attempts_;
}
/**
@@ -295,7 +295,7 @@ private:
switch (s.state())
{
case Slot::State::Accept:
XRPL_ASSERT(s.inbound(), "xrpl::peer_finder::Counts::adjust : input is inbound");
XRPL_ASSERT(s.inbound(), "xrpl::PeerFinder::Counts::adjust : input is inbound");
acceptCount_ += n;
break;
@@ -303,7 +303,7 @@ private:
case Slot::State::Connected:
XRPL_ASSERT(
!s.inbound(),
"xrpl::peer_finder::Counts::adjust : input is not "
"xrpl::PeerFinder::Counts::adjust : input is not "
"inbound");
attempts_ += n;
break;
@@ -331,7 +331,7 @@ private:
// LCOV_EXCL_START
default:
UNREACHABLE("xrpl::peer_finder::Counts::adjust : invalid input state");
UNREACHABLE("xrpl::PeerFinder::Counts::adjust : invalid input state");
break;
// LCOV_EXCL_STOP
};
@@ -391,4 +391,4 @@ private:
int closingCount_{0};
};
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -7,7 +7,7 @@
#include <chrono>
#include <cstddef>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
/**
* Metadata for a Fixed slot.
@@ -36,8 +36,8 @@ public:
void
failure(clock_type::time_point const& now)
{
failures_ = std::min(failures_ + 1, tuning::kConnectionBackoff.size() - 1);
when_ = now + std::chrono::minutes(tuning::kConnectionBackoff[failures_]);
failures_ = std::min(failures_ + 1, Tuning::kConnectionBackoff.size() - 1);
when_ = now + std::chrono::minutes(Tuning::kConnectionBackoff[failures_]);
}
/**
@@ -55,4 +55,4 @@ private:
std::size_t failures_{0};
};
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -12,7 +12,7 @@
#include <utility>
#include <vector>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
namespace detail {
@@ -28,7 +28,7 @@ template <class Target, class HopContainer>
std::size_t
handoutOne(Target& t, HopContainer& h)
{
XRPL_ASSERT(!t.full(), "xrpl::peer_finder::detail::handoutOne : target is not full");
XRPL_ASSERT(!t.full(), "xrpl::PeerFinder::detail::handoutOne : target is not full");
for (auto it = h.begin(); it != h.end(); ++it)
{
auto const& e = *it;
@@ -95,7 +95,7 @@ public:
[[nodiscard]] bool
full() const
{
return list_.size() >= tuning::kRedirectEndpointCount;
return list_.size() >= Tuning::kRedirectEndpointCount;
}
[[nodiscard]] SlotImp::ptr const&
@@ -124,7 +124,7 @@ private:
template <class>
RedirectHandouts::RedirectHandouts(SlotImp::ptr slot) : slot_(std::move(slot))
{
list_.reserve(tuning::kRedirectEndpointCount);
list_.reserve(Tuning::kRedirectEndpointCount);
}
template <class>
@@ -138,7 +138,7 @@ RedirectHandouts::tryInsert(Endpoint const& ep)
// addresses in a peer HTTP handshake instead of
// the tmENDPOINTS message.
//
if (ep.hops > tuning::kMaxHops)
if (ep.hops > Tuning::kMaxHops)
return false;
// Don't send them our address
@@ -181,7 +181,7 @@ public:
[[nodiscard]] bool
full() const
{
return list_.size() >= tuning::kNumberOfEndpoints;
return list_.size() >= Tuning::kNumberOfEndpoints;
}
void
@@ -210,7 +210,7 @@ private:
template <class>
SlotHandouts::SlotHandouts(SlotImp::ptr slot) : slot_(std::move(slot))
{
list_.reserve(tuning::kNumberOfEndpoints);
list_.reserve(Tuning::kNumberOfEndpoints);
}
template <class>
@@ -220,7 +220,7 @@ SlotHandouts::tryInsert(Endpoint const& ep)
if (full())
return false;
if (ep.hops > tuning::kMaxHops)
if (ep.hops > Tuning::kMaxHops)
return false;
if (slot_->recent.filter(ep.address, ep.hops))
@@ -259,9 +259,9 @@ class ConnectHandouts
public:
// Keeps track of addresses we have made outgoing connections
// to, for the purposes of not connecting to them too frequently.
using Squelches = beast::aged_set<beast::ip::Address>;
using Squelches = beast::aged_set<beast::IP::Address>;
using list_type = std::vector<beast::ip::Endpoint>;
using list_type = std::vector<beast::IP::Endpoint>;
private:
std::size_t needed_;
@@ -274,7 +274,7 @@ public:
template <class = void>
bool
tryInsert(beast::ip::Endpoint const& endpoint);
tryInsert(beast::IP::Endpoint const& endpoint);
[[nodiscard]] bool
empty() const
@@ -316,13 +316,13 @@ ConnectHandouts::ConnectHandouts(std::size_t needed, Squelches& squelches)
template <class>
bool
ConnectHandouts::tryInsert(beast::ip::Endpoint const& endpoint)
ConnectHandouts::tryInsert(beast::IP::Endpoint const& endpoint)
{
if (full())
return false;
// Make sure the address isn't already in our list
if (std::ranges::any_of(list_, [&endpoint](beast::ip::Endpoint const& other) {
if (std::ranges::any_of(list_, [&endpoint](beast::IP::Endpoint const& other) {
// Ignore port for security reasons
return other.address() == endpoint.address();
}))
@@ -341,4 +341,4 @@ ConnectHandouts::tryInsert(beast::ip::Endpoint const& endpoint)
return true;
}
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -29,7 +29,7 @@
#include <utility>
#include <vector>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
template <class>
class Livecache;
@@ -188,10 +188,10 @@ class Livecache : protected detail::LivecacheBase
{
private:
using cache_type = beast::aged_map<
beast::ip::Endpoint,
beast::IP::Endpoint,
Element,
std::chrono::steady_clock,
std::less<beast::ip::Endpoint>,
std::less<beast::IP::Endpoint>,
Allocator>;
beast::Journal journal_;
@@ -220,8 +220,8 @@ public:
// but not given out (since they would exceed maxHops). They
// are used for automatic connection attempts.
//
using Histogram = std::array<int, 1 + tuning::kMaxHops + 1>;
using lists_type = std::array<list_type, 1 + tuning::kMaxHops + 1>;
using Histogram = std::array<int, 1 + Tuning::kMaxHops + 1>;
using lists_type = std::array<list_type, 1 + Tuning::kMaxHops + 1>;
template <bool IsConst>
struct Transform
@@ -400,7 +400,7 @@ Livecache<Allocator>::expire()
{
std::size_t n(0);
typename cache_type::time_point const expired(
cache_.clock().now() - tuning::kLiveCacheSecondsToLive);
cache_.clock().now() - Tuning::kLiveCacheSecondsToLive);
for (auto iter(cache_.chronological.begin());
iter != cache_.chronological.end() && iter.when() <= expired;)
{
@@ -427,8 +427,8 @@ Livecache<Allocator>::insert(Endpoint const& ep)
// when redirecting.
//
XRPL_ASSERT(
ep.hops <= (tuning::kMaxHops + 1),
"xrpl::peer_finder::Livecache::insert : maximum input hops");
ep.hops <= (Tuning::kMaxHops + 1),
"xrpl::PeerFinder::Livecache::insert : maximum input hops");
auto result = cache_.emplace(ep.address, ep);
Element& e(result.first->second);
if (result.second)
@@ -468,7 +468,7 @@ void
Livecache<Allocator>::onWrite(beast::PropertyStream::Map& map)
{
typename cache_type::time_point const expired(
cache_.clock().now() - tuning::kLiveCacheSecondsToLive);
cache_.clock().now() - Tuning::kLiveCacheSecondsToLive);
map["size"] = size();
map["hist"] = hops.histogram();
beast::PropertyStream::Set set("entries", map);
@@ -527,8 +527,8 @@ void
Livecache<Allocator>::HopsT::insert(Element& e)
{
XRPL_ASSERT(
e.endpoint.hops <= tuning::kMaxHops + 1,
"xrpl::peer_finder::Livecache::HopsT::insert : maximum input hops");
e.endpoint.hops <= Tuning::kMaxHops + 1,
"xrpl::PeerFinder::Livecache::HopsT::insert : maximum input hops");
// This has security implications without a shuffle
lists_[e.endpoint.hops].push_front(e);
++hist_[e.endpoint.hops];
@@ -539,8 +539,8 @@ void
Livecache<Allocator>::HopsT::reinsert(Element& e, std::uint32_t numHops)
{
XRPL_ASSERT(
numHops <= tuning::kMaxHops + 1,
"xrpl::peer_finder::Livecache::HopsT::reinsert : maximum hops input");
numHops <= Tuning::kMaxHops + 1,
"xrpl::PeerFinder::Livecache::HopsT::reinsert : maximum hops input");
auto& list = lists_[e.endpoint.hops];
list.erase(list.iterator_to(e));
@@ -561,4 +561,4 @@ Livecache<Allocator>::HopsT::remove(Element& e)
list.erase(list.iterator_to(e));
}
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -43,7 +43,7 @@
#include <utility>
#include <vector>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
/**
* The Logic for maintaining the list of Slot addresses.
@@ -57,7 +57,7 @@ public:
// Maps remote endpoints to slots. Since a slot has a
// remote endpoint upon construction, this holds all counts_.
//
using Slots = std::map<beast::ip::Endpoint, std::shared_ptr<SlotImp>>;
using Slots = std::map<beast::IP::Endpoint, std::shared_ptr<SlotImp>>;
beast::Journal journal;
clock_type& clock;
@@ -81,7 +81,7 @@ private:
Counts counts_;
// A list of slots that should always be connected
std::map<beast::ip::Endpoint, Fixed> fixed_;
std::map<beast::IP::Endpoint, Fixed> fixed_;
public:
// Live livecache from mtENDPOINTS messages
@@ -96,7 +96,7 @@ public:
// The addresses (but not port) we are connected to. This includes
// outgoing connection attempts. Note that this set can contain
// duplicates (since the port is not set)
std::multiset<beast::ip::Address> connectedAddresses;
std::multiset<beast::IP::Address> connectedAddresses;
// Set of public keys belonging to active peers
std::set<PublicKey> keys;
@@ -170,13 +170,13 @@ public:
}
void
addFixedPeer(std::string_view name, beast::ip::Endpoint const& ep)
addFixedPeer(std::string_view name, beast::IP::Endpoint const& ep)
{
addFixedPeer(name, std::vector<beast::ip::Endpoint>{ep});
addFixedPeer(name, std::vector<beast::IP::Endpoint>{ep});
}
void
addFixedPeer(std::string_view name, std::vector<beast::ip::Endpoint> const& addresses)
addFixedPeer(std::string_view name, std::vector<beast::IP::Endpoint> const& addresses)
{
std::scoped_lock const _(lock);
@@ -213,8 +213,8 @@ public:
// Called when the Checker completes a connectivity test
void
checkComplete(
beast::ip::Endpoint const& remoteAddress,
beast::ip::Endpoint const& checkedAddress,
beast::IP::Endpoint const& remoteAddress,
beast::IP::Endpoint const& checkedAddress,
boost::system::error_code ec)
{
if (ec == boost::asio::error::operation_aborted)
@@ -256,8 +256,8 @@ public:
std::pair<SlotImp::ptr, Result>
newInboundSlot(
beast::ip::Endpoint const& localEndpoint,
beast::ip::Endpoint const& remoteEndpoint)
beast::IP::Endpoint const& localEndpoint,
beast::IP::Endpoint const& remoteEndpoint)
{
JLOG(journal.debug()) << std::left << std::setw(18) << "Logic accept" << remoteEndpoint
<< " on local " << localEndpoint;
@@ -293,7 +293,7 @@ public:
// Remote address must not already exist
XRPL_ASSERT(
result.second,
"xrpl::peer_finder::Logic::new_inbound_slot : remote endpoint "
"xrpl::PeerFinder::Logic::new_inbound_slot : remote endpoint "
"inserted");
// Add to the connected address list
connectedAddresses.emplace(remoteEndpoint.address());
@@ -306,7 +306,7 @@ public:
// Can't check for self-connect because we don't know the local endpoint
std::pair<SlotImp::ptr, Result>
newOutboundSlot(beast::ip::Endpoint const& remoteEndpoint)
newOutboundSlot(beast::IP::Endpoint const& remoteEndpoint)
{
JLOG(journal.debug()) << std::left << std::setw(18) << "Logic connect " << remoteEndpoint;
@@ -329,7 +329,7 @@ public:
// Remote address must not already exist
XRPL_ASSERT(
result.second,
"xrpl::peer_finder::Logic::new_outbound_slot : remote endpoint "
"xrpl::PeerFinder::Logic::new_outbound_slot : remote endpoint "
"inserted");
// Add to the connected address list
@@ -342,7 +342,7 @@ public:
}
bool
onConnected(SlotImp::ptr const& slot, beast::ip::Endpoint const& localEndpoint)
onConnected(SlotImp::ptr const& slot, beast::IP::Endpoint const& localEndpoint)
{
beast::WrappedSink sink{journal.sink(), slot->prefix()};
beast::Journal const journal{sink};
@@ -354,7 +354,7 @@ public:
// The object must exist in our table
XRPL_ASSERT(
slots.contains(slot->remoteEndpoint()),
"xrpl::peer_finder::Logic::onConnected : valid slot input");
"xrpl::PeerFinder::Logic::onConnected : valid slot input");
// Assign the local endpoint now that it's known
slot->localEndpoint(localEndpoint);
@@ -365,7 +365,7 @@ public:
{
XRPL_ASSERT(
iter->second->localEndpoint() == slot->remoteEndpoint(),
"xrpl::peer_finder::Logic::onConnected : local and remote "
"xrpl::PeerFinder::Logic::onConnected : local and remote "
"endpoints do match");
JLOG(journal.warn()) << "Logic dropping as self connect";
return false;
@@ -393,11 +393,11 @@ public:
// The object must exist in our table
XRPL_ASSERT(
slots.contains(slot->remoteEndpoint()),
"xrpl::peer_finder::Logic::activate : valid slot input");
"xrpl::PeerFinder::Logic::activate : valid slot input");
// Must be accepted or connected
XRPL_ASSERT(
slot->state() == Slot::State::Accept || slot->state() == Slot::State::Connected,
"xrpl::peer_finder::Logic::activate : valid slot state");
"xrpl::PeerFinder::Logic::activate : valid slot state");
// Check for duplicate connection by key
if (keys.contains(key))
@@ -425,7 +425,7 @@ public:
{
[[maybe_unused]] bool const inserted = keys.insert(key).second;
// Public key must not already exist
XRPL_ASSERT(inserted, "xrpl::peer_finder::Logic::activate : public key inserted");
XRPL_ASSERT(inserted, "xrpl::PeerFinder::Logic::activate : public key inserted");
}
// Change state and update counts
@@ -443,7 +443,7 @@ public:
if (iter == fixed_.end())
{
logicError(
"peer_finder::Logic::activate(): remote_endpoint "
"PeerFinder::Logic::activate(): remote_endpoint "
"missing from fixed_");
}
@@ -476,10 +476,10 @@ public:
// VFALCO TODO This should add the returned addresses to the
// squelch list in one go once the list is built,
// rather than having each module add to the squelch list.
std::vector<beast::ip::Endpoint>
std::vector<beast::IP::Endpoint>
autoconnect()
{
std::vector<beast::ip::Endpoint> none;
std::vector<beast::IP::Endpoint> none;
std::scoped_lock const _(lock);
@@ -635,7 +635,7 @@ public:
// either. ipv6 has a slightly more compact string
// representation of 0, so use that for self entries.
ep.address =
beast::ip::Endpoint(beast::ip::AddressV6()).atPort(config_.listeningPort);
beast::IP::Endpoint(beast::IP::AddressV6()).atPort(config_.listeningPort);
for (auto& t : targets)
t.insert(ep);
}
@@ -656,7 +656,7 @@ public:
result.emplace_back(slot, list);
}
whenBroadcast = now + tuning::kSecondsPerMessage;
whenBroadcast = now + Tuning::kSecondsPerMessage;
}
return result;
@@ -675,7 +675,7 @@ public:
entry.second->expire();
// Expire the recent attempts table
beast::expire(squelches, tuning::kRecentAttemptDuration);
beast::expire(squelches, Tuning::kRecentAttemptDuration);
bootcache.periodicActivity();
}
@@ -692,7 +692,7 @@ public:
Endpoint& ep(*iter);
// Enforce hop limit
if (ep.hops > tuning::kMaxHops)
if (ep.hops > Tuning::kMaxHops)
{
JLOG(journal.debug()) << std::left << std::setw(18) << "Endpoints drop "
<< ep.address << " for excess hops " << ep.hops;
@@ -754,10 +754,10 @@ public:
beast::Journal const journal{sink};
// If we're sent too many endpoints, sample them at random:
if (list.size() > tuning::kNumberOfEndpointsMax)
if (list.size() > Tuning::kNumberOfEndpointsMax)
{
std::shuffle(list.begin(), list.end(), defaultPrng());
list.resize(tuning::kNumberOfEndpointsMax);
list.resize(Tuning::kNumberOfEndpointsMax);
}
JLOG(journal.trace()) << "Endpoints contained " << list.size()
@@ -768,12 +768,12 @@ public:
// The object must exist in our table
XRPL_ASSERT(
slots.contains(slot->remoteEndpoint()),
"xrpl::peer_finder::Logic::onEndpoints : valid slot input");
"xrpl::PeerFinder::Logic::onEndpoints : valid slot input");
// Must be handshaked!
XRPL_ASSERT(
slot->state() == Slot::State::Active,
"xrpl::peer_finder::Logic::onEndpoints : valid slot state");
"xrpl::PeerFinder::Logic::onEndpoints : valid slot state");
clock_type::time_point const now(clock.now());
@@ -785,7 +785,7 @@ public:
for (auto const& ep : list)
{
XRPL_ASSERT(ep.hops, "xrpl::peer_finder::Logic::onEndpoints : nonzero hops");
XRPL_ASSERT(ep.hops, "xrpl::PeerFinder::Logic::onEndpoints : nonzero hops");
slot->recent.insert(ep.address, ep.hops);
@@ -837,7 +837,7 @@ public:
bootcache.insert(ep.address);
}
slot->whenAcceptEndpoints = now + tuning::kSecondsPerMessage;
slot->whenAcceptEndpoints = now + Tuning::kSecondsPerMessage;
}
//--------------------------------------------------------------------------
@@ -851,7 +851,7 @@ public:
if (iter == slots.end())
{
logicError(
"peer_finder::Logic::remove(): remote_endpoint "
"PeerFinder::Logic::remove(): remote_endpoint "
"missing from slots_");
}
@@ -866,7 +866,7 @@ public:
if (iter == keys.end())
{
logicError(
"peer_finder::Logic::remove(): public_key missing "
"PeerFinder::Logic::remove(): public_key missing "
"from keys_");
}
@@ -879,7 +879,7 @@ public:
if (iter == connectedAddresses.end())
{
logicError(
"peer_finder::Logic::remove(): remote_endpoint "
"PeerFinder::Logic::remove(): remote_endpoint "
"address missing from connectedAddresses_");
}
@@ -907,7 +907,7 @@ public:
if (iter == fixed_.end())
{
logicError(
"peer_finder::Logic::on_closed(): remote_endpoint "
"PeerFinder::Logic::on_closed(): remote_endpoint "
"missing from fixed_");
}
@@ -943,7 +943,7 @@ public:
// LCOV_EXCL_START
default:
UNREACHABLE(
"xrpl::peer_finder::Logic::on_closed : invalid slot "
"xrpl::PeerFinder::Logic::on_closed : invalid slot "
"state");
break;
// LCOV_EXCL_STOP
@@ -968,17 +968,17 @@ public:
// Returns `true` if the address matches a fixed slot address
// Must have the lock held
bool
fixed(beast::ip::Endpoint const& endpoint) const
fixed(beast::IP::Endpoint const& endpoint) const
{
return std::ranges::any_of(
fixed_, [&endpoint](auto const& entry) { return entry.first == endpoint; });
}
// Returns `true` if the address matches a fixed slot address
// Note that this does not use the port information in the ip::Endpoint
// Note that this does not use the port information in the IP::Endpoint
// Must have the lock held
bool
fixed(beast::ip::Address const& address) const
fixed(beast::IP::Address const& address) const
{
return std::ranges::any_of(
fixed_, [&address](auto const& entry) { return entry.first.address() == address; });
@@ -1097,9 +1097,9 @@ public:
//
//--------------------------------------------------------------------------
// Returns true if the ip::Endpoint contains no invalid data.
// Returns true if the IP::Endpoint contains no invalid data.
bool
isValidAddress(beast::ip::Endpoint const& address)
isValidAddress(beast::IP::Endpoint const& address)
{
if (isUnspecified(address))
return false;
@@ -1220,7 +1220,7 @@ Logic<Checker>::onRedirects(
{
std::scoped_lock const _(lock);
std::size_t n = 0;
for (; first != last && n < tuning::kMaxRedirects; ++first, ++n)
for (; first != last && n < Tuning::kMaxRedirects; ++first, ++n)
bootcache.insert(beast::IPAddressConversion::fromAsio(*first));
if (n > 0)
{
@@ -1229,4 +1229,4 @@ Logic<Checker>::onRedirects(
}
}
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -12,7 +12,7 @@
#include <optional>
#include <string>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
class SlotImp : public Slot
{
@@ -21,13 +21,13 @@ public:
// inbound
SlotImp(
beast::ip::Endpoint const& localEndpoint,
beast::ip::Endpoint remoteEndpoint,
beast::IP::Endpoint const& localEndpoint,
beast::IP::Endpoint remoteEndpoint,
bool fixed,
clock_type& clock);
// outbound
SlotImp(beast::ip::Endpoint remoteEndpoint, bool fixed, clock_type& clock);
SlotImp(beast::IP::Endpoint remoteEndpoint, bool fixed, clock_type& clock);
bool
inbound() const override
@@ -53,13 +53,13 @@ public:
return state_;
}
beast::ip::Endpoint const&
beast::IP::Endpoint const&
remoteEndpoint() const override
{
return remoteEndpoint_;
}
std::optional<beast::ip::Endpoint> const&
std::optional<beast::IP::Endpoint> const&
localEndpoint() const override
{
return localEndpoint_;
@@ -93,13 +93,13 @@ public:
}
void
localEndpoint(beast::ip::Endpoint const& endpoint)
localEndpoint(beast::IP::Endpoint const& endpoint)
{
localEndpoint_ = endpoint;
}
void
remoteEndpoint(beast::ip::Endpoint const& endpoint)
remoteEndpoint(beast::IP::Endpoint const& endpoint)
{
remoteEndpoint_ = endpoint;
}
@@ -140,20 +140,20 @@ public:
* sending a slot the same address too frequently.
*/
void
insert(beast::ip::Endpoint const& ep, std::uint32_t hops);
insert(beast::IP::Endpoint const& ep, std::uint32_t hops);
/**
* Returns `true` if we should not send endpoint to the slot.
*/
bool
filter(beast::ip::Endpoint const& ep, std::uint32_t hops);
filter(beast::IP::Endpoint const& ep, std::uint32_t hops);
private:
void
expire();
friend class SlotImp;
beast::aged_unordered_map<beast::ip::Endpoint, std::uint32_t> cache_;
beast::aged_unordered_map<beast::IP::Endpoint, std::uint32_t> cache_;
} recent;
void
@@ -167,8 +167,8 @@ private:
bool const fixed_;
bool reserved_;
State state_;
beast::ip::Endpoint remoteEndpoint_;
std::optional<beast::ip::Endpoint> localEndpoint_;
beast::IP::Endpoint remoteEndpoint_;
std::optional<beast::IP::Endpoint> localEndpoint_;
std::optional<PublicKey> publicKey_;
static std::int32_t constexpr kUnknownPort = -1;
@@ -196,4 +196,4 @@ public:
clock_type::time_point whenAcceptEndpoints;
};
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -7,7 +7,7 @@
#include <string>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
/**
* A static or dynamic source of peer addresses.
@@ -46,4 +46,4 @@ public:
fetch(Results& results, beast::Journal journal) = 0;
};
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -6,7 +6,7 @@
#include <string>
#include <vector>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
/**
* Provides addresses from a static set of strings.
@@ -22,4 +22,4 @@ public:
make(std::string const& name, Strings const& strings);
};
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -6,7 +6,7 @@
#include <functional>
#include <vector>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
/**
* Abstract persistence for PeerFinder data.
@@ -17,7 +17,7 @@ public:
virtual ~Store() = default;
// load the bootstrap cache
using load_callback = std::function<void(beast::ip::Endpoint, int)>;
using load_callback = std::function<void(beast::IP::Endpoint, int)>;
virtual std::size_t
load(load_callback const& cb) = 0;
@@ -26,11 +26,11 @@ public:
{
explicit Entry() = default;
beast::ip::Endpoint endpoint;
beast::IP::Endpoint endpoint;
int valence{};
};
virtual void
save(std::vector<Entry> const& v) = 0;
};
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -9,7 +9,7 @@
* Heuristically tuned constants.
*/
/** @{ */
namespace xrpl::peer_finder::tuning {
namespace xrpl::PeerFinder::Tuning {
//---------------------------------------------------------
//
@@ -111,5 +111,5 @@ constexpr std::chrono::seconds kLiveCacheSecondsToLive(30);
// Note that we ignore the port for purposes of comparison.
constexpr std::chrono::seconds kRecentAttemptDuration(60);
} // namespace xrpl::peer_finder::tuning
} // namespace xrpl::PeerFinder::Tuning
/** @} */

View File

@@ -10,7 +10,7 @@
#include <memory>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
/**
* @brief Create a new Manager.
@@ -33,4 +33,4 @@ makeManager(
Store& store,
beast::insight::Collector::ptr const& collector);
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -33,7 +33,7 @@ namespace xrpl {
* Command line Requests use apiCommandLineVersion.
*/
namespace rpc {
namespace RPC {
template <unsigned int Version>
static constexpr std::integral_constant<unsigned, Version> kApiVersion = {};
@@ -60,7 +60,7 @@ static_assert(kApiMaximumValidVersion >= kApiMaximumSupportedVersion);
inline void
setVersion(json::Value& parent, unsigned int apiVersion, bool betaEnabled)
{
XRPL_ASSERT(apiVersion != kApiInvalidVersion, "xrpl::rpc::setVersion : input is valid");
XRPL_ASSERT(apiVersion != kApiInvalidVersion, "xrpl::RPC::setVersion : input is valid");
auto& retObj = parent[jss::version] = json::ValueType::Object;
@@ -99,12 +99,12 @@ setVersion(json::Value& parent, unsigned int apiVersion, bool betaEnabled)
inline unsigned int
getAPIVersionNumber(json::Value const& jv, bool betaEnabled)
{
static json::Value const kMinVersion(rpc::kApiMinimumSupportedVersion);
static json::Value const kMinVersion(RPC::kApiMinimumSupportedVersion);
json::Value const maxVersion(
betaEnabled ? rpc::kApiBetaVersion : rpc::kApiMaximumSupportedVersion);
betaEnabled ? RPC::kApiBetaVersion : RPC::kApiMaximumSupportedVersion);
if (!jv.isObject() || !jv.isMember(jss::api_version))
return rpc::kApiVersionIfUnspecified;
return RPC::kApiVersionIfUnspecified;
try
{
@@ -113,33 +113,33 @@ getAPIVersionNumber(json::Value const& jv, bool betaEnabled)
{
case json::ValueType::Int:
if (rawVersion.asInt() < 0)
return rpc::kApiInvalidVersion;
return RPC::kApiInvalidVersion;
[[fallthrough]];
case json::ValueType::UInt: {
auto const apiVersion = rawVersion.asUInt();
if (apiVersion < kMinVersion || apiVersion > maxVersion)
return rpc::kApiInvalidVersion;
return RPC::kApiInvalidVersion;
return apiVersion;
}
default:
return rpc::kApiInvalidVersion;
return RPC::kApiInvalidVersion;
}
}
catch (...)
{
return rpc::kApiInvalidVersion;
return RPC::kApiInvalidVersion;
}
}
} // namespace rpc
} // namespace RPC
template <unsigned MinVer, unsigned MaxVer, typename Fn, typename... Args>
void
forApiVersions(Fn const& fn, Args&&... args)
requires //
(MaxVer >= MinVer) && //
(MinVer >= rpc::kApiMinimumSupportedVersion) && //
(rpc::kApiMaximumValidVersion >= MaxVer) && requires {
(MinVer >= RPC::kApiMinimumSupportedVersion) && //
(RPC::kApiMaximumValidVersion >= MaxVer) && requires {
fn(std::integral_constant<unsigned int, MinVer>{}, std::forward<Args>(args)...);
fn(std::integral_constant<unsigned int, MaxVer>{}, std::forward<Args>(args)...);
}
@@ -158,11 +158,11 @@ template <typename Fn, typename... Args>
void
forAllApiVersions(Fn const& fn, Args&&... args)
requires requires {
forApiVersions<rpc::kApiMinimumSupportedVersion, rpc::kApiMaximumValidVersion>(
forApiVersions<RPC::kApiMinimumSupportedVersion, RPC::kApiMaximumValidVersion>(
fn, std::forward<Args>(args)...);
}
{
forApiVersions<rpc::kApiMinimumSupportedVersion, rpc::kApiMaximumValidVersion>(
forApiVersions<RPC::kApiMinimumSupportedVersion, RPC::kApiMaximumValidVersion>(
fn, std::forward<Args>(args)...);
}

View File

@@ -8,7 +8,7 @@
* Versioning information for this build.
*/
// VFALCO The namespace is deprecated
namespace xrpl::build_info {
namespace xrpl::BuildInfo {
/**
* Server version.
@@ -84,4 +84,4 @@ isXrpldVersion(std::uint64_t version);
bool
isNewerVersion(std::uint64_t version);
} // namespace xrpl::build_info
} // namespace xrpl::BuildInfo

View File

@@ -167,7 +167,7 @@ enum WarningCodeI {
// VFALCO NOTE these should probably not be in the RPC namespace.
namespace rpc {
namespace RPC {
/**
* Maps an rpc error code to its token, default message, and HTTP status.
@@ -337,7 +337,7 @@ containsError(json::Value const& json);
int
errorCodeHttpStatus(ErrorCodeI code);
} // namespace rpc
} // namespace RPC
/**
* Returns a single string with the contents of an RPC error.

View File

@@ -40,8 +40,6 @@ struct LedgerHeader
// If validated is false, it means "not yet validated."
// Once validated is true, it will never be set false at a later time.
// NOTE: If you are accessing this directly, you are probably doing it
// wrong. Use LedgerMaster::isValidated().
// VFALCO TODO Make this not mutable
bool mutable validated = false;
bool accepted = false;

View File

@@ -188,6 +188,6 @@ struct MultiApiJson
// Wrapper for Json for all supported API versions.
using MultiApiJson =
detail::MultiApiJson<rpc::kApiMinimumSupportedVersion, rpc::kApiMaximumValidVersion>;
detail::MultiApiJson<RPC::kApiMinimumSupportedVersion, RPC::kApiMaximumValidVersion>;
} // namespace xrpl

View File

@@ -6,7 +6,7 @@
#include <memory>
namespace xrpl::rpc {
namespace xrpl::RPC {
/**
* Adds common synthetic fields to transaction-related JSON responses
@@ -16,4 +16,4 @@ void
insertNFTSyntheticInJson(json::Value&, std::shared_ptr<STTx const> const&, TxMeta const&);
/** @} */
} // namespace xrpl::rpc
} // namespace xrpl::RPC

View File

@@ -1,10 +1,20 @@
#pragma once
#include <xrpl/basics/base_uint.h>
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/HashPrefix.h>
#include <xrpl/protocol/IOUAmount.h>
#include <xrpl/protocol/Issue.h>
#include <xrpl/protocol/MPTAmount.h>
#include <xrpl/protocol/MPTIssue.h>
#include <xrpl/protocol/STAmount.h>
#include <xrpl/protocol/Serializer.h>
#include <xrpl/protocol/UintTypes.h>
#include <xrpl/protocol/XRPAmount.h>
#include <cstdint>
namespace xrpl {
inline void
@@ -15,4 +25,70 @@ serializePayChanAuthorization(Serializer& msg, uint256 const& key, XRPAmount con
msg.add64(amt.drops());
}
inline void
serializePayChanAuthorization(
Serializer& msg,
uint256 const& key,
IOUAmount const& amt,
Currency const& cur,
AccountID const& iss)
{
msg.add32(HashPrefix::PaymentChannelClaim);
msg.addBitString(key);
if (amt == beast::kZero)
{
msg.add64(STAmount::kIssuedCurrency);
}
else if (amt.signum() == -1)
{ // 512 = not native; the sign is encoded by omitting the 256 flag, so
// the mantissa must be serialized as its absolute value
msg.add64(
static_cast<std::uint64_t>(-amt.mantissa()) |
(static_cast<std::uint64_t>(amt.exponent() + 512 + 97) << (64 - 10)));
}
else
{ // 256 = positive
msg.add64(
amt.mantissa() |
(static_cast<std::uint64_t>(amt.exponent() + 512 + 256 + 97) << (64 - 10)));
}
msg.addBitString(cur);
msg.addBitString(iss);
}
inline void
serializePayChanAuthorization(
Serializer& msg,
uint256 const& key,
MPTAmount const& amt,
MPTID const& mptID,
AccountID const& iss)
{
msg.add32(HashPrefix::PaymentChannelClaim);
msg.addBitString(key);
msg.add64(amt.value());
msg.addBitString(mptID);
msg.addBitString(iss);
}
inline void
serializePayChanAuthorization(Serializer& msg, uint256 const& key, STAmount const& amt)
{
if (amt.native())
{
serializePayChanAuthorization(msg, key, amt.xrp());
}
else if (amt.holds<Issue>())
{
serializePayChanAuthorization(
msg, key, amt.iou(), amt.get<Issue>().currency, amt.get<Issue>().account);
}
else if (amt.holds<MPTIssue>())
{
auto const& mpt = amt.get<MPTIssue>();
auto const& mptID = mpt.getMptID();
serializePayChanAuthorization(msg, key, amt.mpt(), mptID, amt.getIssuer());
}
}
} // namespace xrpl

View File

@@ -139,7 +139,7 @@ tenthBipsOfValue(T value, TenthBips<TBips> bips)
return value * bips.value() / kTenthBipsPerUnity.value();
}
namespace lending {
namespace Lending {
/**
* The maximum management fee rate allowed by a loan broker in 1/10 bips.
*
@@ -236,7 +236,7 @@ static constexpr int kLoanPaymentsPerFeeIncrement = 5;
* without an amendment
*/
static constexpr int kLoanMaximumPaymentsPerTransaction = 100;
} // namespace lending
} // namespace Lending
/**
* The maximum length of a URI inside an NFT

View File

@@ -260,7 +260,7 @@ calcAccountID(PublicKey const& pk);
inline std::string
getFingerprint(
beast::ip::Endpoint const& address,
beast::IP::Endpoint const& address,
std::optional<PublicKey> const& publicKey = std::nullopt,
std::optional<std::string> const& id = std::nullopt)
{

View File

@@ -20,7 +20,7 @@
namespace xrpl {
namespace attestations {
namespace Attestations {
struct AttestationBase
{
@@ -227,7 +227,7 @@ struct CmpByCreateCount
}
};
}; // namespace attestations
}; // namespace Attestations
// Result when checking when two attestation match.
enum class AttestationMatch {
@@ -241,7 +241,7 @@ enum class AttestationMatch {
struct XChainClaimAttestation
{
using TSignedAttestation = attestations::AttestationClaim;
using TSignedAttestation = Attestations::AttestationClaim;
static SField const& arrayFieldName;
AccountID keyAccount;
@@ -297,7 +297,7 @@ struct XChainClaimAttestation
struct XChainCreateAccountAttestation
{
using TSignedAttestation = attestations::AttestationCreateAccount;
using TSignedAttestation = Attestations::AttestationCreateAccount;
static SField const& arrayFieldName;
AccountID keyAccount;

View File

@@ -16,6 +16,7 @@
// Keep it sorted in reverse chronological order.
XRPL_FIX (Cleanup3_4_0, Supported::Yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(TokenPaychan, Supported::Yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(Sponsor, Supported::Yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(BatchV1_1, Supported::Yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(LendingProtocolV1_1, Supported::No, VoteBehavior::DefaultNo)

View File

@@ -369,6 +369,8 @@ LEDGER_ENTRY(ltPAYCHAN, 0x0078, PayChannel, payment_channel, ({
{sfPreviousTxnID, SoeRequired},
{sfPreviousTxnLgrSeq, SoeRequired},
{sfDestinationNode, SoeOptional},
{sfTransferRate, SoeOptional},
{sfIssuerNode, SoeOptional},
}))
/** The ledger object which tracks the AMM.

View File

@@ -191,7 +191,7 @@ TRANSACTION(ttPAYCHAN_CREATE, 13, PaymentChannelCreate,
NoPriv,
({
{sfDestination, SoeRequired},
{sfAmount, SoeRequired},
{sfAmount, SoeRequired, SoeMptSupported},
{sfSettleDelay, SoeRequired},
{sfPublicKey, SoeRequired},
{sfCancelAfter, SoeOptional},
@@ -208,7 +208,7 @@ TRANSACTION(ttPAYCHAN_FUND, 14, PaymentChannelFund,
NoPriv,
({
{sfChannel, SoeRequired},
{sfAmount, SoeRequired},
{sfAmount, SoeRequired, SoeMptSupported},
{sfExpiration, SoeOptional},
}))
@@ -222,8 +222,8 @@ TRANSACTION(ttPAYCHAN_CLAIM, 15, PaymentChannelClaim,
NoPriv,
({
{sfChannel, SoeRequired},
{sfAmount, SoeOptional},
{sfBalance, SoeOptional},
{sfAmount, SoeOptional, SoeMptSupported},
{sfBalance, SoeOptional, SoeMptSupported},
{sfSignature, SoeOptional},
{sfPublicKey, SoeOptional},
{sfCredentialIDs, SoeOptional},

View File

@@ -287,6 +287,54 @@ public:
{
return this->sle_->isFieldPresent(sfDestinationNode);
}
/**
* @brief Get sfTransferRate (SoeOptional)
* @return The field value, or std::nullopt if not present.
*/
[[nodiscard]]
protocol_autogen::Optional<SF_UINT32::type::value_type>
getTransferRate() const
{
if (hasTransferRate())
return this->sle_->at(sfTransferRate);
return std::nullopt;
}
/**
* @brief Check if sfTransferRate is present.
* @return True if the field is present, false otherwise.
*/
[[nodiscard]]
bool
hasTransferRate() const
{
return this->sle_->isFieldPresent(sfTransferRate);
}
/**
* @brief Get sfIssuerNode (SoeOptional)
* @return The field value, or std::nullopt if not present.
*/
[[nodiscard]]
protocol_autogen::Optional<SF_UINT64::type::value_type>
getIssuerNode() const
{
if (hasIssuerNode())
return this->sle_->at(sfIssuerNode);
return std::nullopt;
}
/**
* @brief Check if sfIssuerNode is present.
* @return True if the field is present, false otherwise.
*/
[[nodiscard]]
bool
hasIssuerNode() const
{
return this->sle_->isFieldPresent(sfIssuerNode);
}
};
/**
@@ -508,6 +556,28 @@ public:
return *this;
}
/**
* @brief Set sfTransferRate (SoeOptional)
* @return Reference to this builder for method chaining.
*/
PayChannelBuilder&
setTransferRate(std::decay_t<typename SF_UINT32::type::value_type> const& value)
{
object_[sfTransferRate] = value;
return *this;
}
/**
* @brief Set sfIssuerNode (SoeOptional)
* @return Reference to this builder for method chaining.
*/
PayChannelBuilder&
setIssuerNode(std::decay_t<typename SF_UINT64::type::value_type> const& value)
{
object_[sfIssuerNode] = value;
return *this;
}
/**
* @brief Build and return the completed PayChannel wrapper.
* @param index The ledger entry index.

View File

@@ -60,6 +60,7 @@ public:
/**
* @brief Get sfAmount (SoeOptional)
* @note This field supports MPT (Multi-Purpose Token) amounts.
* @return The field value, or std::nullopt if not present.
*/
[[nodiscard]]
@@ -86,6 +87,7 @@ public:
/**
* @brief Get sfBalance (SoeOptional)
* @note This field supports MPT (Multi-Purpose Token) amounts.
* @return The field value, or std::nullopt if not present.
*/
[[nodiscard]]
@@ -246,6 +248,7 @@ public:
/**
* @brief Set sfAmount (SoeOptional)
* @note This field supports MPT (Multi-Purpose Token) amounts.
* @return Reference to this builder for method chaining.
*/
PaymentChannelClaimBuilder&
@@ -257,6 +260,7 @@ public:
/**
* @brief Set sfBalance (SoeOptional)
* @note This field supports MPT (Multi-Purpose Token) amounts.
* @return Reference to this builder for method chaining.
*/
PaymentChannelClaimBuilder&

View File

@@ -60,6 +60,7 @@ public:
/**
* @brief Get sfAmount (SoeRequired)
* @note This field supports MPT (Multi-Purpose Token) amounts.
* @return The field value.
*/
[[nodiscard]]
@@ -207,6 +208,7 @@ public:
/**
* @brief Set sfAmount (SoeRequired)
* @note This field supports MPT (Multi-Purpose Token) amounts.
* @return Reference to this builder for method chaining.
*/
PaymentChannelCreateBuilder&

View File

@@ -60,6 +60,7 @@ public:
/**
* @brief Get sfAmount (SoeRequired)
* @note This field supports MPT (Multi-Purpose Token) amounts.
* @return The field value.
*/
[[nodiscard]]
@@ -155,6 +156,7 @@ public:
/**
* @brief Set sfAmount (SoeRequired)
* @note This field supports MPT (Multi-Purpose Token) amounts.
* @return Reference to this builder for method chaining.
*/
PaymentChannelFundBuilder&

View File

@@ -4,7 +4,7 @@
#include <ostream>
#include <string>
namespace xrpl::resource {
namespace xrpl::Resource {
/**
* A consumption charge.
@@ -32,7 +32,7 @@ public:
label() const;
/**
* Return the cost of the charge in resource::Manager units.
* Return the cost of the charge in Resource::Manager units.
*/
[[nodiscard]] value_type
cost() const;
@@ -60,4 +60,4 @@ private:
std::ostream&
operator<<(std::ostream& os, Charge const& v);
} // namespace xrpl::resource
} // namespace xrpl::Resource

View File

@@ -8,7 +8,7 @@
#include <ostream>
#include <string>
namespace xrpl::resource {
namespace xrpl::Resource {
struct Entry;
class Logic;
@@ -96,4 +96,4 @@ private:
std::ostream&
operator<<(std::ostream& os, Consumer const& v);
} // namespace xrpl::resource
} // namespace xrpl::Resource

View File

@@ -1,6 +1,6 @@
#pragma once
namespace xrpl::resource {
namespace xrpl::Resource {
/**
* The disposition of a consumer after applying a load charge.
@@ -24,4 +24,4 @@ enum class Disposition {
Drop
};
} // namespace xrpl::resource
} // namespace xrpl::Resource

View File

@@ -2,7 +2,7 @@
#include <xrpl/resource/Charge.h>
namespace xrpl::resource {
namespace xrpl::Resource {
/**
* Schedule of fees charged for imposing load on the server.
@@ -31,4 +31,4 @@ extern Charge const kFeeWarning; // The cost of receiving a warning.
extern Charge const kFeeDrop; // The cost of being dropped for excess load.
/** @} */
} // namespace xrpl::resource
} // namespace xrpl::Resource

View File

@@ -4,7 +4,7 @@
#include <vector>
namespace xrpl::resource {
namespace xrpl::Resource {
/**
* Data format for exchanging consumption information across peers.
@@ -21,10 +21,10 @@ struct Gossip
explicit Item() = default;
int balance{};
beast::ip::Endpoint address;
beast::IP::Endpoint address;
};
std::vector<Item> items;
};
} // namespace xrpl::resource
} // namespace xrpl::Resource

View File

@@ -1,4 +1,4 @@
# resource::Manager
# Resource::Manager
The ResourceManager module has these responsibilities:
@@ -36,7 +36,7 @@ to the general public.
## Consumer Types
Consumers are placed into three classifications (as identified by the
resource::Kind enumeration):
Resource::Kind enumeration):
- InBound,
- OutBound, and
@@ -72,6 +72,6 @@ drop connections to those IP addresses that occur commonly in the gossip.
## Access
In xrpld, the Application holds a unique instance of resource::Manager,
In xrpld, the Application holds a unique instance of Resource::Manager,
which may be retrieved by calling the method
`Application::getResourceManager()`.

View File

@@ -14,7 +14,7 @@
#include <string>
#include <string_view>
namespace xrpl::resource {
namespace xrpl::Resource {
/**
* Tracks load and resource consumption.
@@ -32,10 +32,10 @@ public:
* IP if proxied.
*/
virtual Consumer
newInboundEndpoint(beast::ip::Endpoint const& address) = 0;
newInboundEndpoint(beast::IP::Endpoint const& address) = 0;
virtual Consumer
newInboundEndpoint(
beast::ip::Endpoint const& address,
beast::IP::Endpoint const& address,
bool const proxy,
std::string_view forwardedFor) = 0;
@@ -43,13 +43,13 @@ public:
* Create a new endpoint keyed by outbound IP address and port.
*/
virtual Consumer
newOutboundEndpoint(beast::ip::Endpoint const& address) = 0;
newOutboundEndpoint(beast::IP::Endpoint const& address) = 0;
/**
* Create a new unlimited endpoint keyed by forwarded IP.
*/
virtual Consumer
newUnlimitedEndpoint(beast::ip::Endpoint const& address) = 0;
newUnlimitedEndpoint(beast::IP::Endpoint const& address) = 0;
/**
* Extract packaged consumer information for export.
@@ -78,4 +78,4 @@ public:
std::unique_ptr<Manager>
makeManager(beast::insight::Collector::ptr const& collector, beast::Journal journal);
} // namespace xrpl::resource
} // namespace xrpl::Resource

View File

@@ -12,7 +12,7 @@
#include <ostream>
#include <string>
namespace xrpl::resource {
namespace xrpl::Resource {
using clock_type = beast::AbstractClock<std::chrono::steady_clock>;
@@ -91,4 +91,4 @@ operator<<(std::ostream& os, Entry const& v)
return os;
}
} // namespace xrpl::resource
} // namespace xrpl::Resource

View File

@@ -5,7 +5,7 @@
#include <vector>
namespace xrpl::resource {
namespace xrpl::Resource {
/**
* A set of imported consumer data from a gossip origin.
@@ -32,4 +32,4 @@ struct Import
std::vector<Item> items;
};
} // namespace xrpl::resource
} // namespace xrpl::Resource

View File

@@ -7,17 +7,17 @@
#include <cstddef>
#include <utility>
namespace xrpl::resource {
namespace xrpl::Resource {
// The consumer key
struct Key
{
Kind kind;
beast::ip::Endpoint address;
beast::IP::Endpoint address;
Key() = delete;
Key(Kind k, beast::ip::Endpoint addr) : kind(k), address(std::move(addr))
Key(Kind k, beast::IP::Endpoint addr) : kind(k), address(std::move(addr))
{
}
@@ -47,4 +47,4 @@ struct Key
};
};
} // namespace xrpl::resource
} // namespace xrpl::Resource

View File

@@ -1,6 +1,6 @@
#pragma once
namespace xrpl::resource {
namespace xrpl::Resource {
/**
* Kind of consumer.
@@ -12,4 +12,4 @@ namespace xrpl::resource {
*/
enum class Kind { Inbound, Outbound, Unlimited };
} // namespace xrpl::resource
} // namespace xrpl::Resource

View File

@@ -24,7 +24,7 @@
#include <tuple>
#include <utility>
namespace xrpl::resource {
namespace xrpl::Resource {
class Logic
{
@@ -96,7 +96,7 @@ public:
}
Consumer
newInboundEndpoint(beast::ip::Endpoint const& address)
newInboundEndpoint(beast::IP::Endpoint const& address)
{
Entry* entry(nullptr);
@@ -126,7 +126,7 @@ public:
}
Consumer
newOutboundEndpoint(beast::ip::Endpoint const& address)
newOutboundEndpoint(beast::IP::Endpoint const& address)
{
Entry* entry(nullptr);
@@ -159,7 +159,7 @@ public:
* enabled.
*/
Consumer
newUnlimitedEndpoint(beast::ip::Endpoint const& address)
newUnlimitedEndpoint(beast::IP::Endpoint const& address)
{
Entry* entry(nullptr);
@@ -387,7 +387,7 @@ public:
{
std::scoped_lock const _(lock_);
Entry& entry(iter->second);
XRPL_ASSERT(entry.refcount == 0, "xrpl::resource::Logic::erase : entry not used");
XRPL_ASSERT(entry.refcount == 0, "xrpl::Resource::Logic::erase : entry not used");
inactive_.erase(inactive_.iteratorTo(entry));
table_.erase(iter);
}
@@ -421,7 +421,7 @@ public:
default:
// LCOV_EXCL_START
UNREACHABLE(
"xrpl::resource::Logic::release : invalid entry "
"xrpl::Resource::Logic::release : invalid entry "
"kind");
break;
// LCOV_EXCL_STOP
@@ -440,7 +440,7 @@ public:
static_assert(
kFeeLogAsWarn > kFeeLogAsInfo && kFeeLogAsInfo > kFeeLogAsDebug && kFeeLogAsDebug > 10);
static auto kGetStream = [](resource::Charge::value_type cost, beast::Journal& journal) {
static auto kGetStream = [](Resource::Charge::value_type cost, beast::Journal& journal) {
if (cost >= kFeeLogAsWarn)
return journal.warn();
if (cost >= kFeeLogAsInfo)
@@ -564,4 +564,4 @@ public:
}
};
} // namespace xrpl::resource
} // namespace xrpl::Resource

View File

@@ -2,7 +2,7 @@
#include <chrono>
namespace xrpl::resource {
namespace xrpl::Resource {
/**
* Tunable constants.
@@ -26,4 +26,4 @@ static constexpr std::chrono::seconds kSecondsUntilExpiration{300};
// Number of seconds until imported gossip expires
static constexpr std::chrono::seconds kGossipExpirationSeconds{30};
} // namespace xrpl::resource
} // namespace xrpl::Resource

View File

@@ -62,7 +62,7 @@ public:
using ref = std::shared_ptr<InfoSub> const&;
using Consumer = resource::Consumer;
using Consumer = Resource::Consumer;
public:
/**

View File

@@ -196,7 +196,7 @@ public:
virtual bool
isFull() = 0;
virtual void
setMode(OperatingMode om, char const* reason) = 0;
setMode(OperatingMode om) = 0;
virtual bool
isBlocked() = 0;
virtual bool

View File

@@ -52,7 +52,7 @@ public:
/**
* Returns the remote address of the connection.
*/
virtual beast::ip::Endpoint
virtual beast::IP::Endpoint
remoteAddress() = 0;
/**

View File

@@ -157,7 +157,7 @@ protected:
return port_;
}
beast::ip::Endpoint
beast::IP::Endpoint
remoteAddress() override
{
return beast::IPAddressConversion::fromAsio(remoteAddress_);

View File

@@ -196,7 +196,7 @@ BaseWSPeer<Handler, Impl>::run()
startTimer();
closeOnTimer_ = true;
impl().ws_.set_option(boost::beast::websocket::stream_base::decorator([](auto& res) {
res.set(boost::beast::http::field::server, build_info::getFullVersionString());
res.set(boost::beast::http::field::server, BuildInfo::getFullVersionString());
}));
impl().ws_.async_accept(
request_, bind_executor(strand_, [self = impl().shared_from_this()](error_code const& ec) {

View File

@@ -23,6 +23,9 @@ public:
static TxConsequences
makeTxConsequences(PreflightContext const& ctx);
static bool
checkExtraFeatures(PreflightContext const& ctx);
static NotTEC
preflight(PreflightContext const& ctx);

View File

@@ -23,9 +23,15 @@ public:
static TxConsequences
makeTxConsequences(PreflightContext const& ctx);
static bool
checkExtraFeatures(PreflightContext const& ctx);
static NotTEC
preflight(PreflightContext const& ctx);
static TER
preclaim(PreclaimContext const& ctx);
TER
doApply() override;

View File

@@ -102,10 +102,6 @@ undefined:nudb
# Snappy compression library intentional overflows
unsigned-integer-overflow:snappy.cc
# fast_float parses floats with a SWAR trick (parse_eight_digits_unrolled) that
# multiplies eight packed digits modulo 2^64; the wraparound is by design.
unsigned-integer-overflow:fast_float
# Abseil intentional overflows in hashing, RNG and time arithmetic.
# Matched at library scope (like boost above): the wraparound is by design
# across many absl files (hash mixing, raw_hash_set probing, duration math,
@@ -198,7 +194,7 @@ unsigned-integer-overflow:tests/libxrpl/basics/RangeSet.cpp
unsigned-integer-overflow:test/app/Batch_test.cpp
unsigned-integer-overflow:test/app/ConfidentialTransfer_test.cpp
unsigned-integer-overflow:test/app/Invariants_test.cpp
unsigned-integer-overflow:test/app/lending/LoanSecurity_test.cpp
unsigned-integer-overflow:test/app/Loan_test.cpp
unsigned-integer-overflow:test/app/NFToken_test.cpp
unsigned-integer-overflow:test/app/OfferMPT_test.cpp
unsigned-integer-overflow:test/app/Offer_test.cpp

View File

@@ -255,7 +255,7 @@ public:
if (ec == boost::asio::error::operation_aborted)
return;
std::vector<beast::ip::Endpoint> addresses;
std::vector<beast::IP::Endpoint> addresses;
auto iter = results.begin();
// If we get an error message back, we don't return any
@@ -283,7 +283,7 @@ public:
// first attempt to parse as an endpoint (IP addr + port).
// If that doesn't succeed, fall back to generic name + port parsing
if (auto const result = beast::ip::Endpoint::fromStringChecked(str))
if (auto const result = beast::IP::Endpoint::fromStringChecked(str))
{
return make_pair(result->address().to_string(), std::to_string(result->port()));
}

View File

@@ -74,7 +74,7 @@ parseUrl(ParsedUrl& pUrl, std::string const& strUrl)
// We need to use Endpoint to parse the domain to
// strip surrounding brackets from IPv6 addresses,
// e.g. [::1] => ::1.
auto const result = beast::ip::Endpoint::fromStringChecked(domain);
auto const result = beast::IP::Endpoint::fromStringChecked(domain);
pUrl.domain = result ? result->address().to_string() : domain;
std::string const port = smMatch[5];
if (!port.empty())

View File

@@ -207,7 +207,7 @@ private:
static constexpr auto kMaxPacketSize = 1472;
Journal journal_;
ip::Endpoint address_;
IP::Endpoint address_;
std::string prefix_;
boost::asio::io_context ioContext_;
std::optional<boost::asio::executor_work_guard<boost::asio::io_context::executor_type>> work_;
@@ -222,13 +222,13 @@ private:
std::thread thread_;
static boost::asio::ip::udp::endpoint
toEndpoint(ip::Endpoint const& ep)
toEndpoint(IP::Endpoint const& ep)
{
return boost::asio::ip::udp::endpoint(ep.address(), ep.port());
}
public:
StatsDCollectorImp(ip::Endpoint address, std::string prefix, Journal journal)
StatsDCollectorImp(IP::Endpoint address, std::string prefix, Journal journal)
: journal_(journal)
, address_(std::move(address))
, prefix_(std::move(prefix))
@@ -707,7 +707,7 @@ StatsDMeterImpl::doProcess()
//------------------------------------------------------------------------------
std::shared_ptr<StatsDCollector>
StatsDCollector::make(ip::Endpoint const& address, std::string const& prefix, Journal journal)
StatsDCollector::make(IP::Endpoint const& address, std::string const& prefix, Journal journal)
{
return std::make_shared<detail::StatsDCollectorImp>(address, prefix, journal);
}

View File

@@ -5,7 +5,7 @@
#include <boost/asio/ip/address.hpp>
#include <boost/asio/ip/tcp.hpp>
namespace beast::ip {
namespace beast::IP {
Endpoint
fromAsio(boost::asio::ip::address const& address)
@@ -31,4 +31,4 @@ toAsioEndpoint(Endpoint const& endpoint)
return boost::asio::ip::tcp::endpoint{endpoint.address(), endpoint.port()};
}
} // namespace beast::ip
} // namespace beast::IP

View File

@@ -1,6 +1,6 @@
#include <xrpl/beast/net/IPAddressV4.h>
namespace beast::ip {
namespace beast::IP {
bool
isPrivate(AddressV4 const& addr)
@@ -62,4 +62,4 @@ getClass(AddressV4 const& addr)
return kTable[(addr.to_uint() & 0xE0000000) >> 29];
}
} // namespace beast::ip
} // namespace beast::IP

View File

@@ -4,7 +4,7 @@
#include <boost/asio/ip/address_v6.hpp>
namespace beast::ip {
namespace beast::IP {
bool
isPrivate(AddressV6 const& addr)
@@ -58,4 +58,4 @@ isPublic(AddressV6 const& addr)
return true;
}
} // namespace beast::ip
} // namespace beast::IP

View File

@@ -14,7 +14,7 @@
#include <string>
#include <utility>
namespace beast::ip {
namespace beast::IP {
Endpoint::Endpoint() : port_(0)
{
@@ -176,4 +176,4 @@ operator>>(std::istream& is, Endpoint& endpoint)
return is;
}
} // namespace beast::ip
} // namespace beast::IP

View File

@@ -3,11 +3,9 @@
#include <xrpl/basics/contract.h>
#include <xrpl/json/json_value.h>
#include <fast_float/fast_float.h> // IWYU pragma: keep
#include <fast_float/parse_number.h>
#include <algorithm>
#include <cctype>
#include <charconv>
#include <cstdint>
#include <cstdio>
#include <istream>
@@ -607,14 +605,8 @@ Reader::decodeNumber(Token& token)
bool
Reader::decodeDouble(Token& token)
{
// Sanity check to avoid buffer overflow exploits.
if (token.end < token.start)
{
return addError("Unable to parse token length", token);
}
double value = 0;
auto const [ptr, ec] = fast_float::from_chars(token.start, token.end, value);
auto const [ptr, ec] = std::from_chars(token.start, token.end, value);
// Reject anything from_chars could not turn into a finite double:
// - ec != std::errc{}: no valid conversion, or an out-of-range magnitude

View File

@@ -131,7 +131,7 @@ isRounded(Asset const& asset, Number const& value, std::int32_t scale)
roundToAsset(asset, value, scale, Number::RoundingMode::Upward);
}
namespace accrual {
namespace Accrual {
AccountingDeltas
loanOriginationDeltas(Number const& principalRequested, Number const& interestDue)
@@ -169,9 +169,9 @@ loanPaymentDeltas(LoanPaymentParts const& parts)
.debtTotalDelta = (parts.principalPaid + parts.interestPaid) - parts.valueChange};
}
} // namespace accrual
} // namespace Accrual
namespace cash_basis {
namespace CashBasis {
AccountingDeltas
loanOriginationDeltas(Number const& principalRequested)
@@ -196,7 +196,7 @@ loanPaymentDeltas(LoanPaymentParts const& parts)
return {.assetsTotalDelta = parts.interestPaid, .debtTotalDelta = parts.principalPaid};
}
} // namespace cash_basis
} // namespace CashBasis
namespace {
@@ -219,8 +219,8 @@ loanOriginationDeltas(
Number const& interestDue)
{
return cashBasisEnabled(vaultSle)
? cash_basis::loanOriginationDeltas(principalRequested)
: accrual::loanOriginationDeltas(principalRequested, interestDue);
? CashBasis::loanOriginationDeltas(principalRequested)
: Accrual::loanOriginationDeltas(principalRequested, interestDue);
}
bool
@@ -235,21 +235,21 @@ loanOriginationExceedsVaultMaximum(
return false;
auto const vaultMaximum = vaultSle->at(sfAssetsMaximum);
return accrual::loanOriginationExceedsVaultMaximum(vaultMaximum, vaultTotal, interestDue);
return Accrual::loanOriginationExceedsVaultMaximum(vaultMaximum, vaultTotal, interestDue);
}
Number
loanVaultExposure(SLE::const_ref vaultSle, SLE::const_ref loanSle)
{
return cashBasisEnabled(vaultSle) ? cash_basis::loanVaultExposure(loanSle)
: accrual::loanVaultExposure(loanSle);
return cashBasisEnabled(vaultSle) ? CashBasis::loanVaultExposure(loanSle)
: Accrual::loanVaultExposure(loanSle);
}
AccountingDeltas
loanPaymentDeltas(SLE::const_ref vaultSle, LoanPaymentParts const& parts)
{
return cashBasisEnabled(vaultSle) ? cash_basis::loanPaymentDeltas(parts)
: accrual::loanPaymentDeltas(parts);
return cashBasisEnabled(vaultSle) ? CashBasis::loanPaymentDeltas(parts)
: Accrual::loanPaymentDeltas(parts);
}
namespace detail {
@@ -1617,7 +1617,7 @@ makeRegularPayment(
LoanPaymentType const paymentType,
beast::Journal j)
{
using namespace lending;
using namespace Lending;
XRPL_ASSERT_PARTS(
paymentType == LoanPaymentType::Regular || paymentType == LoanPaymentType::Overpayment,

View File

@@ -3,14 +3,19 @@
#include <xrpl/basics/Log.h>
#include <xrpl/basics/base_uint.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/beast/utility/Zero.h>
#include <xrpl/beast/utility/instrumentation.h>
#include <xrpl/ledger/ApplyView.h>
#include <xrpl/ledger/View.h>
#include <xrpl/ledger/helpers/AccountRootHelpers.h>
#include <xrpl/ledger/helpers/EscrowHelpers.h>
#include <xrpl/protocol/AccountID.h>
#include <xrpl/protocol/Concepts.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/Indexes.h>
#include <xrpl/protocol/Rate.h>
#include <xrpl/protocol/SField.h>
#include <xrpl/protocol/STAmount.h>
#include <xrpl/protocol/STLedgerEntry.h>
#include <xrpl/protocol/TER.h>
@@ -18,12 +23,19 @@
#include <cstdint>
#include <limits>
#include <optional>
#include <variant>
namespace xrpl {
TER
closeChannel(SLE::ref slep, ApplyView& view, uint256 const& key, beast::Journal j)
closeChannel(
SLE::ref slep,
ApplyViewContext ctx,
uint256 const& key,
AccountID const& txAccount,
beast::Journal j)
{
ApplyView& view = ctx.view;
AccountID const src = (*slep)[sfAccount];
// Remove PayChan from owner directory
{
@@ -38,9 +50,9 @@ closeChannel(SLE::ref slep, ApplyView& view, uint256 const& key, beast::Journal
}
// Remove PayChan from recipient's owner directory, if present.
AccountID const dst = (*slep)[sfDestination];
if (auto const page = (*slep)[~sfDestinationNode])
{
auto const dst = (*slep)[sfDestination];
if (!view.dirRemove(keylet::ownerDir(dst), *page, key, true))
{
// LCOV_EXCL_START
@@ -57,7 +69,63 @@ closeChannel(SLE::ref slep, ApplyView& view, uint256 const& key, beast::Journal
XRPL_ASSERT(
(*slep)[sfAmount] >= (*slep)[sfBalance], "xrpl::closeChannel : minimum channel amount");
(*sle)[sfBalance] = (*sle)[sfBalance] + (*slep)[sfAmount] - (*slep)[sfBalance];
auto const reqDelta = (*slep)[sfAmount] - (*slep)[sfBalance];
auto const& issuer = reqDelta.getIssuer();
// Only update the balance if there is a positive delta.
if (reqDelta > beast::kZero)
{
if (isXRP(reqDelta))
{
(*sle)[sfBalance] = (*sle)[sfBalance] + reqDelta;
}
else
{
if (!view.rules().enabled(featureTokenPaychan))
return temDISABLED;
if (auto const ret = std::visit(
[&]<typename T>(T const&) {
return escrowUnlockPreclaimHelper<T>(view, src, reqDelta, false);
},
reqDelta.asset().value());
!isTesSuccess(ret))
return ret;
bool const createAsset = src == txAccount;
if (auto const ret = std::visit(
[&]<typename T>(T const&) {
return escrowUnlockApplyHelper<T>(
ctx,
kParityRate,
sle,
STAmount{(*sle)[sfBalance]}.xrp(),
reqDelta,
issuer,
src,
src,
createAsset,
j);
},
reqDelta.asset().value());
!isTesSuccess(ret))
return ret;
}
}
// Remove PayChan from issuer's owner directory, if present.
if (auto const optPage = (*slep)[~sfIssuerNode])
{
if (!view.dirRemove(keylet::ownerDir(issuer), *optPage, key, true))
{
// LCOV_EXCL_START
JLOG(j.fatal()) << "Could not remove paychan from issuer owner directory";
return tefBAD_LEDGER;
// LCOV_EXCL_STOP
}
}
decreaseOwnerCountForObject(view, sle, slep, 1, j);
view.update(sle);

View File

@@ -16,7 +16,7 @@
#include <ios>
#include <vector>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
Bootcache::Bootcache(Store& store, clock_type& clock, beast::Journal journal)
: store_(store), clock_(clock), journal_(journal), whenUpdate_(clock_.now())
@@ -78,7 +78,7 @@ void
Bootcache::load()
{
clear();
auto const n(store_.load([this](beast::ip::Endpoint const& endpoint, int valence) {
auto const n(store_.load([this](beast::IP::Endpoint const& endpoint, int valence) {
auto const result(this->map_.insert(value_type(endpoint, valence)));
if (!result.second)
{
@@ -96,7 +96,7 @@ Bootcache::load()
}
bool
Bootcache::insert(beast::ip::Endpoint const& endpoint)
Bootcache::insert(beast::IP::Endpoint const& endpoint)
{
auto const result(map_.insert(value_type(endpoint, 0)));
if (result.second)
@@ -109,7 +109,7 @@ Bootcache::insert(beast::ip::Endpoint const& endpoint)
}
bool
Bootcache::insertStatic(beast::ip::Endpoint const& endpoint)
Bootcache::insertStatic(beast::IP::Endpoint const& endpoint)
{
auto result(map_.insert(value_type(endpoint, kStaticValence)));
@@ -130,7 +130,7 @@ Bootcache::insertStatic(beast::ip::Endpoint const& endpoint)
}
void
Bootcache::onSuccess(beast::ip::Endpoint const& endpoint)
Bootcache::onSuccess(beast::IP::Endpoint const& endpoint)
{
auto result(map_.insert(value_type(endpoint, 1)));
if (result.second)
@@ -144,7 +144,7 @@ Bootcache::onSuccess(beast::ip::Endpoint const& endpoint)
++entry.valence();
map_.erase(result.first);
result = map_.insert(value_type(endpoint, entry));
XRPL_ASSERT(result.second, "xrpl::peer_finder::Bootcache::onSuccess : endpoint inserted");
XRPL_ASSERT(result.second, "xrpl::PeerFinder::Bootcache::onSuccess : endpoint inserted");
}
Entry const& entry(result.first->right);
JLOG(journal_.info()) << std::left << std::setw(18) << "Bootcache connect " << endpoint
@@ -154,7 +154,7 @@ Bootcache::onSuccess(beast::ip::Endpoint const& endpoint)
}
void
Bootcache::onFailure(beast::ip::Endpoint const& endpoint)
Bootcache::onFailure(beast::IP::Endpoint const& endpoint)
{
auto result(map_.insert(value_type(endpoint, -1)));
if (result.second)
@@ -168,7 +168,7 @@ Bootcache::onFailure(beast::ip::Endpoint const& endpoint)
--entry.valence();
map_.erase(result.first);
result = map_.insert(value_type(endpoint, entry));
XRPL_ASSERT(result.second, "xrpl::peer_finder::Bootcache::onFailure : endpoint inserted");
XRPL_ASSERT(result.second, "xrpl::PeerFinder::Bootcache::onFailure : endpoint inserted");
}
Entry const& entry(result.first->right);
auto const n(std::abs(entry.valence()));
@@ -201,11 +201,11 @@ Bootcache::onWrite(beast::PropertyStream::Map& map)
void
Bootcache::prune()
{
if (size() <= tuning::kBootcacheSize)
if (size() <= Tuning::kBootcacheSize)
return;
// Calculate the amount to remove
auto count((size() * tuning::kBootcachePrunePercent) / 100);
auto count((size() * Tuning::kBootcachePrunePercent) / 100);
decltype(count) pruned(0);
// Work backwards because bimap doesn't handle
@@ -215,7 +215,7 @@ Bootcache::prune()
{
--count;
--iter;
beast::ip::Endpoint const& endpoint(iter->get_left());
beast::IP::Endpoint const& endpoint(iter->get_left());
Entry const& entry(iter->get_right());
JLOG(journal_.trace()) << std::left << std::setw(18) << "Bootcache pruned" << endpoint
<< " at valence " << entry.valence();
@@ -244,7 +244,7 @@ Bootcache::update()
store_.save(list);
// Reset the flag and cooldown timer
needsUpdate_ = false;
whenUpdate_ = clock_.now() + tuning::kBootcacheCooldownTime;
whenUpdate_ = clock_.now() + Tuning::kBootcacheCooldownTime;
}
// Checks the clock and calls update if we are off the cooldown.
@@ -263,4 +263,4 @@ Bootcache::flagForUpdate()
checkUpdate();
}
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -7,13 +7,13 @@
#include <cstdint>
#include <stdexcept>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
std::size_t
Config::calcOutPeers() const
{
return std::max(
((maxPeers * tuning::kOutPercent) + 50) / 100, std::size_t(tuning::kMinOutCount));
((maxPeers * Tuning::kOutPercent) + 50) / 100, std::size_t(Tuning::kMinOutCount));
}
void
@@ -26,8 +26,8 @@ Config::applyTuning()
// IP addresses.
ipLimit = 2;
if (inPeers > tuning::kDefaultMaxPeers)
ipLimit += std::min(5, static_cast<int>(inPeers / tuning::kDefaultMaxPeers));
if (inPeers > Tuning::kDefaultMaxPeers)
ipLimit += std::min(5, static_cast<int>(inPeers / Tuning::kDefaultMaxPeers));
}
// We don't allow a single IP to consume all incoming slots,
@@ -58,7 +58,7 @@ Config::makeConfig(
int ipLimit,
bool verifyEndpoints)
{
peer_finder::Config config;
PeerFinder::Config config;
if (!limits.maxPeers)
{
@@ -85,7 +85,7 @@ Config::makeConfig(
if (limits.maxPeers && *limits.maxPeers != 0)
config.maxPeers = *limits.maxPeers;
config.maxPeers = std::max<std::size_t>(config.maxPeers, tuning::kMinOutCount);
config.maxPeers = std::max<std::size_t>(config.maxPeers, Tuning::kMinOutCount);
config.outPeers = config.calcOutPeers();
// Calculate the number of outbound peers we want. If we dont want
@@ -132,4 +132,4 @@ Config::makeConfig(
return config;
}
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -5,11 +5,11 @@
#include <cstdint>
#include <utility>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
Endpoint::Endpoint(beast::ip::Endpoint ep, std::uint32_t hops)
: hops(std::min(hops, tuning::kMaxHops + 1)), address(std::move(ep))
Endpoint::Endpoint(beast::IP::Endpoint ep, std::uint32_t hops)
: hops(std::min(hops, Tuning::kMaxHops + 1)), address(std::move(ep))
{
}
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -29,7 +29,7 @@
#include <utility>
#include <vector>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
class ManagerImp : public Manager
{
@@ -98,7 +98,7 @@ public:
}
void
addFixedPeer(std::string_view name, std::vector<beast::ip::Endpoint> const& addresses) override
addFixedPeer(std::string_view name, std::vector<beast::IP::Endpoint> const& addresses) override
{
logic_.addFixedPeer(name, addresses);
}
@@ -119,14 +119,14 @@ public:
std::pair<std::shared_ptr<Slot>, Result>
newInboundSlot(
beast::ip::Endpoint const& localEndpoint,
beast::ip::Endpoint const& remoteEndpoint) override
beast::IP::Endpoint const& localEndpoint,
beast::IP::Endpoint const& remoteEndpoint) override
{
return logic_.newInboundSlot(localEndpoint, remoteEndpoint);
}
std::pair<std::shared_ptr<Slot>, Result>
newOutboundSlot(beast::ip::Endpoint const& remoteEndpoint) override
newOutboundSlot(beast::IP::Endpoint const& remoteEndpoint) override
{
return logic_.newOutboundSlot(remoteEndpoint);
}
@@ -163,7 +163,7 @@ public:
//--------------------------------------------------------------------------
bool
onConnected(std::shared_ptr<Slot> const& slot, beast::ip::Endpoint const& localEndpoint)
onConnected(std::shared_ptr<Slot> const& slot, beast::IP::Endpoint const& localEndpoint)
override
{
SlotImp::ptr const impl(std::dynamic_pointer_cast<SlotImp>(slot));
@@ -184,7 +184,7 @@ public:
return logic_.redirect(impl);
}
std::vector<beast::ip::Endpoint>
std::vector<beast::IP::Endpoint>
autoconnect() override
{
return logic_.autoconnect();
@@ -265,4 +265,4 @@ makeManager(
return std::make_unique<ManagerImp>(ioContext, clock, journal, store, collector);
}
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -9,11 +9,11 @@
#include <cstdint>
#include <utility>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
SlotImp::SlotImp(
beast::ip::Endpoint const& localEndpoint,
beast::ip::Endpoint remoteEndpoint,
beast::IP::Endpoint const& localEndpoint,
beast::IP::Endpoint remoteEndpoint,
bool fixed,
clock_type& clock)
: recent(clock)
@@ -30,7 +30,7 @@ SlotImp::SlotImp(
{
}
SlotImp::SlotImp(beast::ip::Endpoint remoteEndpoint, bool fixed, clock_type& clock)
SlotImp::SlotImp(beast::IP::Endpoint remoteEndpoint, bool fixed, clock_type& clock)
: recent(clock)
, inbound_(false)
, fixed_(fixed)
@@ -49,29 +49,29 @@ SlotImp::state(State state)
{
// Must go through activate() to set active state
XRPL_ASSERT(
state != State::Active, "xrpl::peer_finder::SlotImp::state : input state is not active");
state != State::Active, "xrpl::PeerFinder::SlotImp::state : input state is not active");
// The state must be different
XRPL_ASSERT(
state_ != state,
"xrpl::peer_finder::SlotImp::state : input state is different from "
"xrpl::PeerFinder::SlotImp::state : input state is different from "
"current");
// You can't transition into the initial states
XRPL_ASSERT(
state != State::Accept && state != State::Connect,
"xrpl::peer_finder::SlotImp::state : input state is not an initial");
"xrpl::PeerFinder::SlotImp::state : input state is not an initial");
// Can only become connected from outbound connect state
XRPL_ASSERT(
state != State::Connected || (!inbound_ && state_ == State::Connect),
"xrpl::peer_finder::SlotImp::state : input state is not connected an "
"xrpl::PeerFinder::SlotImp::state : input state is not connected an "
"invalid state");
// Can't gracefully close on an outbound connection attempt
XRPL_ASSERT(
state != State::Closing || state_ != State::Connect,
"xrpl::peer_finder::SlotImp::state : input state is not closing an "
"xrpl::PeerFinder::SlotImp::state : input state is not closing an "
"invalid state");
state_ = state;
@@ -83,7 +83,7 @@ SlotImp::activate(clock_type::time_point const& now)
// Can only become active from the accept or connected state
XRPL_ASSERT(
state_ == State::Accept || state_ == State::Connected,
"xrpl::peer_finder::SlotImp::activate : valid state");
"xrpl::PeerFinder::SlotImp::activate : valid state");
state_ = State::Active;
whenAcceptEndpoints = now;
@@ -100,7 +100,7 @@ SlotImp::RecentT::RecentT(clock_type& clock) : cache_(clock)
}
void
SlotImp::RecentT::insert(beast::ip::Endpoint const& ep, std::uint32_t hops)
SlotImp::RecentT::insert(beast::IP::Endpoint const& ep, std::uint32_t hops)
{
auto const result(cache_.emplace(ep, hops));
if (!result.second)
@@ -115,7 +115,7 @@ SlotImp::RecentT::insert(beast::ip::Endpoint const& ep, std::uint32_t hops)
}
bool
SlotImp::RecentT::filter(beast::ip::Endpoint const& ep, std::uint32_t hops)
SlotImp::RecentT::filter(beast::IP::Endpoint const& ep, std::uint32_t hops)
{
auto const iter(cache_.find(ep));
if (iter == cache_.end())
@@ -129,7 +129,7 @@ SlotImp::RecentT::filter(beast::ip::Endpoint const& ep, std::uint32_t hops)
void
SlotImp::RecentT::expire()
{
beast::expire(cache_, tuning::kLiveCacheSecondsToLive);
beast::expire(cache_, Tuning::kLiveCacheSecondsToLive);
}
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -8,7 +8,7 @@
#include <string>
#include <utility>
namespace xrpl::peer_finder {
namespace xrpl::PeerFinder {
class SourceStringsImp : public SourceStrings
{
@@ -33,9 +33,9 @@ public:
results.addresses.reserve(strings_.size());
for (auto const& str : strings_)
{
beast::ip::Endpoint ep(beast::ip::Endpoint::fromString(str));
beast::IP::Endpoint ep(beast::IP::Endpoint::fromString(str));
if (isUnspecified(ep))
ep = beast::ip::Endpoint::fromString(str);
ep = beast::IP::Endpoint::fromString(str);
if (!isUnspecified(ep))
results.addresses.push_back(ep);
}
@@ -54,4 +54,4 @@ SourceStrings::make(std::string const& name, Strings const& strings)
return std::make_shared<SourceStringsImp>(name, strings);
}
} // namespace xrpl::peer_finder
} // namespace xrpl::PeerFinder

View File

@@ -13,7 +13,7 @@
#include <string>
#include <string_view>
namespace xrpl::build_info {
namespace xrpl::BuildInfo {
namespace {
@@ -173,4 +173,4 @@ isNewerVersion(std::uint64_t version)
return false;
}
} // namespace xrpl::build_info
} // namespace xrpl::BuildInfo

View File

@@ -9,7 +9,7 @@
#include <string>
namespace xrpl {
namespace rpc {
namespace RPC {
namespace detail {
@@ -215,12 +215,12 @@ errorCodeHttpStatus(ErrorCodeI code)
return getErrorInfo(code).httpStatus;
}
} // namespace rpc
} // namespace RPC
std::string
rpcErrorString(json::Value const& jv)
{
XRPL_ASSERT(rpc::containsError(jv), "xrpl::rpc::rpcErrorString : input contains an error");
XRPL_ASSERT(RPC::containsError(jv), "xrpl::RPC::rpcErrorString : input contains an error");
return jv[jss::error].asString() + jv[jss::error_message].asString();
}

View File

@@ -9,7 +9,7 @@
#include <memory>
namespace xrpl::rpc {
namespace xrpl::RPC {
void
insertNFTSyntheticInJson(
@@ -21,4 +21,4 @@ insertNFTSyntheticInJson(
insertNFTokenOfferID(response[jss::meta], transaction, transactionMeta);
}
} // namespace xrpl::rpc
} // namespace xrpl::RPC

View File

@@ -13,7 +13,7 @@ json::Value
rpcError(ErrorCodeI iError)
{
json::Value jvResult(json::ValueType::Object);
rpc::injectError(iError, jvResult);
RPC::injectError(iError, jvResult);
return jvResult;
}

View File

@@ -48,7 +48,7 @@
namespace xrpl {
namespace st_parsed_json_detail {
namespace STParsedJSONDetail {
template <typename U, typename S>
constexpr U
toUnsigned(S value)
@@ -93,7 +93,7 @@ makeName(std::string const& object, std::string const& field)
static inline json::Value
notAnObject(std::string const& object, std::string const& field)
{
return rpc::makeError(
return RPC::makeError(
RpcInvalidParams, "Field '" + makeName(object, field) + "' is not a JSON object.");
}
@@ -106,33 +106,33 @@ notAnObject(std::string const& object)
static inline json::Value
notAnArray(std::string const& object)
{
return rpc::makeError(RpcInvalidParams, "Field '" + object + "' is not a JSON array.");
return RPC::makeError(RpcInvalidParams, "Field '" + object + "' is not a JSON array.");
}
static inline json::Value
unknownField(std::string const& object, std::string const& field)
{
return rpc::makeError(RpcInvalidParams, "Field '" + makeName(object, field) + "' is unknown.");
return RPC::makeError(RpcInvalidParams, "Field '" + makeName(object, field) + "' is unknown.");
}
static inline json::Value
outOfRange(std::string const& object, std::string const& field)
{
return rpc::makeError(
return RPC::makeError(
RpcInvalidParams, "Field '" + makeName(object, field) + "' is out of range.");
}
static inline json::Value
badType(std::string const& object, std::string const& field)
{
return rpc::makeError(
return RPC::makeError(
RpcInvalidParams, "Field '" + makeName(object, field) + "' has bad type.");
}
static inline json::Value
invalidData(std::string const& object, std::string const& field)
{
return rpc::makeError(
return RPC::makeError(
RpcInvalidParams, "Field '" + makeName(object, field) + "' has invalid data.");
}
@@ -145,14 +145,14 @@ invalidData(std::string const& object)
static inline json::Value
arrayExpected(std::string const& object, std::string const& field)
{
return rpc::makeError(
return RPC::makeError(
RpcInvalidParams, "Field '" + makeName(object, field) + "' must be a JSON array.");
}
static inline json::Value
arrayTooBig(std::string const& object, std::string const& field)
{
return rpc::makeError(
return RPC::makeError(
RpcInvalidParams,
"Field '" + makeName(object, field) + "' exceeds allowed JSON array size of " +
std::to_string(kMaxParsedJsonArraySize) + " elements per field.");
@@ -161,20 +161,20 @@ arrayTooBig(std::string const& object, std::string const& field)
static inline json::Value
stringExpected(std::string const& object, std::string const& field)
{
return rpc::makeError(
return RPC::makeError(
RpcInvalidParams, "Field '" + makeName(object, field) + "' must be a string.");
}
static inline json::Value
tooDeep(std::string const& object)
{
return rpc::makeError(RpcInvalidParams, "Field '" + object + "' exceeds nesting depth limit.");
return RPC::makeError(RpcInvalidParams, "Field '" + object + "' exceeds nesting depth limit.");
}
static inline json::Value
singletonExpected(std::string const& object, unsigned int index)
{
return rpc::makeError(
return RPC::makeError(
RpcInvalidParams,
"Field '" + object + "[" + std::to_string(index) +
"]' must be an object with a single key/object value.");
@@ -183,7 +183,7 @@ singletonExpected(std::string const& object, unsigned int index)
static inline json::Value
templateMismatch(SField const& sField)
{
return rpc::makeError(
return RPC::makeError(
RpcInvalidParams,
"Object '" + sField.getName() + "' contents did not meet requirements for that type.");
}
@@ -191,7 +191,7 @@ templateMismatch(SField const& sField)
static inline json::Value
nonObjectInArray(std::string const& item, json::UInt index)
{
return rpc::makeError(
return RPC::makeError(
RpcInvalidParams,
"Item '" + item + "' at index " + std::to_string(index) +
" is not an object. Arrays may only contain objects.");
@@ -791,7 +791,7 @@ parseLeaf(
if (pathEl.isMember(jss::currency) && pathEl.isMember(jss::mpt_issuance_id))
{
error = rpc::makeError(RpcInvalidParams, "Invalid Asset.");
error = RPC::makeError(RpcInvalidParams, "Invalid Asset.");
return ret;
}
@@ -1195,13 +1195,13 @@ parseArray(
}
}
} // namespace st_parsed_json_detail
} // namespace STParsedJSONDetail
//------------------------------------------------------------------------------
STParsedJSONObject::STParsedJSONObject(std::string const& name, json::Value const& json)
{
using namespace st_parsed_json_detail;
using namespace STParsedJSONDetail;
object = parseObject(name, json, sfGeneric, 0, error);
}

Some files were not shown because too many files have changed in this diff Show More