Merge branch 'develop' into ximinez/number-perf

This commit is contained in:
Ed Hennis
2026-05-01 14:35:59 -04:00
committed by GitHub
300 changed files with 3128 additions and 2206 deletions

View File

@@ -7,6 +7,7 @@ Checks: "-*,
bugprone-bad-signal-to-kill-thread,
bugprone-bool-pointer-implicit-conversion,
bugprone-casting-through-void,
bugprone-capturing-this-in-member-variable,
bugprone-chained-comparison,
bugprone-compare-pointer-to-member-virtual-function,
bugprone-copy-constructor-init,
@@ -28,6 +29,7 @@ Checks: "-*,
bugprone-misplaced-operator-in-strlen-in-alloc,
bugprone-misplaced-pointer-arithmetic-in-alloc,
bugprone-misplaced-widening-cast,
bugprone-misleading-setter-of-reference,
bugprone-move-forwarding-reference,
bugprone-multi-level-implicit-pointer-conversion,
bugprone-multiple-new-in-one-expression,
@@ -85,6 +87,7 @@ Checks: "-*,
cppcoreguidelines-pro-type-static-cast-downcast,
cppcoreguidelines-rvalue-reference-param-not-moved,
cppcoreguidelines-use-default-member-init,
cppcoreguidelines-use-enum-class,
cppcoreguidelines-virtual-class-destructor,
hicpp-ignored-remove-result,
misc-const-correctness,
@@ -109,6 +112,7 @@ Checks: "-*,
modernize-use-nodiscard,
modernize-use-override,
modernize-use-ranges,
modernize-use-scoped-lock,
modernize-use-starts-ends-with,
modernize-use-std-numbers,
modernize-use-using,
@@ -122,6 +126,7 @@ Checks: "-*,
performance-move-constructor-init,
performance-no-automatic-move,
performance-trivially-destructible,
readability-ambiguous-smartptr-reset-call,
readability-avoid-nested-conditional-operator,
readability-avoid-return-with-void-value,
readability-braces-around-statements,

View File

@@ -1,43 +0,0 @@
name: Print build environment
description: "Print environment and some tooling versions"
runs:
using: composite
steps:
- name: Check configuration (Windows)
if: ${{ runner.os == 'Windows' }}
shell: bash
run: |
echo 'Checking environment variables.'
set
- name: Check configuration (Linux and macOS)
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
shell: bash
run: |
echo 'Checking path.'
echo ${PATH} | tr ':' '\n'
echo 'Checking environment variables.'
env | sort
echo 'Checking compiler version.'
${{ runner.os == 'Linux' && '${CC}' || 'clang' }} --version
echo 'Checking Ninja version.'
ninja --version
echo 'Checking nproc version.'
nproc --version
- name: Check configuration (all)
shell: bash
run: |
echo 'Checking Ccache version.'
ccache --version
echo 'Checking CMake version.'
cmake --version
echo 'Checking Conan version.'
conan --version

View File

@@ -33,17 +33,6 @@ updates:
prefix: "ci: [DEPENDABOT] "
target-branch: develop
- package-ecosystem: github-actions
directory: .github/actions/print-env/
schedule:
interval: weekly
day: monday
time: "04:00"
timezone: Etc/GMT
commit-message:
prefix: "ci: [DEPENDABOT] "
target-branch: develop
- package-ecosystem: github-actions
directory: .github/actions/setup-conan/
schedule:

View File

@@ -14,7 +14,7 @@ on:
jobs:
# Call the workflow in the XRPLF/actions repo that runs the pre-commit hooks.
run-hooks:
uses: XRPLF/actions/.github/workflows/pre-commit.yml@9307df762265e15c745ddcdb38a581c989f7f349
uses: XRPLF/actions/.github/workflows/pre-commit.yml@5e942d61bf32f7557a7c159cfac4712a687b3e3a
with:
runs_on: ubuntu-latest
container: '{ "image": "ghcr.io/xrplf/ci/tools-rippled-pre-commit:sha-41ec7c1" }'

View File

@@ -116,7 +116,7 @@ jobs:
run: echo "CCACHE_LOGFILE=${{ runner.temp }}/ccache.log" >> "${GITHUB_ENV}"
- name: Print build environment
uses: ./.github/actions/print-env
uses: XRPLF/actions/print-build-env@59dec886e4afb05a1724443af08baccbc045b574
- name: Get number of processors
uses: XRPLF/actions/get-nproc@cf0433aa74563aead044a1e395610c96d65a37cf

View File

@@ -40,7 +40,7 @@ jobs:
enable_ccache: false
- name: Print build environment
uses: ./.github/actions/print-env
uses: XRPLF/actions/print-build-env@59dec886e4afb05a1724443af08baccbc045b574
- name: Get number of processors
uses: XRPLF/actions/get-nproc@cf0433aa74563aead044a1e395610c96d65a37cf

View File

@@ -75,7 +75,7 @@ jobs:
enable_ccache: false
- name: Print build environment
uses: ./.github/actions/print-env
uses: XRPLF/actions/print-build-env@59dec886e4afb05a1724443af08baccbc045b574
- name: Get number of processors
uses: XRPLF/actions/get-nproc@cf0433aa74563aead044a1e395610c96d65a37cf

View File

@@ -28,6 +28,8 @@ This section contains changes targeting a future version.
### Additions
- `ledger_entry`, `account_objects`: The `Delegate` ledger entry now includes an optional `DestinationNode` field, which stores the index into the authorized account's owner directory. This field is present on entries created after bidirectional directory tracking was introduced and may appear in RPC responses for those entries. ([#6681](https://github.com/XRPLF/rippled/pull/6681))
- `server_definitions`: Added the following new sections to the response ([#6321](https://github.com/XRPLF/rippled/pull/6321)):
- `TRANSACTION_FORMATS`: Describes the fields and their optionality for each transaction type, including common fields shared across all transactions.
- `LEDGER_ENTRY_FORMATS`: Describes the fields and their optionality for each ledger entry type, including common fields shared across all ledger entries.
@@ -40,6 +42,14 @@ This section contains changes targeting a future version.
- Peer Crawler: The `port` field in `overlay.active[]` now consistently returns an integer instead of a string for outbound peers. [#6318](https://github.com/XRPLF/rippled/pull/6318)
- `ping`: The `ip` field is no longer returned as an empty string for proxied connections without a forwarded-for header. It is now omitted, consistent with the behavior for identified connections. [#6730](https://github.com/XRPLF/rippled/pull/6730)
- gRPC `GetLedgerDiff`: Fixed error message that incorrectly said "base ledger not validated" when the desired ledger was not validated. [#6730](https://github.com/XRPLF/rippled/pull/6730)
- `account_channels`: The `destination_account` field now returns an error if the value is not a string. [#6529](https://github.com/XRPLF/rippled/pull/6529)
- `subscribe`: The `taker` field in the `books` array now returns an error if the value is not a string. [#6529](https://github.com/XRPLF/rippled/pull/6529)
- `account_info`: The `urlgravatar` field now uses HTTPS instead of HTTP. [#6529](https://github.com/XRPLF/rippled/pull/6529)
- `ledger`: The `full`, `accounts`, `transactions`, `expand`, `binary`, `owner_funds`, and `queue` fields now return an error if the value is not a boolean. [#6529](https://github.com/XRPLF/rippled/pull/6529)
- `ledger_data`: The `binary` field now returns an error if the value is not a boolean. [#6529](https://github.com/XRPLF/rippled/pull/6529)
- `submit`: The `fail_hard` field now returns an error if the value is not a boolean. [#6529](https://github.com/XRPLF/rippled/pull/6529)
- `subscribe`: The `taker` field in the `books` array now returns `actMalformed` instead of `badIssuer` if the value is not a valid account. [#6529](https://github.com/XRPLF/rippled/pull/6529)
- Fixed a bug in `Forwarded` HTTP header parsing where the extracted IP address could be incorrect when no comma or semicolon delimiter follows the address. This could cause the server to misidentify a client's IP address when operating behind a reverse proxy. [#6529](https://github.com/XRPLF/rippled/pull/6529)
## XRP Ledger server version 3.1.0

View File

@@ -23,7 +23,6 @@ target_compile_definitions(
BOOST_FILESYSTEM_NO_DEPRECATED
>
$<$<NOT:$<BOOL:${boost_show_deprecated}>>:
BOOST_COROUTINES2_NO_DEPRECATION_WARNING
BOOST_BEAST_ALLOW_DEPRECATED
BOOST_FILESYSTEM_DEPRECATED
>

View File

@@ -34,10 +34,12 @@
* -fsanitize=<types>: Links sanitizer runtime libraries
* -mcmodel=large/medium: (GCC only) Matches compile-time code model
- SANITIZERS_RELOCATION_FLAGS: (GCC only) Code model flags for linking.
- SANITIZERS_RELOCATION_FLAGS: (GCC only, x86_64 only) Code model flags for linking.
Used to handle large instrumented binaries on x86_64:
* -mcmodel=large: For AddressSanitizer (prevents relocation errors)
* -mcmodel=medium: For ThreadSanitizer (large model is incompatible)
On ARM64, these flags are omitted since GCC does not support
-mcmodel=large with -fPIC, and -mcmodel=medium does not exist.
#]===================================================================]
include(CompilationEnv)
@@ -151,9 +153,11 @@ if(is_gcc)
elseif(enable_tsan)
# GCC doesn't support atomic_thread_fence with tsan. Suppress warnings.
list(APPEND SANITIZERS_COMPILE_FLAGS "-Wno-tsan")
message(STATUS " Using medium code model (-mcmodel=medium)")
list(APPEND SANITIZERS_COMPILE_FLAGS "-mcmodel=medium")
list(APPEND SANITIZERS_RELOCATION_FLAGS "-mcmodel=medium")
if(is_amd64)
message(STATUS " Using medium code model (-mcmodel=medium)")
list(APPEND SANITIZERS_COMPILE_FLAGS "-mcmodel=medium")
list(APPEND SANITIZERS_RELOCATION_FLAGS "-mcmodel=medium")
endif()
endif()
# Join sanitizer flags with commas for -fsanitize option

View File

@@ -1,5 +1,6 @@
include(default)
{% set compiler, version, compiler_exe = detect_api.detect_default_compiler() %}
{% set arch = detect_api.detect_arch() %}
{% set sanitizers = os.getenv("SANITIZERS") %}
[conf]
@@ -13,12 +14,16 @@ include(default)
{% if "address" in sanitizers %}
{% set _ = sanitizer_list.append("address") %}
{% set model_code = "-mcmodel=large" %}
{% if arch == "x86_64" %}
{% set model_code = "-mcmodel=large" %}
{% endif %}
{% set _ = defines.append("BOOST_USE_ASAN")%}
{% set _ = defines.append("BOOST_USE_UCONTEXT")%}
{% elif "thread" in sanitizers %}
{% set _ = sanitizer_list.append("thread") %}
{% set model_code = "-mcmodel=medium" %}
{% if arch == "x86_64" %}
{% set model_code = "-mcmodel=medium" %}
{% endif %}
{% set _ = extra_cxxflags.append("-Wno-tsan") %}
{% set _ = defines.append("BOOST_USE_TSAN")%}
{% set _ = defines.append("BOOST_USE_UCONTEXT")%}
@@ -82,5 +87,12 @@ tools.info.package_id:confs+=["tools.build:cxxflags", "tools.build:exelinkflags"
boost/*:without_context=False
# Boost stacktrace fails to build with some sanitizers
boost/*:without_stacktrace=True
{% elif "thread" in sanitizers %}
# Build Boost.Context with ucontext backend for TSAN. fcontext (assembly)
# has no TSAN annotations, so without this the BOOST_USE_TSAN/BOOST_USE_UCONTEXT
# defines in [conf] would be ineffective.
boost/*:extra_b2_flags=context-impl=ucontext thread-sanitizer=on define=BOOST_USE_TSAN=1
boost/*:without_context=False
boost/*:without_stacktrace=True
{% endif %}
{% endif %}

View File

@@ -129,12 +129,6 @@ class Xrpl(ConanFile):
if self.settings.compiler in ["clang", "gcc"]:
self.options["boost"].without_cobalt = True
# Check if environment variable exists
if "SANITIZERS" in os.environ:
sanitizers = os.environ["SANITIZERS"]
if "address" in sanitizers.lower():
self.default_options["fPIC"] = False
def requirements(self):
self.requires("boost/1.90.0", force=True, transitive_headers=True)
self.requires("date/3.0.4", transitive_headers=True)

View File

@@ -15,6 +15,7 @@
namespace xrpl {
// DEPRECATED use beast::severities::Severity instead
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum LogSeverity {
lsINVALID = -1, // used to indicate an invalid severity
lsTRACE = 0, // Very low-level progress information, details inside
@@ -207,6 +208,8 @@ public:
fromString(std::string const& s);
private:
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum {
// Maximum line length for log messages.
// If the message exceeds this length it will be truncated with

View File

@@ -131,7 +131,7 @@ public:
* @tparam LockType The type of lock to use
* @return A lock on the mutex and a reference to the protected data
*/
template <template <typename...> typename LockType = std::lock_guard>
template <template <typename...> typename LockType = std::scoped_lock>
Lock<ProtectedDataType const, LockType, MutexType>
lock() const
{
@@ -144,7 +144,7 @@ public:
* @tparam LockType The type of lock to use
* @return A lock on the mutex and a reference to the protected data
*/
template <template <typename...> typename LockType = std::lock_guard>
template <template <typename...> typename LockType = std::scoped_lock>
Lock<ProtectedDataType, LockType, MutexType>
lock()
{

View File

@@ -70,7 +70,7 @@ isPowerOfTen(T value)
struct MantissaRange
{
using rep = std::uint64_t;
enum mantissa_scale { small, large };
enum class mantissa_scale { small, large };
explicit constexpr MantissaRange(mantissa_scale scale_)
: min(getMin(scale_)), log(logTen(min).value_or(-1)), scale(scale_)
@@ -88,9 +88,9 @@ private:
{
switch (scale_)
{
case small:
case mantissa_scale::small:
return 1'000'000'000'000'000ULL;
case large:
case mantissa_scale::large:
return 1'000'000'000'000'000'000ULL;
default:
// Since this can never be called outside a non-constexpr
@@ -384,7 +384,7 @@ public:
root2(Number f);
// Thread local rounding control. Default is to_nearest
enum rounding_mode { to_nearest, towards_zero, downward, upward };
enum class rounding_mode { to_nearest, towards_zero, downward, upward };
static rounding_mode
getround();
// Returns previously set mode
@@ -443,14 +443,14 @@ private:
static thread_local rounding_mode mode_;
// The available ranges for mantissa
constexpr static MantissaRange smallRange{MantissaRange::small};
constexpr static MantissaRange smallRange{MantissaRange::mantissa_scale::small};
static_assert(isPowerOfTen(smallRange.min));
static_assert(smallRange.min == 1'000'000'000'000'000LL);
static_assert(smallRange.max == 9'999'999'999'999'999LL);
static_assert(smallRange.log == 15);
static_assert(smallRange.min < maxRep);
static_assert(smallRange.max < maxRep);
constexpr static MantissaRange largeRange{MantissaRange::large};
constexpr static MantissaRange largeRange{MantissaRange::mantissa_scale::large};
static_assert(isPowerOfTen(largeRange.min));
static_assert(largeRange.min == 1'000'000'000'000'000'000ULL);
static_assert(largeRange.max == internalrep(9'999'999'999'999'999'999ULL));
@@ -759,9 +759,9 @@ to_string(MantissaRange::mantissa_scale const& scale)
{
switch (scale)
{
case MantissaRange::small:
case MantissaRange::mantissa_scale::small:
return "small";
case MantissaRange::large:
case MantissaRange::mantissa_scale::large:
return "large";
default:
throw std::runtime_error("Bad scale");

View File

@@ -92,7 +92,7 @@ class SlabAllocator
std::uint8_t* ret = nullptr; // NOLINT(misc-const-correctness)
{
std::lock_guard const l(m_);
std::scoped_lock const l(m_);
ret = l_;
@@ -121,7 +121,7 @@ class SlabAllocator
{
XRPL_ASSERT(own(ptr), "xrpl::SlabAllocator::SlabBlock::deallocate : own input");
std::lock_guard const l(m_);
std::scoped_lock const l(m_);
// Use memcpy to avoid unaligned UB
// (will optimize to equivalent code)

View File

@@ -166,7 +166,7 @@ public:
private:
SharedPointerType
initialFetch(key_type const& key, std::lock_guard<mutex_type> const& l);
initialFetch(key_type const& key, std::scoped_lock<mutex_type> const& l);
void
collect_metrics();
@@ -266,7 +266,7 @@ private:
typename KeyValueCacheType::map_type& partition,
SweptPointersVector& stuffToSweep,
std::atomic<int>& allRemovals,
std::lock_guard<std::recursive_mutex> const&);
std::scoped_lock<std::recursive_mutex> const&);
[[nodiscard]] std::thread
sweepHelper(
@@ -275,7 +275,7 @@ private:
typename KeyOnlyCacheType::map_type& partition,
SweptPointersVector&,
std::atomic<int>& allRemovals,
std::lock_guard<std::recursive_mutex> const&);
std::scoped_lock<std::recursive_mutex> const&);
beast::Journal m_journal;
clock_type& m_clock;

View File

@@ -69,7 +69,7 @@ inline std::size_t
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
size() const
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
return m_cache.size();
}
@@ -86,7 +86,7 @@ inline int
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
getCacheSize() const
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
return m_cache_count;
}
@@ -103,7 +103,7 @@ inline int
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
getTrackSize() const
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
return m_cache.size();
}
@@ -120,7 +120,7 @@ inline float
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
getHitRate()
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
auto const total = static_cast<float>(m_hits + m_misses);
return m_hits * (100.0f / std::max(1.0f, total));
}
@@ -138,7 +138,7 @@ inline void
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
clear()
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
m_cache.clear();
m_cache_count = 0;
}
@@ -156,7 +156,7 @@ inline void
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
reset()
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
m_cache.clear();
m_cache_count = 0;
m_hits = 0;
@@ -177,7 +177,7 @@ inline bool
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
touch_if_exists(KeyComparable const& key)
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
auto const iter(m_cache.find(key));
if (iter == m_cache.end())
{
@@ -212,7 +212,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
auto const start = std::chrono::steady_clock::now();
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
if (m_target_size == 0 || (static_cast<int>(m_cache.size()) <= m_target_size))
{
@@ -269,7 +269,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
{
// Remove from cache, if !valid, remove from map too. Returns true if
// removed from cache
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
auto cit = m_cache.find(key);
@@ -309,7 +309,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
{
// Return canonical value, store if needed, refresh in cache
// Return values: true=we had the data already
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
auto cit = m_cache.find(key);
@@ -423,7 +423,7 @@ inline SharedPointerType
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
fetch(key_type const& key)
{
std::lock_guard<mutex_type> l(m_mutex);
std::scoped_lock<mutex_type> l(m_mutex);
auto ret = initialFetch(key, l);
if (!ret)
++m_misses;
@@ -474,7 +474,7 @@ inline auto
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
insert(key_type const& key) -> std::enable_if_t<IsKeyCache, ReturnType>
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
clock_type::time_point const now(m_clock.now());
auto [it, inserted] = m_cache.emplace(
std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(now));
@@ -538,7 +538,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
std::vector<key_type> v;
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
v.reserve(m_cache.size());
for (auto const& _ : m_cache)
v.push_back(_.first);
@@ -560,7 +560,7 @@ inline double
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
rate() const
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
auto const tot = m_hits + m_misses;
if (tot == 0)
return 0;
@@ -582,7 +582,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
fetch(key_type const& digest, Handler const& h)
{
{
std::lock_guard l(m_mutex);
std::scoped_lock l(m_mutex);
if (auto ret = initialFetch(digest, l))
return ret;
}
@@ -591,7 +591,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
if (!sle)
return {};
std::lock_guard l(m_mutex);
std::scoped_lock l(m_mutex);
++m_misses;
auto const [it, inserted] = m_cache.emplace(digest, Entry(m_clock.now(), std::move(sle)));
if (!inserted)
@@ -611,7 +611,7 @@ template <
class Mutex>
inline SharedPointerType
TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash, KeyEqual, Mutex>::
initialFetch(key_type const& key, std::lock_guard<mutex_type> const& l)
initialFetch(key_type const& key, std::scoped_lock<mutex_type> const& l)
{
auto cit = m_cache.find(key);
if (cit == m_cache.end())
@@ -655,7 +655,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
{
beast::insight::Gauge::value_type hit_rate(0);
{
std::lock_guard lock(m_mutex);
std::scoped_lock lock(m_mutex);
auto const total(m_hits + m_misses);
if (total != 0)
hit_rate = (m_hits * 100) / total;
@@ -681,7 +681,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
typename KeyValueCacheType::map_type& partition,
SweptPointersVector& stuffToSweep,
std::atomic<int>& allRemovals,
std::lock_guard<std::recursive_mutex> const&)
std::scoped_lock<std::recursive_mutex> const&)
{
return std::thread([&, this]() {
int cacheRemovals = 0;
@@ -761,7 +761,7 @@ TaggedCache<Key, T, IsKeyCache, SharedWeakUnionPointer, SharedPointerType, Hash,
typename KeyOnlyCacheType::map_type& partition,
SweptPointersVector&,
std::atomic<int>& allRemovals,
std::lock_guard<std::recursive_mutex> const&)
std::scoped_lock<std::recursive_mutex> const&)
{
return std::thread([&, this]() {
int cacheRemovals = 0;

View File

@@ -32,7 +32,7 @@ make_seed_pair() noexcept
// state_t& operator=(state_t const&) = delete;
};
static state_t state;
std::lock_guard const lock(state.mutex);
std::scoped_lock const lock(state.mutex);
return {state.dist(state.gen), state.dist(state.gen)};
}

View File

@@ -60,7 +60,7 @@ default_prng()
thread_local beast::xor_shift_engine engine = [] {
std::uint64_t seed = 0;
{
std::lock_guard const lk(m);
std::scoped_lock const lk(m);
std::uniform_int_distribution<std::uint64_t> distribution{1};
seed = distribution(seeder);
}

View File

@@ -83,7 +83,7 @@ public:
void
sample_one(Handler&& handler)
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
if (m_cancel)
throw std::logic_error("io_latency_probe is canceled");
boost::asio::post(
@@ -98,7 +98,7 @@ public:
void
sample(Handler&& handler)
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
if (m_cancel)
throw std::logic_error("io_latency_probe is canceled");
boost::asio::post(
@@ -122,14 +122,14 @@ private:
void
addref()
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
++m_count;
}
void
release()
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
if (--m_count == 0)
m_cond.notify_all();
}
@@ -192,7 +192,7 @@ private:
m_handler(elapsed);
{
std::lock_guard const lock(m_probe->m_mutex);
std::scoped_lock const lock(m_probe->m_mutex);
if (m_probe->m_cancel)
return;
}

View File

@@ -115,7 +115,7 @@ enable_yield_to::spawn(F0&& f, FN&&... fn)
boost::context::fixedsize_stack(2 * 1024 * 1024),
[&](yield_context yield) {
f(yield);
std::lock_guard const lock{m_};
std::scoped_lock const lock{m_};
if (--running_ == 0)
cv_.notify_all();
},

View File

@@ -14,7 +14,7 @@ namespace beast::unit_test {
class selector
{
public:
enum mode_t {
enum class mode_t {
// Run all tests except manual ones
all,
@@ -53,8 +53,8 @@ public:
template <class>
selector::selector(mode_t mode, std::string const& pattern) : mode_(mode), pat_(pattern)
{
if (mode_ == automatch && pattern.empty())
mode_ = all;
if (mode_ == mode_t::automatch && pattern.empty())
mode_ = mode_t::all;
}
template <class>
@@ -63,18 +63,18 @@ selector::operator()(suite_info const& s)
{
switch (mode_)
{
case automatch:
case mode_t::automatch:
// suite or full name
if (s.name() == pat_ || s.full_name() == pat_)
{
mode_ = none;
mode_ = mode_t::none;
return true;
}
// check module
if (pat_ == s.module())
{
mode_ = module;
mode_ = mode_t::module;
library_ = s.library();
return !s.manual();
}
@@ -82,7 +82,7 @@ selector::operator()(suite_info const& s)
// check library
if (pat_ == s.library())
{
mode_ = library;
mode_ = mode_t::library;
return !s.manual();
}
@@ -96,19 +96,19 @@ selector::operator()(suite_info const& s)
return false;
case suite:
case mode_t::suite:
return pat_ == s.name();
case module:
case mode_t::module:
return pat_ == s.module() && !s.manual();
case library:
case mode_t::library:
return pat_ == s.library() && !s.manual();
case none:
case mode_t::none:
return false;
case all:
case mode_t::all:
default:
break;
};
@@ -138,28 +138,28 @@ selector::operator()(suite_info const& s)
inline selector
match_auto(std::string const& name)
{
return selector(selector::automatch, name);
return selector(selector::mode_t::automatch, name);
}
/** Return a predicate that matches all suites not marked manual. */
inline selector
match_all()
{
return selector(selector::all);
return selector(selector::mode_t::all);
}
/** Returns a predicate that matches a specific suite. */
inline selector
match_suite(std::string const& name)
{
return selector(selector::suite, name);
return selector(selector::mode_t::suite, name);
}
/** Returns a predicate that matches all suites in a library. */
inline selector
match_library(std::string const& name)
{
return selector(selector::library, name);
return selector(selector::mode_t::library, name);
}
} // namespace beast::unit_test

View File

@@ -62,6 +62,8 @@ private:
{
using run_time = std::pair<std::string, typename clock_type::duration>;
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum { max_top = 10 };
std::size_t suites = 0;

View File

@@ -231,7 +231,7 @@ template <class>
void
runner::testcase(std::string const& name)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
// Name may not be empty
BOOST_ASSERT(default_ || !name.empty());
// Forgot to call pass or fail
@@ -247,7 +247,7 @@ template <class>
void
runner::pass()
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
if (default_)
testcase("");
on_pass();
@@ -258,7 +258,7 @@ template <class>
void
runner::fail(std::string const& reason)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
if (default_)
testcase("");
on_fail(reason);
@@ -270,7 +270,7 @@ template <class>
void
runner::log(std::string const& s)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
if (default_)
testcase("");
on_log(s);

View File

@@ -37,7 +37,7 @@ make_reason(String const& reason, char const* file, int line)
class Thread;
enum abort_t { no_abort_on_fail, abort_on_fail };
enum class abort_t { no_abort_on_fail, abort_on_fail };
/** A testsuite class.
@@ -127,7 +127,7 @@ private:
@param abort Determines if suite continues running after a failure.
*/
void
operator()(std::string const& name, abort_t abort = no_abort_on_fail);
operator()(std::string const& name, abort_t abort = abort_t::no_abort_on_fail);
scoped_testcase
operator()(abort_t abort);
@@ -363,14 +363,14 @@ public:
inline void
suite::testcase_t::operator()(std::string const& name, abort_t abort)
{
suite_.abort_ = abort == abort_on_fail;
suite_.abort_ = abort == abort_t::abort_on_fail;
suite_.runner_->testcase(name);
}
inline suite::scoped_testcase
suite::testcase_t::operator()(abort_t abort)
{
suite_.abort_ = abort == abort_on_fail;
suite_.abort_ = abort == abort_t::abort_on_fail;
return {suite_, ss_};
}

View File

@@ -9,6 +9,8 @@ namespace beast {
/** A namespace for easy access to logging severity values. */
namespace severities {
/** Severity level / threshold of a Journal message. */
// Hundreds of usages via logging macros
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum Severity {
kAll = 0,

View File

@@ -56,7 +56,7 @@ private:
// a lock. This removes a small timing window that occurs if the
// waiting thread is handling a spurious wakeup when closureCount_
// drops to zero.
std::lock_guard const lock{mutex_};
std::scoped_lock const lock{mutex_};
// Update closureCount_. Notify if stopping and closureCount_ == 0.
if ((--closureCount_ == 0) && waitForClosures_)
@@ -170,7 +170,7 @@ public:
{
std::optional<Substitute<Closure>> ret;
std::lock_guard const lock{mutex_};
std::scoped_lock const lock{mutex_};
if (!waitForClosures_)
ret.emplace(*this, std::forward<Closure>(closure));
@@ -193,7 +193,7 @@ public:
bool
joined() const
{
std::lock_guard const lock{mutex_};
std::scoped_lock const lock{mutex_};
return waitForClosures_;
}
};

View File

@@ -2,17 +2,19 @@
namespace xrpl {
/// Coroutine stack size (1.5 MB). Increased from 1 MB because
/// ASAN-instrumented deep call stacks exceeded the original limit.
constexpr std::size_t coroStackSize = 1536 * 1024;
template <class F>
JobQueue::Coro::Coro(Coro_create_t, JobQueue& jq, JobType type, std::string const& name, F&& f)
: jq_(jq)
, type_(type)
, name_(name)
, coro_(
// Stack size of 1MB wasn't sufficient for deep calls. ASAN tests flagged the issue. Hence
// increasing the size to 1.5MB.
boost::context::protected_fixedsize_stack(1536 * 1024),
[this, fn = std::forward<F>(f)](
boost::coroutines2::asymmetric_coroutine<void>::push_type& do_yield) {
boost::context::protected_fixedsize_stack(coroStackSize),
[this,
fn = std::forward<F>(f)](boost::coroutines2::coroutine<void>::push_type& do_yield) {
yield_ = &do_yield;
yield();
fn(shared_from_this());
@@ -34,7 +36,7 @@ inline void
JobQueue::Coro::yield() const
{
{
std::lock_guard lock(jq_.m_mutex);
std::scoped_lock lock(jq_.m_mutex);
++jq_.nSuspend_;
}
(*yield_)();
@@ -44,7 +46,7 @@ inline bool
JobQueue::Coro::post()
{
{
std::lock_guard lk(mutex_run_);
std::scoped_lock lk(mutex_run_);
running_ = true;
}
@@ -55,7 +57,7 @@ JobQueue::Coro::post()
}
// The coroutine will not run. Clean up running_.
std::lock_guard lk(mutex_run_);
std::scoped_lock lk(mutex_run_);
running_ = false;
cv_.notify_all();
return false;
@@ -65,16 +67,16 @@ inline void
JobQueue::Coro::resume()
{
{
std::lock_guard lk(mutex_run_);
std::scoped_lock lk(mutex_run_);
running_ = true;
}
{
std::lock_guard lk(jq_.m_mutex);
std::scoped_lock lk(jq_.m_mutex);
--jq_.nSuspend_;
}
auto saved = detail::getLocalValues().release();
detail::getLocalValues().reset(&lvs_);
std::lock_guard lock(mutex_);
std::scoped_lock lock(mutex_);
// A late resume() can arrive after the coroutine has already completed.
// This is an expected (if rare) outcome of the race condition documented
// in JobQueue.h:354-377 where post() schedules a resume job before the
@@ -89,7 +91,7 @@ JobQueue::Coro::resume()
}
detail::getLocalValues().release();
detail::getLocalValues().reset(saved);
std::lock_guard lk(mutex_run_);
std::scoped_lock lk(mutex_run_);
running_ = false;
cv_.notify_all();
}
@@ -113,7 +115,7 @@ JobQueue::Coro::expectEarlyExit()
//
// That said, since we're outside the Coro's stack, we need to
// decrement the nSuspend that the Coro's call to yield caused.
std::lock_guard lock(jq_.m_mutex);
std::scoped_lock lock(jq_.m_mutex);
--jq_.nSuspend_;
#ifndef NDEBUG
finished_ = true;

View File

@@ -11,6 +11,8 @@ namespace xrpl {
// Note that this queue should only be used for CPU-bound jobs
// It is primarily intended for signature checking
// Protocol-wide
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum JobType {
// Special type indicating an invalid job - will go away soon.
jtINVALID = -1,

View File

@@ -67,7 +67,7 @@ public:
bool
contains(PublicKey const& nodeId)
{
std::lock_guard const lock(this->mutex_);
std::scoped_lock const lock(this->mutex_);
return table_.contains({.nodeId = nodeId, .description = {}});
}

View File

@@ -55,7 +55,7 @@ public:
void
notify()
{
std::lock_guard const lock{m_mutex};
std::scoped_lock const lock{m_mutex};
++m_count;
m_cond.notify_one();
}
@@ -76,7 +76,7 @@ public:
bool
try_wait()
{
std::lock_guard lock{m_mutex};
std::scoped_lock lock{m_mutex};
if (m_count == 0)
return false;
--m_count;

View File

@@ -107,7 +107,7 @@ namespace Json {
class Writer
{
public:
enum CollectionType { array, object };
enum class CollectionType { array, object };
explicit Writer(Output const& output);
Writer(Writer&&) noexcept;

View File

@@ -70,6 +70,8 @@ public:
static constexpr unsigned nest_limit{25};
private:
// 53 files, protocol-wide
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TokenType {
tokenEndOfStream = 0,
tokenObjectBegin,

View File

@@ -15,6 +15,8 @@ namespace Json {
/** \brief Type of the value held by a Value object.
*/
// Used throughout JSON layer
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum ValueType {
nullValue = 0, ///< 'null' value
intValue, ///< signed integer value
@@ -147,6 +149,8 @@ private:
class CZString
{
public:
// Stored as int field, implicit conversion
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum DuplicationPolicy { noDuplication = 0, duplicate, duplicateOnCopy };
CZString(int index);
CZString(char const* cstr, DuplicationPolicy allocate);
@@ -471,6 +475,8 @@ operator>=(Value const& x, Value const& y)
class ValueAllocator
{
public:
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum { unknown = (unsigned)-1 };
virtual ~ValueAllocator() = default;

View File

@@ -7,6 +7,8 @@
namespace xrpl {
// Bitwise flag enum with existing operator overloads
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum ApplyFlags : std::uint32_t {
tapNONE = 0x00,

View File

@@ -229,19 +229,6 @@ public:
std::shared_ptr<Serializer const> const& txn,
std::shared_ptr<Serializer const> const& metaData) override;
// Insert the transaction, and return the hash of the SHAMap leaf node
// holding the transaction. The hash can be used to fetch the transaction
// directly, instead of traversing the SHAMap
// @param key transaction ID
// @param txn transaction
// @param metaData transaction metadata
// @return hash of SHAMap leaf node that holds the transaction
uint256
rawTxInsertWithHash(
uint256 const& key,
std::shared_ptr<Serializer const> const& txn,
std::shared_ptr<Serializer const> const& metaData);
//--------------------------------------------------------------------------
void

View File

@@ -31,7 +31,7 @@ public:
bool
startWork(LedgerIndex seq)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
auto it = map_.find(seq);
@@ -54,7 +54,7 @@ public:
void
finishWork(LedgerIndex seq)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
map_.erase(seq);
await_.notify_all();
@@ -64,7 +64,7 @@ public:
bool
pending(LedgerIndex seq)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
return map_.contains(seq);
}
@@ -117,7 +117,7 @@ public:
std::map<LedgerIndex, bool>
getSnapshot() const
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
return map_;
}

View File

@@ -28,7 +28,7 @@ reduceOffer(auto const& amount)
static Number const reducedOfferPct(9999, -4);
// Make sure the result is always less than amount or zero.
NumberRoundModeGuard const mg(Number::towards_zero);
NumberRoundModeGuard const mg(Number::rounding_mode::towards_zero);
return amount * reducedOfferPct;
}
@@ -180,7 +180,7 @@ getAMMOfferStartWithTakerGets(
if (targetQuality.rate() == beast::zero)
return std::nullopt;
NumberRoundModeGuard const mg(Number::to_nearest);
NumberRoundModeGuard const mg(Number::rounding_mode::to_nearest);
auto const f = feeMult(tfee);
auto const a = 1;
auto const b = pool.in * (1 - 1 / f) / targetQuality.rate() - 2 * pool.out;
@@ -202,7 +202,7 @@ getAMMOfferStartWithTakerGets(
// Round downward to minimize the offer and to maximize the quality.
// This has the most impact when takerGets is XRP.
auto const takerGets =
toAmount<TOut>(getAsset(pool.out), nTakerGetsProposed, Number::downward);
toAmount<TOut>(getAsset(pool.out), nTakerGetsProposed, Number::rounding_mode::downward);
return TAmounts<TIn, TOut>{swapAssetOut(pool, takerGets, tfee), takerGets};
};
@@ -247,7 +247,7 @@ getAMMOfferStartWithTakerPays(
if (targetQuality.rate() == beast::zero)
return std::nullopt;
NumberRoundModeGuard const mg(Number::to_nearest);
NumberRoundModeGuard const mg(Number::rounding_mode::to_nearest);
auto const f = feeMult(tfee);
auto const& a = f;
auto const b = pool.in * (1 + f);
@@ -269,7 +269,7 @@ getAMMOfferStartWithTakerPays(
// Round downward to minimize the offer and to maximize the quality.
// This has the most impact when takerPays is XRP.
auto const takerPays =
toAmount<TIn>(getAsset(pool.in), nTakerPaysProposed, Number::downward);
toAmount<TIn>(getAsset(pool.in), nTakerPaysProposed, Number::rounding_mode::downward);
return TAmounts<TIn, TOut>{takerPays, swapAssetIn(pool, takerPays, tfee)};
};
@@ -341,7 +341,8 @@ changeSpotPriceQuality(
<< " " << to_string(pool.out) << " " << quality << " " << tfee;
return std::nullopt;
}
auto const takerPays = toAmount<TIn>(getAsset(pool.in), nTakerPays, Number::upward);
auto const takerPays =
toAmount<TIn>(getAsset(pool.in), nTakerPays, Number::rounding_mode::upward);
// should not fail
if (auto amounts = TAmounts<TIn, TOut>{takerPays, swapAssetIn(pool, takerPays, tfee)};
Quality{amounts} < quality &&
@@ -447,32 +448,32 @@ swapAssetIn(TAmounts<TIn, TOut> const& pool, TIn const& assetIn, std::uint16_t t
// fee
saveNumberRoundMode const _{Number::getround()};
Number::setround(Number::upward);
Number::setround(Number::rounding_mode::upward);
auto const numerator = pool.in * pool.out;
auto const fee = getFee(tfee);
Number::setround(Number::downward);
Number::setround(Number::rounding_mode::downward);
auto const denom = pool.in + assetIn * (1 - fee);
if (denom.signum() <= 0)
return toAmount<TOut>(getAsset(pool.out), 0);
Number::setround(Number::upward);
Number::setround(Number::rounding_mode::upward);
auto const ratio = numerator / denom;
Number::setround(Number::downward);
Number::setround(Number::rounding_mode::downward);
auto const swapOut = pool.out - ratio;
if (swapOut.signum() < 0)
return toAmount<TOut>(getAsset(pool.out), 0);
return toAmount<TOut>(getAsset(pool.out), swapOut, Number::downward);
return toAmount<TOut>(getAsset(pool.out), swapOut, Number::rounding_mode::downward);
}
return toAmount<TOut>(
getAsset(pool.out),
pool.out - (pool.in * pool.out) / (pool.in + assetIn * feeMult(tfee)),
Number::downward);
Number::rounding_mode::downward);
}
/** Swap assetOut out of the pool and swap in a proportional amount
@@ -509,36 +510,36 @@ swapAssetOut(TAmounts<TIn, TOut> const& pool, TOut const& assetOut, std::uint16_
saveNumberRoundMode const _{Number::getround()};
Number::setround(Number::upward);
Number::setround(Number::rounding_mode::upward);
auto const numerator = pool.in * pool.out;
Number::setround(Number::downward);
Number::setround(Number::rounding_mode::downward);
auto const denom = pool.out - assetOut;
if (denom.signum() <= 0)
{
return toMaxAmount<TIn>(getAsset(pool.in));
}
Number::setround(Number::upward);
Number::setround(Number::rounding_mode::upward);
auto const ratio = numerator / denom;
auto const numerator2 = ratio - pool.in;
auto const fee = getFee(tfee);
Number::setround(Number::downward);
Number::setround(Number::rounding_mode::downward);
auto const feeMult = 1 - fee;
Number::setround(Number::upward);
Number::setround(Number::rounding_mode::upward);
auto const swapIn = numerator2 / feeMult;
if (swapIn.signum() < 0)
return toAmount<TIn>(getAsset(pool.in), 0);
return toAmount<TIn>(getAsset(pool.in), swapIn, Number::upward);
return toAmount<TIn>(getAsset(pool.in), swapIn, Number::rounding_mode::upward);
}
return toAmount<TIn>(
getAsset(pool.in),
((pool.in * pool.out) / (pool.out - assetOut) - pool.in) / feeMult(tfee),
Number::upward);
Number::rounding_mode::upward);
}
/** Return square of n.
@@ -597,7 +598,8 @@ getLPTokenRounding(IsDeposit isDeposit)
{
// Minimize on deposit, maximize on withdraw to ensure
// AMM invariant sqrt(poolAsset1 * poolAsset2) >= LPTokensBalance
return isDeposit == IsDeposit::Yes ? Number::downward : Number::upward;
return isDeposit == IsDeposit::Yes ? Number::rounding_mode::downward
: Number::rounding_mode::upward;
}
inline Number::rounding_mode
@@ -605,7 +607,8 @@ getAssetRounding(IsDeposit isDeposit)
{
// Maximize on deposit, minimize on withdraw to ensure
// AMM invariant sqrt(poolAsset1 * poolAsset2) >= LPTokensBalance
return isDeposit == IsDeposit::Yes ? Number::upward : Number::downward;
return isDeposit == IsDeposit::Yes ? Number::rounding_mode::upward
: Number::rounding_mode::downward;
}
} // namespace detail

View File

@@ -19,7 +19,7 @@ loanPeriodicRate(TenthBips32 interestRate, std::uint32_t paymentInterval);
inline Number
roundPeriodicPayment(Asset const& asset, Number const& periodicPayment, std::int32_t scale)
{
return roundToAsset(asset, periodicPayment, scale, Number::upward);
return roundToAsset(asset, periodicPayment, scale, Number::rounding_mode::upward);
}
/* Represents the breakdown of amounts to be paid and changes applied to the

View File

@@ -21,13 +21,13 @@ namespace xrpl {
//------------------------------------------------------------------------------
/** Controls the treatment of frozen account balances */
enum FreezeHandling { fhIGNORE_FREEZE, fhZERO_IF_FROZEN };
enum class FreezeHandling { fhIGNORE_FREEZE, fhZERO_IF_FROZEN };
/** Controls the treatment of unauthorized MPT balances */
enum AuthHandling { ahIGNORE_AUTH, ahZERO_IF_UNAUTHORIZED };
enum class AuthHandling { ahIGNORE_AUTH, ahZERO_IF_UNAUTHORIZED };
/** Controls whether to include the account's full spendable balance */
enum SpendableHandling { shSIMPLE_BALANCE, shFULL_BALANCE };
enum class SpendableHandling { shSIMPLE_BALANCE, shFULL_BALANCE };
enum class WaiveTransferFee : bool { No = false, Yes };
@@ -135,7 +135,7 @@ accountHolds(
AccountID const& issuer,
FreezeHandling zeroIfFrozen,
beast::Journal j,
SpendableHandling includeFullBalance = shSIMPLE_BALANCE);
SpendableHandling includeFullBalance = SpendableHandling::shSIMPLE_BALANCE);
[[nodiscard]] STAmount
accountHolds(
@@ -144,7 +144,7 @@ accountHolds(
Issue const& issue,
FreezeHandling zeroIfFrozen,
beast::Journal j,
SpendableHandling includeFullBalance = shSIMPLE_BALANCE);
SpendableHandling includeFullBalance = SpendableHandling::shSIMPLE_BALANCE);
[[nodiscard]] STAmount
accountHolds(
@@ -154,7 +154,7 @@ accountHolds(
FreezeHandling zeroIfFrozen,
AuthHandling zeroIfUnauthorized,
beast::Journal j,
SpendableHandling includeFullBalance = shSIMPLE_BALANCE);
SpendableHandling includeFullBalance = SpendableHandling::shSIMPLE_BALANCE);
[[nodiscard]] STAmount
accountHolds(
@@ -164,7 +164,7 @@ accountHolds(
FreezeHandling zeroIfFrozen,
AuthHandling zeroIfUnauthorized,
beast::Journal j,
SpendableHandling includeFullBalance = shSIMPLE_BALANCE);
SpendableHandling includeFullBalance = SpendableHandling::shSIMPLE_BALANCE);
// Returns the amount an account can spend of the currency type saDefault, or
// returns saDefault if this account is the issuer of the currency in

View File

@@ -9,7 +9,7 @@
namespace xrpl {
/** The types of node objects. */
enum NodeObjectType : std::uint32_t {
enum class NodeObjectType : std::uint32_t {
hotUNKNOWN = 0,
hotLEDGER = 1,
hotACCOUNT_NODE = 3,

View File

@@ -6,6 +6,8 @@
namespace xrpl::NodeStore {
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum {
// This is only used to pre-allocate the array for
// batch objects and does not affect the amount written.
@@ -20,7 +22,7 @@ enum {
};
/** Return codes from Backend operations. */
enum Status {
enum class Status {
ok = 0,
notFound = 1,
dataCorrupt = 2,

View File

@@ -127,7 +127,7 @@ nodeobject_decompress(void const* in, std::size_t in_size, BufferFactory&& bf)
ostream os(out, result.second);
write<std::uint32_t>(os, 0);
write<std::uint32_t>(os, 0);
write<std::uint8_t>(os, hotUNKNOWN);
write<std::uint8_t>(os, static_cast<std::uint8_t>(NodeObjectType::hotUNKNOWN));
write<std::uint32_t>(os, static_cast<std::uint32_t>(HashPrefix::innerNode));
if (mask == 0)
Throw<std::runtime_error>("nodeobject codec v1: empty inner node");
@@ -173,7 +173,7 @@ nodeobject_decompress(void const* in, std::size_t in_size, BufferFactory&& bf)
ostream os(out, result.second);
write<std::uint32_t>(os, 0);
write<std::uint32_t>(os, 0);
write<std::uint8_t>(os, hotUNKNOWN);
write<std::uint8_t>(os, static_cast<std::uint8_t>(NodeObjectType::hotUNKNOWN));
write<std::uint32_t>(os, static_cast<std::uint32_t>(HashPrefix::innerNode));
write(os, is(512), 512);
break;
@@ -307,7 +307,7 @@ filter_inner(void* in, std::size_t in_size)
ostream os(in, 9);
write<std::uint32_t>(os, 0);
write<std::uint32_t>(os, 0);
write<std::uint8_t>(os, hotUNKNOWN);
write<std::uint8_t>(os, static_cast<std::uint8_t>(NodeObjectType::hotUNKNOWN));
}
}
}

View File

@@ -17,6 +17,8 @@ namespace xrpl {
//
// Please only append to this table. Do not "fill-in" gaps and do not re-use
// or repurpose error code values.
// Protocol-wide, 50+ files
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum error_code_i {
// -1 represents codes not listed in this enumeration
rpcUNKNOWN = -1,
@@ -148,6 +150,8 @@ enum error_code_i {
These values need to remain stable.
*/
// Protocol-wide, 50+ files
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum warning_code_i {
warnRPC_UNSUPPORTED_MAJORITY = 1001,
warnRPC_AMENDMENT_BLOCKED = 1002,

View File

@@ -29,6 +29,8 @@ namespace xrpl {
@ingroup protocol
*/
// Protocol-critical, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum LedgerEntryType : std::uint16_t {
#pragma push_macro("LEDGER_ENTRY")
@@ -214,6 +216,8 @@ enum LedgerEntryType : std::uint16_t {
#define TO_VALUE(name, value) name = (value),
#define NULL_NAME(name, values) values
#define NULL_OUTPUT(name, value)
// Bitwise flag enum
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum LedgerSpecificFlags : std::uint32_t { XMACRO(NULL_NAME, TO_VALUE, NULL_OUTPUT) };
// Create getter functions for each set of flags using Meyer's singleton pattern.

View File

@@ -66,8 +66,7 @@ struct MultiApiJson
a[key] = v;
}
// Intentionally not using class enum here, MultivarJson is scope enough
enum IsMemberResult : int { none = 0, some, all };
enum class IsMemberResult : int { none = 0, some, all };
[[nodiscard]] IsMemberResult
isMember(char const* key) const
@@ -80,8 +79,8 @@ struct MultiApiJson
}
if (count == 0)
return none;
return count < size ? some : all;
return IsMemberResult::none;
return count < size ? IsMemberResult::some : IsMemberResult::all;
}
static constexpr struct visitor_t final

View File

@@ -16,6 +16,8 @@ namespace xrpl {
* conflicts with TxType, the GranularPermissionType is always set to a value
* greater than the maximum value of uint16.
*/
// Macro-generated, complex
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum GranularPermissionType : std::uint32_t {
#pragma push_macro("PERMISSION")
#undef PERMISSION
@@ -28,6 +30,9 @@ enum GranularPermissionType : std::uint32_t {
#pragma pop_macro("PERMISSION")
};
// Injected bare enumerators (xrpl::delegable / xrpl::notDelegable) are required by preprocessor
// tricks in tests and macro-generated code; enum class would break that.
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum Delegation { delegable, notDelegable };
class Permission

View File

@@ -8,6 +8,21 @@
namespace xrpl {
/** Check whether a feature is enabled in the current ledger rules
*
* @param feature The feature to be tested.
* @param resultIfNoRules What to return if called from outside a Transactor context.
*/
bool
isFeatureEnabled(uint256 const& feature, bool resultIfNoRules);
/** Check whether a feature is enabled in the current ledger rules
*
* @param feature The feature to be tested.
*
* Returns false if no global Rules object is available. i.e. Outside of
* a Transactor context
*/
bool
isFeatureEnabled(uint256 const& feature);

View File

@@ -87,6 +87,8 @@ class STCurrency;
#define TO_ENUM(name, value) name = (value),
#define TO_MAP(name, value) {#name, value},
// Protocol infrastructure, 39+ files
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum SerializedTypeID { XMACRO(TO_ENUM) };
static std::map<std::string, int> const sTypeMap = {XMACRO(TO_MAP)};
@@ -125,6 +127,8 @@ field_code(int id, int index)
class SField
{
public:
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum {
sMD_Never = 0x00,
sMD_ChangeOrig = 0x01, // original value when it changes

View File

@@ -11,6 +11,8 @@
namespace xrpl {
/** Kind of element in each entry of an SOTemplate. */
// 2026 usages, 129 files
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum SOEStyle {
soeINVALID = -1,
soeREQUIRED = 0, // required
@@ -20,7 +22,8 @@ enum SOEStyle {
// constructed with STObject::makeInnerObject()
};
/** Amount fields that can support MPT */
// Part of a Python-parsed DSL (transactions.macro); bare enumerator names required by the parser
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum SOETxMPTIssue { soeMPTNone, soeMPTSupported, soeMPTNotSupported };
//------------------------------------------------------------------------------

View File

@@ -319,7 +319,7 @@ STAmount::STAmount(
: STBase(name), mAsset(asset), mValue(mantissa), mOffset(exponent), mIsNegative(negative)
{
// mValue is uint64, but needs to fit in the range of int64
if (Number::getMantissaScale() == MantissaRange::small)
if (Number::getMantissaScale() == MantissaRange::mantissa_scale::small)
{
XRPL_ASSERT(
mValue <= std::numeric_limits<std::int64_t>::max(),

View File

@@ -18,6 +18,8 @@ struct JsonOptions
using underlying_t = unsigned int;
underlying_t value;
// Bitwise flags with operator~
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum values : underlying_t {
// clang-format off
none = 0b0000'0000,

View File

@@ -413,9 +413,9 @@ public:
class FieldErr;
private:
enum WhichFields : bool {
enum class WhichFields : bool {
// These values are carefully chosen to do the right thing if passed
// to SField::shouldInclude (bool)
// to SField::shouldInclude (bool) via static_cast<bool>
omitSigningFields = false,
withAllFields = true
};
@@ -987,7 +987,7 @@ STObject::isFree() const
inline void
STObject::addWithoutSigningFields(Serializer& s) const
{
add(s, omitSigningFields);
add(s, WhichFields::omitSigningFields);
}
// VFALCO NOTE does this return an expensive copy of an object with a
@@ -997,7 +997,7 @@ inline Serializer
STObject::getSerializer() const
{
Serializer s;
add(s, withAllFields);
add(s, WhichFields::withAllFields);
return s;
}

View File

@@ -25,6 +25,8 @@ class STPathElement final : public CountedObject<STPathElement>
std::size_t hash_value_;
public:
// Bitwise values (typeCurrency | typeMPT)
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum Type {
typeNone = 0x00,
typeAccount = 0x01, // Rippling through an account (vs taking an offer).

View File

@@ -35,7 +35,7 @@ namespace xrpl {
class SeqProxy
{
public:
enum Type : std::uint8_t { seq = 0, ticket };
enum class Type : std::uint8_t { seq = 0, ticket };
private:
std::uint32_t value_;
@@ -67,13 +67,13 @@ public:
[[nodiscard]] constexpr bool
isSeq() const
{
return type_ == seq;
return type_ == Type::seq;
}
[[nodiscard]] constexpr bool
isTicket() const
{
return type_ == ticket;
return type_ == Type::ticket;
}
// Occasionally it is convenient to be able to increase the value_

View File

@@ -19,6 +19,8 @@ using TERUnderlyingType = int;
//------------------------------------------------------------------------------
// Protocol-critical, mixed with custom TER wrapper type, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TELcodes : TERUnderlyingType {
// Note: Range is stable.
// Exact numbers are used in ripple-binary-codec:
@@ -50,6 +52,8 @@ enum TELcodes : TERUnderlyingType {
//------------------------------------------------------------------------------
// Protocol-critical, mixed with custom TER wrapper type, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TEMcodes : TERUnderlyingType {
// Note: Range is stable.
// Exact numbers are used in ripple-binary-codec:
@@ -126,6 +130,8 @@ enum TEMcodes : TERUnderlyingType {
//------------------------------------------------------------------------------
// Protocol-critical, mixed with custom TER wrapper type, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TEFcodes : TERUnderlyingType {
// Note: Range is stable.
// Exact numbers are used in ripple-binary-codec:
@@ -170,6 +176,8 @@ enum TEFcodes : TERUnderlyingType {
//------------------------------------------------------------------------------
// Protocol-critical, mixed with custom TER wrapper type, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TERcodes : TERUnderlyingType {
// Note: Range is stable.
// Exact numbers are used in ripple-binary-codec:
@@ -214,6 +222,8 @@ enum TERcodes : TERUnderlyingType {
//------------------------------------------------------------------------------
// Protocol-critical, mixed with custom TER wrapper type, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TEScodes : TERUnderlyingType {
// Note: Exact number must stay stable. This code is stored by value
// in metadata for historic transactions.
@@ -229,6 +239,8 @@ enum TEScodes : TERUnderlyingType {
//------------------------------------------------------------------------------
// Protocol-critical, mixed with custom TER wrapper type, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TECcodes : TERUnderlyingType {
// Note: Exact numbers must stay stable. These codes are stored by
// value in metadata for historic transactions.

View File

@@ -35,6 +35,8 @@ namespace xrpl {
@ingroup protocol
*/
// clang-format off
// Protocol-critical, hundreds of usages
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum TxType : std::uint16_t
{

View File

@@ -19,7 +19,6 @@ XRPL_FIX (Cleanup3_2_0, Supported::no, VoteBehavior::DefaultNo
XRPL_FEATURE(MPTokensV2, Supported::no, VoteBehavior::DefaultNo)
XRPL_FIX (Security3_1_3, Supported::no, VoteBehavior::DefaultNo)
XRPL_FIX (PermissionedDomainInvariant, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FIX (ExpiredNFTokenOfferRemoval, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FIX (BatchInnerSigs, Supported::no, VoteBehavior::DefaultNo)
XRPL_FEATURE(LendingProtocol, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(PermissionDelegationV1_1, Supported::no, VoteBehavior::DefaultNo)

View File

@@ -466,6 +466,7 @@ LEDGER_ENTRY(ltDELEGATE, 0x0083, Delegate, delegate, ({
{sfAuthorize, soeREQUIRED},
{sfPermissions, soeREQUIRED},
{sfOwnerNode, soeREQUIRED},
{sfDestinationNode, soeOPTIONAL},
{sfPreviousTxnID, soeREQUIRED},
{sfPreviousTxnLgrSeq, soeREQUIRED},
}))

View File

@@ -90,6 +90,30 @@ public:
return this->sle_->at(sfOwnerNode);
}
/**
* @brief Get sfDestinationNode (soeOPTIONAL)
* @return The field value, or std::nullopt if not present.
*/
[[nodiscard]]
protocol_autogen::Optional<SF_UINT64::type::value_type>
getDestinationNode() const
{
if (hasDestinationNode())
return this->sle_->at(sfDestinationNode);
return std::nullopt;
}
/**
* @brief Check if sfDestinationNode is present.
* @return True if the field is present, false otherwise.
*/
[[nodiscard]]
bool
hasDestinationNode() const
{
return this->sle_->isFieldPresent(sfDestinationNode);
}
/**
* @brief Get sfPreviousTxnID (soeREQUIRED)
* @return The field value.
@@ -203,6 +227,17 @@ public:
return *this;
}
/**
* @brief Set sfDestinationNode (soeOPTIONAL)
* @return Reference to this builder for method chaining.
*/
DelegateBuilder&
setDestinationNode(std::decay_t<typename SF_UINT64::type::value_type> const& value)
{
object_[sfDestinationNode] = value;
return *this;
}
/**
* @brief Set sfPreviousTxnID (soeREQUIRED)
* @return Reference to this builder for method chaining.

View File

@@ -3,7 +3,7 @@
namespace xrpl::Resource {
/** The disposition of a consumer after applying a load charge. */
enum Disposition {
enum class Disposition {
/** No action required. */
ok

View File

@@ -39,7 +39,7 @@ struct Entry : public beast::List<Entry>::Node
[[nodiscard]] bool
isUnlimited() const
{
return key->kind == kindUnlimited;
return key->kind == Kind::kindUnlimited;
}
// Balance including remote contributions

View File

@@ -10,6 +10,6 @@ namespace xrpl::Resource {
* subjected to administrative restrictions, such as
* use of some RPC commands like "stop".
*/
enum Kind { kindInbound, kindOutbound, kindUnlimited };
enum class Kind { kindInbound, kindOutbound, kindUnlimited };
} // namespace xrpl::Resource

View File

@@ -92,11 +92,11 @@ public:
Entry* entry(nullptr);
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
auto [resultIt, resultInserted] = table_.emplace(
std::piecewise_construct,
std::make_tuple(kindInbound, address.at_port(0)), // Key
std::make_tuple(m_clock.now())); // Entry
std::make_tuple(Kind::kindInbound, address.at_port(0)), // Key
std::make_tuple(m_clock.now())); // Entry
entry = &resultIt->second;
entry->key = &resultIt->first;
@@ -122,11 +122,11 @@ public:
Entry* entry(nullptr);
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
auto [resultIt, resultInserted] = table_.emplace(
std::piecewise_construct,
std::make_tuple(kindOutbound, address), // Key
std::make_tuple(m_clock.now())); // Entry
std::make_tuple(Kind::kindOutbound, address), // Key
std::make_tuple(m_clock.now())); // Entry
entry = &resultIt->second;
entry->key = &resultIt->first;
@@ -155,11 +155,11 @@ public:
Entry* entry(nullptr);
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
auto [resultIt, resultInserted] = table_.emplace(
std::piecewise_construct,
std::make_tuple(kindUnlimited, address.at_port(1)), // Key
std::make_tuple(m_clock.now())); // Entry
std::make_tuple(Kind::kindUnlimited, address.at_port(1)), // Key
std::make_tuple(m_clock.now())); // Entry
entry = &resultIt->second;
entry->key = &resultIt->first;
@@ -190,7 +190,7 @@ public:
clock_type::time_point const now(m_clock.now());
Json::Value ret(Json::objectValue);
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
for (auto& inboundEntry : inbound_)
{
@@ -235,7 +235,7 @@ public:
clock_type::time_point const now(m_clock.now());
Gossip gossip;
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
gossip.items.reserve(inbound_.size());
@@ -260,7 +260,7 @@ public:
{
auto const elapsed = m_clock.now();
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
auto [resultIt, resultInserted] = importTable_.emplace(
std::piecewise_construct,
std::make_tuple(origin), // Key
@@ -317,7 +317,7 @@ public:
void
periodicActivity()
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
auto const elapsed = m_clock.now();
@@ -375,7 +375,7 @@ public:
void
erase(Table::iterator iter)
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
Entry& entry(iter->second);
XRPL_ASSERT(entry.refcount == 0, "xrpl::Resource::Logic::erase : entry not used");
inactive_.erase(inactive_.iterator_to(entry));
@@ -385,27 +385,27 @@ public:
void
acquire(Entry& entry)
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
++entry.refcount;
}
void
release(Entry& entry)
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
if (--entry.refcount == 0)
{
JLOG(m_journal.debug()) << "Inactive " << entry;
switch (entry.key->kind)
{
case kindInbound:
case Kind::kindInbound:
inbound_.erase(inbound_.iterator_to(entry));
break;
case kindOutbound:
case Kind::kindOutbound:
outbound_.erase(outbound_.iterator_to(entry));
break;
case kindUnlimited:
case Kind::kindUnlimited:
admin_.erase(admin_.iterator_to(entry));
break;
default:
@@ -443,7 +443,7 @@ public:
if (!context.empty())
context = " (" + context + ")";
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
clock_type::time_point const now(m_clock.now());
int const balance(entry.add(fee.cost(), now));
JLOG(getStream(fee.cost(), m_journal)) << "Charging " << entry << " for " << fee << context;
@@ -456,7 +456,7 @@ public:
if (entry.isUnlimited())
return false;
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
bool notify(false);
auto const elapsed = m_clock.now();
if (entry.balance(m_clock.now()) >= warningThreshold && elapsed != entry.lastWarningTime)
@@ -479,7 +479,7 @@ public:
if (entry.isUnlimited())
return false;
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
bool drop(false);
clock_type::time_point const now(m_clock.now());
int const balance(entry.balance(now));
@@ -501,7 +501,7 @@ public:
int
balance(Entry& entry)
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
return entry.balance(m_clock.now());
}
@@ -530,7 +530,7 @@ public:
{
clock_type::time_point const now(m_clock.now());
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
{
beast::PropertyStream::Set s("inbound", map);

View File

@@ -5,6 +5,8 @@
namespace xrpl::Resource {
/** Tunable constants. */
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum {
// Balance at which a warning is issued
warningThreshold = 5000

View File

@@ -35,28 +35,28 @@ public:
setRemoteFee(std::uint32_t f)
{
JLOG(j_.trace()) << "setRemoteFee: " << f;
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
remoteTxnLoadFee_ = f;
}
std::uint32_t
getRemoteFee() const
{
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
return remoteTxnLoadFee_;
}
std::uint32_t
getLocalFee() const
{
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
return localTxnLoadFee_;
}
std::uint32_t
getClusterFee() const
{
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
return clusterTxnLoadFee_;
}
@@ -69,14 +69,14 @@ public:
std::uint32_t
getLoadFactor() const
{
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
return std::max({clusterTxnLoadFee_, localTxnLoadFee_, remoteTxnLoadFee_});
}
std::pair<std::uint32_t, std::uint32_t>
getScalingFactors() const
{
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
return std::make_pair(
std::max(localTxnLoadFee_, remoteTxnLoadFee_),
@@ -87,7 +87,7 @@ public:
setClusterFee(std::uint32_t fee)
{
JLOG(j_.trace()) << "setClusterFee: " << fee;
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
clusterTxnLoadFee_ = fee;
}
@@ -99,14 +99,14 @@ public:
bool
isLoadedLocal() const
{
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
return (raiseCount_ != 0) || (localTxnLoadFee_ != lftNormalFee);
}
bool
isLoadedCluster() const
{
std::lock_guard const sl(lock_);
std::scoped_lock const sl(lock_);
return (raiseCount_ != 0) || (localTxnLoadFee_ != lftNormalFee) ||
(clusterTxnLoadFee_ != lftNormalFee);
}

View File

@@ -38,6 +38,8 @@ protected:
using endpoint_type = boost::asio::ip::tcp::endpoint;
using yield_context = boost::asio::yield_context;
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum {
// Size of our read/write buffer
bufferSize = 4 * 1024,
@@ -303,7 +305,7 @@ BaseHTTPPeer<Handler, Impl>::on_write(error_code const& ec, std::size_t bytes_tr
return fail(ec, "write");
bytes_out_ += bytes_transferred;
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
wq2_.clear();
wq2_.reserve(wq_.size());
std::swap(wq2_, wq_);
@@ -395,7 +397,7 @@ BaseHTTPPeer<Handler, Impl>::write(void const* buf, std::size_t bytes)
if (bytes == 0)
return;
if ([&] {
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
wq_.emplace_back(buf, bytes);
return wq_.size() == 1 && wq2_.size() == 0;
}())
@@ -449,7 +451,7 @@ BaseHTTPPeer<Handler, Impl>::complete()
complete_ = true;
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
if (!wq_.empty() && !wq2_.empty())
return;
}
@@ -484,7 +486,7 @@ BaseHTTPPeer<Handler, Impl>::close(bool graceful)
{
graceful_ = true;
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
if (!wq_.empty() || !wq2_.empty())
return;
}

View File

@@ -62,6 +62,8 @@ class ServerImpl : public Server
private:
using clock_type = std::chrono::system_clock;
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum { historySize = 100 };
Handler& handler_;

View File

@@ -165,7 +165,7 @@ io_list::work::destroy()
return;
std::function<void(void)> f;
{
std::lock_guard const lock(ios_->m_);
std::scoped_lock const lock(ios_->m_);
ios_->map_.erase(this);
if (--ios_->n_ == 0 && ios_->closed_)
{
@@ -195,7 +195,7 @@ io_list::emplace(Args&&... args)
auto sp = std::make_shared<T>(std::forward<Args>(args)...);
decltype(sp) dead;
std::lock_guard const lock(m_);
std::scoped_lock const lock(m_);
if (!closed_)
{
++n_;

View File

@@ -22,6 +22,8 @@ private:
using CacheType = KeyCache;
public:
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum { defaultCacheTargetSize = 0 };
using key_type = uint256;

View File

@@ -123,6 +123,8 @@ public:
Transactor(Transactor const&) = delete;
Transactor&
operator=(Transactor const&) = delete;
// 68 transactor subclass files
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum ConsequencesFactoryType { Normal, Blocker, Custom };
/** Process the transaction. */

View File

@@ -39,7 +39,7 @@ class TxConsequences
public:
/// Describes how the transaction affects subsequent
/// transactions
enum Category {
enum class Category {
/// Moves currency around, creates offers, etc.
normal = 0,
/// Affects the ability of subsequent transactions

View File

@@ -25,6 +25,8 @@ not have the relevant amendments enabled_. It's intentionally a pain in the neck
so that bad code gets caught and fixed as early as possible.
*/
// Bitwise flags, 86 files
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum Privilege {
noPriv = 0x0000, // The transaction can not do any of the enumerated operations
createAcct = 0x0001, // The transaction can create a new ACCOUNT_ROOT object.

View File

@@ -35,10 +35,10 @@ public:
*/
class ValidMPTPayment
{
enum Order { Before = 0, After = 1 };
enum class Order { Before = 0, After = 1 };
struct MPTData
{
std::array<std::int64_t, After + 1> outstanding{};
std::array<std::int64_t, 2> outstanding{};
// sum (MPT after - MPT before)
std::int64_t mptAmount{0};
};

View File

@@ -21,7 +21,7 @@ class AMMContext;
enum class DebtDirection { issues, redeems };
enum class QualityDirection { in, out };
enum class StrandDirection { forward, reverse };
enum OfferCrossing { no = 0, yes = 1, sell = 2 };
enum class OfferCrossing { no = 0, yes = 1, sell = 2 };
inline bool
redeems(DebtDirection dir)

View File

@@ -665,7 +665,7 @@ flow(
// the previous strand execution failed. It has to be reset
// since this strand might not have AMM liquidity.
ammContext.clear();
if (offerCrossing && limitQuality)
if (offerCrossing != OfferCrossing::no && limitQuality)
{
auto const strandQ = qualityUpperBound(sb, *strand);
if (!strandQ || *strandQ < *limitQuality)
@@ -797,7 +797,8 @@ flow(
// fixFillOrKill amendment:
// That case is handled here if tfSell is also not set; i.e,
// case 1.
if (!offerCrossing || (fillOrKillEnabled && offerCrossing != OfferCrossing::sell))
if (offerCrossing == OfferCrossing::no ||
(fillOrKillEnabled && offerCrossing != OfferCrossing::sell))
return {tecPATH_PARTIAL, actualIn, actualOut, std::move(ofrsToRmOnFail)};
}
else if (actualOut == beast::zero)
@@ -805,7 +806,7 @@ flow(
return {tecPATH_DRY, std::move(ofrsToRmOnFail)};
}
}
if (offerCrossing &&
if (offerCrossing != OfferCrossing::no &&
(!partialPayment && (!fillOrKillEnabled || offerCrossing == OfferCrossing::sell)))
{
// If we're offer crossing and partialPayment is *not* true, then

View File

@@ -18,8 +18,8 @@ class SignerListSet : public Transactor
{
private:
// Values determined during preCompute for use later.
enum Operation { unknown, set, destroy };
Operation do_{unknown};
enum class Operation { unknown, set, destroy };
Operation do_{Operation::unknown};
std::uint32_t quorum_{0};
std::vector<SignerEntries::SignerEntry> signers_;

View File

@@ -38,11 +38,7 @@ public:
// Interface used by AccountDelete
static TER
deleteDelegate(
ApplyView& view,
std::shared_ptr<SLE> const& sle,
AccountID const& account,
beast::Journal j);
deleteDelegate(ApplyView& view, std::shared_ptr<SLE> const& sle, beast::Journal j);
};
} // namespace xrpl

View File

@@ -7,7 +7,7 @@ namespace xrpl {
class LedgerStateFix : public Transactor
{
public:
enum FixType : std::uint16_t {
enum class FixType : std::uint16_t {
nfTokenPageLink = 1,
};

View File

@@ -120,7 +120,7 @@ Logs::open(boost::filesystem::path const& pathToLogFile)
beast::Journal::Sink&
Logs::get(std::string const& name)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
auto const result = sinks_.emplace(name, makeSink(name, thresh_));
return *result.first->second;
}
@@ -146,7 +146,7 @@ Logs::threshold() const
void
Logs::threshold(beast::severities::Severity thresh)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
thresh_ = thresh;
for (auto& sink : sinks_)
sink.second->threshold(thresh);
@@ -156,7 +156,7 @@ std::vector<std::pair<std::string, std::string>>
Logs::partition_severities() const
{
std::vector<std::pair<std::string, std::string>> list;
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
list.reserve(sinks_.size());
for (auto const& [name, sink] : sinks_)
list.emplace_back(name, toString(fromSeverity(sink->threshold())));
@@ -172,7 +172,7 @@ Logs::write(
{
std::string s;
format(s, text, level, partition);
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
file_.writeln(s);
if (!silent_)
std::cerr << s << '\n';
@@ -184,7 +184,7 @@ Logs::write(
std::string
Logs::rotate()
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
bool const wasOpened = file_.closeAndReopen();
if (wasOpened)
return "The log file was closed and reopened.";
@@ -412,7 +412,7 @@ public:
std::unique_ptr<beast::Journal::Sink>
set(std::unique_ptr<beast::Journal::Sink> sink)
{
std::lock_guard const _(m_);
std::scoped_lock const _(m_);
using std::swap;
swap(holder_, sink);
@@ -432,7 +432,7 @@ public:
beast::Journal::Sink&
get()
{
std::lock_guard const _(m_);
std::scoped_lock const _(m_);
return sink_.get();
}
};

View File

@@ -27,7 +27,7 @@ using int128_t = __int128_t;
namespace xrpl {
thread_local Number::rounding_mode Number::mode_ = Number::to_nearest;
thread_local Number::rounding_mode Number::mode_ = Number::rounding_mode::to_nearest;
thread_local std::reference_wrapper<MantissaRange const> Number::range_ = largeRange;
Number::rounding_mode
@@ -51,9 +51,10 @@ Number::getMantissaScale()
void
Number::setMantissaScale(MantissaRange::mantissa_scale scale)
{
if (scale != MantissaRange::small && scale != MantissaRange::large)
if (scale != MantissaRange::mantissa_scale::small &&
scale != MantissaRange::mantissa_scale::large)
LogicError("Unknown mantissa scale");
range_ = scale == MantissaRange::small ? smallRange : largeRange;
range_ = scale == MantissaRange::mantissa_scale::small ? smallRange : largeRange;
}
// Guard
@@ -176,10 +177,10 @@ Number::Guard::round() const noexcept
{
auto mode = Number::getround();
if (mode == towards_zero)
if (mode == rounding_mode::towards_zero)
return -1;
if (mode == downward)
if (mode == rounding_mode::downward)
{
if (sbit_)
{
@@ -189,7 +190,7 @@ Number::Guard::round() const noexcept
return -1;
}
if (mode == upward)
if (mode == rounding_mode::upward)
{
if (sbit_)
return -1;
@@ -729,7 +730,7 @@ Number::operator/=(Number const& y)
// f can be up to 10^(38-19) = 10^19 safely
static_assert(smallRange.log == 15);
static_assert(largeRange.log == 18);
bool const small = Number::getMantissaScale() == MantissaRange::small;
bool const small = Number::getMantissaScale() == MantissaRange::mantissa_scale::small;
uint128_t const f = small ? 100'000'000'000'000'000 : 10'000'000'000'000'000'000ULL;
XRPL_ASSERT_PARTS(f >= minMantissa * 10, "Number::operator/=", "factor expected size");

View File

@@ -177,7 +177,7 @@ public:
if (m_stopped.exchange(false))
{
{
std::lock_guard const lk{m_mut};
std::scoped_lock const lk{m_mut};
m_asyncHandlersCompleted = false;
}
addReference();

View File

@@ -42,7 +42,7 @@ seconds_clock_thread::~seconds_clock_thread()
XRPL_ASSERT(
thread_.joinable(), "beast::seconds_clock_thread::~seconds_clock_thread : thread joinable");
{
std::lock_guard const lock(mut_);
std::scoped_lock const lock(mut_);
stop_ = true;
} // publish stop_ asap so if waiting thread times-out, it will see it
cv_.notify_one();

View File

@@ -81,12 +81,9 @@ setCurrentThreadNameImpl(std::string_view name)
{
// truncate and set the thread name.
char boundedName[maxThreadNameLength + 1];
std::snprintf(
boundedName,
sizeof(boundedName),
"%.*s",
static_cast<int>(maxThreadNameLength),
name.data()); // NOLINT(bugprone-suspicious-stringview-data-usage)
auto const boundedSize = name.size() < maxThreadNameLength ? name.size() : maxThreadNameLength;
name.copy(boundedName, boundedSize);
boundedName[boundedSize] = '\0';
pthread_setname_np(pthread_self(), boundedName);

View File

@@ -204,6 +204,8 @@ class StatsDCollectorImp : public StatsDCollector,
public std::enable_shared_from_this<StatsDCollectorImp>
{
private:
// Need to be named before converting
// NOLINTNEXTLINE(cppcoreguidelines-use-enum-class)
enum {
// max_packet_size = 484
max_packet_size = 1472
@@ -293,14 +295,14 @@ public:
void
add(StatsDMetricBase& metric)
{
std::lock_guard const _(metricsLock_);
std::scoped_lock const _(metricsLock_);
metrics_.push_back(metric);
}
void
remove(StatsDMetricBase& metric)
{
std::lock_guard const _(metricsLock_);
std::scoped_lock const _(metricsLock_);
metrics_.erase(metrics_.iterator_to(metric));
}
@@ -444,7 +446,7 @@ public:
return;
}
std::lock_guard const _(metricsLock_);
std::scoped_lock const _(metricsLock_);
for (auto& m : metrics_)
m.do_process();

View File

@@ -158,7 +158,7 @@ PropertyStream::Source::Source(std::string name) : m_name(std::move(name)), item
PropertyStream::Source::~Source()
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
if (parent_ != nullptr)
parent_->remove(*this);
removeAll();
@@ -173,9 +173,7 @@ PropertyStream::Source::name() const
void
PropertyStream::Source::add(Source& source)
{
std::lock(lock_, source.lock_);
std::lock_guard const lk1(lock_, std::adopt_lock);
std::lock_guard const lk2(source.lock_, std::adopt_lock);
std::scoped_lock const lock(lock_, source.lock_);
XRPL_ASSERT(
source.parent_ == nullptr, "beast::PropertyStream::Source::add : null source parent");
@@ -186,9 +184,7 @@ PropertyStream::Source::add(Source& source)
void
PropertyStream::Source::remove(Source& child)
{
std::lock(lock_, child.lock_);
std::lock_guard const lk1(lock_, std::adopt_lock);
std::lock_guard const lk2(child.lock_, std::adopt_lock);
std::scoped_lock const lock(lock_, child.lock_);
XRPL_ASSERT(
child.parent_ == this, "beast::PropertyStream::Source::remove : child parent match");
@@ -199,10 +195,10 @@ PropertyStream::Source::remove(Source& child)
void
PropertyStream::Source::removeAll()
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
for (auto iter = children_.begin(); iter != children_.end();)
{
std::lock_guard const _cl((*iter)->lock_);
std::scoped_lock const _cl((*iter)->lock_);
remove(*(*iter));
}
}
@@ -222,7 +218,7 @@ PropertyStream::Source::write(PropertyStream& stream)
Map map(m_name, stream);
onWrite(map);
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
for (auto& child : children_)
child.source().write(stream);
@@ -324,7 +320,7 @@ PropertyStream::Source::find_one_deep(std::string const& name)
if (found != nullptr)
return found;
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
for (auto& s : children_)
{
found = s.source().find_one_deep(name);
@@ -355,7 +351,7 @@ PropertyStream::Source::find_path(std::string path)
PropertyStream::Source*
PropertyStream::Source::find_one(std::string const& name)
{
std::lock_guard const _(lock_);
std::scoped_lock const _(lock_);
for (auto& s : children_)
{
if (s.source().m_name == name)

View File

@@ -34,7 +34,7 @@ HashRouter::emplace(uint256 const& key) -> std::pair<Entry&, bool>
void
HashRouter::addSuppression(uint256 const& key)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
emplace(key);
}
@@ -48,7 +48,7 @@ HashRouter::addSuppressionPeer(uint256 const& key, PeerShortID peer)
std::pair<bool, std::optional<Stopwatch::time_point>>
HashRouter::addSuppressionPeerWithStatus(uint256 const& key, PeerShortID peer)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
auto result = emplace(key);
result.first.addPeer(peer);
@@ -58,7 +58,7 @@ HashRouter::addSuppressionPeerWithStatus(uint256 const& key, PeerShortID peer)
bool
HashRouter::addSuppressionPeer(uint256 const& key, PeerShortID peer, HashRouterFlags& flags)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
auto [s, created] = emplace(key);
s.addPeer(peer);
@@ -73,7 +73,7 @@ HashRouter::shouldProcess(
HashRouterFlags& flags,
std::chrono::seconds tx_interval)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
auto result = emplace(key);
auto& s = result.first;
@@ -85,7 +85,7 @@ HashRouter::shouldProcess(
HashRouterFlags
HashRouter::getFlags(uint256 const& key)
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
return emplace(key).first.getFlags();
}
@@ -95,7 +95,7 @@ HashRouter::setFlags(uint256 const& key, HashRouterFlags flags)
{
XRPL_ASSERT(static_cast<bool>(flags), "xrpl::HashRouter::setFlags : valid input");
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
auto& s = emplace(key).first;
@@ -109,7 +109,7 @@ HashRouter::setFlags(uint256 const& key, HashRouterFlags flags)
auto
HashRouter::shouldRelay(uint256 const& key) -> std::optional<std::set<PeerShortID>>
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
auto& s = emplace(key).first;

View File

@@ -39,7 +39,7 @@ JobQueue::JobQueue(
job_count = m_collector->make_gauge("job_count");
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
for (auto const& x : JobTypes::instance())
{
@@ -65,7 +65,7 @@ JobQueue::~JobQueue()
void
JobQueue::collect()
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
job_count = m_jobSet.size();
}
@@ -91,7 +91,7 @@ JobQueue::addRefCountedJob(JobType type, std::string const& name, JobFunction co
"requires no threads");
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
auto result = m_jobSet.emplace(type, name, ++m_lastJob, data.load(), func);
auto const& job = *result.first;
@@ -119,7 +119,7 @@ JobQueue::addRefCountedJob(JobType type, std::string const& name, JobFunction co
int
JobQueue::getJobCount(JobType t) const
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
JobDataMap::const_iterator const c = m_jobData.find(t);
@@ -129,7 +129,7 @@ JobQueue::getJobCount(JobType t) const
int
JobQueue::getJobCountTotal(JobType t) const
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
JobDataMap::const_iterator const c = m_jobData.find(t);
@@ -142,7 +142,7 @@ JobQueue::getJobCountGE(JobType t) const
// return the number of jobs at this priority level or greater
int ret = 0;
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
for (auto const& x : m_jobData)
{
@@ -192,7 +192,7 @@ JobQueue::getJson(int c)
Json::Value priorities = Json::arrayValue;
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
for (auto& x : m_jobData)
{
@@ -349,7 +349,7 @@ JobQueue::processTask(int instance)
{
Job job;
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
getNextJob(job);
++m_processCount;
}
@@ -376,7 +376,7 @@ JobQueue::processTask(int instance)
}
{
std::lock_guard const lock(m_mutex);
std::scoped_lock const lock(m_mutex);
// Job should be destroyed before stopping
// otherwise destructors with side effects can access
// parent objects that are already destroyed.

View File

@@ -108,7 +108,7 @@ LoadMonitor::addLoadSample(LoadEvent const& s)
void
LoadMonitor::addSamples(int count, std::chrono::milliseconds latency)
{
std::lock_guard const sl(mutex_);
std::scoped_lock const sl(mutex_);
update();
mCounts += count;
@@ -140,7 +140,7 @@ LoadMonitor::isOverTarget(std::chrono::milliseconds avg, std::chrono::millisecon
bool
LoadMonitor::isOver()
{
std::lock_guard const sl(mutex_);
std::scoped_lock const sl(mutex_);
update();
@@ -157,7 +157,7 @@ LoadMonitor::getStats()
using namespace std::chrono_literals;
Stats stats;
std::lock_guard const sl(mutex_);
std::scoped_lock const sl(mutex_);
update();

View File

@@ -151,7 +151,7 @@ Workers::Worker::Worker(Workers& workers, std::string threadName, int const inst
Workers::Worker::~Worker()
{
{
std::lock_guard const lock{mutex_};
std::scoped_lock const lock{mutex_};
++wakeCount_;
shouldExit_ = true;
}
@@ -163,7 +163,7 @@ Workers::Worker::~Worker()
void
Workers::Worker::notify()
{
std::lock_guard const lock{mutex_};
std::scoped_lock const lock{mutex_};
++wakeCount_;
wakeup_.notify_one();
}
@@ -179,7 +179,7 @@ Workers::Worker::run()
//
if (++m_workers.m_activeCount == 1)
{
std::lock_guard const lk{m_workers.m_mut};
std::scoped_lock const lk{m_workers.m_mut};
m_workers.m_allPaused = false;
}
@@ -226,7 +226,7 @@ Workers::Worker::run()
// the predicate evaluation and the actual sleep.
if (--m_workers.m_runningTaskCount == 0)
{
std::lock_guard const lk{m_workers.m_mut};
std::scoped_lock const lk{m_workers.m_mut};
m_workers.m_cv.notify_all();
}
}
@@ -242,7 +242,7 @@ Workers::Worker::run()
//
if (--m_workers.m_activeCount == 0)
{
std::lock_guard const lk{m_workers.m_mut};
std::scoped_lock const lk{m_workers.m_mut};
m_workers.m_allPaused = true;
m_workers.m_cv.notify_all();
}

View File

@@ -43,7 +43,7 @@ csprng_engine::mix_entropy(void* buffer, std::size_t count)
e = rd();
}
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
// We add data to the pool, but we conservatively assume that
// it contributes no actual entropy.
@@ -60,7 +60,7 @@ csprng_engine::operator()(void* ptr, std::size_t count)
// with thread support, so we don't need to grab a mutex.
// https://mta.openssl.org/pipermail/openssl-users/2020-November/013146.html
#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || !defined(OPENSSL_THREADS)
std::lock_guard lock(mutex_);
std::scoped_lock lock(mutex_);
#endif
auto const result = RAND_bytes(reinterpret_cast<unsigned char*>(ptr), count);

View File

@@ -45,7 +45,7 @@ outputJson(Json::Value const& value, Writer& writer)
}
case Json::arrayValue: {
writer.startRoot(Writer::array);
writer.startRoot(Writer::CollectionType::array);
for (auto const& i : value)
{
writer.rawAppend();
@@ -56,7 +56,7 @@ outputJson(Json::Value const& value, Writer& writer)
}
case Json::objectValue: {
writer.startRoot(Writer::object);
writer.startRoot(Writer::CollectionType::object);
auto members = value.getMemberNames();
for (auto const& tag : members)
{

View File

@@ -81,7 +81,7 @@ public:
void
start(CollectionType ct)
{
char const ch = (ct == array) ? openBracket : openBrace;
char const ch = (ct == CollectionType::array) ? openBracket : openBrace;
output({&ch, 1});
stack_.emplace(Collection{.type = ct});
}
@@ -134,7 +134,9 @@ public:
auto t = stack_.top().type;
if (t != type)
{
check(false, "Not an " + ((type == array ? "array: " : "object: ") + message));
check(
false,
"Not an " + ((type == CollectionType::array ? "array: " : "object: ") + message));
}
if (stack_.top().isFirst)
{
@@ -171,7 +173,7 @@ public:
{
check(!empty(), "Empty stack in finish()");
auto isArray = stack_.top().type == array;
auto isArray = stack_.top().type == CollectionType::array;
auto ch = isArray ? closeBracket : closeBrace;
output_({&ch, 1});
stack_.pop();
@@ -301,7 +303,7 @@ Writer::finishAll()
void
Writer::rawAppend()
{
impl_->nextCollectionEntry(array, "append");
impl_->nextCollectionEntry(CollectionType::array, "append");
}
void
@@ -309,7 +311,7 @@ Writer::rawSet(std::string const& tag)
{
check(!tag.empty(), "Tag can't be empty");
impl_->nextCollectionEntry(object, "set");
impl_->nextCollectionEntry(CollectionType::object, "set");
impl_->writeObjectTag(tag);
}
@@ -322,14 +324,14 @@ Writer::startRoot(CollectionType type)
void
Writer::startAppend(CollectionType type)
{
impl_->nextCollectionEntry(array, "startAppend");
impl_->nextCollectionEntry(CollectionType::array, "startAppend");
impl_->start(type);
}
void
Writer::startSet(CollectionType type, std::string const& key)
{
impl_->nextCollectionEntry(object, "startSet");
impl_->nextCollectionEntry(CollectionType::object, "startSet");
impl_->writeObjectTag(key);
impl_->start(type);
}

View File

@@ -62,8 +62,8 @@ AcceptedLedgerTx::AcceptedLedgerTx(
*ledger,
account,
amount,
fhIGNORE_FREEZE,
ahIGNORE_AUTH,
FreezeHandling::fhIGNORE_FREEZE,
AuthHandling::ahIGNORE_AUTH,
beast::Journal{beast::Journal::getNullSink()});
mJson[jss::transaction][jss::owner_funds] = ownerFunds.getText();
}

View File

@@ -13,21 +13,21 @@ namespace xrpl {
void
BookListeners::addSubscriber(InfoSub::ref sub)
{
std::lock_guard const sl(mLock);
std::scoped_lock const sl(mLock);
mListeners[sub->getSeq()] = sub;
}
void
BookListeners::removeSubscriber(std::uint64_t seq)
{
std::lock_guard const sl(mLock);
std::scoped_lock const sl(mLock);
mListeners.erase(seq);
}
void
BookListeners::publish(MultiApiJson const& jvObj, hash_set<std::uint64_t>& havePublished)
{
std::lock_guard const sl(mLock);
std::scoped_lock const sl(mLock);
auto it = mListeners.cbegin();
while (it != mListeners.cend())

View File

@@ -30,7 +30,7 @@ CachedViewImpl::read(Keylet const& k) const
auto const digest = [&]() -> std::optional<uint256> {
{
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
auto const iter = map_.find(k.key);
if (iter != map_.end())
{
@@ -66,7 +66,7 @@ CachedViewImpl::read(Keylet const& k) const
// Avoid acquiring this lock unless necessary. It is only necessary if
// the key was not found in the map_. The lock is needed to add the key
// and digest.
std::lock_guard const lock(mutex_);
std::scoped_lock const lock(mutex_);
map_.emplace(k.key, *digest);
}
if (!sle || !k.check(*sle))

View File

@@ -14,7 +14,6 @@
#include <xrpl/nodestore/NodeObject.h>
#include <xrpl/protocol/Feature.h>
#include <xrpl/protocol/Fees.h>
#include <xrpl/protocol/HashPrefix.h>
#include <xrpl/protocol/Indexes.h>
#include <xrpl/protocol/KeyType.h>
#include <xrpl/protocol/Keylet.h>
@@ -31,7 +30,6 @@
#include <xrpl/protocol/Seed.h>
#include <xrpl/protocol/Serializer.h>
#include <xrpl/protocol/SystemParameters.h>
#include <xrpl/protocol/digest.h>
#include <xrpl/shamap/Family.h>
#include <xrpl/shamap/SHAMap.h>
#include <xrpl/shamap/SHAMapItem.h>
@@ -43,7 +41,6 @@
#include <exception>
#include <memory>
#include <optional>
#include <stdexcept>
#include <utility>
#include <vector>
@@ -204,7 +201,7 @@ Ledger::Ledger(
rawInsert(sle);
}
stateMap_.flushDirty(hotACCOUNT_NODE);
stateMap_.flushDirty(NodeObjectType::hotACCOUNT_NODE);
setImmutable();
}
@@ -493,14 +490,14 @@ void
Ledger::rawErase(std::shared_ptr<SLE> const& sle)
{
if (!stateMap_.delItem(sle->key()))
Throw<std::logic_error>("Ledger::rawErase: key not found");
LogicError("Ledger::rawErase: key not found");
}
void
Ledger::rawErase(uint256 const& key)
{
if (!stateMap_.delItem(key))
Throw<std::logic_error>("Ledger::rawErase: key not found");
LogicError("Ledger::rawErase: key not found");
}
void
@@ -510,7 +507,7 @@ Ledger::rawInsert(std::shared_ptr<SLE> const& sle)
sle->add(ss);
if (!stateMap_.addGiveItem(
SHAMapNodeType::tnACCOUNT_STATE, make_shamapitem(sle->key(), ss.slice())))
Throw<std::logic_error>("Ledger::rawInsert: key already exists");
LogicError("Ledger::rawInsert: key already exists");
}
void
@@ -520,7 +517,7 @@ Ledger::rawReplace(std::shared_ptr<SLE> const& sle)
sle->add(ss);
if (!stateMap_.updateGiveItem(
SHAMapNodeType::tnACCOUNT_STATE, make_shamapitem(sle->key(), ss.slice())))
Throw<std::logic_error>("Ledger::rawReplace: key not found");
LogicError("Ledger::rawReplace: key not found");
}
void
@@ -536,27 +533,7 @@ Ledger::rawTxInsert(
s.addVL(txn->peekData());
s.addVL(metaData->peekData());
if (!txMap_.addGiveItem(SHAMapNodeType::tnTRANSACTION_MD, make_shamapitem(key, s.slice())))
Throw<std::logic_error>("duplicate_tx: " + to_string(key));
}
uint256
Ledger::rawTxInsertWithHash(
uint256 const& key,
std::shared_ptr<Serializer const> const& txn,
std::shared_ptr<Serializer const> const& metaData)
{
XRPL_ASSERT(metaData, "xrpl::Ledger::rawTxInsertWithHash : non-null metadata input");
// low-level - just add to table
Serializer s(txn->getDataLength() + metaData->getDataLength() + 16);
s.addVL(txn->peekData());
s.addVL(metaData->peekData());
auto item = make_shamapitem(key, s.slice());
auto hash = sha512Half(HashPrefix::txNode, item->slice(), item->key());
if (!txMap_.addGiveItem(SHAMapNodeType::tnTRANSACTION_MD, std::move(item)))
Throw<std::logic_error>("duplicate_tx: " + to_string(key));
return hash;
LogicError("duplicate_tx: " + to_string(key));
}
bool

View File

@@ -46,7 +46,8 @@ STAmount
ammLPTokens(STAmount const& asset1, STAmount const& asset2, Asset const& lptIssue)
{
// AMM invariant: sqrt(asset1 * asset2) >= LPTokensBalance
auto const rounding = isFeatureEnabled(fixAMMv1_3) ? Number::downward : Number::getround();
auto const rounding =
isFeatureEnabled(fixAMMv1_3) ? Number::rounding_mode::downward : Number::getround();
NumberRoundModeGuard const g(rounding);
auto const tokens = root2(asset1 * asset2);
return toSTAmount(lptIssue, tokens);
@@ -77,7 +78,7 @@ lpTokensOut(
// minimize tokens out
auto const frac = (r - c) / (1 + c);
return multiply(lptAMMBalance, frac, Number::downward);
return multiply(lptAMMBalance, frac, Number::rounding_mode::downward);
}
/* Equation 4 solves equation 3 for b:
@@ -113,7 +114,7 @@ ammAssetIn(
// maximize deposit
auto const frac = solveQuadraticEq(a, b, c);
return multiply(asset1Balance, frac, Number::upward);
return multiply(asset1Balance, frac, Number::rounding_mode::upward);
}
/* Equation 7:
@@ -138,7 +139,7 @@ lpTokensIn(
// maximize tokens in
auto const frac = (c - root2(c * c - 4 * fr)) / 2;
return multiply(lptAMMBalance, frac, Number::upward);
return multiply(lptAMMBalance, frac, Number::rounding_mode::upward);
}
/* Equation 8 solves equation 7 for b:
@@ -168,7 +169,7 @@ ammAssetOut(
// minimize withdraw
auto const frac = (t1 * t1 - t1 * (2 - f)) / (t1 * f - 1);
return multiply(assetBalance, frac, Number::downward);
return multiply(assetBalance, frac, Number::rounding_mode::downward);
}
Number

View File

@@ -93,8 +93,8 @@ loanPeriodicRate(TenthBips32 interestRate, std::uint32_t paymentInterval)
bool
isRounded(Asset const& asset, Number const& value, std::int32_t scale)
{
return roundToAsset(asset, value, scale, Number::downward) ==
roundToAsset(asset, value, scale, Number::upward);
return roundToAsset(asset, value, scale, Number::rounding_mode::downward) ==
roundToAsset(asset, value, scale, Number::rounding_mode::upward);
}
namespace detail {
@@ -458,7 +458,11 @@ tryOverpayment(
// preserved rounding errors. This ensures the loan's tracked state remains
// consistent with its payment history.
auto const principalOutstanding = std::clamp(
roundToAsset(asset, newTheoreticalState.principalOutstanding, loanScale, Number::upward),
roundToAsset(
asset,
newTheoreticalState.principalOutstanding,
loanScale,
Number::rounding_mode::upward),
numZero,
roundedOldState.principalOutstanding);
auto const totalValueOutstanding = std::clamp(
@@ -466,7 +470,7 @@ tryOverpayment(
asset,
principalOutstanding + newTheoreticalState.interestOutstanding(),
loanScale,
Number::upward),
Number::rounding_mode::upward),
numZero,
roundedOldState.valueOutstanding);
auto const managementFeeOutstanding = std::clamp(
@@ -836,7 +840,8 @@ computeFullPayment(
// Split the full payment interest into net interest (to vault) and
// management fee (to broker), applying proper rounding.
auto const [roundedFullInterest, roundedFullManagementFee] = [&]() {
auto const interest = roundToAsset(asset, fullPaymentInterest, loanScale, Number::downward);
auto const interest =
roundToAsset(asset, fullPaymentInterest, loanScale, Number::rounding_mode::downward);
return computeInterestAndFeeParts(asset, interest, managementFeeRate, loanScale);
}();
@@ -1286,7 +1291,7 @@ checkLoanGuards(
// loan can't be amortized in the specified number of payments, raise an
// error
{
NumberRoundModeGuard const mg(Number::upward);
NumberRoundModeGuard const mg(Number::rounding_mode::upward);
if (std::int64_t const computedPayments{
properties.loanState.valueOutstanding / roundedPayment};
@@ -1465,7 +1470,8 @@ computeManagementFee(
TenthBips32 managementFeeRate,
std::int32_t scale)
{
return roundToAsset(asset, tenthBipsOfValue(value, managementFeeRate), scale, Number::downward);
return roundToAsset(
asset, tenthBipsOfValue(value, managementFeeRate), scale, Number::rounding_mode::downward);
}
/*
@@ -1519,7 +1525,8 @@ computeLoanProperties(
auto const [totalValueOutstanding, loanScale] = [&]() {
// only round up if there should be interest
NumberRoundModeGuard const mg(periodicRate == 0 ? Number::to_nearest : Number::upward);
NumberRoundModeGuard const mg(
periodicRate == 0 ? Number::rounding_mode::to_nearest : Number::rounding_mode::upward);
// Use STAmount's internal rounding instead of roundToAsset, because
// we're going to use this result to determine the scale for all the
// other rounding.
@@ -1548,7 +1555,7 @@ computeLoanProperties(
// validate that the principal fits in it, so to allow this function to
// succeed, round it here, and let the caller do the validation.
auto const roundedPrincipalOutstanding =
roundToAsset(asset, principalOutstanding, loanScale, Number::to_nearest);
roundToAsset(asset, principalOutstanding, loanScale, Number::rounding_mode::to_nearest);
// Equation (31) from XLS-66 spec, Section A-2 Equation Glossary
auto const totalInterestOutstanding = totalValueOutstanding - roundedPrincipalOutstanding;

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