diff --git a/.github/scripts/levelization/results/ordering.txt b/.github/scripts/levelization/results/ordering.txt index d26a5a1963..38e77dedf8 100644 --- a/.github/scripts/levelization/results/ordering.txt +++ b/.github/scripts/levelization/results/ordering.txt @@ -21,6 +21,7 @@ libxrpl.protocol > xrpl.json libxrpl.protocol > xrpl.protocol libxrpl.protocol_autogen > xrpl.protocol_autogen libxrpl.rdb > xrpl.basics +libxrpl.rdb > xrpl.core libxrpl.rdb > xrpl.rdb libxrpl.resource > xrpl.basics libxrpl.resource > xrpl.json @@ -90,6 +91,7 @@ test.core > xrpl.server test.csf > xrpl.basics test.csf > xrpld.consensus test.csf > xrpl.json +test.csf > xrpl.ledger test.csf > xrpl.protocol test.json > test.jtx test.json > xrpl.json @@ -108,7 +110,6 @@ test.jtx > xrpl.tx test.ledger > test.jtx test.ledger > test.toplevel test.ledger > xrpl.basics -test.ledger > xrpld.app test.ledger > xrpld.core test.ledger > xrpl.ledger test.ledger > xrpl.protocol @@ -125,6 +126,7 @@ test.overlay > xrpl.basics test.overlay > xrpld.app test.overlay > xrpld.overlay test.overlay > xrpld.peerfinder +test.overlay > xrpl.ledger test.overlay > xrpl.nodestore test.overlay > xrpl.protocol test.overlay > xrpl.shamap @@ -183,7 +185,6 @@ xrpl.conditions > xrpl.basics xrpl.conditions > xrpl.protocol xrpl.core > xrpl.basics xrpl.core > xrpl.json -xrpl.core > xrpl.ledger xrpl.core > xrpl.protocol xrpl.json > xrpl.basics xrpl.ledger > xrpl.basics @@ -234,6 +235,7 @@ xrpld.app > xrpl.shamap xrpld.app > xrpl.tx xrpld.consensus > xrpl.basics xrpld.consensus > xrpl.json +xrpld.consensus > xrpl.ledger xrpld.consensus > xrpl.protocol xrpld.core > xrpl.basics xrpld.core > xrpl.core diff --git a/.github/workflows/conflicting-pr.yml b/.github/workflows/conflicting-pr.yml new file mode 100644 index 0000000000..6e667632a0 --- /dev/null +++ b/.github/workflows/conflicting-pr.yml @@ -0,0 +1,25 @@ +name: Label PRs with merge conflicts + +on: + # So that PRs touching the same files as the push are updated. + push: + # So that the `dirtyLabel` is removed if conflicts are resolved. + # We recommend `pull_request_target` so that github secrets are available. + # In `pull_request` we wouldn't be able to change labels of fork PRs. + pull_request_target: + types: [synchronize] + +permissions: + pull-requests: write + +jobs: + main: + runs-on: ubuntu-latest + steps: + - name: Check if PRs are dirty + uses: eps1lon/actions-label-merge-conflict@1df065ebe6e3310545d4f4c4e862e43bdca146f0 # v3.0.3 + with: + dirtyLabel: "PR: has conflicts" + repoToken: "${{ secrets.GITHUB_TOKEN }}" + commentOnDirty: "This PR has conflicts, please resolve them in order for the PR to be reviewed." + commentOnClean: "All conflicts have been resolved. Assigned reviewers can now start or resume their review." diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 4b840405bb..0c706c1ba0 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -6,7 +6,6 @@ on: push: branches: - "develop" - - "release*" paths: - ".github/workflows/publish-docs.yml" - "*.md" diff --git a/.github/workflows/reusable-build-test-config.yml b/.github/workflows/reusable-build-test-config.yml index 1cc768f9fa..85a033766e 100644 --- a/.github/workflows/reusable-build-test-config.yml +++ b/.github/workflows/reusable-build-test-config.yml @@ -199,7 +199,7 @@ jobs: fi - name: Upload the binary (Linux) - if: ${{ github.repository == 'XRPLF/rippled' && runner.os == 'Linux' }} + if: ${{ github.event.repository.visibility == 'public' && runner.os == 'Linux' }} uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 with: name: xrpld-${{ inputs.config_name }} diff --git a/.github/workflows/reusable-clang-tidy-files.yml b/.github/workflows/reusable-clang-tidy-files.yml index 5d3230f7d1..2abc9de43b 100644 --- a/.github/workflows/reusable-clang-tidy-files.yml +++ b/.github/workflows/reusable-clang-tidy-files.yml @@ -83,7 +83,7 @@ jobs: run-clang-tidy -j ${{ steps.nproc.outputs.nproc }} -p "${BUILD_DIR}" ${TARGETS} 2>&1 | tee clang-tidy-output.txt - name: Upload clang-tidy output - if: steps.run_clang_tidy.outcome != 'success' + if: ${{ github.event.repository.visibility == 'public' && steps.run_clang_tidy.outcome != 'success' }} uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 with: name: clang-tidy-results diff --git a/.github/workflows/reusable-clang-tidy.yml b/.github/workflows/reusable-clang-tidy.yml index 3d4bc3b2e3..4c927dec9f 100644 --- a/.github/workflows/reusable-clang-tidy.yml +++ b/.github/workflows/reusable-clang-tidy.yml @@ -51,5 +51,5 @@ jobs: if: ${{ always() && !cancelled() && (!inputs.check_only_changed || needs.determine-files.outputs.any_cpp_changed == 'true' || needs.determine-files.outputs.clang_tidy_config_changed == 'true') }} uses: ./.github/workflows/reusable-clang-tidy-files.yml with: - files: ${{ needs.determine-files.outputs.clang_tidy_config_changed == 'true' && '' || (inputs.check_only_changed && needs.determine-files.outputs.all_changed_files || '') }} + files: ${{ (needs.determine-files.outputs.clang_tidy_config_changed != 'true' && inputs.check_only_changed) && needs.determine-files.outputs.all_changed_files || '' }} create_issue_on_failure: ${{ inputs.create_issue_on_failure }} diff --git a/.gitignore b/.gitignore index 643f0d25dc..7ee6d0c70a 100644 --- a/.gitignore +++ b/.gitignore @@ -71,6 +71,8 @@ DerivedData /.zed/ # AI tools. +/.agent +/.agents /.augment /.claude /CLAUDE.md diff --git a/BUILD.md b/BUILD.md index 4d01700a61..4f709a032b 100644 --- a/BUILD.md +++ b/BUILD.md @@ -125,9 +125,9 @@ default profile. ### Patched recipes -The recipes in Conan Center occasionally need to be patched for compatibility -with the latest version of `xrpld`. We maintain a fork of the Conan Center -[here](https://github.com/XRPLF/conan-center-index/) containing the patches. +Occasionally, we need patched recipes or recipes not present in Conan Center. +We maintain a fork of the Conan Center Index +[here](https://github.com/XRPLF/conan-center-index/) containing the modified and newly added recipes. To ensure our patched recipes are used, you must add our Conan remote at a higher index than the default Conan Center remote, so it is consulted first. You @@ -137,19 +137,11 @@ can do this by running: conan remote add --index 0 xrplf https://conan.ripplex.io ``` -Alternatively, you can pull the patched recipes into the repository and use them -locally: +Alternatively, you can pull our recipes from the repository and export them locally: ```bash -# Extract the version number from the lockfile. -function extract_version { - version=$(cat conan.lock | sed -nE "s@.+${1}/(.+)#.+@\1@p" | head -n1) - echo ${version} -} - # Define which recipes to export. -recipes=('ed25519' 'grpc' 'nudb' 'openssl' 'secp256k1' 'snappy' 'soci') -folders=('all' 'all' 'all' '3.x.x' 'all' 'all' 'all') +recipes=('abseil' 'ed25519' 'grpc' 'm4' 'mpt-crypto' 'nudb' 'openssl' 'secp256k1' 'snappy' 'soci' 'wasm-xrplf' 'wasmi') # Selectively check out the recipes from our CCI fork. cd external @@ -158,29 +150,19 @@ cd conan-center-index git init git remote add origin git@github.com:XRPLF/conan-center-index.git git sparse-checkout init -for ((index = 1; index <= ${#recipes[@]}; index++)); do - recipe=${recipes[index]} - folder=${folders[index]} - echo "Checking out recipe '${recipe}' from folder '${folder}'..." - git sparse-checkout add recipes/${recipe}/${folder} +for recipe in "${recipes[@]}"; do + echo "Checking out recipe '${recipe}'..." + git sparse-checkout add recipes/${recipe} done git fetch origin master git checkout master -cd ../.. -# Export the recipes into the local cache. -for ((index = 1; index <= ${#recipes[@]}; index++)); do - recipe=${recipes[index]} - folder=${folders[index]} - version=$(extract_version ${recipe}) - echo "Exporting '${recipe}/${version}' from '${recipe}/${folder}'..." - conan export --version $(extract_version ${recipe}) \ - external/conan-center-index/recipes/${recipe}/${folder} -done +./export_all.sh +cd ../../ ``` In the case we switch to a newer version of a dependency that still requires a -patch, it will be necessary for you to pull in the changes and re-export the +patch or add a new dependency, it will be necessary for you to pull in the changes and re-export the updated dependencies with the newer version. However, if we switch to a newer version that no longer requires a patch, no action is required on your part, as the new recipe will be automatically pulled from the official Conan Center. @@ -189,6 +171,8 @@ the new recipe will be automatically pulled from the official Conan Center. > You might need to add `--lockfile=""` to your `conan install` command > to avoid automatic use of the existing `conan.lock` file when you run > `conan export` manually on your machine +> +> This is not recommended though, as you might end up using different revisions of recipes. ### Conan profile tweaks @@ -204,39 +188,14 @@ Possible values are ['5.0', '5.1', '6.0', '6.1', '7.0', '7.3', '8.0', '8.1', Read "http://docs.conan.io/2/knowledge/faq.html#error-invalid-setting" ``` -you need to amend the list of compiler versions in -`$(conan config home)/settings.yml`, by appending the required version number(s) +you need to add your compiler to the list of compiler versions in +`$(conan config home)/settings_user.yml`, by adding the required version number(s) to the `version` array specific for your compiler. For example: ```yaml -apple-clang: - version: - [ - "5.0", - "5.1", - "6.0", - "6.1", - "7.0", - "7.3", - "8.0", - "8.1", - "9.0", - "9.1", - "10.0", - "11.0", - "12.0", - "13", - "13.0", - "13.1", - "14", - "14.0", - "15", - "15.0", - "16", - "16.0", - "17", - "17.0", - ] +compiler: + apple-clang: + version: ["17.0"] ``` #### Multiple compilers diff --git a/LICENSE.md b/LICENSE.md index c5e3ad0532..7e6e62994c 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,7 +1,7 @@ ISC License Copyright (c) 2011, Arthur Britto, David Schwartz, Jed McCaleb, Vinnie Falco, Bob Way, Eric Lombrozo, Nikolaos D. Bougalis, Howard Hinnant. -Copyright (c) 2012-2025, the XRP Ledger developers. +Copyright (c) 2012-present, the XRP Ledger developers. Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/cmake/XrplProtocolAutogen.cmake b/cmake/XrplProtocolAutogen.cmake index 44857712cd..e48d28959d 100644 --- a/cmake/XrplProtocolAutogen.cmake +++ b/cmake/XrplProtocolAutogen.cmake @@ -140,6 +140,28 @@ function(setup_protocol_autogen) ) endif() + # Check pip index URL configuration + execute_process( + COMMAND ${VENV_PIP} config get global.index-url + OUTPUT_VARIABLE PIP_INDEX_URL + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + + # Default PyPI URL + set(DEFAULT_PIP_INDEX "https://pypi.org/simple") + + # Show warning if using non-default index + if(PIP_INDEX_URL AND NOT PIP_INDEX_URL STREQUAL "") + if(NOT PIP_INDEX_URL STREQUAL DEFAULT_PIP_INDEX) + message( + WARNING + "Private pip index URL detected: ${PIP_INDEX_URL}\n" + "You may need to connect to VPN to access this URL." + ) + endif() + endif() + message(STATUS "Installing Python dependencies...") execute_process( COMMAND ${VENV_PIP} install --upgrade pip diff --git a/conan.lock b/conan.lock index 291258441f..575be2e071 100644 --- a/conan.lock +++ b/conan.lock @@ -1,16 +1,16 @@ { "version": "0.5", "requires": [ - "zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1765850150.075", + "zlib/1.3.1#cac0f6daea041b0ccf42934163defb20%1774439233.809", "xxhash/0.8.3#681d36a0a6111fc56e5e45ea182c19cc%1765850149.987", - "sqlite3/3.49.1#8631739a4c9b93bd3d6b753bac548a63%1765850149.926", - "soci/4.0.3#a9f8d773cd33e356b5879a4b0564f287%1765850149.46", + "sqlite3/3.51.0#66aa11eabd0e34954c5c1c061ad44abe%1763899256.358", + "soci/4.0.3#fe32b9ad5eb47e79ab9e45a68f363945%1774450067.231", "snappy/1.1.10#968fef506ff261592ec30c574d4a7809%1765850147.878", "secp256k1/0.7.1#481881709eb0bdd0185a12b912bbe8ad%1770910500.329", "rocksdb/10.5.1#4a197eca381a3e5ae8adf8cffa5aacd0%1765850186.86", - "re2/20251105#8579cfd0bda4daf0683f9e3898f964b4%1772560729.95", - "protobuf/6.32.1#f481fd276fc23a33b85a3ed1e898b693%1765850161.038", - "openssl/3.5.5#e6399de266349245a4542fc5f6c71552%1774367199.56", + "re2/20251105#8579cfd0bda4daf0683f9e3898f964b4%1774398111.888", + "protobuf/6.33.5#d96d52ba5baaaa532f47bda866ad87a5%1773224203.27", + "openssl/3.6.1#e6399de266349245a4542fc5f6c71552%1774458290.139", "nudb/2.0.9#0432758a24204da08fee953ec9ea03cb%1769436073.32", "lz4/1.10.0#59fc63cac7f10fbe8e05c7e62c2f3504%1765850143.914", "libiconv/1.17#1e65319e945f2d31941a9d28cc13c058%1765842973.492", @@ -18,24 +18,23 @@ "libarchive/3.8.1#ffee18995c706e02bf96e7a2f7042e0d%1765850144.736", "jemalloc/5.3.0#e951da9cf599e956cebc117880d2d9f8%1729241615.244", "gtest/1.17.0#5224b3b3ff3b4ce1133cbdd27d53ee7d%1768312129.152", - "grpc/1.72.0#500d27f2cbb105a0ffb708e64a0f1781%1774369626.679", + "grpc/1.78.1#b1a9e74b145cc471bed4dc64dc6eb2c1%1772623605.068", "ed25519/2015.03#ae761bdc52730a843f0809bdf6c1b1f6%1765850143.772", "date/3.0.4#862e11e80030356b53c2c38599ceb32b%1765850143.772", - "c-ares/1.34.5#5581c2b62a608b40bb85d965ab3ec7c8%1765850144.336", + "c-ares/1.34.6#545240bb1c40e2cacd4362d6b8967650%1774439234.681", "bzip2/1.0.8#c470882369c2d95c5c77e970c0c7e321%1765850143.837", "boost/1.90.0#d5e8defe7355494953be18524a7f135b%1769454080.269", "abseil/20250127.0#bb0baf1f362bc4a725a24eddd419b8f7%1774365460.196" ], "build_requires": [ - "zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1765850150.075", - "strawberryperl/5.32.1.1#707032463aa0620fa17ec0d887f5fe41%1765850165.196", - "protobuf/6.32.1#f481fd276fc23a33b85a3ed1e898b693%1765850161.038", + "zlib/1.3.1#cac0f6daea041b0ccf42934163defb20%1774439233.809", + "strawberryperl/5.32.1.1#8d114504d172cfea8ea1662d09b6333e%1774447376.964", + "protobuf/6.33.5#d96d52ba5baaaa532f47bda866ad87a5%1773224203.27", "nasm/2.16.01#31e26f2ee3c4346ecd347911bd126904%1765850144.707", "msys2/cci.latest#d22fe7b2808f5fd34d0a7923ace9c54f%1770657326.649", "m4/1.4.19#5d7a4994e5875d76faf7acf3ed056036%1774365463.87", - "cmake/4.2.0#ae0a44f44a1ef9ab68fd4b3e9a1f8671%1765850153.937", - "cmake/3.31.10#313d16a1aa16bbdb2ca0792467214b76%1765850153.479", - "b2/5.3.3#107c15377719889654eb9a162a673975%1765850144.355", + "cmake/4.3.0#b939a42e98f593fb34d3a8c5cc860359%1774439249.183", + "b2/5.4.2#ffd6084a119587e70f11cd45d1a386e2%1774439233.447", "automake/1.16.5#b91b7c384c3deaa9d535be02da14d04f%1755524470.56", "autoconf/2.71#51077f068e61700d65bb05541ea1e4b0%1731054366.86", "abseil/20250127.0#bb0baf1f362bc4a725a24eddd419b8f7%1774365460.196" @@ -47,13 +46,13 @@ "boost/1.90.0" ], "protobuf/[>=5.27.0 <7]": [ - "protobuf/6.32.1" + "protobuf/6.33.5" ], "lz4/1.9.4": [ "lz4/1.10.0" ], - "sqlite3/3.44.2": [ - "sqlite3/3.49.1" + "sqlite3/[>=3.44 <4]": [ + "sqlite3/3.51.0" ], "boost/1.83.0": [ "boost/1.90.0" diff --git a/conanfile.py b/conanfile.py index e16d7eb69e..4949516bfe 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,10 +1,9 @@ -import re import os +import re from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout from conan import ConanFile -from conan import __version__ as conan_version class Xrpl(ConanFile): @@ -30,10 +29,10 @@ class Xrpl(ConanFile): requires = [ "ed25519/2015.03", - "grpc/1.72.0", + "grpc/1.78.1", "libarchive/3.8.1", "nudb/2.0.9", - "openssl/3.5.5", + "openssl/3.6.1", "secp256k1/0.7.1", "soci/4.0.3", "zlib/1.3.1", @@ -44,7 +43,7 @@ class Xrpl(ConanFile): ] tool_requires = [ - "protobuf/6.32.1", + "protobuf/6.33.5", ] default_options = { @@ -137,20 +136,16 @@ class Xrpl(ConanFile): self.default_options["fPIC"] = False def requirements(self): - # Conan 2 requires transitive headers to be specified - transitive_headers_opt = ( - {"transitive_headers": True} if conan_version.split(".")[0] == "2" else {} - ) - self.requires("boost/1.90.0", force=True, **transitive_headers_opt) - self.requires("date/3.0.4", **transitive_headers_opt) + self.requires("boost/1.90.0", force=True, transitive_headers=True) + self.requires("date/3.0.4", transitive_headers=True) self.requires("lz4/1.10.0", force=True) - self.requires("protobuf/6.32.1", force=True) - self.requires("sqlite3/3.49.1", force=True) + self.requires("protobuf/6.33.5", force=True) + self.requires("sqlite3/3.51.0", force=True) if self.options.jemalloc: self.requires("jemalloc/5.3.0") if self.options.rocksdb: self.requires("rocksdb/10.5.1") - self.requires("xxhash/0.8.3", **transitive_headers_opt) + self.requires("xxhash/0.8.3", transitive_headers=True) exports_sources = ( "CMakeLists.txt", diff --git a/cspell.config.yaml b/cspell.config.yaml index d1b8504021..63edba587d 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -297,6 +297,7 @@ words: - venv - vfalco - vinnie + - wasmi - wextra - wptr - writeme diff --git a/include/xrpl/core/Coro.ipp b/include/xrpl/core/Coro.ipp index e7c08e65a6..dca9504679 100644 --- a/include/xrpl/core/Coro.ipp +++ b/include/xrpl/core/Coro.ipp @@ -70,14 +70,24 @@ JobQueue::Coro::resume() running_ = true; } { - std::lock_guard lock(jq_.m_mutex); + std::lock_guard lk(jq_.m_mutex); --jq_.nSuspend_; } auto saved = detail::getLocalValues().release(); detail::getLocalValues().reset(&lvs_); std::lock_guard lock(mutex_); - XRPL_ASSERT(static_cast(coro_), "xrpl::JobQueue::Coro::resume : is runnable"); - coro_(); + // 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 + // coroutine yields — the mutex serializes access, but by the time this + // resume() acquires the lock the coroutine may have already run to + // completion. Calling operator() on a completed boost::coroutine2 is + // undefined behavior, so we must check and skip invoking the coroutine + // body if it has already completed. + if (coro_) + { + coro_(); + } detail::getLocalValues().release(); detail::getLocalValues().reset(saved); std::lock_guard lk(mutex_run_); diff --git a/include/xrpl/core/JobQueue.h b/include/xrpl/core/JobQueue.h index 583e8bc26a..fdb708ee57 100644 --- a/include/xrpl/core/JobQueue.h +++ b/include/xrpl/core/JobQueue.h @@ -99,8 +99,8 @@ public: Effects: The coroutine continues execution from where it last left off using this same thread. - Undefined behavior if called after the coroutine has completed - with a return (as opposed to a yield()). + If the coroutine has already completed, returns immediately + (handles the documented post-before-yield race condition). Undefined behavior if resume() or post() called consecutively without a corresponding yield. */ @@ -357,8 +357,10 @@ private: If the post() job were to be executed before yield(), undefined behavior would occur. The lock ensures that coro_ is not called again until we exit the coroutine. At which point a scheduled resume() job waiting on the lock - would gain entry, harmlessly call coro_ and immediately return as we have - already completed the coroutine. + would gain entry. resume() checks if the coroutine has already completed + (coro_ converts to false) and, if so, skips invoking operator() since + calling operator() on a completed boost::coroutine2 pull_type is undefined + behavior. The race condition occurs as follows: diff --git a/include/xrpl/core/ServiceRegistry.h b/include/xrpl/core/ServiceRegistry.h index 1a2e33d5ee..9f2555dc34 100644 --- a/include/xrpl/core/ServiceRegistry.h +++ b/include/xrpl/core/ServiceRegistry.h @@ -3,7 +3,6 @@ #include #include #include -#include #include @@ -23,6 +22,20 @@ class PerfLog; // This is temporary until we migrate all code to use ServiceRegistry. class Application; +template < + class Key, + class T, + bool IsKeyCache, + class SharedWeakUnionPointer, + class SharedPointerType, + class Hash, + class KeyEqual, + class Mutex> +class TaggedCache; +class STLedgerEntry; +using SLE = STLedgerEntry; +using CachedSLEs = TaggedCache; + // Forward declarations class AcceptedLedger; class AmendmentTable; @@ -45,7 +58,7 @@ class NetworkIDService; class OpenLedger; class OrderBookDB; class Overlay; -class PathRequests; +class PathRequestManager; class PeerReservationTable; class PendingSaves; class RelationalDatabase; @@ -89,7 +102,7 @@ public: getNodeFamily() = 0; virtual TimeKeeper& - timeKeeper() = 0; + getTimeKeeper() = 0; virtual JobQueue& getJobQueue() = 0; @@ -98,7 +111,7 @@ public: getTempNodeCache() = 0; virtual CachedSLEs& - cachedSLEs() = 0; + getCachedSLEs() = 0; virtual NetworkIDService& getNetworkIDService() = 0; @@ -120,26 +133,26 @@ public: getValidations() = 0; virtual ValidatorList& - validators() = 0; + getValidators() = 0; virtual ValidatorSite& - validatorSites() = 0; + getValidatorSites() = 0; virtual ManifestCache& - validatorManifests() = 0; + getValidatorManifests() = 0; virtual ManifestCache& - publisherManifests() = 0; + getPublisherManifests() = 0; // Network services virtual Overlay& - overlay() = 0; + getOverlay() = 0; virtual Cluster& - cluster() = 0; + getCluster() = 0; virtual PeerReservationTable& - peerReservations() = 0; + getPeerReservations() = 0; virtual Resource::Manager& getResourceManager() = 0; @@ -174,13 +187,13 @@ public: getLedgerReplayer() = 0; virtual PendingSaves& - pendingSaves() = 0; + getPendingSaves() = 0; virtual OpenLedger& - openLedger() = 0; + getOpenLedger() = 0; virtual OpenLedger const& - openLedger() const = 0; + getOpenLedger() const = 0; // Transaction and operation services virtual NetworkOPs& @@ -195,8 +208,8 @@ public: virtual TxQ& getTxQ() = 0; - virtual PathRequests& - getPathRequests() = 0; + virtual PathRequestManager& + getPathRequestManager() = 0; // Server services virtual ServerHandler& @@ -210,16 +223,16 @@ public: isStopping() const = 0; virtual beast::Journal - journal(std::string const& name) = 0; + getJournal(std::string const& name) = 0; virtual boost::asio::io_context& getIOContext() = 0; virtual Logs& - logs() = 0; + getLogs() = 0; virtual std::optional const& - trapTxID() const = 0; + getTrapTxID() const = 0; /** Retrieve the "wallet database" */ virtual DatabaseCon& @@ -228,7 +241,7 @@ public: // Temporary: Get the underlying Application for functions that haven't // been migrated yet. This should be removed once all code is migrated. virtual Application& - app() = 0; + getApp() = 0; }; } // namespace xrpl diff --git a/src/xrpld/app/misc/CanonicalTXSet.h b/include/xrpl/ledger/CanonicalTXSet.h similarity index 100% rename from src/xrpld/app/misc/CanonicalTXSet.h rename to include/xrpl/ledger/CanonicalTXSet.h diff --git a/src/xrpld/app/ledger/Ledger.h b/include/xrpl/ledger/Ledger.h similarity index 84% rename from src/xrpld/app/ledger/Ledger.h rename to include/xrpl/ledger/Ledger.h index f040e93369..75a8f55dc0 100644 --- a/src/xrpld/app/ledger/Ledger.h +++ b/include/xrpl/ledger/Ledger.h @@ -1,13 +1,12 @@ #pragma once -#include -#include - #include #include #include #include +#include #include +#include #include #include #include @@ -15,7 +14,7 @@ namespace xrpl { -class Application; +class ServiceRegistry; class Job; class TransactionMaster; @@ -83,21 +82,26 @@ public: */ Ledger( create_genesis_t, - Config const& config, + Rules const& rules, + Fees const& fees, std::vector const& amendments, Family& family); - Ledger(LedgerHeader const& info, Config const& config, Family& family); + Ledger(LedgerHeader const& info, Rules const& rules, Family& family); /** Used for ledgers loaded from JSON files @param acquire If true, acquires the ledger if not found locally + + @note The fees parameter provides default values, but setup() may + override them from the ledger state if fee-related SLEs exist. */ Ledger( LedgerHeader const& info, bool& loaded, bool acquire, - Config const& config, + Rules const& rules, + Fees const& fees, Family& family, beast::Journal j); @@ -113,7 +117,8 @@ public: Ledger( std::uint32_t ledgerSeq, NetClock::time_point closeTime, - Config const& config, + Rules const& rules, + Fees const& fees, Family& family); ~Ledger() = default; @@ -322,7 +327,7 @@ public: walkLedger(beast::Journal j, bool parallel = false) const; bool - assertSensible(beast::Journal ledgerJ) const; + isSensible() const; void invariants() const; @@ -379,8 +384,26 @@ private: bool setup(); - void - defaultFees(Config const& config); + /** @brief Deserialize a SHAMapItem containing a single STTx. + * + * @param item The SHAMapItem to deserialize. + * @return A shared pointer to the deserialized transaction. + * @throw May throw on deserialization error. + */ + static std::shared_ptr + deserializeTx(SHAMapItem const& item); + + /** @brief Deserialize a SHAMapItem containing STTx + STObject metadata. + * + * The SHAMapItem must contain two variable length serialization objects. + * + * @param item The SHAMapItem to deserialize. + * @return A pair containing shared pointers to the deserialized transaction + * and metadata. + * @throw May throw on deserialization error. + */ + static std::pair, std::shared_ptr> + deserializeTxPlusMeta(SHAMapItem const& item); bool mImmutable; @@ -402,54 +425,4 @@ private: /** A ledger wrapped in a CachedView. */ using CachedLedger = CachedView; -//------------------------------------------------------------------------------ -// -// API -// -//------------------------------------------------------------------------------ - -extern bool -pendSaveValidated( - Application& app, - std::shared_ptr const& ledger, - bool isSynchronous, - bool isCurrent); - -std::shared_ptr -loadLedgerHelper(LedgerHeader const& sinfo, Application& app, bool acquire); - -std::shared_ptr -loadByIndex(std::uint32_t ledgerIndex, Application& app, bool acquire = true); - -std::shared_ptr -loadByHash(uint256 const& ledgerHash, Application& app, bool acquire = true); - -// Fetch the ledger with the highest sequence contained in the database -extern std::tuple, std::uint32_t, uint256> -getLatestLedger(Application& app); - -/** Deserialize a SHAMapItem containing a single STTx - - Throw: - - May throw on deserializaton error -*/ -std::shared_ptr -deserializeTx(SHAMapItem const& item); - -/** Deserialize a SHAMapItem containing STTx + STObject metadata - - The SHAMap must contain two variable length - serialization objects. - - Throw: - - May throw on deserializaton error -*/ -std::pair, std::shared_ptr> -deserializeTxPlusMeta(SHAMapItem const& item); - -uint256 -calculateLedgerHash(LedgerHeader const& info); - } // namespace xrpl diff --git a/src/xrpld/consensus/LedgerTiming.h b/include/xrpl/ledger/LedgerTiming.h similarity index 100% rename from src/xrpld/consensus/LedgerTiming.h rename to include/xrpl/ledger/LedgerTiming.h diff --git a/src/xrpld/app/ledger/PendingSaves.h b/include/xrpl/ledger/PendingSaves.h similarity index 100% rename from src/xrpld/app/ledger/PendingSaves.h rename to include/xrpl/ledger/PendingSaves.h diff --git a/include/xrpl/protocol/Fees.h b/include/xrpl/protocol/Fees.h index 84c8ffe81f..ddf4acbf67 100644 --- a/include/xrpl/protocol/Fees.h +++ b/include/xrpl/protocol/Fees.h @@ -4,6 +4,10 @@ namespace xrpl { +// Deprecated constant for backwards compatibility with pre-XRPFees amendment. +// This was the reference fee units used in the old fee calculation. +inline constexpr std::uint32_t FEE_UNITS_DEPRECATED = 10; + /** Reflects the fee settings for a particular ledger. The fees are always the same for any transactions applied @@ -11,15 +15,25 @@ namespace xrpl { */ struct Fees { - XRPAmount base{0}; // Reference tx cost (drops) - XRPAmount reserve{0}; // Reserve base (drops) - XRPAmount increment{0}; // Reserve increment (drops) + /** @brief Cost of a reference transaction in drops. */ + XRPAmount base{0}; + + /** @brief Minimum XRP an account must hold to exist on the ledger. */ + XRPAmount reserve{0}; + + /** @brief Additional XRP reserve required per owned ledger object. */ + XRPAmount increment{0}; explicit Fees() = default; Fees(Fees const&) = default; Fees& operator=(Fees const&) = default; + Fees(XRPAmount base_, XRPAmount reserve_, XRPAmount increment_) + : base(base_), reserve(reserve_), increment(increment_) + { + } + /** Returns the account reserve given the owner count, in drops. The reserve is calculated as the reserve base plus diff --git a/include/xrpl/protocol/LedgerHeader.h b/include/xrpl/protocol/LedgerHeader.h index 1dc67cada5..6e22ad268d 100644 --- a/include/xrpl/protocol/LedgerHeader.h +++ b/include/xrpl/protocol/LedgerHeader.h @@ -72,4 +72,8 @@ deserializeHeader(Slice data, bool hasHash = false); LedgerHeader deserializePrefixedHeader(Slice data, bool hasHash = false); +/** Calculate the hash of a ledger header. */ +uint256 +calculateLedgerHash(LedgerHeader const& info); + } // namespace xrpl diff --git a/include/xrpl/protocol/detail/features.macro b/include/xrpl/protocol/detail/features.macro index a40d524c70..d8d9dc0117 100644 --- a/include/xrpl/protocol/detail/features.macro +++ b/include/xrpl/protocol/detail/features.macro @@ -16,6 +16,7 @@ // Add new amendments to the top of this list. // Keep it sorted in reverse chronological order. +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) diff --git a/include/xrpl/rdb/DatabaseCon.h b/include/xrpl/rdb/DatabaseCon.h index d1fb7114e3..b7231f4859 100644 --- a/include/xrpl/rdb/DatabaseCon.h +++ b/include/xrpl/rdb/DatabaseCon.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -94,7 +95,7 @@ public: struct CheckpointerSetup { JobQueue* jobQueue; - Logs* logs; + std::reference_wrapper registry; }; template @@ -129,7 +130,7 @@ public: beast::Journal journal) : DatabaseCon(setup, dbName, pragma, initSQL, journal) { - setupCheckpointing(checkpointerSetup.jobQueue, *checkpointerSetup.logs); + setupCheckpointing(checkpointerSetup.jobQueue, checkpointerSetup.registry.get()); } template @@ -154,7 +155,7 @@ public: beast::Journal journal) : DatabaseCon(dataDir, dbName, pragma, initSQL, journal) { - setupCheckpointing(checkpointerSetup.jobQueue, *checkpointerSetup.logs); + setupCheckpointing(checkpointerSetup.jobQueue, checkpointerSetup.registry.get()); } ~DatabaseCon(); @@ -177,7 +178,7 @@ public: private: void - setupCheckpointing(JobQueue*, Logs&); + setupCheckpointing(JobQueue*, ServiceRegistry&); template DatabaseCon( diff --git a/include/xrpl/rdb/SociDB.h b/include/xrpl/rdb/SociDB.h index acfc183076..83758677b9 100644 --- a/include/xrpl/rdb/SociDB.h +++ b/include/xrpl/rdb/SociDB.h @@ -13,8 +13,8 @@ #pragma clang diagnostic ignored "-Wdeprecated" #endif -#include #include +#include #define SOCI_USE_BOOST #include @@ -111,7 +111,7 @@ public: and so must outlive them both. */ std::shared_ptr -makeCheckpointer(std::uintptr_t id, std::weak_ptr, JobQueue&, Logs&); +makeCheckpointer(std::uintptr_t id, std::weak_ptr, JobQueue&, ServiceRegistry&); } // namespace xrpl diff --git a/include/xrpl/tx/invariants/InvariantCheck.h b/include/xrpl/tx/invariants/InvariantCheck.h index a053d127fb..e7ced63785 100644 --- a/include/xrpl/tx/invariants/InvariantCheck.h +++ b/include/xrpl/tx/invariants/InvariantCheck.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/include/xrpl/tx/invariants/LoanBrokerInvariant.h b/include/xrpl/tx/invariants/LoanBrokerInvariant.h new file mode 100644 index 0000000000..e7d14a638b --- /dev/null +++ b/include/xrpl/tx/invariants/LoanBrokerInvariant.h @@ -0,0 +1,55 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +namespace xrpl { + +/** + * @brief Invariants: Loan brokers are internally consistent + * + * 1. If `LoanBroker.OwnerCount = 0` the `DirectoryNode` will have at most one + * node (the root), which will only hold entries for `RippleState` or + * `MPToken` objects. + * + */ +class ValidLoanBroker +{ + // Not all of these elements will necessarily be populated. Remaining items + // will be looked up as needed. + struct BrokerInfo + { + SLE::const_pointer brokerBefore = nullptr; + // After is used for most of the checks, except + // those that check changed values. + SLE::const_pointer brokerAfter = nullptr; + }; + // Collect all the LoanBrokers found directly or indirectly through + // pseudo-accounts. Key is the brokerID / index. It will be used to find the + // LoanBroker object if brokerBefore and brokerAfter are nullptr + std::map brokers_; + // Collect all the modified trust lines. Their high and low accounts will be + // loaded to look for LoanBroker pseudo-accounts. + std::vector lines_; + // Collect all the modified MPTokens. Their accounts will be loaded to look + // for LoanBroker pseudo-accounts. + std::vector mpts_; + + static bool + goodZeroDirectory(ReadView const& view, SLE::const_ref dir, beast::Journal const& j); + +public: + void + visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); + + bool + finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&); +}; + +} // namespace xrpl diff --git a/include/xrpl/tx/invariants/LoanInvariant.h b/include/xrpl/tx/invariants/LoanInvariant.h index 02e9db1698..bda9c51653 100644 --- a/include/xrpl/tx/invariants/LoanInvariant.h +++ b/include/xrpl/tx/invariants/LoanInvariant.h @@ -1,57 +1,14 @@ #pragma once -#include #include #include #include #include -#include #include namespace xrpl { -/** - * @brief Invariants: Loan brokers are internally consistent - * - * 1. If `LoanBroker.OwnerCount = 0` the `DirectoryNode` will have at most one - * node (the root), which will only hold entries for `RippleState` or - * `MPToken` objects. - * - */ -class ValidLoanBroker -{ - // Not all of these elements will necessarily be populated. Remaining items - // will be looked up as needed. - struct BrokerInfo - { - SLE::const_pointer brokerBefore = nullptr; - // After is used for most of the checks, except - // those that check changed values. - SLE::const_pointer brokerAfter = nullptr; - }; - // Collect all the LoanBrokers found directly or indirectly through - // pseudo-accounts. Key is the brokerID / index. It will be used to find the - // LoanBroker object if brokerBefore and brokerAfter are nullptr - std::map brokers_; - // Collect all the modified trust lines. Their high and low accounts will be - // loaded to look for LoanBroker pseudo-accounts. - std::vector lines_; - // Collect all the modified MPTokens. Their accounts will be loaded to look - // for LoanBroker pseudo-accounts. - std::vector mpts_; - - static bool - goodZeroDirectory(ReadView const& view, SLE::const_ref dir, beast::Journal const& j); - -public: - void - visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - - bool - finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&); -}; - /** * @brief Invariants: Loans are internally consistent * diff --git a/src/xrpld/app/paths/AMMLiquidity.h b/include/xrpl/tx/paths/AMMLiquidity.h similarity index 100% rename from src/xrpld/app/paths/AMMLiquidity.h rename to include/xrpl/tx/paths/AMMLiquidity.h diff --git a/src/xrpld/app/paths/AMMOffer.h b/include/xrpl/tx/paths/AMMOffer.h similarity index 100% rename from src/xrpld/app/paths/AMMOffer.h rename to include/xrpl/tx/paths/AMMOffer.h diff --git a/include/xrpl/tx/paths/RippleCalc.h b/include/xrpl/tx/paths/RippleCalc.h index a5cecc18bf..4fc4c54f2b 100644 --- a/include/xrpl/tx/paths/RippleCalc.h +++ b/include/xrpl/tx/paths/RippleCalc.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include @@ -92,7 +92,7 @@ public: STPathSet const& spsPaths, std::optional const& domainID, - Logs& l, + ServiceRegistry& registry, Input const* const pInputs = nullptr); // The view we are currently working on diff --git a/src/xrpld/app/paths/detail/StepChecks.h b/include/xrpl/tx/paths/detail/StepChecks.h similarity index 100% rename from src/xrpld/app/paths/detail/StepChecks.h rename to include/xrpl/tx/paths/detail/StepChecks.h diff --git a/src/xrpld/app/misc/CanonicalTXSet.cpp b/src/libxrpl/ledger/CanonicalTXSet.cpp similarity index 97% rename from src/xrpld/app/misc/CanonicalTXSet.cpp rename to src/libxrpl/ledger/CanonicalTXSet.cpp index f971c100eb..72f45731fb 100644 --- a/src/xrpld/app/misc/CanonicalTXSet.cpp +++ b/src/libxrpl/ledger/CanonicalTXSet.cpp @@ -1,4 +1,4 @@ -#include +#include namespace xrpl { diff --git a/src/xrpld/app/ledger/Ledger.cpp b/src/libxrpl/ledger/Ledger.cpp similarity index 74% rename from src/xrpld/app/ledger/Ledger.cpp rename to src/libxrpl/ledger/Ledger.cpp index 7be1b5e762..47009d198a 100644 --- a/src/xrpld/app/ledger/Ledger.cpp +++ b/src/libxrpl/ledger/Ledger.cpp @@ -1,19 +1,9 @@ -#include -#include -#include -#include -#include -#include -#include - #include #include #include -#include -#include #include -#include -#include +#include +#include #include #include #include @@ -21,7 +11,6 @@ #include #include #include -#include #include #include @@ -30,23 +19,6 @@ namespace xrpl { create_genesis_t const create_genesis{}; -uint256 -calculateLedgerHash(LedgerHeader const& info) -{ - // VFALCO This has to match addRaw in View.h. - return sha512Half( - HashPrefix::ledgerMaster, - std::uint32_t(info.seq), - std::uint64_t(info.drops.drops()), - info.parentHash, - info.txHash, - info.accountHash, - std::uint32_t(info.parentCloseTime.time_since_epoch().count()), - std::uint32_t(info.closeTime.time_since_epoch().count()), - std::uint8_t(info.closeTimeResolution.count()), - std::uint8_t(info.closeFlags)); -} - //------------------------------------------------------------------------------ class Ledger::sles_iter_impl : public sles_type::iter_base @@ -138,8 +110,8 @@ public: { auto const& item = *iter_; if (metadata_) - return deserializeTxPlusMeta(item); - return {deserializeTx(item), nullptr}; + return Ledger::deserializeTxPlusMeta(item); + return {Ledger::deserializeTx(item), nullptr}; } }; @@ -147,13 +119,15 @@ public: Ledger::Ledger( create_genesis_t, - Config const& config, + Rules const& rules, + Fees const& fees, std::vector const& amendments, Family& family) : mImmutable(false) , txMap_(SHAMapType::TRANSACTION, family) , stateMap_(SHAMapType::STATE, family) - , rules_{config.features} + , fees_(fees) + , rules_(rules) , j_(beast::Journal(beast::Journal::getNullSink())) { header_.seq = 1; @@ -182,19 +156,19 @@ Ledger::Ledger( // Whether featureXRPFees is supported will depend on startup options. if (std::find(amendments.begin(), amendments.end(), featureXRPFees) != amendments.end()) { - sle->at(sfBaseFeeDrops) = config.FEES.reference_fee; - sle->at(sfReserveBaseDrops) = config.FEES.account_reserve; - sle->at(sfReserveIncrementDrops) = config.FEES.owner_reserve; + sle->at(sfBaseFeeDrops) = fees.base; + sle->at(sfReserveBaseDrops) = fees.reserve; + sle->at(sfReserveIncrementDrops) = fees.increment; } else { - if (auto const f = config.FEES.reference_fee.dropsAs()) + if (auto const f = fees.base.dropsAs()) sle->at(sfBaseFee) = *f; - if (auto const f = config.FEES.account_reserve.dropsAs()) + if (auto const f = fees.reserve.dropsAs()) sle->at(sfReserveBase) = *f; - if (auto const f = config.FEES.owner_reserve.dropsAs()) + if (auto const f = fees.increment.dropsAs()) sle->at(sfReserveIncrement) = *f; - sle->at(sfReferenceFeeUnits) = Config::FEE_UNITS_DEPRECATED; + sle->at(sfReferenceFeeUnits) = FEE_UNITS_DEPRECATED; } rawInsert(sle); } @@ -207,13 +181,15 @@ Ledger::Ledger( LedgerHeader const& info, bool& loaded, bool acquire, - Config const& config, + Rules const& rules, + Fees const& fees, Family& family, beast::Journal j) : mImmutable(true) , txMap_(SHAMapType::TRANSACTION, info.txHash, family) , stateMap_(SHAMapType::STATE, info.accountHash, family) - , rules_(config.features) + , fees_(fees) + , rules_(rules) , header_(info) , j_(j) { @@ -235,7 +211,6 @@ Ledger::Ledger( txMap_.setImmutable(); stateMap_.setImmutable(); - defaultFees(config); if (!setup()) loaded = false; @@ -275,11 +250,11 @@ Ledger::Ledger(Ledger const& prevLedger, NetClock::time_point closeTime) } } -Ledger::Ledger(LedgerHeader const& info, Config const& config, Family& family) +Ledger::Ledger(LedgerHeader const& info, Rules const& rules, Family& family) : mImmutable(true) , txMap_(SHAMapType::TRANSACTION, info.txHash, family) , stateMap_(SHAMapType::STATE, info.accountHash, family) - , rules_{config.features} + , rules_(rules) , header_(info) , j_(beast::Journal(beast::Journal::getNullSink())) { @@ -289,18 +264,19 @@ Ledger::Ledger(LedgerHeader const& info, Config const& config, Family& family) Ledger::Ledger( std::uint32_t ledgerSeq, NetClock::time_point closeTime, - Config const& config, + Rules const& rules, + Fees const& fees, Family& family) : mImmutable(false) , txMap_(SHAMapType::TRANSACTION, family) , stateMap_(SHAMapType::STATE, family) - , rules_{config.features} + , fees_(fees) + , rules_(rules) , j_(beast::Journal(beast::Journal::getNullSink())) { header_.seq = ledgerSeq; header_.closeTime = closeTime; header_.closeTimeResolution = ledgerDefaultTimeResolution; - defaultFees(config); setup(); } @@ -350,14 +326,14 @@ Ledger::addSLE(SLE const& sle) //------------------------------------------------------------------------------ std::shared_ptr -deserializeTx(SHAMapItem const& item) +Ledger::deserializeTx(SHAMapItem const& item) { SerialIter sit(item.slice()); return std::make_shared(sit); } std::pair, std::shared_ptr> -deserializeTxPlusMeta(SHAMapItem const& item) +Ledger::deserializeTxPlusMeta(SHAMapItem const& item) { std::pair, std::shared_ptr> result; SerialIter sit(item.slice()); @@ -636,20 +612,6 @@ Ledger::setup() return ret; } -void -Ledger::defaultFees(Config const& config) -{ - XRPL_ASSERT( - fees_.base == 0 && fees_.reserve == 0 && fees_.increment == 0, - "xrpl::Ledger::defaultFees : zero fees"); - if (fees_.base == 0) - fees_.base = config.FEES.reference_fee; - if (fees_.reserve == 0) - fees_.reserve = config.FEES.account_reserve; - if (fees_.increment == 0) - fees_.increment = config.FEES.owner_reserve; -} - std::shared_ptr Ledger::peek(Keylet const& k) const { @@ -816,27 +778,17 @@ Ledger::walkLedger(beast::Journal j, bool parallel) const } bool -Ledger::assertSensible(beast::Journal ledgerJ) const +Ledger::isSensible() const { - if (header_.hash.isNonZero() && header_.accountHash.isNonZero() && - (header_.accountHash == stateMap_.getHash().as_uint256()) && - (header_.txHash == txMap_.getHash().as_uint256())) - { - return true; - } - - // LCOV_EXCL_START - Json::Value j = getJson({*this, {}}); - - j[jss::accountTreeHash] = to_string(header_.accountHash); - j[jss::transTreeHash] = to_string(header_.txHash); - - JLOG(ledgerJ.fatal()) << "ledger is not sensible" << j; - - UNREACHABLE("xrpl::Ledger::assertSensible : ledger is not sensible"); - - return false; - // LCOV_EXCL_STOP + if (header_.hash.isZero()) + return false; + if (header_.accountHash.isZero()) + return false; + if (header_.accountHash != stateMap_.getHash().as_uint256()) + return false; + if (header_.txHash != txMap_.getHash().as_uint256()) + return false; + return true; } // update the skip list with the information from our previous ledger @@ -925,76 +877,6 @@ Ledger::isVotingLedger() const return ::xrpl::isVotingLedger(header_.seq + 1); } -static bool -saveValidatedLedger(Application& app, std::shared_ptr const& ledger, bool current) -{ - auto j = app.journal("Ledger"); - auto seq = ledger->header().seq; - if (!app.pendingSaves().startWork(seq)) - { - // The save was completed synchronously - JLOG(j.debug()) << "Save aborted"; - return true; - } - - auto& db = app.getRelationalDatabase(); - - auto const res = db.saveValidatedLedger(ledger, current); - - // Clients can now trust the database for - // information about this ledger sequence. - app.pendingSaves().finishWork(seq); - return res; -} - -/** Save, or arrange to save, a fully-validated ledger - Returns false on error -*/ -bool -pendSaveValidated( - Application& app, - std::shared_ptr const& ledger, - bool isSynchronous, - bool isCurrent) -{ - if (!app.getHashRouter().setFlags(ledger->header().hash, HashRouterFlags::SAVED)) - { - // We have tried to save this ledger recently - auto stream = app.journal("Ledger").debug(); - JLOG(stream) << "Double pend save for " << ledger->header().seq; - - if (!isSynchronous || !app.pendingSaves().pending(ledger->header().seq)) - { - // Either we don't need it to be finished - // or it is finished - return true; - } - } - - XRPL_ASSERT(ledger->isImmutable(), "xrpl::pendSaveValidated : immutable ledger"); - - if (!app.pendingSaves().shouldWork(ledger->header().seq, isSynchronous)) - { - auto stream = app.journal("Ledger").debug(); - JLOG(stream) << "Pend save with seq in pending saves " << ledger->header().seq; - - return true; - } - - // See if we can use the JobQueue. - if (!isSynchronous && - app.getJobQueue().addJob( - isCurrent ? jtPUBLEDGER : jtPUBOLDLEDGER, - std::to_string(ledger->seq()), - [&app, ledger, isCurrent]() { saveValidatedLedger(app, ledger, isCurrent); })) - { - return true; - } - - // The JobQueue won't do the Job. Do the save synchronously. - return saveValidatedLedger(app, ledger, isCurrent); -} - void Ledger::unshare() const { @@ -1008,84 +890,5 @@ Ledger::invariants() const stateMap_.invariants(); txMap_.invariants(); } -//------------------------------------------------------------------------------ - -/* - * Make ledger using info loaded from database. - * - * @param LedgerHeader: Ledger information. - * @param app: Link to the Application. - * @param acquire: Acquire the ledger if not found locally. - * @return Shared pointer to the ledger. - */ -std::shared_ptr -loadLedgerHelper(LedgerHeader const& info, Application& app, bool acquire) -{ - bool loaded = false; - auto ledger = std::make_shared( - info, loaded, acquire, app.config(), app.getNodeFamily(), app.journal("Ledger")); - - if (!loaded) - ledger.reset(); - - return ledger; -} - -static void -finishLoadByIndexOrHash( - std::shared_ptr const& ledger, - Config const& config, - beast::Journal j) -{ - if (!ledger) - return; - - XRPL_ASSERT( - ledger->header().seq < XRP_LEDGER_EARLIEST_FEES || ledger->read(keylet::fees()), - "xrpl::finishLoadByIndexOrHash : valid ledger fees"); - ledger->setImmutable(); - - JLOG(j.trace()) << "Loaded ledger: " << to_string(ledger->header().hash); - - ledger->setFull(); -} - -std::tuple, std::uint32_t, uint256> -getLatestLedger(Application& app) -{ - std::optional const info = app.getRelationalDatabase().getNewestLedgerInfo(); - if (!info) - return {std::shared_ptr(), {}, {}}; - return {loadLedgerHelper(*info, app, true), info->seq, info->hash}; -} - -std::shared_ptr -loadByIndex(std::uint32_t ledgerIndex, Application& app, bool acquire) -{ - if (std::optional info = - app.getRelationalDatabase().getLedgerInfoByIndex(ledgerIndex)) - { - std::shared_ptr ledger = loadLedgerHelper(*info, app, acquire); - finishLoadByIndexOrHash(ledger, app.config(), app.journal("Ledger")); - return ledger; - } - return {}; -} - -std::shared_ptr -loadByHash(uint256 const& ledgerHash, Application& app, bool acquire) -{ - if (std::optional info = - app.getRelationalDatabase().getLedgerInfoByHash(ledgerHash)) - { - std::shared_ptr ledger = loadLedgerHelper(*info, app, acquire); - finishLoadByIndexOrHash(ledger, app.config(), app.journal("Ledger")); - XRPL_ASSERT( - !ledger || ledger->header().hash == ledgerHash, - "xrpl::loadByHash : ledger hash match if loaded"); - return ledger; - } - return {}; -} } // namespace xrpl diff --git a/src/libxrpl/ledger/helpers/DirectoryHelpers.cpp b/src/libxrpl/ledger/helpers/DirectoryHelpers.cpp index f0ca83f2cd..dba71e0acd 100644 --- a/src/libxrpl/ledger/helpers/DirectoryHelpers.cpp +++ b/src/libxrpl/ledger/helpers/DirectoryHelpers.cpp @@ -69,7 +69,7 @@ forEachItem( for (auto const& key : sle->getFieldV256(sfIndexes)) f(view.read(keylet::child(key))); auto const next = sle->getFieldU64(sfIndexNext); - if (!next) + if (next == 0u) return; pos = keylet::page(root, next); } diff --git a/src/libxrpl/ledger/helpers/RippleStateHelpers.cpp b/src/libxrpl/ledger/helpers/RippleStateHelpers.cpp index e88afe0cfb..22a0967939 100644 --- a/src/libxrpl/ledger/helpers/RippleStateHelpers.cpp +++ b/src/libxrpl/ledger/helpers/RippleStateHelpers.cpp @@ -224,10 +224,10 @@ trustCreate( bSetHigh ? sfLowLimit : sfHighLimit, STAmount(Issue{saBalance.getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID})); - if (uQualityIn) + if (uQualityIn != 0u) sleRippleState->setFieldU32(bSetHigh ? sfHighQualityIn : sfLowQualityIn, uQualityIn); - if (uQualityOut) + if (uQualityOut != 0u) sleRippleState->setFieldU32(bSetHigh ? sfHighQualityOut : sfLowQualityOut, uQualityOut); std::uint32_t uFlags = bSetHigh ? lsfHighReserve : lsfLowReserve; @@ -327,16 +327,16 @@ updateTrustLine( // Sender balance was positive. && after <= beast::zero // Sender is zero or negative. - && (flags & (!bSenderHigh ? lsfLowReserve : lsfHighReserve)) + && ((flags & (!bSenderHigh ? lsfLowReserve : lsfHighReserve)) != 0u) // Sender reserve is set. && static_cast(flags & (!bSenderHigh ? lsfLowNoRipple : lsfHighNoRipple)) != static_cast(sle->getFlags() & lsfDefaultRipple) && - !(flags & (!bSenderHigh ? lsfLowFreeze : lsfHighFreeze)) && + ((flags & (!bSenderHigh ? lsfLowFreeze : lsfHighFreeze)) == 0u) && !state->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit) // Sender trust limit is 0. - && !state->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn) + && (state->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn) == 0u) // Sender quality in is 0. - && !state->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut)) + && (state->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut) == 0u)) // Sender quality out is 0. { // VFALCO Where is the line being deleted? @@ -348,7 +348,7 @@ updateTrustLine( // Balance is zero, receiver reserve is clear. if (!after // Balance is zero. - && !(flags & (bSenderHigh ? lsfLowReserve : lsfHighReserve))) + && ((flags & (bSenderHigh ? lsfLowReserve : lsfHighReserve)) == 0u)) return true; } return false; @@ -539,11 +539,12 @@ requireAuth(ReadView const& view, Issue const& issue, AccountID const& account, // If this is a weak or legacy check, or if the account has a line, fail if // auth is required and not set on the line if (auto const issuerAccount = view.read(keylet::account(issue.account)); - issuerAccount && (*issuerAccount)[sfFlags] & lsfRequireAuth) + issuerAccount && (((*issuerAccount)[sfFlags] & lsfRequireAuth) != 0u)) { if (trustLine) { - return ((*trustLine)[sfFlags] & ((account > issue.account) ? lsfLowAuth : lsfHighAuth)) + return (((*trustLine)[sfFlags] & + ((account > issue.account) ? lsfLowAuth : lsfHighAuth)) != 0u) ? tesSUCCESS : TER{tecNO_AUTH}; } @@ -575,7 +576,7 @@ canTransfer(ReadView const& view, Issue const& issue, AccountID const& from, Acc bool const issuerHigh = issuerId > account; return line->isFlag(issuerHigh ? lsfHighNoRipple : lsfLowNoRipple); } - return sleIssuer->isFlag(lsfDefaultRipple) == false; + return !sleIssuer->isFlag(lsfDefaultRipple); }; // Fail if rippling disabled on both trust lines @@ -748,7 +749,7 @@ deleteAMMTrustLine( } auto const uFlags = !ammLow ? lsfLowReserve : lsfHighReserve; - if (!(sleState->getFlags() & uFlags)) + if ((sleState->getFlags() & uFlags) == 0u) return tecINTERNAL; // LCOV_EXCL_LINE adjustOwnerCount(view, !ammLow ? sleLow : sleHigh, -1, j); diff --git a/src/libxrpl/ledger/helpers/TokenHelpers.cpp b/src/libxrpl/ledger/helpers/TokenHelpers.cpp index 7a98445b0a..9eb1b4bf11 100644 --- a/src/libxrpl/ledger/helpers/TokenHelpers.cpp +++ b/src/libxrpl/ledger/helpers/TokenHelpers.cpp @@ -570,17 +570,18 @@ rippleCreditIOU( // Sender balance was positive. && saBalance <= beast::zero // Sender is zero or negative. - && (uFlags & (!bSenderHigh ? lsfLowReserve : lsfHighReserve)) + && ((uFlags & (!bSenderHigh ? lsfLowReserve : lsfHighReserve)) != 0u) // Sender reserve is set. && static_cast(uFlags & (!bSenderHigh ? lsfLowNoRipple : lsfHighNoRipple)) != static_cast( view.read(keylet::account(uSenderID))->getFlags() & lsfDefaultRipple) && - !(uFlags & (!bSenderHigh ? lsfLowFreeze : lsfHighFreeze)) && + ((uFlags & (!bSenderHigh ? lsfLowFreeze : lsfHighFreeze)) == 0u) && !sleRippleState->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit) // Sender trust limit is 0. - && !sleRippleState->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn) + && (sleRippleState->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn) == 0u) // Sender quality in is 0. - && !sleRippleState->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut)) + && + (sleRippleState->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut) == 0u)) // Sender quality out is 0. { // Clear the reserve of the sender, possibly delete the line! @@ -592,7 +593,7 @@ rippleCreditIOU( // Balance is zero, receiver reserve is clear. bDelete = !saBalance // Balance is zero. - && !(uFlags & (bSenderHigh ? lsfLowReserve : lsfHighReserve)); + && ((uFlags & (bSenderHigh ? lsfLowReserve : lsfHighReserve)) == 0u); // Receiver reserve is clear. } diff --git a/src/libxrpl/protocol/LedgerHeader.cpp b/src/libxrpl/protocol/LedgerHeader.cpp index 270833c6fa..38e7a7f6dd 100644 --- a/src/libxrpl/protocol/LedgerHeader.cpp +++ b/src/libxrpl/protocol/LedgerHeader.cpp @@ -1,7 +1,9 @@ #include #include +#include #include #include +#include namespace xrpl { @@ -51,4 +53,21 @@ deserializePrefixedHeader(Slice data, bool hasHash) return deserializeHeader(data + 4, hasHash); } +uint256 +calculateLedgerHash(LedgerHeader const& info) +{ + // VFALCO This has to match addRaw in View.h. + return sha512Half( + HashPrefix::ledgerMaster, + std::uint32_t(info.seq), + std::uint64_t(info.drops.drops()), + info.parentHash, + info.txHash, + info.accountHash, + std::uint32_t(info.parentCloseTime.time_since_epoch().count()), + std::uint32_t(info.closeTime.time_since_epoch().count()), + std::uint8_t(info.closeTimeResolution.count()), + std::uint8_t(info.closeFlags)); +} + } // namespace xrpl diff --git a/src/libxrpl/rdb/DatabaseCon.cpp b/src/libxrpl/rdb/DatabaseCon.cpp index 6552a1d7ce..81686c78a6 100644 --- a/src/libxrpl/rdb/DatabaseCon.cpp +++ b/src/libxrpl/rdb/DatabaseCon.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -40,11 +40,14 @@ public: } std::shared_ptr - create(std::shared_ptr const& session, JobQueue& jobQueue, Logs& logs) + create( + std::shared_ptr const& session, + JobQueue& jobQueue, + ServiceRegistry& registry) { std::lock_guard lock{mutex_}; auto const id = nextId_++; - auto const r = makeCheckpointer(id, session, jobQueue, logs); + auto const r = makeCheckpointer(id, session, jobQueue, registry); checkpointers_[id] = r; return r; } @@ -82,11 +85,11 @@ DatabaseCon::~DatabaseCon() std::unique_ptr const> DatabaseCon::Setup::globalPragma; void -DatabaseCon::setupCheckpointing(JobQueue* q, Logs& l) +DatabaseCon::setupCheckpointing(JobQueue* q, ServiceRegistry& registry) { if (q == nullptr) Throw("No JobQueue"); - checkpointer_ = checkpointers.create(session_, *q, l); + checkpointer_ = checkpointers.create(session_, *q, registry); } } // namespace xrpl diff --git a/src/libxrpl/rdb/SociDB.cpp b/src/libxrpl/rdb/SociDB.cpp index 576105016e..ac96985407 100644 --- a/src/libxrpl/rdb/SociDB.cpp +++ b/src/libxrpl/rdb/SociDB.cpp @@ -187,8 +187,11 @@ public: std::uintptr_t id, std::weak_ptr session, JobQueue& q, - Logs& logs) - : id_(id), session_(std::move(session)), jobQueue_(q), j_(logs.journal("WALCheckpointer")) + ServiceRegistry& registry) + : id_(id) + , session_(std::move(session)) + , jobQueue_(q) + , j_(registry.getJournal("WALCheckpointer")) { if (auto [conn, keepAlive] = getConnection(); conn) { @@ -307,9 +310,9 @@ makeCheckpointer( std::uintptr_t id, std::weak_ptr session, JobQueue& queue, - Logs& logs) + ServiceRegistry& registry) { - return std::make_shared(id, std::move(session), queue, logs); + return std::make_shared(id, std::move(session), queue, registry); } } // namespace xrpl diff --git a/src/xrpld/app/misc/detail/Manifest.cpp b/src/libxrpl/server/Manifest.cpp similarity index 100% rename from src/xrpld/app/misc/detail/Manifest.cpp rename to src/libxrpl/server/Manifest.cpp diff --git a/src/libxrpl/tx/SignerEntries.cpp b/src/libxrpl/tx/SignerEntries.cpp index aca1f2c19a..75659a7f04 100644 --- a/src/libxrpl/tx/SignerEntries.cpp +++ b/src/libxrpl/tx/SignerEntries.cpp @@ -12,8 +12,6 @@ namespace xrpl { Expected, NotTEC> SignerEntries::deserialize(STObject const& obj, beast::Journal journal, std::string_view annotation) { - std::pair, NotTEC> s; - if (!obj.isFieldPresent(sfSignerEntries)) { JLOG(journal.trace()) << "Malformed " << annotation << ": Need signer entry array."; diff --git a/src/libxrpl/tx/Transactor.cpp b/src/libxrpl/tx/Transactor.cpp index d579d26c67..5c87d4342f 100644 --- a/src/libxrpl/tx/Transactor.cpp +++ b/src/libxrpl/tx/Transactor.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -302,7 +301,7 @@ Transactor::calculateOwnerReserveFee(ReadView const& view, STTx const& tx) // need to rethink charging an owner reserve as a transaction fee. // TODO: This function is static, and I don't want to add more parameters. // When it is finally refactored to be in a context that has access to the - // Application, include "app().overlay().networkID() > 2 ||" in the + // Application, include "app().getOverlay().networkID() > 2 ||" in the // condition. XRPL_ASSERT( view.fees().increment > view.fees().base * 100, @@ -677,8 +676,7 @@ Transactor::checkSign( } // Look up the account. - auto const idSigner = - pkSigner.empty() ? idAccount : calcAccountID(PublicKey(makeSlice(pkSigner))); + auto const idSigner = calcAccountID(PublicKey(makeSlice(pkSigner))); auto const sleAccount = view.read(keylet::account(idAccount)); if (!sleAccount) return terNO_ACCOUNT; @@ -1097,7 +1095,7 @@ Transactor::operator()() } #endif - if (auto const& trap = ctx_.registry.trapTxID(); trap && *trap == ctx_.tx.getTransactionID()) + if (auto const& trap = ctx_.registry.getTrapTxID(); trap && *trap == ctx_.tx.getTransactionID()) { trapTransaction(*trap); } @@ -1199,16 +1197,25 @@ Transactor::operator()() // If necessary, remove any offers found unfunded during processing if ((result == tecOVERSIZE) || (result == tecKILLED)) - removeUnfundedOffers(view(), removedOffers, ctx_.registry.journal("View")); + { + removeUnfundedOffers(view(), removedOffers, ctx_.registry.getJournal("View")); + } if (result == tecEXPIRED) - removeExpiredNFTokenOffers(view(), expiredNFTokenOffers, ctx_.registry.journal("View")); + { + removeExpiredNFTokenOffers( + view(), expiredNFTokenOffers, ctx_.registry.getJournal("View")); + } if (result == tecINCOMPLETE) - removeDeletedTrustLines(view(), removedTrustLines, ctx_.registry.journal("View")); + { + removeDeletedTrustLines(view(), removedTrustLines, ctx_.registry.getJournal("View")); + } if (result == tecEXPIRED) - removeExpiredCredentials(view(), expiredCredentials, ctx_.registry.journal("View")); + { + removeExpiredCredentials(view(), expiredCredentials, ctx_.registry.getJournal("View")); + } applied = isTecClaim(result); } diff --git a/src/libxrpl/tx/invariants/LoanBrokerInvariant.cpp b/src/libxrpl/tx/invariants/LoanBrokerInvariant.cpp new file mode 100644 index 0000000000..2bc9e622ad --- /dev/null +++ b/src/libxrpl/tx/invariants/LoanBrokerInvariant.cpp @@ -0,0 +1,194 @@ +#include +// +#include +#include +#include +#include +#include +#include +#include +#include + +namespace xrpl { + +void +ValidLoanBroker::visitEntry( + bool isDelete, + std::shared_ptr const& before, + std::shared_ptr const& after) +{ + if (after) + { + if (after->getType() == ltLOAN_BROKER) + { + auto& broker = brokers_[after->key()]; + broker.brokerBefore = before; + broker.brokerAfter = after; + } + else if (after->getType() == ltACCOUNT_ROOT && after->isFieldPresent(sfLoanBrokerID)) + { + auto const& loanBrokerID = after->at(sfLoanBrokerID); + // create an entry if one doesn't already exist + brokers_.emplace(loanBrokerID, BrokerInfo{}); + } + else if (after->getType() == ltRIPPLE_STATE) + { + lines_.emplace_back(after); + } + else if (after->getType() == ltMPTOKEN) + { + mpts_.emplace_back(after); + } + } +} + +bool +ValidLoanBroker::goodZeroDirectory( + ReadView const& view, + SLE::const_ref dir, + beast::Journal const& j) +{ + auto const next = dir->at(~sfIndexNext); + auto const prev = dir->at(~sfIndexPrevious); + if ((prev && (*prev != 0u)) || (next && (*next != 0u))) + { + JLOG(j.fatal()) << "Invariant failed: Loan Broker with zero " + "OwnerCount has multiple directory pages"; + return false; + } + auto indexes = dir->getFieldV256(sfIndexes); + if (indexes.size() > 1) + { + JLOG(j.fatal()) << "Invariant failed: Loan Broker with zero " + "OwnerCount has multiple indexes in the Directory root"; + return false; + } + if (indexes.size() == 1) + { + auto const index = indexes.value().front(); + auto const sle = view.read(keylet::unchecked(index)); + if (!sle) + { + JLOG(j.fatal()) << "Invariant failed: Loan Broker directory corrupt"; + return false; + } + if (sle->getType() != ltRIPPLE_STATE && sle->getType() != ltMPTOKEN) + { + JLOG(j.fatal()) << "Invariant failed: Loan Broker with zero " + "OwnerCount has an unexpected entry in the directory"; + return false; + } + } + + return true; +} + +bool +ValidLoanBroker::finalize( + STTx const& tx, + TER const, + XRPAmount const, + ReadView const& view, + beast::Journal const& j) +{ + // Loan Brokers will not exist on ledger if the Lending Protocol amendment + // is not enabled, so there's no need to check it. + + for (auto const& line : lines_) + { + for (auto const& field : {&sfLowLimit, &sfHighLimit}) + { + auto const account = view.read(keylet::account(line->at(*field).getIssuer())); + // This Invariant doesn't know about the rules for Trust Lines, so + // if the account is missing, don't treat it as an error. This + // loop is only concerned with finding Broker pseudo-accounts + if (account && account->isFieldPresent(sfLoanBrokerID)) + { + auto const& loanBrokerID = account->at(sfLoanBrokerID); + // create an entry if one doesn't already exist + brokers_.emplace(loanBrokerID, BrokerInfo{}); + } + } + } + for (auto const& mpt : mpts_) + { + auto const account = view.read(keylet::account(mpt->at(sfAccount))); + // This Invariant doesn't know about the rules for MPTokens, so + // if the account is missing, don't treat is as an error. This + // loop is only concerned with finding Broker pseudo-accounts + if (account && account->isFieldPresent(sfLoanBrokerID)) + { + auto const& loanBrokerID = account->at(sfLoanBrokerID); + // create an entry if one doesn't already exist + brokers_.emplace(loanBrokerID, BrokerInfo{}); + } + } + + for (auto const& [brokerID, broker] : brokers_) + { + auto const& after = + broker.brokerAfter ? broker.brokerAfter : view.read(keylet::loanbroker(brokerID)); + + if (!after) + { + JLOG(j.fatal()) << "Invariant failed: Loan Broker missing"; + return false; + } + + auto const& before = broker.brokerBefore; + + // https://github.com/Tapanito/XRPL-Standards/blob/xls-66-lending-protocol/XLS-0066d-lending-protocol/README.md#3123-invariants + // If `LoanBroker.OwnerCount = 0` the `DirectoryNode` will have at most + // one node (the root), which will only hold entries for `RippleState` + // or `MPToken` objects. + if (after->at(sfOwnerCount) == 0) + { + auto const dir = view.read(keylet::ownerDir(after->at(sfAccount))); + if (dir) + { + if (!goodZeroDirectory(view, dir, j)) + { + return false; + } + } + } + if (before && before->at(sfLoanSequence) > after->at(sfLoanSequence)) + { + JLOG(j.fatal()) << "Invariant failed: Loan Broker sequence number " + "decreased"; + return false; + } + if (after->at(sfDebtTotal) < 0) + { + JLOG(j.fatal()) << "Invariant failed: Loan Broker debt total is negative"; + return false; + } + if (after->at(sfCoverAvailable) < 0) + { + JLOG(j.fatal()) << "Invariant failed: Loan Broker cover available is negative"; + return false; + } + auto const vault = view.read(keylet::vault(after->at(sfVaultID))); + if (!vault) + { + JLOG(j.fatal()) << "Invariant failed: Loan Broker vault ID is invalid"; + return false; + } + auto const& vaultAsset = vault->at(sfAsset); + if (after->at(sfCoverAvailable) < accountHolds( + view, + after->at(sfAccount), + vaultAsset, + FreezeHandling::fhIGNORE_FREEZE, + AuthHandling::ahIGNORE_AUTH, + j)) + { + JLOG(j.fatal()) << "Invariant failed: Loan Broker cover available " + "is less than pseudo-account asset balance"; + return false; + } + } + return true; +} + +} // namespace xrpl diff --git a/src/libxrpl/tx/invariants/LoanInvariant.cpp b/src/libxrpl/tx/invariants/LoanInvariant.cpp index c0ce320846..6ce1261612 100644 --- a/src/libxrpl/tx/invariants/LoanInvariant.cpp +++ b/src/libxrpl/tx/invariants/LoanInvariant.cpp @@ -2,197 +2,11 @@ // #include #include -#include -#include -#include #include #include -#include namespace xrpl { -void -ValidLoanBroker::visitEntry( - bool isDelete, - std::shared_ptr const& before, - std::shared_ptr const& after) -{ - if (after) - { - if (after->getType() == ltLOAN_BROKER) - { - auto& broker = brokers_[after->key()]; - broker.brokerBefore = before; - broker.brokerAfter = after; - } - else if (after->getType() == ltACCOUNT_ROOT && after->isFieldPresent(sfLoanBrokerID)) - { - auto const& loanBrokerID = after->at(sfLoanBrokerID); - // create an entry if one doesn't already exist - brokers_.emplace(loanBrokerID, BrokerInfo{}); - } - else if (after->getType() == ltRIPPLE_STATE) - { - lines_.emplace_back(after); - } - else if (after->getType() == ltMPTOKEN) - { - mpts_.emplace_back(after); - } - } -} - -bool -ValidLoanBroker::goodZeroDirectory( - ReadView const& view, - SLE::const_ref dir, - beast::Journal const& j) -{ - auto const next = dir->at(~sfIndexNext); - auto const prev = dir->at(~sfIndexPrevious); - if ((prev && (*prev != 0u)) || (next && (*next != 0u))) - { - JLOG(j.fatal()) << "Invariant failed: Loan Broker with zero " - "OwnerCount has multiple directory pages"; - return false; - } - auto indexes = dir->getFieldV256(sfIndexes); - if (indexes.size() > 1) - { - JLOG(j.fatal()) << "Invariant failed: Loan Broker with zero " - "OwnerCount has multiple indexes in the Directory root"; - return false; - } - if (indexes.size() == 1) - { - auto const index = indexes.value().front(); - auto const sle = view.read(keylet::unchecked(index)); - if (!sle) - { - JLOG(j.fatal()) << "Invariant failed: Loan Broker directory corrupt"; - return false; - } - if (sle->getType() != ltRIPPLE_STATE && sle->getType() != ltMPTOKEN) - { - JLOG(j.fatal()) << "Invariant failed: Loan Broker with zero " - "OwnerCount has an unexpected entry in the directory"; - return false; - } - } - - return true; -} - -bool -ValidLoanBroker::finalize( - STTx const& tx, - TER const, - XRPAmount const, - ReadView const& view, - beast::Journal const& j) -{ - // Loan Brokers will not exist on ledger if the Lending Protocol amendment - // is not enabled, so there's no need to check it. - - for (auto const& line : lines_) - { - for (auto const& field : {&sfLowLimit, &sfHighLimit}) - { - auto const account = view.read(keylet::account(line->at(*field).getIssuer())); - // This Invariant doesn't know about the rules for Trust Lines, so - // if the account is missing, don't treat it as an error. This - // loop is only concerned with finding Broker pseudo-accounts - if (account && account->isFieldPresent(sfLoanBrokerID)) - { - auto const& loanBrokerID = account->at(sfLoanBrokerID); - // create an entry if one doesn't already exist - brokers_.emplace(loanBrokerID, BrokerInfo{}); - } - } - } - for (auto const& mpt : mpts_) - { - auto const account = view.read(keylet::account(mpt->at(sfAccount))); - // This Invariant doesn't know about the rules for MPTokens, so - // if the account is missing, don't treat is as an error. This - // loop is only concerned with finding Broker pseudo-accounts - if (account && account->isFieldPresent(sfLoanBrokerID)) - { - auto const& loanBrokerID = account->at(sfLoanBrokerID); - // create an entry if one doesn't already exist - brokers_.emplace(loanBrokerID, BrokerInfo{}); - } - } - - for (auto const& [brokerID, broker] : brokers_) - { - auto const& after = - broker.brokerAfter ? broker.brokerAfter : view.read(keylet::loanbroker(brokerID)); - - if (!after) - { - JLOG(j.fatal()) << "Invariant failed: Loan Broker missing"; - return false; - } - - auto const& before = broker.brokerBefore; - - // https://github.com/Tapanito/XRPL-Standards/blob/xls-66-lending-protocol/XLS-0066d-lending-protocol/README.md#3123-invariants - // If `LoanBroker.OwnerCount = 0` the `DirectoryNode` will have at most - // one node (the root), which will only hold entries for `RippleState` - // or `MPToken` objects. - if (after->at(sfOwnerCount) == 0) - { - auto const dir = view.read(keylet::ownerDir(after->at(sfAccount))); - if (dir) - { - if (!goodZeroDirectory(view, dir, j)) - { - return false; - } - } - } - if (before && before->at(sfLoanSequence) > after->at(sfLoanSequence)) - { - JLOG(j.fatal()) << "Invariant failed: Loan Broker sequence number " - "decreased"; - return false; - } - if (after->at(sfDebtTotal) < 0) - { - JLOG(j.fatal()) << "Invariant failed: Loan Broker debt total is negative"; - return false; - } - if (after->at(sfCoverAvailable) < 0) - { - JLOG(j.fatal()) << "Invariant failed: Loan Broker cover available is negative"; - return false; - } - auto const vault = view.read(keylet::vault(after->at(sfVaultID))); - if (!vault) - { - JLOG(j.fatal()) << "Invariant failed: Loan Broker vault ID is invalid"; - return false; - } - auto const& vaultAsset = vault->at(sfAsset); - if (after->at(sfCoverAvailable) < accountHolds( - view, - after->at(sfAccount), - vaultAsset, - FreezeHandling::fhIGNORE_FREEZE, - AuthHandling::ahIGNORE_AUTH, - j)) - { - JLOG(j.fatal()) << "Invariant failed: Loan Broker cover available " - "is less than pseudo-account asset balance"; - return false; - } - } - return true; -} - -//------------------------------------------------------------------------------ - void ValidLoan::visitEntry( bool isDelete, @@ -236,8 +50,7 @@ ValidLoan::finalize( after->at(sfPrincipalOutstanding) == beast::zero && after->at(sfManagementFeeOutstanding) == beast::zero) { - JLOG(j.fatal()) << "Invariant failed: Loan with zero payments " - "remaining has not been paid off"; + JLOG(j.fatal()) << "Invariant failed: Fully paid off Loan still has payments remaining"; return false; } if (before && (before->isFlag(lsfLoanOverpayment) != after->isFlag(lsfLoanOverpayment))) diff --git a/src/xrpld/app/paths/detail/AMMLiquidity.cpp b/src/libxrpl/tx/paths/AMMLiquidity.cpp similarity index 99% rename from src/xrpld/app/paths/detail/AMMLiquidity.cpp rename to src/libxrpl/tx/paths/AMMLiquidity.cpp index 72ee8eb261..4d6b67fa68 100644 --- a/src/xrpld/app/paths/detail/AMMLiquidity.cpp +++ b/src/libxrpl/tx/paths/AMMLiquidity.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include namespace xrpl { diff --git a/src/xrpld/app/paths/detail/AMMOffer.cpp b/src/libxrpl/tx/paths/AMMOffer.cpp similarity index 98% rename from src/xrpld/app/paths/detail/AMMOffer.cpp rename to src/libxrpl/tx/paths/AMMOffer.cpp index 4871d2251a..2168d80094 100644 --- a/src/xrpld/app/paths/detail/AMMOffer.cpp +++ b/src/libxrpl/tx/paths/AMMOffer.cpp @@ -1,7 +1,6 @@ -#include -#include - #include +#include +#include namespace xrpl { diff --git a/src/xrpld/app/paths/detail/BookStep.cpp b/src/libxrpl/tx/paths/BookStep.cpp similarity index 99% rename from src/xrpld/app/paths/detail/BookStep.cpp rename to src/libxrpl/tx/paths/BookStep.cpp index df1e849b81..3e492d8a19 100644 --- a/src/xrpld/app/paths/detail/BookStep.cpp +++ b/src/libxrpl/tx/paths/BookStep.cpp @@ -1,6 +1,3 @@ -#include -#include - #include #include #include @@ -11,6 +8,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/src/xrpld/app/paths/detail/DirectStep.cpp b/src/libxrpl/tx/paths/DirectStep.cpp similarity index 99% rename from src/xrpld/app/paths/detail/DirectStep.cpp rename to src/libxrpl/tx/paths/DirectStep.cpp index d1d540eda5..9cae103d8f 100644 --- a/src/xrpld/app/paths/detail/DirectStep.cpp +++ b/src/libxrpl/tx/paths/DirectStep.cpp @@ -1,5 +1,3 @@ -#include - #include #include #include @@ -7,6 +5,7 @@ #include #include #include +#include #include #include diff --git a/src/xrpld/app/paths/detail/PaySteps.cpp b/src/libxrpl/tx/paths/PaySteps.cpp similarity index 100% rename from src/xrpld/app/paths/detail/PaySteps.cpp rename to src/libxrpl/tx/paths/PaySteps.cpp diff --git a/src/libxrpl/tx/paths/RippleCalc.cpp b/src/libxrpl/tx/paths/RippleCalc.cpp index cebb5c6dcc..c9f0c9e0fb 100644 --- a/src/libxrpl/tx/paths/RippleCalc.cpp +++ b/src/libxrpl/tx/paths/RippleCalc.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -35,12 +34,12 @@ RippleCalc::rippleCalculate( STPathSet const& spsPaths, std::optional const& domainID, - Logs& l, + ServiceRegistry& registry, Input const* const pInputs) { Output flowOut; PaymentSandbox flowSB(&view); - auto j = l.journal("Flow"); + auto j = registry.getJournal("Flow"); { bool const defaultPaths = (pInputs == nullptr) ? true : pInputs->defaultPathsAllowed; diff --git a/src/xrpld/app/paths/detail/XRPEndpointStep.cpp b/src/libxrpl/tx/paths/XRPEndpointStep.cpp similarity index 99% rename from src/xrpld/app/paths/detail/XRPEndpointStep.cpp rename to src/libxrpl/tx/paths/XRPEndpointStep.cpp index 8b1835069b..7452f57ecd 100644 --- a/src/xrpld/app/paths/detail/XRPEndpointStep.cpp +++ b/src/libxrpl/tx/paths/XRPEndpointStep.cpp @@ -1,5 +1,3 @@ -#include - #include #include #include @@ -9,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/src/libxrpl/tx/transactors/account/SignerListSet.cpp b/src/libxrpl/tx/transactors/account/SignerListSet.cpp index fcc74a6b2c..70e8f21df5 100644 --- a/src/libxrpl/tx/transactors/account/SignerListSet.cpp +++ b/src/libxrpl/tx/transactors/account/SignerListSet.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -197,7 +196,7 @@ removeSignersFromLedger( } adjustOwnerCount( - view, view.peek(accountKeylet), removeFromOwnerCount, registry.journal("View")); + view, view.peek(accountKeylet), removeFromOwnerCount, registry.getJournal("View")); view.erase(signers); @@ -315,7 +314,7 @@ SignerListSet::replaceSignerList() view().insert(signerList); writeSignersToSLE(signerList, flags); - auto viewJ = ctx_.registry.journal("View"); + auto viewJ = ctx_.registry.getJournal("View"); // Add the signer list to the account's directory. auto const page = ctx_.view().dirInsert(ownerDirKeylet, signerListKeylet, describeOwnerDir(account_)); diff --git a/src/libxrpl/tx/transactors/check/CheckCancel.cpp b/src/libxrpl/tx/transactors/check/CheckCancel.cpp index 2d08b2f1b0..50aab27f2b 100644 --- a/src/libxrpl/tx/transactors/check/CheckCancel.cpp +++ b/src/libxrpl/tx/transactors/check/CheckCancel.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -58,7 +57,7 @@ CheckCancel::doApply() AccountID const srcId{sleCheck->getAccountID(sfAccount)}; AccountID const dstId{sleCheck->getAccountID(sfDestination)}; - auto viewJ = ctx_.registry.journal("View"); + auto viewJ = ctx_.registry.getJournal("View"); // If the check is not written to self (and it shouldn't be), remove the // check from the destination account root. diff --git a/src/libxrpl/tx/transactors/check/CheckCash.cpp b/src/libxrpl/tx/transactors/check/CheckCash.cpp index 2546c2635c..ea770bf37f 100644 --- a/src/libxrpl/tx/transactors/check/CheckCash.cpp +++ b/src/libxrpl/tx/transactors/check/CheckCash.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -233,7 +232,7 @@ CheckCash::doApply() // // If it is not a check to self (as should be the case), then there's // work to do... - auto viewJ = ctx_.registry.journal("View"); + auto viewJ = ctx_.registry.getJournal("View"); auto const optDeliverMin = ctx_.tx[~sfDeliverMin]; if (srcId != account_) diff --git a/src/libxrpl/tx/transactors/check/CheckCreate.cpp b/src/libxrpl/tx/transactors/check/CheckCreate.cpp index 1aa4ac15ba..dfcc528f7b 100644 --- a/src/libxrpl/tx/transactors/check/CheckCreate.cpp +++ b/src/libxrpl/tx/transactors/check/CheckCreate.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -169,7 +168,7 @@ CheckCreate::doApply() view().insert(sleCheck); - auto viewJ = ctx_.registry.journal("View"); + auto viewJ = ctx_.registry.getJournal("View"); // If it's not a self-send (and it shouldn't be), add Check to the // destination's owner directory. if (dstAccountId != account_) diff --git a/src/libxrpl/tx/transactors/dex/OfferCancel.cpp b/src/libxrpl/tx/transactors/dex/OfferCancel.cpp index a9e7cac85a..7e094306e9 100644 --- a/src/libxrpl/tx/transactors/dex/OfferCancel.cpp +++ b/src/libxrpl/tx/transactors/dex/OfferCancel.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -54,7 +53,7 @@ OfferCancel::doApply() if (auto sleOffer = view().peek(keylet::offer(account_, offerSequence))) { JLOG(j_.debug()) << "Trying to cancel offer #" << offerSequence; - return offerDelete(view(), sleOffer, ctx_.registry.journal("View")); + return offerDelete(view(), sleOffer, ctx_.registry.getJournal("View")); } JLOG(j_.debug()) << "Offer #" << offerSequence << " can't be found."; diff --git a/src/libxrpl/tx/transactors/dex/OfferCreate.cpp b/src/libxrpl/tx/transactors/dex/OfferCreate.cpp index 17dd2d2c57..602fa9f447 100644 --- a/src/libxrpl/tx/transactors/dex/OfferCreate.cpp +++ b/src/libxrpl/tx/transactors/dex/OfferCreate.cpp @@ -144,7 +144,7 @@ OfferCreate::preclaim(PreclaimContext const& ctx) std::uint32_t const uAccountSequence = sleCreator->getFieldU32(sfSequence); - auto viewJ = ctx.registry.journal("View"); + auto viewJ = ctx.registry.getJournal("View"); if (isGlobalFrozen(ctx.view, uPaysIssuerID) || isGlobalFrozen(ctx.view, uGetsIssuerID)) { @@ -536,7 +536,7 @@ OfferCreate::applyGuts(Sandbox& sb, Sandbox& sbCancel) // end up on the books. auto uRate = getRate(saTakerGets, saTakerPays); - auto viewJ = ctx_.registry.journal("View"); + auto viewJ = ctx_.registry.getJournal("View"); TER result = tesSUCCESS; diff --git a/src/libxrpl/tx/transactors/payment/Payment.cpp b/src/libxrpl/tx/transactors/payment/Payment.cpp index c95afc33f9..5f2a78917c 100644 --- a/src/libxrpl/tx/transactors/payment/Payment.cpp +++ b/src/libxrpl/tx/transactors/payment/Payment.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -435,7 +434,7 @@ Payment::doApply() account_, ctx_.tx.getFieldPathSet(sfPaths), ctx_.tx[~sfDomainID], - ctx_.registry.logs(), + ctx_.registry, &rcInput); // VFALCO NOTE We might not need to apply, depending // on the TER. But always applying *should* diff --git a/src/libxrpl/tx/transactors/payment_channel/PaymentChannelClaim.cpp b/src/libxrpl/tx/transactors/payment_channel/PaymentChannelClaim.cpp index dccaf8f071..10508dda96 100644 --- a/src/libxrpl/tx/transactors/payment_channel/PaymentChannelClaim.cpp +++ b/src/libxrpl/tx/transactors/payment_channel/PaymentChannelClaim.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -109,7 +108,7 @@ PaymentChannelClaim::doApply() auto const closeTime = ctx_.view().header().parentCloseTime.time_since_epoch().count(); if ((cancelAfter && closeTime >= *cancelAfter) || (curExpiration && closeTime >= *curExpiration)) - return closeChannel(slep, ctx_.view(), k.key, ctx_.registry.journal("View")); + return closeChannel(slep, ctx_.view(), k.key, ctx_.registry.getJournal("View")); } if (txAccount != src && txAccount != dst) @@ -170,7 +169,7 @@ PaymentChannelClaim::doApply() { // Channel will close immediately if dry or the receiver closes if (dst == txAccount || (*slep)[sfBalance] == (*slep)[sfAmount]) - return closeChannel(slep, ctx_.view(), k.key, ctx_.registry.journal("View")); + return closeChannel(slep, ctx_.view(), k.key, ctx_.registry.getJournal("View")); auto const settleExpiration = ctx_.view().header().parentCloseTime.time_since_epoch().count() + diff --git a/src/libxrpl/tx/transactors/payment_channel/PaymentChannelFund.cpp b/src/libxrpl/tx/transactors/payment_channel/PaymentChannelFund.cpp index 6c08cc466c..1ffb19ce6f 100644 --- a/src/libxrpl/tx/transactors/payment_channel/PaymentChannelFund.cpp +++ b/src/libxrpl/tx/transactors/payment_channel/PaymentChannelFund.cpp @@ -38,7 +38,7 @@ PaymentChannelFund::doApply() auto const cancelAfter = (*slep)[~sfCancelAfter]; auto const closeTime = ctx_.view().header().parentCloseTime.time_since_epoch().count(); if ((cancelAfter && closeTime >= *cancelAfter) || (expiration && closeTime >= *expiration)) - return closeChannel(slep, ctx_.view(), k.key, ctx_.registry.journal("View")); + return closeChannel(slep, ctx_.view(), k.key, ctx_.registry.getJournal("View")); } if (src != txAccount) diff --git a/src/libxrpl/tx/transactors/system/TicketCreate.cpp b/src/libxrpl/tx/transactors/system/TicketCreate.cpp index a064c158d1..e5100164df 100644 --- a/src/libxrpl/tx/transactors/system/TicketCreate.cpp +++ b/src/libxrpl/tx/transactors/system/TicketCreate.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -71,7 +70,7 @@ TicketCreate::doApply() return tecINSUFFICIENT_RESERVE; } - beast::Journal viewJ{ctx_.registry.journal("View")}; + beast::Journal viewJ{ctx_.registry.getJournal("View")}; // The starting ticket sequence is the same as the current account // root sequence. Before we got here to doApply(), the transaction diff --git a/src/libxrpl/tx/transactors/token/TrustSet.cpp b/src/libxrpl/tx/transactors/token/TrustSet.cpp index 918620c3de..9602eb61d5 100644 --- a/src/libxrpl/tx/transactors/token/TrustSet.cpp +++ b/src/libxrpl/tx/transactors/token/TrustSet.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -367,7 +366,7 @@ TrustSet::doApply() bool const bSetDeepFreeze = (uTxFlags & tfSetDeepFreeze) != 0u; bool const bClearDeepFreeze = (uTxFlags & tfClearDeepFreeze) != 0u; - auto viewJ = ctx_.registry.journal("View"); + auto viewJ = ctx_.registry.getJournal("View"); SLE::pointer sleDst = view().peek(keylet::account(uDstAccountID)); diff --git a/src/test/app/AMMExtended_test.cpp b/src/test/app/AMMExtended_test.cpp index 93ad92af3d..9de1714389 100644 --- a/src/test/app/AMMExtended_test.cpp +++ b/src/test/app/AMMExtended_test.cpp @@ -5,11 +5,10 @@ #include #include -#include - #include #include #include +#include #include #include #include @@ -1927,7 +1926,7 @@ private: BEAST_EXPECT(isOffer(env, carol, BTC(1'000), EUR(1))); BEAST_EXPECT(isOffer(env, bob, EUR(50), USD(50))); - auto flowJournal = env.app().logs().journal("Flow"); + auto flowJournal = env.app().getJournal("Flow"); auto const flowResult = [&] { STAmount deliver(USD(51)); STAmount smax(BTC(61)); @@ -1966,7 +1965,7 @@ private: }(); BEAST_EXPECT(flowResult.removableOffers.size() == 1); - env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { + env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) { if (flowResult.removableOffers.empty()) return false; Sandbox sb(&view, tapNONE); diff --git a/src/test/app/AccountSet_test.cpp b/src/test/app/AccountSet_test.cpp index 7af917a0b9..748f276433 100644 --- a/src/test/app/AccountSet_test.cpp +++ b/src/test/app/AccountSet_test.cpp @@ -403,7 +403,7 @@ public: // Note that we're bypassing almost all of the ledger's safety // checks with this modify() call. If you call close() between // here and the end of the test all the effort will be lost. - env.app().openLedger().modify([&gw, transferRate](OpenView& view, beast::Journal j) { + env.app().getOpenLedger().modify([&gw, transferRate](OpenView& view, beast::Journal j) { // Get the account root we want to hijack. auto const sle = view.read(keylet::account(gw.id())); if (!sle) @@ -552,7 +552,7 @@ public: auto stx = std::make_shared(*jtx.stx); stx->at(sfSigningPubKey) = makeSlice(std::string("badkey")); - env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { + env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) { auto const result = xrpl::apply(env.app(), view, *stx, tapNONE, j); BEAST_EXPECT(result.ter == temBAD_SIGNATURE); BEAST_EXPECT(!result.applied); diff --git a/src/test/app/Batch_test.cpp b/src/test/app/Batch_test.cpp index 9fe9e9cd3a..adc36e4340 100644 --- a/src/test/app/Batch_test.cpp +++ b/src/test/app/Batch_test.cpp @@ -1379,7 +1379,7 @@ class Batch_test : public beast::unit_test::suite batch::inner(pay(alice, bob, XRP(1)), aliceSeq), batch::inner(pay(alice, bob, XRP(1)), aliceSeq)); - env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { + env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) { auto const result = xrpl::apply(env.app(), view, *jt.stx, tapNONE, j); BEAST_EXPECT(!result.applied && result.ter == temARRAY_TOO_LARGE); return result.applied; @@ -1422,7 +1422,7 @@ class Batch_test : public beast::unit_test::suite batch::inner(pay(alice, bob, XRP(5)), aliceSeq + 2), batch::sig(bob, bob, bob, bob, bob, bob, bob, bob, bob, bob)); - env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { + env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) { auto const result = xrpl::apply(env.app(), view, *jt.stx, tapNONE, j); BEAST_EXPECT(!result.applied && result.ter == temARRAY_TOO_LARGE); return result.applied; @@ -3627,7 +3627,7 @@ class Batch_test : public beast::unit_test::suite BEAST_EXPECT(isPseudoTx(stx)); BEAST_EXPECT(!passesLocalChecks(stx, reason)); BEAST_EXPECT(reason == "Cannot submit pseudo transactions."); - env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { + env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) { auto const result = xrpl::apply(env.app(), view, stx, tapNONE, j); BEAST_EXPECT(!result.applied && result.ter == temINVALID_FLAG); return result.applied; diff --git a/src/test/app/EscrowToken_test.cpp b/src/test/app/EscrowToken_test.cpp index ff537a2f5e..619b584ddb 100644 --- a/src/test/app/EscrowToken_test.cpp +++ b/src/test/app/EscrowToken_test.cpp @@ -2518,7 +2518,7 @@ struct EscrowToken_test : public beast::unit_test::suite env.close(); auto const seq1 = env.seq(alice); - env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { + env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) { Sandbox sb(&view, tapNONE); auto sleNew = std::make_shared(keylet::escrow(alice, seq1)); MPTIssue const mpt{MPTIssue{makeMptID(1, AccountID(0x4985601))}}; @@ -2745,7 +2745,7 @@ struct EscrowToken_test : public beast::unit_test::suite env.fund(XRP(10'000), alice, bob); auto const seq1 = env.seq(alice); - env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { + env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) { Sandbox sb(&view, tapNONE); auto sleNew = std::make_shared(keylet::escrow(alice, seq1)); MPTIssue const mpt{MPTIssue{makeMptID(1, AccountID(0x4985601))}}; diff --git a/src/test/app/FeeVote_test.cpp b/src/test/app/FeeVote_test.cpp index 923e7b58b2..3c84f9e007 100644 --- a/src/test/app/FeeVote_test.cpp +++ b/src/test/app/FeeVote_test.cpp @@ -1,6 +1,5 @@ #include -#include #include #include @@ -251,12 +250,13 @@ class FeeVote_test : public beast::unit_test::suite jtx::Env env(*this, jtx::testable_amendments() - featureXRPFees); auto ledger = std::make_shared( create_genesis, - env.app().config(), + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), std::vector{}, env.app().getNodeFamily()); // Create the next ledger to apply transaction to - ledger = std::make_shared(*ledger, env.app().timeKeeper().closeTime()); + ledger = std::make_shared(*ledger, env.app().getTimeKeeper().closeTime()); // Test successful fee transaction with legacy fields @@ -280,12 +280,13 @@ class FeeVote_test : public beast::unit_test::suite jtx::Env env(*this, jtx::testable_amendments() | featureXRPFees); auto ledger = std::make_shared( create_genesis, - env.app().config(), + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), std::vector{}, env.app().getNodeFamily()); // Create the next ledger to apply transaction to - ledger = std::make_shared(*ledger, env.app().timeKeeper().closeTime()); + ledger = std::make_shared(*ledger, env.app().getTimeKeeper().closeTime()); FeeSettingsFields fields{ .baseFeeDrops = XRPAmount{10}, @@ -312,12 +313,13 @@ class FeeVote_test : public beast::unit_test::suite jtx::Env env(*this, jtx::testable_amendments() - featureXRPFees); auto ledger = std::make_shared( create_genesis, - env.app().config(), + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), std::vector{}, env.app().getNodeFamily()); // Create the next ledger to apply transaction to - ledger = std::make_shared(*ledger, env.app().timeKeeper().closeTime()); + ledger = std::make_shared(*ledger, env.app().getTimeKeeper().closeTime()); // Test transaction with missing required legacy fields auto invalidTx = createInvalidFeeTx(ledger->rules(), ledger->seq(), true, false, 1); @@ -333,12 +335,13 @@ class FeeVote_test : public beast::unit_test::suite jtx::Env env(*this, jtx::testable_amendments() | featureXRPFees); auto ledger = std::make_shared( create_genesis, - env.app().config(), + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), std::vector{}, env.app().getNodeFamily()); // Create the next ledger to apply transaction to - ledger = std::make_shared(*ledger, env.app().timeKeeper().closeTime()); + ledger = std::make_shared(*ledger, env.app().getTimeKeeper().closeTime()); // Test transaction with missing required new fields auto invalidTx = createInvalidFeeTx(ledger->rules(), ledger->seq(), true, false, 3); @@ -358,10 +361,14 @@ class FeeVote_test : public beast::unit_test::suite jtx::Env env(*this, jtx::testable_amendments()); auto ledger = std::make_shared( - create_genesis, env.app().config(), std::vector{}, env.app().getNodeFamily()); + create_genesis, + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); // Create the next ledger to apply transaction to - ledger = std::make_shared(*ledger, env.app().timeKeeper().closeTime()); + ledger = std::make_shared(*ledger, env.app().getTimeKeeper().closeTime()); auto feeTx = createFeeTx( ledger->rules(), @@ -393,9 +400,13 @@ class FeeVote_test : public beast::unit_test::suite jtx::Env env(*this, jtx::testable_amendments() | featureXRPFees); auto ledger = std::make_shared( - create_genesis, env.app().config(), std::vector{}, env.app().getNodeFamily()); + create_genesis, + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); - ledger = std::make_shared(*ledger, env.app().timeKeeper().closeTime()); + ledger = std::make_shared(*ledger, env.app().getTimeKeeper().closeTime()); FeeSettingsFields fields1{ .baseFeeDrops = XRPAmount{10}, @@ -412,7 +423,7 @@ class FeeVote_test : public beast::unit_test::suite BEAST_EXPECT(verifyFeeObject(ledger, ledger->rules(), fields1)); // Apply second fee transaction with different values - ledger = std::make_shared(*ledger, env.app().timeKeeper().closeTime()); + ledger = std::make_shared(*ledger, env.app().getTimeKeeper().closeTime()); FeeSettingsFields fields2{ .baseFeeDrops = XRPAmount{20}, @@ -437,9 +448,13 @@ class FeeVote_test : public beast::unit_test::suite jtx::Env env(*this, jtx::testable_amendments() | featureXRPFees); auto ledger = std::make_shared( - create_genesis, env.app().config(), std::vector{}, env.app().getNodeFamily()); + create_genesis, + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); - ledger = std::make_shared(*ledger, env.app().timeKeeper().closeTime()); + ledger = std::make_shared(*ledger, env.app().getTimeKeeper().closeTime()); // Test transaction with wrong ledger sequence auto feeTx = createFeeTx( @@ -464,9 +479,13 @@ class FeeVote_test : public beast::unit_test::suite jtx::Env env(*this, jtx::testable_amendments() | featureXRPFees); auto ledger = std::make_shared( - create_genesis, env.app().config(), std::vector{}, env.app().getNodeFamily()); + create_genesis, + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); - ledger = std::make_shared(*ledger, env.app().timeKeeper().closeTime()); + ledger = std::make_shared(*ledger, env.app().getTimeKeeper().closeTime()); FeeSettingsFields fields1{ .baseFeeDrops = XRPAmount{10}, @@ -482,7 +501,7 @@ class FeeVote_test : public beast::unit_test::suite BEAST_EXPECT(verifyFeeObject(ledger, ledger->rules(), fields1)); - ledger = std::make_shared(*ledger, env.app().timeKeeper().closeTime()); + ledger = std::make_shared(*ledger, env.app().getTimeKeeper().closeTime()); // Apply partial update (only some fields) FeeSettingsFields fields2{ @@ -506,9 +525,13 @@ class FeeVote_test : public beast::unit_test::suite jtx::Env env(*this, jtx::testable_amendments() | featureXRPFees); auto ledger = std::make_shared( - create_genesis, env.app().config(), std::vector{}, env.app().getNodeFamily()); + create_genesis, + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); - ledger = std::make_shared(*ledger, env.app().timeKeeper().closeTime()); + ledger = std::make_shared(*ledger, env.app().getTimeKeeper().closeTime()); // Test invalid transaction with non-zero account - this should fail // validation @@ -540,11 +563,12 @@ class FeeVote_test : public beast::unit_test::suite // Test with XRPFees enabled { Env env(*this, testable_amendments() | featureXRPFees); - auto feeVote = make_FeeVote(setup, env.app().journal("FeeVote")); + auto feeVote = make_FeeVote(setup, env.app().getJournal("FeeVote")); auto ledger = std::make_shared( create_genesis, - env.app().config(), + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), std::vector{}, env.app().getNodeFamily()); @@ -552,7 +576,7 @@ class FeeVote_test : public beast::unit_test::suite auto pub = derivePublicKey(KeyType::secp256k1, sec); auto val = std::make_shared( - env.app().timeKeeper().now(), pub, sec, calcNodeID(pub), [](STValidation& v) { + env.app().getTimeKeeper().now(), pub, sec, calcNodeID(pub), [](STValidation& v) { v.setFieldU32(sfLedgerSequence, 12345); }); @@ -569,11 +593,12 @@ class FeeVote_test : public beast::unit_test::suite // Test with XRPFees disabled (legacy format) { Env env(*this, testable_amendments() - featureXRPFees); - auto feeVote = make_FeeVote(setup, env.app().journal("FeeVote")); + auto feeVote = make_FeeVote(setup, env.app().getJournal("FeeVote")); auto ledger = std::make_shared( create_genesis, - env.app().config(), + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), std::vector{}, env.app().getNodeFamily()); @@ -581,7 +606,7 @@ class FeeVote_test : public beast::unit_test::suite auto pub = derivePublicKey(KeyType::secp256k1, sec); auto val = std::make_shared( - env.app().timeKeeper().now(), pub, sec, calcNodeID(pub), [](STValidation& v) { + env.app().getTimeKeeper().now(), pub, sec, calcNodeID(pub), [](STValidation& v) { v.setFieldU32(sfLedgerSequence, 12345); }); @@ -614,15 +639,19 @@ class FeeVote_test : public beast::unit_test::suite BEAST_EXPECT(env.current()->fees().reserve == XRPAmount{200'000'000}); BEAST_EXPECT(env.current()->fees().increment == XRPAmount{50'000'000}); - auto feeVote = make_FeeVote(setup, env.app().journal("FeeVote")); + auto feeVote = make_FeeVote(setup, env.app().getJournal("FeeVote")); auto ledger = std::make_shared( - create_genesis, env.app().config(), std::vector{}, env.app().getNodeFamily()); + create_genesis, + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); // doVoting requires a flag ledger (every 256th ledger) // We need to create a ledger at sequence 256 to make it a flag ledger for (int i = 0; i < 256 - 1; ++i) { - ledger = std::make_shared(*ledger, env.app().timeKeeper().closeTime()); + ledger = std::make_shared(*ledger, env.app().getTimeKeeper().closeTime()); } BEAST_EXPECT(ledger->isFlagLedger()); @@ -635,7 +664,7 @@ class FeeVote_test : public beast::unit_test::suite auto pub = derivePublicKey(KeyType::secp256k1, sec); auto val = std::make_shared( - env.app().timeKeeper().now(), pub, sec, calcNodeID(pub), [&](STValidation& v) { + env.app().getTimeKeeper().now(), pub, sec, calcNodeID(pub), [&](STValidation& v) { v.setFieldU32(sfLedgerSequence, ledger->seq()); // Vote for different fees than current v.setFieldAmount(sfBaseFeeDrops, XRPAmount{setup.reference_fee}); diff --git a/src/test/app/Flow_test.cpp b/src/test/app/Flow_test.cpp index 473f8bce20..25bcb4ee64 100644 --- a/src/test/app/Flow_test.cpp +++ b/src/test/app/Flow_test.cpp @@ -435,7 +435,7 @@ struct Flow_test : public beast::unit_test::suite BEAST_EXPECT(isOffer(env, bob, BTC(60), EUR(50))); BEAST_EXPECT(isOffer(env, carol, BTC(1000), EUR(1))); - auto flowJournal = env.app().logs().journal("Flow"); + auto flowJournal = env.app().getJournal("Flow"); auto const flowResult = [&] { STAmount deliver(USD(51)); STAmount smax(BTC(61)); @@ -474,7 +474,7 @@ struct Flow_test : public beast::unit_test::suite }(); BEAST_EXPECT(flowResult.removableOffers.size() == 1); - env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { + env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) { if (flowResult.removableOffers.empty()) return false; Sandbox sb(&view, tapNONE); diff --git a/src/test/app/LedgerHistory_test.cpp b/src/test/app/LedgerHistory_test.cpp index 93ab4a6210..dbc20fe8f2 100644 --- a/src/test/app/LedgerHistory_test.cpp +++ b/src/test/app/LedgerHistory_test.cpp @@ -38,7 +38,8 @@ public: assert(!stx); return std::make_shared( create_genesis, - env.app().config(), + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), std::vector{}, env.app().getNodeFamily()); } diff --git a/src/test/app/LedgerReplay_test.cpp b/src/test/app/LedgerReplay_test.cpp index 59304f1894..cc7cfa413c 100644 --- a/src/test/app/LedgerReplay_test.cpp +++ b/src/test/app/LedgerReplay_test.cpp @@ -464,7 +464,7 @@ struct LedgerServer assert(param.initLedgers > 0); createAccounts(param.initAccounts); createLedgerHistory(); - app.logs().threshold(beast::severities::kWarning); + app.getLogs().threshold(beast::severities::kWarning); } /** @@ -803,8 +803,8 @@ logAll( LedgerReplayClient& client, beast::severities::Severity level = Severity::kTrace) { - server.app.logs().threshold(level); - client.app.logs().threshold(level); + server.app.getLogs().threshold(level); + client.app.getLogs().threshold(level); } // logAll(net.server, net.client); diff --git a/src/test/app/NFTokenAuth_test.cpp b/src/test/app/NFTokenAuth_test.cpp index 59faeb1eeb..551882b51a 100644 --- a/src/test/app/NFTokenAuth_test.cpp +++ b/src/test/app/NFTokenAuth_test.cpp @@ -110,7 +110,7 @@ public: view.rawInsert(sleA1); return true; }; - env.app().openLedger().modify(unauthTrustline); + env.app().getOpenLedger().modify(unauthTrustline); if (features[fixEnforceNFTokenTrustlineV2]) { @@ -173,7 +173,7 @@ public: view.rawInsert(sleA1); return true; }; - env.app().openLedger().modify(unauthTrustline); + env.app().getOpenLedger().modify(unauthTrustline); if (features[fixEnforceNFTokenTrustlineV2]) { // test: check that offer can't be accepted even with balance @@ -293,7 +293,7 @@ public: view.rawInsert(sleA1); return true; }; - env.app().openLedger().modify(unauthTrustline); + env.app().getOpenLedger().modify(unauthTrustline); if (features[fixEnforceNFTokenTrustlineV2]) { env(token::acceptSellOffer(A1, sellIdx), ter(tecNO_AUTH)); @@ -412,7 +412,7 @@ public: view.rawInsert(sleA1); return true; }; - env.app().openLedger().modify(unauthTrustline); + env.app().getOpenLedger().modify(unauthTrustline); if (features[fixEnforceNFTokenTrustlineV2]) { diff --git a/src/test/app/NFToken_test.cpp b/src/test/app/NFToken_test.cpp index 40fb78bb20..bd61c959fc 100644 --- a/src/test/app/NFToken_test.cpp +++ b/src/test/app/NFToken_test.cpp @@ -399,7 +399,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite // Note that we're bypassing almost all of the ledger's safety // checks with this modify() call. If you call close() between // here and the end of the test all the effort will be lost. - env.app().openLedger().modify([&alice](OpenView& view, beast::Journal j) { + env.app().getOpenLedger().modify([&alice](OpenView& view, beast::Journal j) { // Get the account root we want to hijack. auto const sle = view.read(keylet::account(alice.id())); if (!sle) diff --git a/src/test/app/PayStrand_test.cpp b/src/test/app/PayStrand_test.cpp index d2e79a58f8..256c5ae716 100644 --- a/src/test/app/PayStrand_test.cpp +++ b/src/test/app/PayStrand_test.cpp @@ -623,7 +623,7 @@ struct PayStrand_test : public beast::unit_test::suite OfferCrossing::no, ammContext, std::nullopt, - env.app().logs().journal("Flow")); + env.app().getJournal("Flow")); BEAST_EXPECT(ter == expTer); if (sizeof...(expSteps) != 0) BEAST_EXPECT(equal(strand, std::forward(expSteps)...)); @@ -650,7 +650,7 @@ struct PayStrand_test : public beast::unit_test::suite OfferCrossing::no, ammContext, std::nullopt, - env.app().logs().journal("Flow")); + env.app().getJournal("Flow")); (void)_; BEAST_EXPECT(isTesSuccess(ter)); } @@ -668,7 +668,7 @@ struct PayStrand_test : public beast::unit_test::suite OfferCrossing::no, ammContext, std::nullopt, - env.app().logs().journal("Flow")); + env.app().getJournal("Flow")); (void)_; BEAST_EXPECT(isTesSuccess(ter)); } @@ -765,7 +765,7 @@ struct PayStrand_test : public beast::unit_test::suite { // The root account can't be the src or dst - auto flowJournal = env.app().logs().journal("Flow"); + auto flowJournal = env.app().getJournal("Flow"); { // The root account can't be the dst auto r = toStrand( @@ -936,7 +936,7 @@ struct PayStrand_test : public beast::unit_test::suite OfferCrossing::no, ammContext, std::nullopt, - env.app().logs().journal("Flow")); + env.app().getJournal("Flow")); BEAST_EXPECT(isTesSuccess(ter)); BEAST_EXPECT(equal(strand, D{alice, gw, usdC})); } @@ -964,7 +964,7 @@ struct PayStrand_test : public beast::unit_test::suite OfferCrossing::no, ammContext, std::nullopt, - env.app().logs().journal("Flow")); + env.app().getJournal("Flow")); BEAST_EXPECT(isTesSuccess(ter)); BEAST_EXPECT(equal( strand, D{alice, gw, usdC}, B{USD.issue(), xrpIssue(), std::nullopt}, XRPS{bob})); @@ -1145,7 +1145,7 @@ struct PayStrand_test : public beast::unit_test::suite noAccount(), pathSet, std::nullopt, - env.app().logs(), + env.app(), &inputs); BEAST_EXPECT(r.result() == temBAD_PATH); } @@ -1158,7 +1158,7 @@ struct PayStrand_test : public beast::unit_test::suite srcAcc, pathSet, std::nullopt, - env.app().logs(), + env.app(), &inputs); BEAST_EXPECT(r.result() == temBAD_PATH); } @@ -1171,7 +1171,7 @@ struct PayStrand_test : public beast::unit_test::suite srcAcc, pathSet, std::nullopt, - env.app().logs(), + env.app(), &inputs); BEAST_EXPECT(r.result() == temBAD_PATH); } @@ -1184,7 +1184,7 @@ struct PayStrand_test : public beast::unit_test::suite srcAcc, pathSet, std::nullopt, - env.app().logs(), + env.app(), &inputs); BEAST_EXPECT(r.result() == temBAD_PATH); } diff --git a/src/test/app/PseudoTx_test.cpp b/src/test/app/PseudoTx_test.cpp index 79346a3fe1..a9180d0e03 100644 --- a/src/test/app/PseudoTx_test.cpp +++ b/src/test/app/PseudoTx_test.cpp @@ -70,7 +70,7 @@ struct PseudoTx_test : public beast::unit_test::suite BEAST_EXPECT(isPseudoTx(stx)); BEAST_EXPECT(!passesLocalChecks(stx, reason)); BEAST_EXPECT(reason == "Cannot submit pseudo transactions."); - env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { + env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) { auto const result = xrpl::apply(env.app(), view, stx, tapNONE, j); BEAST_EXPECT(!result.applied && result.ter == temINVALID); return result.applied; diff --git a/src/test/app/RCLValidations_test.cpp b/src/test/app/RCLValidations_test.cpp index 63f295e3b7..e15569102a 100644 --- a/src/test/app/RCLValidations_test.cpp +++ b/src/test/app/RCLValidations_test.cpp @@ -1,10 +1,10 @@ #include #include -#include #include #include +#include namespace xrpl { namespace test { @@ -57,11 +57,15 @@ class RCLValidations_test : public beast::unit_test::suite jtx::Env env(*this); Config config; auto prev = std::make_shared( - create_genesis, config, std::vector{}, env.app().getNodeFamily()); + create_genesis, + Rules{config.features}, + config.FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); history.push_back(prev); for (auto i = 0; i < ((2 * maxAncestors) + 1); ++i) { - auto next = std::make_shared(*prev, env.app().timeKeeper().closeTime()); + auto next = std::make_shared(*prev, env.app().getTimeKeeper().closeTime()); next->updateSkipList(); history.push_back(next); prev = next; @@ -78,7 +82,7 @@ class RCLValidations_test : public beast::unit_test::suite bool forceHash = true; while (altHistory.size() < history.size()) { - auto next = std::make_shared(*prev, env.app().timeKeeper().closeTime()); + auto next = std::make_shared(*prev, env.app().getTimeKeeper().closeTime()); // Force a different hash on the first iteration next->updateSkipList(); BEAST_EXPECT(next->read(keylet::fees())); @@ -219,11 +223,15 @@ class RCLValidations_test : public beast::unit_test::suite auto& j = env.journal; Config config; auto prev = std::make_shared( - create_genesis, config, std::vector{}, env.app().getNodeFamily()); + create_genesis, + Rules{config.features}, + config.FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); history.push_back(prev); for (auto i = 0; i < (maxAncestors + 10); ++i) { - auto next = std::make_shared(*prev, env.app().timeKeeper().closeTime()); + auto next = std::make_shared(*prev, env.app().getTimeKeeper().closeTime()); next->updateSkipList(); history.push_back(next); prev = next; diff --git a/src/test/app/Regression_test.cpp b/src/test/app/Regression_test.cpp index d7535d5578..55b4b9a87c 100644 --- a/src/test/app/Regression_test.cpp +++ b/src/test/app/Regression_test.cpp @@ -45,14 +45,18 @@ struct Regression_test : public beast::unit_test::suite // be reproduced against an open ledger. Make a local // closed ledger and work with it directly. auto closed = std::make_shared( - create_genesis, env.app().config(), std::vector{}, env.app().getNodeFamily()); + create_genesis, + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); auto expectedDrops = INITIAL_XRP; BEAST_EXPECT(closed->header().drops == expectedDrops); auto const aliceXRP = 400; auto const aliceAmount = XRP(aliceXRP); - auto next = std::make_shared(*closed, env.app().timeKeeper().closeTime()); + auto next = std::make_shared(*closed, env.app().getTimeKeeper().closeTime()); { // Fund alice auto const jt = env.jt(pay(env.master, "alice", aliceAmount)); @@ -269,7 +273,7 @@ struct Regression_test : public beast::unit_test::suite if (BEAST_EXPECT(bob_index.isNonZero()) && BEAST_EXPECT(digest.has_value())) { - auto& cache = env.app().cachedSLEs(); + auto& cache = env.app().getCachedSLEs(); cache.del(*digest, false); // NOLINT(bugprone-unchecked-optional-access) auto const beforeCounts = mapCounts(CountedObjects::getInstance().getCounts(0)); diff --git a/src/test/app/SHAMapStore_test.cpp b/src/test/app/SHAMapStore_test.cpp index e5471ab74e..73cbf1c617 100644 --- a/src/test/app/SHAMapStore_test.cpp +++ b/src/test/app/SHAMapStore_test.cpp @@ -481,7 +481,7 @@ public: section, megabytes(env.app().config().getValueFor(SizedItem::burstSize, std::nullopt)), scheduler, - env.app().logs().journal("NodeStoreTest"))}; + env.app().getJournal("NodeStoreTest"))}; backend->open(); return backend; } @@ -514,7 +514,7 @@ public: std::move(writableBackend), std::move(archiveBackend), nscfg, - env.app().logs().journal("NodeStoreTest")); + env.app().getJournal("NodeStoreTest")); ///////////////////////////////////////////////////////////// // Check basic functionality diff --git a/src/test/app/TxQ_test.cpp b/src/test/app/TxQ_test.cpp index a758167319..566551fe2a 100644 --- a/src/test/app/TxQ_test.cpp +++ b/src/test/app/TxQ_test.cpp @@ -950,7 +950,7 @@ public: Env::ParsedResult parsed; - env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { + env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) { auto const result = xrpl::apply(env.app(), view, *jt.stx, tapNONE, env.journal); parsed.ter = result.ter; return result.applied; @@ -3873,7 +3873,7 @@ public: // (This requires calling directly into the open ledger, // which won't work if unit tests are separated to only // be callable via RPC.) - env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { + env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) { auto const tx = env.jt(noop(alice), seq(aliceSeq), fee(openLedgerCost(env))); auto const result = xrpl::apply(env.app(), view, *tx.stx, tapUNLIMITED, j); BEAST_EXPECT(isTesSuccess(result.ter) && result.applied); @@ -3941,7 +3941,7 @@ public: // (This requires calling directly into the open ledger, // which won't work if unit tests are separated to only // be callable via RPC.) - env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { + env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) { auto const tx = env.jt(noop(alice), ticket::use(tktSeq0 + 1), fee(openLedgerCost(env))); auto const result = xrpl::apply(env.app(), view, *tx.stx, tapUNLIMITED, j); BEAST_EXPECT(isTesSuccess(result.ter) && result.applied); diff --git a/src/test/app/ValidatorKeys_test.cpp b/src/test/app/ValidatorKeys_test.cpp index 9efe318662..29876dea7c 100644 --- a/src/test/app/ValidatorKeys_test.cpp +++ b/src/test/app/ValidatorKeys_test.cpp @@ -59,7 +59,7 @@ public: // We're only using Env for its Journal. That Journal gives better // coverage in unit tests. test::jtx::Env env{*this, test::jtx::envconfig(), nullptr, beast::severities::kDisabled}; - beast::Journal journal{env.app().journal("ValidatorKeys_test")}; + beast::Journal journal{env.app().getJournal("ValidatorKeys_test")}; // Keys/ID when using [validation_seed] SecretKey const seedSecretKey = diff --git a/src/test/app/ValidatorList_test.cpp b/src/test/app/ValidatorList_test.cpp index c4229514a1..10e34cacad 100644 --- a/src/test/app/ValidatorList_test.cpp +++ b/src/test/app/ValidatorList_test.cpp @@ -534,7 +534,7 @@ private: auto trustedKeys = std::make_unique( manifests, manifests, - env.app().timeKeeper(), + env.app().getTimeKeeper(), app.config().legacy("database_path"), env.journal); @@ -813,7 +813,7 @@ private: {}, effective6 + 1s, env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); expectUntrusted(lists.at(3)); @@ -831,7 +831,7 @@ private: {}, effective8 + 1s, env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); expectUntrusted(lists.at(6)); @@ -896,7 +896,7 @@ private: auto trustedKeys = std::make_unique( manifests, manifests, - env.app().timeKeeper(), + env.app().getTimeKeeper(), app.config().legacy("database_path"), env.journal); @@ -1062,7 +1062,7 @@ private: activeValidatorsOuter, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); for (auto const& val : unseenValidators) @@ -1088,7 +1088,7 @@ private: activeValidatorsOuter, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(changes.added.empty()); BEAST_EXPECT(changes.removed.empty()); @@ -1112,7 +1112,7 @@ private: activeValidatorsOuter, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(changes.added == asNodeIDs({masterPublic})); BEAST_EXPECT(changes.removed.empty()); @@ -1173,7 +1173,7 @@ private: activeValidatorsOuter, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(changes.removed == asNodeIDs({masterPublic})); BEAST_EXPECT(changes.added.empty()); @@ -1208,7 +1208,7 @@ private: activeValidatorsOuter, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(changes.removed.empty()); BEAST_EXPECT(changes.added.empty()); @@ -1240,7 +1240,7 @@ private: activeValidatorsOuter, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(changes.removed.empty()); BEAST_EXPECT(changes.added.size() == 1); @@ -1287,7 +1287,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(changes.removed.empty()); BEAST_EXPECT(changes.added == expectedTrusted); @@ -1299,7 +1299,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(changes.removed.empty()); BEAST_EXPECT(changes.added.empty()); @@ -1310,7 +1310,7 @@ private: auto trustedKeys = std::make_unique( manifestsOuter, manifestsOuter, - env.app().timeKeeper(), + env.app().getTimeKeeper(), app.config().legacy("database_path"), env.journal); @@ -1349,7 +1349,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(changes.removed.empty()); BEAST_EXPECT(changes.added == activeValidators); @@ -1365,7 +1365,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(changes.removed == activeValidators); BEAST_EXPECT(changes.added.empty()); @@ -1390,7 +1390,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(changes.removed.empty()); BEAST_EXPECT( @@ -1431,7 +1431,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(changes.removed.empty()); BEAST_EXPECT(changes.added == asNodeIDs({valKey})); @@ -1468,7 +1468,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(changes.removed.empty()); if (cfgKeys.size() > 2) @@ -1560,7 +1560,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(valKeys.size() * 0.8f)); @@ -1675,7 +1675,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil((valKeys.size() - 3) * 0.8f)); @@ -1706,7 +1706,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil((valKeys.size() - 6) * 0.8f)); @@ -1739,7 +1739,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::numeric_limits::max()); @@ -1809,7 +1809,7 @@ private: auto trustedKeys = std::make_unique( manifests, manifests, - env.app().timeKeeper(), + env.app().getTimeKeeper(), app.config().legacy("database_path"), env.journal); @@ -1907,7 +1907,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT( trustedKeys->expires() && @@ -1924,7 +1924,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT( trustedKeys->expires() && @@ -1969,7 +1969,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); if (minimumQuorum == trustedKeys->quorum() || trustedKeys->quorum() == std::ceil(cfgKeys.size() * 0.8f)) @@ -2019,7 +2019,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT( validators->quorum() == @@ -2063,7 +2063,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); return validators->quorum() == quorum; } @@ -2094,7 +2094,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(validators->quorum() == 39); } @@ -2121,7 +2121,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(validators->quorum() == 30); hash_set nUnl; @@ -2136,7 +2136,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(validators->quorum() == 30); } @@ -2629,7 +2629,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -2650,7 +2650,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == 1); @@ -2688,7 +2688,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -2708,7 +2708,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().empty()); @@ -2753,7 +2753,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -2773,7 +2773,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == 1); @@ -2822,7 +2822,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -2843,7 +2843,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == 1); @@ -2889,7 +2889,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -2909,7 +2909,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == 1); @@ -2956,7 +2956,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -2976,7 +2976,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().empty()); @@ -3021,7 +3021,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3042,7 +3042,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3080,7 +3080,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3101,7 +3101,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3139,7 +3139,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3159,7 +3159,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3195,7 +3195,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3215,7 +3215,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3260,7 +3260,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3281,7 +3281,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == 1); @@ -3327,7 +3327,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3347,7 +3347,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == 1); @@ -3394,7 +3394,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3414,7 +3414,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().empty()); @@ -3453,7 +3453,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3474,7 +3474,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == 1); @@ -3514,7 +3514,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3535,7 +3535,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == 1); @@ -3576,7 +3576,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3596,7 +3596,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().empty()); @@ -3637,7 +3637,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3658,7 +3658,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == 1); @@ -3700,7 +3700,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3738,7 +3738,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3784,7 +3784,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3805,7 +3805,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == 1); @@ -3853,7 +3853,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == std::ceil(keysTotal * 0.8f)); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == keysTotal); @@ -3873,7 +3873,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(trustedKeys->quorum() == quorumDisabled); BEAST_EXPECT(trustedKeys->getTrustedMasterKeys().size() == 1); diff --git a/src/test/app/ValidatorSite_test.cpp b/src/test/app/ValidatorSite_test.cpp index f1e3b57b1e..160da452ee 100644 --- a/src/test/app/ValidatorSite_test.cpp +++ b/src/test/app/ValidatorSite_test.cpp @@ -139,7 +139,7 @@ private: p->legacy("database_path", good.subdir().string()); return p; }()); - auto& trustedKeys = env.app().validators(); + auto& trustedKeys = env.app().getValidators(); env.timeKeeper().set(env.timeKeeper().now() + 30s); test::StreamSink sink; diff --git a/src/test/app/Vault_test.cpp b/src/test/app/Vault_test.cpp index fa935eba6e..37ad3ae334 100644 --- a/src/test/app/Vault_test.cpp +++ b/src/test/app/Vault_test.cpp @@ -3366,23 +3366,24 @@ class Vault_test : public beast::unit_test::suite env.memoize(vaultAccount); auto const peek = [keylet, &env, this](std::function fn) -> bool { - return env.app().openLedger().modify([&](OpenView& view, beast::Journal j) -> bool { - Sandbox sb(&view, tapNONE); - auto vault = sb.peek(keylet::vault(keylet.key)); - if (!BEAST_EXPECT(vault != nullptr)) + return env.app().getOpenLedger().modify( + [&](OpenView& view, beast::Journal j) -> bool { + Sandbox sb(&view, tapNONE); + auto vault = sb.peek(keylet::vault(keylet.key)); + if (!BEAST_EXPECT(vault != nullptr)) + return false; + auto shares = sb.peek(keylet::mptIssuance(vault->at(sfShareMPTID))); + if (!BEAST_EXPECT(shares != nullptr)) + return false; + if (fn(*vault, *shares)) + { + sb.update(vault); + sb.update(shares); + sb.apply(view); + return true; + } return false; - auto shares = sb.peek(keylet::mptIssuance(vault->at(sfShareMPTID))); - if (!BEAST_EXPECT(shares != nullptr)) - return false; - if (fn(*vault, *shares)) - { - sb.update(vault); - sb.update(shares); - sb.apply(view); - return true; - } - return false; - }); + }); }; test( diff --git a/src/test/basics/PerfLog_test.cpp b/src/test/basics/PerfLog_test.cpp index 1647ce241e..470a52d220 100644 --- a/src/test/basics/PerfLog_test.cpp +++ b/src/test/basics/PerfLog_test.cpp @@ -29,7 +29,7 @@ class PerfLog_test : public beast::unit_test::suite // We're only using Env for its Journal. That Journal gives better // coverage in unit tests. test::jtx::Env env_{*this, test::jtx::envconfig(), nullptr, beast::severities::kDisabled}; - beast::Journal j_{env_.app().journal("PerfLog_test")}; + beast::Journal j_{env_.app().getJournal("PerfLog_test")}; struct Fixture { diff --git a/src/test/beast/beast_io_latency_probe_test.cpp b/src/test/beast/beast_io_latency_probe_test.cpp index f2423550d3..b2163f2630 100644 --- a/src/test/beast/beast_io_latency_probe_test.cpp +++ b/src/test/beast/beast_io_latency_probe_test.cpp @@ -50,7 +50,7 @@ class io_latency_probe_test : public beast::unit_test::suite, public beast::test bool done = false; boost::system::error_code wait_err; - while (--num_samples) + while (--num_samples > 0u) { auto const start{MeasureClock::now()}; done = false; diff --git a/src/test/consensus/LedgerTiming_test.cpp b/src/test/consensus/LedgerTiming_test.cpp index 945f6b4ff0..4441184af4 100644 --- a/src/test/consensus/LedgerTiming_test.cpp +++ b/src/test/consensus/LedgerTiming_test.cpp @@ -1,6 +1,5 @@ -#include - #include +#include namespace xrpl { namespace test { diff --git a/src/test/consensus/NegativeUNL_test.cpp b/src/test/consensus/NegativeUNL_test.cpp index 019d8ee545..cf8c8e87ef 100644 --- a/src/test/consensus/NegativeUNL_test.cpp +++ b/src/test/consensus/NegativeUNL_test.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include @@ -211,7 +210,11 @@ class NegativeUNL_test : public beast::unit_test::suite std::vector publicKeys = createPublicKeys(3); // genesis ledger auto l = std::make_shared( - create_genesis, env.app().config(), std::vector{}, env.app().getNodeFamily()); + create_genesis, + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); // Record the public keys and ledger sequences of expected negative UNL // validators when we build the ledger history @@ -219,7 +222,7 @@ class NegativeUNL_test : public beast::unit_test::suite { //(1) the ledger after genesis, not a flag ledger - l = std::make_shared(*l, env.app().timeKeeper().closeTime()); + l = std::make_shared(*l, env.app().getTimeKeeper().closeTime()); auto txDisable_0 = createTx(true, l->seq(), publicKeys[0]); auto txReEnable_1 = createTx(false, l->seq(), publicKeys[1]); @@ -236,7 +239,7 @@ class NegativeUNL_test : public beast::unit_test::suite // generate more ledgers for (auto i = 0; i < 256 - 2; ++i) { - l = std::make_shared(*l, env.app().timeKeeper().closeTime()); + l = std::make_shared(*l, env.app().getTimeKeeper().closeTime()); } BEAST_EXPECT(l->isFlagLedger()); l->updateNegativeUNL(); @@ -271,7 +274,7 @@ class NegativeUNL_test : public beast::unit_test::suite BEAST_EXPECT(good_size); if (good_size) BEAST_EXPECT(l->validatorToDisable() == publicKeys[0]); - l = std::make_shared(*l, env.app().timeKeeper().closeTime()); + l = std::make_shared(*l, env.app().getTimeKeeper().closeTime()); } BEAST_EXPECT(l->isFlagLedger()); l->updateNegativeUNL(); @@ -323,7 +326,7 @@ class NegativeUNL_test : public beast::unit_test::suite BEAST_EXPECT(l->validatorToDisable() == publicKeys[1]); BEAST_EXPECT(l->validatorToReEnable() == publicKeys[0]); } - l = std::make_shared(*l, env.app().timeKeeper().closeTime()); + l = std::make_shared(*l, env.app().getTimeKeeper().closeTime()); } BEAST_EXPECT(l->isFlagLedger()); l->updateNegativeUNL(); @@ -365,7 +368,7 @@ class NegativeUNL_test : public beast::unit_test::suite BEAST_EXPECT(l->negativeUNL().count(publicKeys[1])); BEAST_EXPECT(l->validatorToDisable() == publicKeys[0]); } - l = std::make_shared(*l, env.app().timeKeeper().closeTime()); + l = std::make_shared(*l, env.app().getTimeKeeper().closeTime()); } BEAST_EXPECT(l->isFlagLedger()); l->updateNegativeUNL(); @@ -414,7 +417,7 @@ class NegativeUNL_test : public beast::unit_test::suite BEAST_EXPECT(l->negativeUNL().count(publicKeys[1])); BEAST_EXPECT(l->validatorToReEnable() == publicKeys[0]); } - l = std::make_shared(*l, env.app().timeKeeper().closeTime()); + l = std::make_shared(*l, env.app().getTimeKeeper().closeTime()); } BEAST_EXPECT(l->isFlagLedger()); l->updateNegativeUNL(); @@ -456,7 +459,7 @@ class NegativeUNL_test : public beast::unit_test::suite BEAST_EXPECT(l->negativeUNL().count(publicKeys[1])); BEAST_EXPECT(l->validatorToReEnable() == publicKeys[1]); } - l = std::make_shared(*l, env.app().timeKeeper().closeTime()); + l = std::make_shared(*l, env.app().getTimeKeeper().closeTime()); } BEAST_EXPECT(l->isFlagLedger()); l->updateNegativeUNL(); @@ -470,7 +473,7 @@ class NegativeUNL_test : public beast::unit_test::suite for (auto i = 0; i < 256; ++i) { BEAST_EXPECT(negUnlSizeTest(l, 0, false, false)); - l = std::make_shared(*l, env.app().timeKeeper().closeTime()); + l = std::make_shared(*l, env.app().getTimeKeeper().closeTime()); } BEAST_EXPECT(l->isFlagLedger()); l->updateNegativeUNL(); @@ -543,7 +546,8 @@ struct NetworkHistory static uint256 fake_amendment; // So we have different genesis ledgers auto l = std::make_shared( create_genesis, - env.app().config(), + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), std::vector{fake_amendment++}, env.app().getNodeFamily()); history.push_back(l); @@ -553,7 +557,7 @@ struct NetworkHistory int nidx = 0; while (l->seq() <= param.numLedgers) { - l = std::make_shared(*l, env.app().timeKeeper().closeTime()); + l = std::make_shared(*l, env.app().getTimeKeeper().closeTime()); history.push_back(l); if (l->isFlagLedger()) @@ -601,7 +605,11 @@ struct NetworkHistory { static auto keyPair = randomKeyPair(KeyType::secp256k1); return std::make_shared( - env.app().timeKeeper().now(), keyPair.first, keyPair.second, v, [&](STValidation& v) { + env.app().getTimeKeeper().now(), + keyPair.first, + keyPair.second, + v, + [&](STValidation& v) { v.setFieldH256(sfLedgerHash, ledger->header().hash); v.setFieldU32(sfLedgerSequence, ledger->seq()); v.setFlag(vfFullValidation); @@ -1670,11 +1678,15 @@ class NegativeUNLVoteFilterValidations_test : public beast::unit_test::suite testcase("Filter Validations"); jtx::Env env(*this); auto l = std::make_shared( - create_genesis, env.app().config(), std::vector{}, env.app().getNodeFamily()); + create_genesis, + Rules{env.app().config().features}, + env.app().config().FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); auto createSTVal = [&](std::pair const& keys) { return std::make_shared( - env.app().timeKeeper().now(), + env.app().getTimeKeeper().now(), keys.first, keys.second, calcNodeID(keys.first), @@ -1705,7 +1717,7 @@ class NegativeUNLVoteFilterValidations_test : public beast::unit_test::suite } // setup the ValidatorList - auto& validators = env.app().validators(); + auto& validators = env.app().getValidators(); auto& local = *nUnlKeys.begin(); std::vector cfgPublishers; validators.load(local, cfgKeys, cfgPublishers); @@ -1713,7 +1725,7 @@ class NegativeUNLVoteFilterValidations_test : public beast::unit_test::suite activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT(validators.getTrustedMasterKeys().size() == numNodes); validators.setNegativeUNL(nUnlKeys); diff --git a/src/test/core/ClosureCounter_test.cpp b/src/test/core/ClosureCounter_test.cpp index 736b833d76..088b7b9ff9 100644 --- a/src/test/core/ClosureCounter_test.cpp +++ b/src/test/core/ClosureCounter_test.cpp @@ -17,7 +17,7 @@ class ClosureCounter_test : public beast::unit_test::suite // We're only using Env for its Journal. That Journal gives better // coverage in unit tests. test::jtx::Env env_{*this, jtx::envconfig(), nullptr, beast::severities::kDisabled}; - beast::Journal j{env_.app().journal("ClosureCounter_test")}; + beast::Journal j{env_.app().getJournal("ClosureCounter_test")}; void testConstruction() diff --git a/src/test/csf/ledgers.h b/src/test/csf/ledgers.h index 6e50f3584b..67a7427af6 100644 --- a/src/test/csf/ledgers.h +++ b/src/test/csf/ledgers.h @@ -2,13 +2,12 @@ #include -#include - #include #include #include #include #include +#include #include diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index a103d42ca3..b494ade31c 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -11,17 +11,17 @@ #include #include -#include #include #include -#include #include +#include #include #include #include #include #include +#include #include #include #include @@ -189,7 +189,7 @@ public: beast::severities::Severity thresh = beast::severities::kError) : test(suite_) , bundle_(suite_, std::move(config), std::move(logs), thresh) - , journal{bundle_.app->journal("Env")} + , journal{bundle_.app->getJournal("Env")} { memoize(Account::master); Pathfinder::initPathTable(); @@ -328,7 +328,7 @@ public: std::shared_ptr current() const { - return app().openLedger().current(); + return app().getOpenLedger().current(); } /** Returns the last closed ledger. diff --git a/src/test/jtx/impl/AMM.cpp b/src/test/jtx/impl/AMM.cpp index ccad604070..7109a2131d 100644 --- a/src/test/jtx/impl/AMM.cpp +++ b/src/test/jtx/impl/AMM.cpp @@ -775,7 +775,7 @@ AMM::expectAuctionSlot(auto&& cb) const // to avoid the failure. auto const slotFee = auctionSlot[~sfDiscountedFee].value_or(0); auto const slotInterval = ammAuctionTimeSlot( - env_.app().timeKeeper().now().time_since_epoch().count(), auctionSlot); + env_.app().getTimeKeeper().now().time_since_epoch().count(), auctionSlot); auto const slotPrice = auctionSlot[sfPrice].iou(); auto const authAccounts = auctionSlot.getFieldArray(sfAuthAccounts); return cb(slotFee, slotInterval, slotPrice, authAccounts); diff --git a/src/test/jtx/impl/Env.cpp b/src/test/jtx/impl/Env.cpp index 6967b48518..3f49a54ae6 100644 --- a/src/test/jtx/impl/Env.cpp +++ b/src/test/jtx/impl/Env.cpp @@ -61,7 +61,7 @@ Env::AppBundle::AppBundle( config->SSL_VERIFY_DIR, config->SSL_VERIFY_FILE, config->SSL_VERIFY, debugLog()); owned = make_Application(std::move(config), std::move(logs), std::move(timeKeeper_)); app = owned.get(); - app->logs().threshold(thresh); + app->getLogs().threshold(thresh); if (!app->setup({})) Throw("Env::AppBundle: setup failed"); timeKeeper->set(app->getLedgerMaster().getClosedLedger()->header().closeTime); @@ -637,14 +637,14 @@ Env::do_rpc( std::vector const& args, std::unordered_map const& headers) { - auto response = rpcClient(args, app().config(), app().logs(), apiVersion, headers); + auto response = rpcClient(args, app().config(), app().getLogs(), apiVersion, headers); for (unsigned ctr = 0; (ctr < retries_) and (response.first == rpcINTERNAL); ++ctr) { JLOG(journal.error()) << "Env::do_rpc error, retrying, attempt #" << ctr + 1 << " ..."; std::this_thread::sleep_for(std::chrono::milliseconds(500)); - response = rpcClient(args, app().config(), app().logs(), apiVersion, headers); + response = rpcClient(args, app().config(), app().getLogs(), apiVersion, headers); } return response.second; diff --git a/src/test/jtx/impl/directory.cpp b/src/test/jtx/impl/directory.cpp index bf63bc523b..da0a338e7c 100644 --- a/src/test/jtx/impl/directory.cpp +++ b/src/test/jtx/impl/directory.cpp @@ -15,7 +15,7 @@ bumpLastPage( std::function adjust) -> Expected { Expected res{}; - env.app().openLedger().modify([&](OpenView& view, beast::Journal j) -> bool { + env.app().getOpenLedger().modify([&](OpenView& view, beast::Journal j) -> bool { Sandbox sb(&view, tapNONE); // Find the root page diff --git a/src/test/jtx/impl/paths.cpp b/src/test/jtx/impl/paths.cpp index e26f214fe4..af72b8bd5a 100644 --- a/src/test/jtx/impl/paths.cpp +++ b/src/test/jtx/impl/paths.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include @@ -30,7 +30,7 @@ paths::operator()(Env& env, JTx& jt) const } Pathfinder pf( - std::make_shared(env.current(), env.app().journal("RippleLineCache")), + std::make_shared(env.current(), env.app().getJournal("RippleLineCache")), from, to, in_.currency, diff --git a/src/test/jtx/utility.h b/src/test/jtx/utility.h index 895d00f12b..15c323f047 100644 --- a/src/test/jtx/utility.h +++ b/src/test/jtx/utility.h @@ -2,9 +2,8 @@ #include -#include - #include +#include #include #include diff --git a/src/test/ledger/PaymentSandbox_test.cpp b/src/test/ledger/PaymentSandbox_test.cpp index a5023aa328..df23381ed3 100644 --- a/src/test/ledger/PaymentSandbox_test.cpp +++ b/src/test/ledger/PaymentSandbox_test.cpp @@ -88,7 +88,7 @@ class PaymentSandbox_test : public beast::unit_test::suite env.fund(XRP(10000), alice, gw1, gw2); - auto j = env.app().journal("View"); + auto j = env.app().getJournal("View"); auto const USD_gw1 = gw1["USD"]; auto const USD_gw2 = gw2["USD"]; diff --git a/src/test/ledger/PendingSaves_test.cpp b/src/test/ledger/PendingSaves_test.cpp index ddf371e913..5e08fc53e4 100644 --- a/src/test/ledger/PendingSaves_test.cpp +++ b/src/test/ledger/PendingSaves_test.cpp @@ -1,6 +1,5 @@ -#include - #include +#include namespace xrpl { namespace test { diff --git a/src/test/ledger/SkipList_test.cpp b/src/test/ledger/SkipList_test.cpp index 8430db3904..ba339878ef 100644 --- a/src/test/ledger/SkipList_test.cpp +++ b/src/test/ledger/SkipList_test.cpp @@ -1,8 +1,7 @@ #include -#include - #include +#include #include namespace xrpl { @@ -18,11 +17,15 @@ class SkipList_test : public beast::unit_test::suite { Config config; auto prev = std::make_shared( - create_genesis, config, std::vector{}, env.app().getNodeFamily()); + create_genesis, + Rules{config.features}, + config.FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); history.push_back(prev); for (auto i = 0; i < 1023; ++i) { - auto next = std::make_shared(*prev, env.app().timeKeeper().closeTime()); + auto next = std::make_shared(*prev, env.app().getTimeKeeper().closeTime()); next->updateSkipList(); history.push_back(next); prev = next; diff --git a/src/test/ledger/View_test.cpp b/src/test/ledger/View_test.cpp index f57cb609cc..6e11508156 100644 --- a/src/test/ledger/View_test.cpp +++ b/src/test/ledger/View_test.cpp @@ -1,9 +1,9 @@ #include -#include #include #include +#include #include #include #include @@ -116,8 +116,13 @@ class View_test : public beast::unit_test::suite Env env(*this); Config config; std::shared_ptr const genesis = std::make_shared( - create_genesis, config, std::vector{}, env.app().getNodeFamily()); - auto const ledger = std::make_shared(*genesis, env.app().timeKeeper().closeTime()); + create_genesis, + Rules{config.features}, + config.FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); + auto const ledger = + std::make_shared(*genesis, env.app().getTimeKeeper().closeTime()); wipe(*ledger); ReadView& v = *ledger; succ(v, 0, std::nullopt); @@ -147,7 +152,7 @@ class View_test : public beast::unit_test::suite using namespace jtx; Env env(*this); - wipe(env.app().openLedger()); + wipe(env.app().getOpenLedger()); auto const open = env.current(); ApplyViewImpl v(&*open, tapNONE); succ(v, 0, std::nullopt); @@ -180,7 +185,7 @@ class View_test : public beast::unit_test::suite using namespace jtx; Env env(*this); - wipe(env.app().openLedger()); + wipe(env.app().getOpenLedger()); auto const open = env.current(); ApplyViewImpl v0(&*open, tapNONE); v0.insert(sle(1)); @@ -246,7 +251,7 @@ class View_test : public beast::unit_test::suite using namespace jtx; Env env(*this); - wipe(env.app().openLedger()); + wipe(env.app().getOpenLedger()); auto const open = env.current(); ApplyViewImpl v0(&*open, tapNONE); v0.rawInsert(sle(1, 1)); @@ -315,7 +320,7 @@ class View_test : public beast::unit_test::suite using namespace std::chrono; { Env env(*this); - wipe(env.app().openLedger()); + wipe(env.app().getOpenLedger()); auto const open = env.current(); OpenView v0(open.get()); BEAST_EXPECT(v0.seq() != 98); @@ -379,8 +384,13 @@ class View_test : public beast::unit_test::suite Env env(*this); Config config; std::shared_ptr const genesis = std::make_shared( - create_genesis, config, std::vector{}, env.app().getNodeFamily()); - auto const ledger = std::make_shared(*genesis, env.app().timeKeeper().closeTime()); + create_genesis, + Rules{config.features}, + config.FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); + auto const ledger = + std::make_shared(*genesis, env.app().getTimeKeeper().closeTime()); auto setup = [&ledger](std::vector const& vec) { wipe(*ledger); @@ -583,8 +593,13 @@ class View_test : public beast::unit_test::suite Env env(*this); Config config; std::shared_ptr const genesis = std::make_shared( - create_genesis, config, std::vector{}, env.app().getNodeFamily()); - auto const ledger = std::make_shared(*genesis, env.app().timeKeeper().closeTime()); + create_genesis, + Rules{config.features}, + config.FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); + auto const ledger = + std::make_shared(*genesis, env.app().getTimeKeeper().closeTime()); auto setup123 = [&ledger, this]() { // erase middle element wipe(*ledger); @@ -929,9 +944,13 @@ class View_test : public beast::unit_test::suite Env env(*this); Config config; std::shared_ptr const genesis = std::make_shared( - create_genesis, config, std::vector{}, env.app().getNodeFamily()); + create_genesis, + Rules{config.features}, + config.FEES.toFees(), + std::vector{}, + env.app().getNodeFamily()); auto const ledger = - std::make_shared(*genesis, env.app().timeKeeper().closeTime()); + std::make_shared(*genesis, env.app().getTimeKeeper().closeTime()); wipe(*ledger); ledger->rawInsert(sle(1)); ReadView& v0 = *ledger; @@ -947,9 +966,9 @@ class View_test : public beast::unit_test::suite // Make sure OpenLedger::empty works { Env env(*this); - BEAST_EXPECT(env.app().openLedger().empty()); + BEAST_EXPECT(env.app().getOpenLedger().empty()); env.fund(XRP(10000), Account("test")); - BEAST_EXPECT(!env.app().openLedger().empty()); + BEAST_EXPECT(!env.app().getOpenLedger().empty()); } } diff --git a/src/test/overlay/TMGetObjectByHash_test.cpp b/src/test/overlay/TMGetObjectByHash_test.cpp index b899ceb084..e4da8a28c7 100644 --- a/src/test/overlay/TMGetObjectByHash_test.cpp +++ b/src/test/overlay/TMGetObjectByHash_test.cpp @@ -95,7 +95,7 @@ class TMGetObjectByHash_test : public beast::unit_test::suite std::shared_ptr createPeer(jtx::Env& env) { - auto& overlay = dynamic_cast(env.app().overlay()); + auto& overlay = dynamic_cast(env.app().getOverlay()); boost::beast::http::request request; auto stream_ptr = std::make_unique(socket_type(env.app().getIOContext()), *context_); diff --git a/src/test/overlay/compression_test.cpp b/src/test/overlay/compression_test.cpp index 38b60c2251..8cee7df7d2 100644 --- a/src/test/overlay/compression_test.cpp +++ b/src/test/overlay/compression_test.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -15,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/src/test/overlay/reduce_relay_test.cpp b/src/test/overlay/reduce_relay_test.cpp index b4a47bac53..895332b94f 100644 --- a/src/test/overlay/reduce_relay_test.cpp +++ b/src/test/overlay/reduce_relay_test.cpp @@ -507,7 +507,7 @@ class OverlaySim : public Overlay, public reduce_relay::SquelchHandler public: using id_t = Peer::id_t; using clock_type = ManualClock; - OverlaySim(Application& app) : slots_(app.logs(), *this, app.config()), logs_(app.logs()) + OverlaySim(Application& app) : slots_(app, *this, app.config()), registry_(app) { } @@ -561,7 +561,7 @@ public: Peer::id_t id = 0; if (peersCache_.empty() || !useCache) { - peer = std::make_shared(*this, logs_.journal("Squelch")); + peer = std::make_shared(*this, registry_.getJournal("Squelch")); id = peer->id(); } else @@ -673,7 +673,7 @@ private: Peers peers_; Peers peersCache_; reduce_relay::Slots slots_; - Logs& logs_; + ServiceRegistry& registry_; }; class Network @@ -1406,7 +1406,7 @@ vp_base_squelch_max_selected_peers=2 auto createSlots = [&](bool baseSquelchEnabled) -> reduce_relay::Slots { env_.app().config().VP_REDUCE_RELAY_BASE_SQUELCH_ENABLE = baseSquelchEnabled; return reduce_relay::Slots( - env_.app().logs(), network_.overlay(), env_.app().config()); + env_.app(), network_.overlay(), env_.app().config()); }; // base squelching must not be ready if squelching is disabled BEAST_EXPECT(!createSlots(false).baseSquelchReady()); @@ -1487,8 +1487,7 @@ vp_base_squelch_max_selected_peers=2 auto run = [&](int npeers) { handler.maxDuration_ = 0; - reduce_relay::Slots slots( - env_.app().logs(), handler, env_.app().config()); + reduce_relay::Slots slots(env_.app(), handler, env_.app().config()); // 1st message from a new peer switches the slot // to counting state and resets the counts of all peers + // MAX_MESSAGE_THRESHOLD + 1 messages to reach the threshold diff --git a/src/test/overlay/tx_reduce_relay_test.cpp b/src/test/overlay/tx_reduce_relay_test.cpp index 11b5c95a4e..04d8bae768 100644 --- a/src/test/overlay/tx_reduce_relay_test.cpp +++ b/src/test/overlay/tx_reduce_relay_test.cpp @@ -151,7 +151,7 @@ private: void addPeer(jtx::Env& env, std::vector>& peers, std::uint16_t& nDisabled) { - auto& overlay = dynamic_cast(env.app().overlay()); + auto& overlay = dynamic_cast(env.app().getOverlay()); boost::beast::http::request request; (nDisabled == 0) ? request.insert("X-Protocol-Ctl", makeFeaturesRequestHeader(false, false, true, false)) @@ -216,7 +216,7 @@ private: m.set_rawtransaction(s.data(), s.size()); m.set_deferred(false); m.set_status(protocol::TransactionStatus::tsNEW); - env.app().overlay().relay(uint256{0}, m, toSkip); + env.app().getOverlay().relay(uint256{0}, m, toSkip); BEAST_EXPECT(PeerTest::sendTx_ == expectRelay && PeerTest::queueTx_ == expectQueue); } } diff --git a/src/test/rpc/LedgerEntry_test.cpp b/src/test/rpc/LedgerEntry_test.cpp index 8f4a096e2a..fd7efaede4 100644 --- a/src/test/rpc/LedgerEntry_test.cpp +++ b/src/test/rpc/LedgerEntry_test.cpp @@ -673,7 +673,7 @@ class LedgerEntry_test : public beast::unit_test::suite view.rawInsert(sle); return true; }; - env.app().openLedger().modify(amendments); + env.app().getOpenLedger().modify(amendments); } Json::Value jvParams; @@ -1561,7 +1561,7 @@ class LedgerEntry_test : public beast::unit_test::suite view.rawInsert(sle); return true; }; - env.app().openLedger().modify(nUNL); + env.app().getOpenLedger().modify(nUNL); } Json::Value jvParams; diff --git a/src/test/rpc/Peers_test.cpp b/src/test/rpc/Peers_test.cpp index d72ad6d878..de46fd766c 100644 --- a/src/test/rpc/Peers_test.cpp +++ b/src/test/rpc/Peers_test.cpp @@ -34,7 +34,7 @@ class Peers_test : public beast::unit_test::suite std::string name = "Node " + std::to_string(i); using namespace std::chrono_literals; - env.app().cluster().update(kp.first, name, 200, env.timeKeeper().now() - 10s); + env.app().getCluster().update(kp.first, name, 200, env.timeKeeper().now() - 10s); nodes.insert(std::make_pair(toBase58(TokenType::NodePublic, kp.first), name)); } diff --git a/src/test/rpc/ValidatorRPC_test.cpp b/src/test/rpc/ValidatorRPC_test.cpp index 43ba188f6a..eece5c4448 100644 --- a/src/test/rpc/ValidatorRPC_test.cpp +++ b/src/test/rpc/ValidatorRPC_test.cpp @@ -122,7 +122,7 @@ public: auto k2 = randomKeyPair(KeyType::ed25519).first; disabledKeys.insert(k1); disabledKeys.insert(k2); - env.app().validators().setNegativeUNL(disabledKeys); + env.app().getValidators().setNegativeUNL(disabledKeys); auto const jrr = env.rpc("validators")[jss::result]; auto& jrrnUnl = jrr[jss::NegativeUNL]; @@ -138,7 +138,7 @@ public: } disabledKeys.clear(); - env.app().validators().setNegativeUNL(disabledKeys); + env.app().getValidators().setNegativeUNL(disabledKeys); auto const jrrUpdated = env.rpc("validators")[jss::result]; BEAST_EXPECT(jrrUpdated[jss::NegativeUNL].isNull()); } @@ -192,8 +192,8 @@ public: }), }; - env.app().validatorSites().start(); - env.app().validatorSites().join(); + env.app().getValidatorSites().start(); + env.app().getValidatorSites().join(); { auto const jrr = env.rpc("server_info")[jss::result]; @@ -252,8 +252,8 @@ public: }), }; - env.app().validatorSites().start(); - env.app().validatorSites().join(); + env.app().getValidatorSites().start(); + env.app().getValidatorSites().join(); { auto const jrr = env.rpc("server_info")[jss::result]; @@ -315,17 +315,17 @@ public: }), }; - env.app().validatorSites().start(); - env.app().validatorSites().join(); + env.app().getValidatorSites().start(); + env.app().getValidatorSites().join(); hash_set startKeys; for (auto const& val : validators) startKeys.insert(calcNodeID(val.masterPublic)); - env.app().validators().updateTrusted( + env.app().getValidators().updateTrusted( startKeys, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); { @@ -408,17 +408,17 @@ public: }), }; - env.app().validatorSites().start(); - env.app().validatorSites().join(); + env.app().getValidatorSites().start(); + env.app().getValidatorSites().join(); hash_set startKeys; for (auto const& val : validators) startKeys.insert(calcNodeID(val.masterPublic)); - env.app().validators().updateTrusted( + env.app().getValidators().updateTrusted( startKeys, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); { diff --git a/src/xrpld/app/consensus/RCLConsensus.cpp b/src/xrpld/app/consensus/RCLConsensus.cpp index 315f9f2ab5..71f3d1cf2a 100644 --- a/src/xrpld/app/consensus/RCLConsensus.cpp +++ b/src/xrpld/app/consensus/RCLConsensus.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -11,7 +10,6 @@ #include #include #include -#include #include #include @@ -20,6 +18,8 @@ #include #include #include +#include +#include #include #include #include @@ -145,7 +145,7 @@ RCLConsensus::Adaptor::share(RCLCxPeerPos const& peerPos) auto const sig = peerPos.signature(); prop.set_signature(sig.data(), sig.size()); - app_.overlay().relay(prop, peerPos.suppressionID(), peerPos.publicKey()); + app_.getOverlay().relay(prop, peerPos.suppressionID(), peerPos.publicKey()); } void @@ -159,9 +159,9 @@ RCLConsensus::Adaptor::share(RCLCxTx const& tx) protocol::TMTransaction msg; msg.set_rawtransaction(slice.data(), slice.size()); msg.set_status(protocol::tsNEW); - msg.set_receivetimestamp(app_.timeKeeper().now().time_since_epoch().count()); + msg.set_receivetimestamp(app_.getTimeKeeper().now().time_since_epoch().count()); static std::set skip{}; - app_.overlay().relay(tx.id(), msg, skip); + app_.getOverlay().relay(tx.id(), msg, skip); } else { @@ -207,7 +207,7 @@ RCLConsensus::Adaptor::propose(RCLCxPeerPos::Proposal const& proposal) app_.getHashRouter().addSuppression(suppression); - app_.overlay().broadcast(prop); + app_.getOverlay().broadcast(prop); } void @@ -229,7 +229,7 @@ RCLConsensus::Adaptor::acquireTxSet(RCLTxSet::ID const& setId) bool RCLConsensus::Adaptor::hasOpenTransactions() const { - return !app_.openLedger().empty(); + return !app_.getOpenLedger().empty(); } std::size_t @@ -284,7 +284,7 @@ RCLConsensus::Adaptor::onClose( // Tell the ledger master not to acquire the ledger we're probably building ledgerMaster_.setBuildingLedger(prevLedger->header().seq + 1); - auto initialLedger = app_.openLedger().current(); + auto initialLedger = app_.getOpenLedger().current(); auto initialSet = std::make_shared(SHAMapType::TRANSACTION, app_.getNodeFamily()); initialSet->setUnbacked(); @@ -308,9 +308,9 @@ RCLConsensus::Adaptor::onClose( // previous ledger was flag ledger, add fee and amendment // pseudo-transactions auto validations = - app_.validators().negativeUNLFilter(app_.getValidations().getTrustedForLedger( + app_.getValidators().negativeUNLFilter(app_.getValidations().getTrustedForLedger( prevLedger->header().parentHash, prevLedger->seq() - 1)); - if (validations.size() >= app_.validators().quorum()) + if (validations.size() >= app_.getValidators().quorum()) { feeVote_->doVoting(prevLedger, validations, initialSet); app_.getAmendmentTable().doVoting(prevLedger, validations, initialSet, j_); @@ -323,7 +323,7 @@ RCLConsensus::Adaptor::onClose( // add negative UNL pseudo-transactions nUnlVote_.doVoting( prevLedger, - app_.validators().getTrustedMasterKeys(), + app_.getValidators().getTrustedMasterKeys(), app_.getValidations(), initialSet); } @@ -355,7 +355,7 @@ RCLConsensus::Adaptor::onClose( RCLCxPeerPos::Proposal::seqJoin, setHash, closeTime, - app_.timeKeeper().closeTime(), + app_.getTimeKeeper().closeTime(), validatorKeys_.nodeID}}; } @@ -496,7 +496,7 @@ RCLConsensus::Adaptor::doAccept( censorshipDetector_.check( std::move(accepted), - [curr = built.seq(), j = app_.journal("CensorshipDetector"), &failed]( + [curr = built.seq(), j = app_.getJournal("CensorshipDetector"), &failed]( uint256 const& id, LedgerIndex seq) { if (failed.contains(id)) return true; @@ -592,7 +592,7 @@ RCLConsensus::Adaptor::doAccept( { rules.emplace(app_.config().features); } - app_.openLedger().accept( + app_.getOpenLedger().accept( app_, *rules, built.ledger_, @@ -620,7 +620,7 @@ RCLConsensus::Adaptor::doAccept( ledgerMaster_.getClosedLedger()->header().hash == built.id(), "xrpl::RCLConsensus::Adaptor::doAccept : ledger hash match"); XRPL_ASSERT( - app_.openLedger().current()->header().parentHash == built.id(), + app_.getOpenLedger().current()->header().parentHash == built.id(), "xrpl::RCLConsensus::Adaptor::doAccept : parent hash match"); } @@ -655,7 +655,7 @@ RCLConsensus::Adaptor::doAccept( JLOG(j_.info()) << "Our close offset is estimated at " << offset.count() << " (" << closeCount << ")"; - app_.timeKeeper().adjustCloseTime(offset); + app_.getTimeKeeper().adjustCloseTime(offset); } } @@ -677,7 +677,7 @@ RCLConsensus::Adaptor::notify( } s.set_ledgerseq(ledger.seq()); - s.set_networktime(app_.timeKeeper().now().time_since_epoch().count()); + s.set_networktime(app_.getTimeKeeper().now().time_since_epoch().count()); s.set_ledgerhashprevious( ledger.parentID().begin(), std::decay_t::bytes); s.set_ledgerhash(ledger.id().begin(), std::decay_t::bytes); @@ -695,7 +695,7 @@ RCLConsensus::Adaptor::notify( } s.set_firstseq(uMin); s.set_lastseq(uMax); - app_.overlay().foreach(send_always(std::make_shared(s, protocol::mtSTATUS_CHANGE))); + app_.getOverlay().foreach(send_always(std::make_shared(s, protocol::mtSTATUS_CHANGE))); JLOG(j_.trace()) << "send status change to peer"; } @@ -751,7 +751,7 @@ RCLConsensus::Adaptor::validate(RCLCxLedger const& ledger, RCLTxSet const& txns, { using namespace std::chrono_literals; - auto validationTime = app_.timeKeeper().closeTime(); + auto validationTime = app_.getTimeKeeper().closeTime(); if (validationTime <= lastValidationTime_) validationTime = lastValidationTime_ + 1s; lastValidationTime_ = validationTime; @@ -827,7 +827,7 @@ RCLConsensus::Adaptor::validate(RCLCxLedger const& ledger, RCLTxSet const& txns, // Broadcast to all our peers: protocol::TMValidation val; val.set_validation(serialized.data(), serialized.size()); - app_.overlay().broadcast(val); + app_.getOverlay().broadcast(val); // Publish to all our subscribers: app_.getOPs().pubValidation(v); @@ -925,11 +925,11 @@ RCLConsensus::Adaptor::preStartRound(RCLCxLedger const& prevLgr, hash_set> RCLConsensus::Adaptor::getQuorumKeys() const { - return app_.validators().getQuorumKeys(); + return app_.getValidators().getQuorumKeys(); } std::size_t diff --git a/src/xrpld/app/consensus/RCLCxLedger.h b/src/xrpld/app/consensus/RCLCxLedger.h index 6b96fc8af3..09111ebdb6 100644 --- a/src/xrpld/app/consensus/RCLCxLedger.h +++ b/src/xrpld/app/consensus/RCLCxLedger.h @@ -1,8 +1,8 @@ #pragma once -#include #include +#include #include #include diff --git a/src/xrpld/app/consensus/RCLValidations.cpp b/src/xrpld/app/consensus/RCLValidations.cpp index a968acb1a7..27fba69bb6 100644 --- a/src/xrpld/app/consensus/RCLValidations.cpp +++ b/src/xrpld/app/consensus/RCLValidations.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -100,7 +99,7 @@ RCLValidationsAdaptor::RCLValidationsAdaptor(Application& app, beast::Journal j) NetClock::time_point RCLValidationsAdaptor::now() const { - return app_.timeKeeper().closeTime(); + return app_.getTimeKeeper().closeTime(); } std::optional @@ -148,14 +147,14 @@ handleNewValidation( auto const seq = val->getFieldU32(sfLedgerSequence); // Ensure validation is marked as trusted if signer currently trusted - auto masterKey = app.validators().getTrustedKey(signingKey); + auto masterKey = app.getValidators().getTrustedKey(signingKey); if (!val->isTrusted() && masterKey) val->setTrusted(); // If not currently trusted, see if signer is currently listed if (!masterKey) - masterKey = app.validators().getListedKey(signingKey); + masterKey = app.getValidators().getListedKey(signingKey); auto& validations = app.getValidations(); diff --git a/src/xrpld/app/consensus/RCLValidations.h b/src/xrpld/app/consensus/RCLValidations.h index 35c1686f9e..8da82e6425 100644 --- a/src/xrpld/app/consensus/RCLValidations.h +++ b/src/xrpld/app/consensus/RCLValidations.h @@ -1,8 +1,8 @@ #pragma once -#include #include +#include #include #include #include diff --git a/src/xrpld/app/ledger/ConsensusTransSetSF.cpp b/src/xrpld/app/ledger/ConsensusTransSetSF.cpp index 48080aaedb..2313d29f86 100644 --- a/src/xrpld/app/ledger/ConsensusTransSetSF.cpp +++ b/src/xrpld/app/ledger/ConsensusTransSetSF.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -12,7 +11,7 @@ namespace xrpl { ConsensusTransSetSF::ConsensusTransSetSF(Application& app, NodeCache& nodeCache) - : app_(app), m_nodeCache(nodeCache), j_(app.journal("TransactionAcquire")) + : app_(app), m_nodeCache(nodeCache), j_(app.getJournal("TransactionAcquire")) { } diff --git a/src/xrpld/app/ledger/InboundLedger.h b/src/xrpld/app/ledger/InboundLedger.h index ef1362365d..4795ea8f9f 100644 --- a/src/xrpld/app/ledger/InboundLedger.h +++ b/src/xrpld/app/ledger/InboundLedger.h @@ -1,11 +1,11 @@ #pragma once -#include #include #include #include #include +#include #include #include diff --git a/src/xrpld/app/ledger/LedgerHistory.cpp b/src/xrpld/app/ledger/LedgerHistory.cpp index 5ff5555fff..b96760f04d 100644 --- a/src/xrpld/app/ledger/LedgerHistory.cpp +++ b/src/xrpld/app/ledger/LedgerHistory.cpp @@ -1,7 +1,8 @@ #include +#include #include +#include -#include #include #include #include @@ -19,14 +20,14 @@ LedgerHistory::LedgerHistory(beast::insight::Collector::ptr const& collector, Ap app_.config().getValueFor(SizedItem::ledgerSize), std::chrono::seconds{app_.config().getValueFor(SizedItem::ledgerAge)}, stopwatch(), - app_.journal("TaggedCache")) + app_.getJournal("TaggedCache")) , m_consensus_validated( "ConsensusValidated", 64, std::chrono::minutes{5}, stopwatch(), - app_.journal("TaggedCache")) - , j_(app.journal("LedgerHistory")) + app_.getJournal("TaggedCache")) + , j_(app.getJournal("LedgerHistory")) { } @@ -73,7 +74,9 @@ LedgerHistory::getLedgerBySeq(LedgerIndex index) } } - std::shared_ptr ret = loadByIndex(index, app_); + Rules const rules{app_.config().features}; + Fees const fees = app_.config().FEES.toFees(); + std::shared_ptr ret = loadByIndex(index, rules, fees, app_); if (!ret) return ret; @@ -111,7 +114,9 @@ LedgerHistory::getLedgerByHash(LedgerHash const& hash) return ret; } - ret = loadByHash(hash, app_); + Rules const rules{app_.config().features}; + Fees const fees = app_.config().FEES.toFees(); + ret = loadByHash(hash, rules, fees, app_); if (!ret) return ret; diff --git a/src/xrpld/app/ledger/LedgerHistory.h b/src/xrpld/app/ledger/LedgerHistory.h index 6ec279b28a..b988d152ad 100644 --- a/src/xrpld/app/ledger/LedgerHistory.h +++ b/src/xrpld/app/ledger/LedgerHistory.h @@ -1,9 +1,9 @@ #pragma once -#include #include #include +#include #include #include diff --git a/src/xrpld/app/ledger/LedgerMaster.h b/src/xrpld/app/ledger/LedgerMaster.h index c25e553455..16e35c3dcd 100644 --- a/src/xrpld/app/ledger/LedgerMaster.h +++ b/src/xrpld/app/ledger/LedgerMaster.h @@ -2,17 +2,18 @@ #include #include -#include #include #include #include #include -#include +#include #include #include #include #include +#include +#include #include #include #include diff --git a/src/xrpld/app/ledger/LedgerPersistence.h b/src/xrpld/app/ledger/LedgerPersistence.h new file mode 100644 index 0000000000..e131932af4 --- /dev/null +++ b/src/xrpld/app/ledger/LedgerPersistence.h @@ -0,0 +1,90 @@ +#pragma once + +#include + +#include +#include + +namespace xrpl { + +class ServiceRegistry; +struct Fees; + +/** Save, or arrange to save, a fully-validated ledger. + + @param registry The service registry providing access to required services. + @param ledger The fully-validated ledger to save. + @param isSynchronous If true, wait for the save to complete. + @param isCurrent If true, the ledger is the current validated ledger. + + @return false on error. +*/ +bool +pendSaveValidated( + ServiceRegistry& registry, + std::shared_ptr const& ledger, + bool isSynchronous, + bool isCurrent); + +/** Make ledger using info loaded from database. + + @param info Ledger information. + @param rules Rules to use (may be overwritten by setup()). + @param fees Fees to use (may be overwritten by setup()). + @param registry Service registry for dependency injection. + @param acquire Acquire the ledger if not found locally. + @return Shared pointer to the ledger. +*/ +std::shared_ptr +loadLedgerHelper( + LedgerHeader const& info, + Rules const& rules, + Fees const& fees, + ServiceRegistry& registry, + bool acquire); + +/** Load a ledger by its sequence number. + + @param ledgerIndex The sequence number of the ledger to load. + @param rules Rules to use (may be overwritten by setup()). + @param fees Fees to use (may be overwritten by setup()). + @param registry Service registry for dependency injection. + @param acquire Acquire the ledger if not found locally. + @return Shared pointer to the ledger, or nullptr if not found. +*/ +std::shared_ptr +loadByIndex( + std::uint32_t ledgerIndex, + Rules const& rules, + Fees const& fees, + ServiceRegistry& registry, + bool acquire = true); + +/** Load a ledger by its hash. + + @param ledgerHash The hash of the ledger to load. + @param rules Rules to use (may be overwritten by setup()). + @param fees Fees to use (may be overwritten by setup()). + @param registry Service registry for dependency injection. + @param acquire Acquire the ledger if not found locally. + @return Shared pointer to the ledger, or nullptr if not found. +*/ +std::shared_ptr +loadByHash( + uint256 const& ledgerHash, + Rules const& rules, + Fees const& fees, + ServiceRegistry& registry, + bool acquire = true); + +/** Fetch the ledger with the highest sequence contained in the database. + + @param rules Rules to use (may be overwritten by setup()). + @param fees Fees to use (may be overwritten by setup()). + @param registry Service registry for dependency injection. + @return Tuple of (ledger, sequence, hash), or empty if not found. +*/ +std::tuple, std::uint32_t, uint256> +getLatestLedger(Rules const& rules, Fees const& fees, ServiceRegistry& registry); + +} // namespace xrpl diff --git a/src/xrpld/app/ledger/LedgerReplay.h b/src/xrpld/app/ledger/LedgerReplay.h index f4cbf9c69e..a2b2e60e8e 100644 --- a/src/xrpld/app/ledger/LedgerReplay.h +++ b/src/xrpld/app/ledger/LedgerReplay.h @@ -4,6 +4,7 @@ #include #include +#include namespace xrpl { diff --git a/src/xrpld/app/ledger/LedgerToJson.h b/src/xrpld/app/ledger/LedgerToJson.h index 9def1c3826..3686311656 100644 --- a/src/xrpld/app/ledger/LedgerToJson.h +++ b/src/xrpld/app/ledger/LedgerToJson.h @@ -1,11 +1,11 @@ #pragma once -#include #include #include #include #include +#include #include namespace xrpl { diff --git a/src/xrpld/app/ledger/LocalTxs.h b/src/xrpld/app/ledger/LocalTxs.h index 34dfede40f..cb17be5bdb 100644 --- a/src/xrpld/app/ledger/LocalTxs.h +++ b/src/xrpld/app/ledger/LocalTxs.h @@ -1,7 +1,6 @@ #pragma once -#include - +#include #include #include diff --git a/src/xrpld/app/ledger/OpenLedger.h b/src/xrpld/app/ledger/OpenLedger.h index 76123bafae..5b1d611b44 100644 --- a/src/xrpld/app/ledger/OpenLedger.h +++ b/src/xrpld/app/ledger/OpenLedger.h @@ -1,7 +1,5 @@ #pragma once -#include -#include #include #include @@ -9,6 +7,8 @@ #include #include #include +#include +#include #include #include diff --git a/src/xrpld/app/ledger/OrderBookDBImpl.cpp b/src/xrpld/app/ledger/OrderBookDBImpl.cpp index 2691935911..7626d148bd 100644 --- a/src/xrpld/app/ledger/OrderBookDBImpl.cpp +++ b/src/xrpld/app/ledger/OrderBookDBImpl.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include #include @@ -14,7 +13,7 @@ OrderBookDBImpl::OrderBookDBImpl(ServiceRegistry& registry, OrderBookDBConfig co , pathSearchMax_(config.pathSearchMax) , standalone_(config.standalone) , seq_(0) - , j_(registry.journal("OrderBookDB")) + , j_(registry.getJournal("OrderBookDB")) { } @@ -58,7 +57,7 @@ OrderBookDBImpl::setup(std::shared_ptr const& ledger) else { registry_.getJobQueue().addJob( - jtUPDATE_PF, "OrderBookUpd" + std::to_string(ledger->seq()), [this, ledger]() { + jtUPDATE_PF, "OBUpd" + std::to_string(ledger->seq()), [this, ledger]() { update(ledger); }); } diff --git a/src/xrpld/app/ledger/detail/BuildLedger.cpp b/src/xrpld/app/ledger/detail/BuildLedger.cpp index 37325835a9..3b48ab13c5 100644 --- a/src/xrpld/app/ledger/detail/BuildLedger.cpp +++ b/src/xrpld/app/ledger/detail/BuildLedger.cpp @@ -1,10 +1,10 @@ #include -#include #include #include #include -#include +#include +#include #include #include diff --git a/src/xrpld/app/ledger/detail/InboundLedger.cpp b/src/xrpld/app/ledger/detail/InboundLedger.cpp index 9f7312ea34..4e7190c8c8 100644 --- a/src/xrpld/app/ledger/detail/InboundLedger.cpp +++ b/src/xrpld/app/ledger/detail/InboundLedger.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -66,7 +65,7 @@ InboundLedger::InboundLedger( hash, ledgerAcquireTimeout, {jtLEDGER_DATA, "InboundLedger", 5}, - app.journal("InboundLedger")) + app.getJournal("InboundLedger")) , m_clock(clock) , mHaveHeader(false) , mHaveState(false) @@ -121,7 +120,7 @@ InboundLedger::getPeerCount() const { auto const& peerIds = mPeerSet->getPeerIds(); return std::count_if(peerIds.begin(), peerIds.end(), [this](auto id) { - return (app_.overlay().findPeerByShortID(id) != nullptr); + return (app_.getOverlay().findPeerByShortID(id) != nullptr); }); } @@ -224,8 +223,9 @@ InboundLedger::tryDB(NodeStore::Database& srcDB) { auto makeLedger = [&, this](Blob const& data) { JLOG(journal_.trace()) << "Ledger header found in fetch pack"; + Rules const rules{app_.config().features}; mLedger = std::make_shared( - deserializePrefixedHeader(makeSlice(data)), app_.config(), app_.getNodeFamily()); + deserializePrefixedHeader(makeSlice(data)), rules, app_.getNodeFamily()); if (mLedger->header().hash != hash_ || (mSeq != 0 && mSeq != mLedger->header().seq)) { // We know for a fact the ledger can never be acquired @@ -529,7 +529,7 @@ InboundLedger::trigger(std::shared_ptr const& peer, TriggerReason reason) auto packet = std::make_shared(tmBH, protocol::mtGET_OBJECTS); auto const& peerIds = mPeerSet->getPeerIds(); std::for_each(peerIds.begin(), peerIds.end(), [this, &packet](auto id) { - if (auto p = app_.overlay().findPeerByShortID(id)) + if (auto p = app_.getOverlay().findPeerByShortID(id)) { mByHash = false; p->send(packet); @@ -777,7 +777,8 @@ InboundLedger::takeHeader(std::string const& data) return true; auto* f = &app_.getNodeFamily(); - mLedger = std::make_shared(deserializeHeader(makeSlice(data)), app_.config(), *f); + Rules const rules{app_.config().features}; + mLedger = std::make_shared(deserializeHeader(makeSlice(data)), rules, *f); if (mLedger->header().hash != hash_ || (mSeq != 0 && mSeq != mLedger->header().seq)) { JLOG(journal_.warn()) << "Acquire hash mismatch: " << mLedger->header().hash diff --git a/src/xrpld/app/ledger/detail/InboundLedgers.cpp b/src/xrpld/app/ledger/detail/InboundLedgers.cpp index be7577a2c3..3a83aa6018 100644 --- a/src/xrpld/app/ledger/detail/InboundLedgers.cpp +++ b/src/xrpld/app/ledger/detail/InboundLedgers.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -38,7 +37,7 @@ public: std::unique_ptr peerSetBuilder) : app_(app) , fetchRate_(clock.now()) - , j_(app.journal("InboundLedger")) + , j_(app.getJournal("InboundLedger")) , m_clock(clock) , mRecentFailures(clock) , mCounter(collector->make_counter("ledger_fetches")) diff --git a/src/xrpld/app/ledger/detail/InboundTransactions.cpp b/src/xrpld/app/ledger/detail/InboundTransactions.cpp index f27f2c33f0..064953f665 100644 --- a/src/xrpld/app/ledger/detail/InboundTransactions.cpp +++ b/src/xrpld/app/ledger/detail/InboundTransactions.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -54,7 +53,7 @@ public: , m_zeroSet(m_map[uint256()]) , m_gotSet(std::move(gotSet)) , m_peerSetBuilder(std::move(peerSetBuilder)) - , j_(app_.journal("InboundTransactions")) + , j_(app_.getJournal("InboundTransactions")) { m_zeroSet.mSet = std::make_shared(SHAMapType::TRANSACTION, uint256(), app_.getNodeFamily()); diff --git a/src/xrpld/app/ledger/detail/LedgerCleaner.cpp b/src/xrpld/app/ledger/detail/LedgerCleaner.cpp index 3052f787dc..af358fbfc6 100644 --- a/src/xrpld/app/ledger/detail/LedgerCleaner.cpp +++ b/src/xrpld/app/ledger/detail/LedgerCleaner.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include @@ -261,7 +263,9 @@ private: return false; } - auto dbLedger = loadByIndex(ledgerIndex, app_); + Rules const rules{app_.config().features}; + Fees const fees = app_.config().FEES.toFees(); + auto const dbLedger = loadByIndex(ledgerIndex, rules, fees, app_); if (!dbLedger || (dbLedger->header().hash != ledgerHash) || (dbLedger->header().parentHash != nodeLedger->header().parentHash)) { @@ -276,7 +280,7 @@ private: doTxns = true; } - if (doNodes && !nodeLedger->walkLedger(app_.journal("Ledger"))) + if (doNodes && !nodeLedger->walkLedger(app_.getJournal("Ledger"))) { JLOG(j_.debug()) << "Ledger " << ledgerIndex << " is missing nodes"; app_.getLedgerMaster().clearLedger(ledgerIndex); diff --git a/src/xrpld/app/ledger/detail/LedgerDeltaAcquire.cpp b/src/xrpld/app/ledger/detail/LedgerDeltaAcquire.cpp index cb2e2e57ea..1d48a9741d 100644 --- a/src/xrpld/app/ledger/detail/LedgerDeltaAcquire.cpp +++ b/src/xrpld/app/ledger/detail/LedgerDeltaAcquire.cpp @@ -21,7 +21,7 @@ LedgerDeltaAcquire::LedgerDeltaAcquire( ledgerHash, LedgerReplayParameters::SUB_TASK_TIMEOUT, {jtREPLAY_TASK, "LedReplDelta", LedgerReplayParameters::MAX_QUEUED_TASKS}, - app.journal("LedgerReplayDelta")) + app.getJournal("LedgerReplayDelta")) , inboundLedgers_(inboundLedgers) , ledgerSeq_(ledgerSeq) , peerSet_(std::move(peerSet)) @@ -124,7 +124,8 @@ LedgerDeltaAcquire::processData( if (info.seq == ledgerSeq_) { // create a temporary ledger for building a LedgerReplay object later - replayTemp_ = std::make_shared(info, app_.config(), app_.getNodeFamily()); + Rules const rules{app_.config().features}; + replayTemp_ = std::make_shared(info, rules, app_.getNodeFamily()); if (replayTemp_) { complete_ = true; diff --git a/src/xrpld/app/ledger/detail/LedgerDeltaAcquire.h b/src/xrpld/app/ledger/detail/LedgerDeltaAcquire.h index 2877d997e6..9ac58c2e7c 100644 --- a/src/xrpld/app/ledger/detail/LedgerDeltaAcquire.h +++ b/src/xrpld/app/ledger/detail/LedgerDeltaAcquire.h @@ -1,11 +1,11 @@ #pragma once #include -#include #include #include #include +#include #include diff --git a/src/xrpld/app/ledger/detail/LedgerMaster.cpp b/src/xrpld/app/ledger/detail/LedgerMaster.cpp index 320c4bc722..52ccd27ba4 100644 --- a/src/xrpld/app/ledger/detail/LedgerMaster.cpp +++ b/src/xrpld/app/ledger/detail/LedgerMaster.cpp @@ -1,20 +1,18 @@ #include -#include #include +#include #include #include -#include #include #include #include #include #include -#include #include #include #include +#include -#include #include #include #include @@ -22,7 +20,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -94,7 +94,7 @@ LedgerMaster::LedgerMaster( 65536, std::chrono::seconds{45}, stopwatch, - app_.journal("TaggedCache")) + app_.getJournal("TaggedCache")) , m_stats(std::bind(&LedgerMaster::collect_metrics, this), collector) { } @@ -102,7 +102,7 @@ LedgerMaster::LedgerMaster( LedgerIndex LedgerMaster::getCurrentLedgerIndex() { - return app_.openLedger().current()->header().seq; + return app_.getOpenLedger().current()->header().seq; } LedgerIndex @@ -145,7 +145,7 @@ LedgerMaster::getPublishedLedgerAge() return weeks{2}; } - std::chrono::seconds ret = app_.timeKeeper().closeTime().time_since_epoch(); + std::chrono::seconds ret = app_.getTimeKeeper().closeTime().time_since_epoch(); ret -= pubClose; ret = (ret > 0s) ? ret : 0s; static std::chrono::seconds lastRet = -1s; @@ -170,7 +170,7 @@ LedgerMaster::getValidatedLedgerAge() return weeks{2}; } - std::chrono::seconds ret = app_.timeKeeper().closeTime().time_since_epoch(); + std::chrono::seconds ret = app_.getTimeKeeper().closeTime().time_since_epoch(); ret -= valClose; ret = (ret > 0s) ? ret : 0s; static std::chrono::seconds lastRet = -1s; @@ -216,7 +216,7 @@ LedgerMaster::setValidLedger(std::shared_ptr const& l) if (!standalone_) { - auto validations = app_.validators().negativeUNLFilter( + auto validations = app_.getValidators().negativeUNLFilter( app_.getValidations().getTrustedForLedger(l->header().hash, l->header().seq)); times.reserve(validations.size()); for (auto const& val : validations) @@ -228,7 +228,7 @@ LedgerMaster::setValidLedger(std::shared_ptr const& l) NetClock::time_point signTime; - if (!times.empty() && times.size() >= app_.validators().quorum()) + if (!times.empty() && times.size() >= app_.getValidators().quorum()) { // Calculate the sample median std::sort(times.begin(), times.end()); @@ -329,7 +329,7 @@ LedgerMaster::canBeCurrent(std::shared_ptr const& ledger) // we perform this check. Otherwise, we only do it if we've built a // few ledgers as our clock can be off when we first start up - auto closeTime = app_.timeKeeper().closeTime(); + auto closeTime = app_.getTimeKeeper().closeTime(); auto ledgerClose = ledger->header().parentCloseTime; using namespace std::chrono_literals; @@ -425,7 +425,7 @@ LedgerMaster::applyHeldTransactions() std::lock_guard sl(m_mutex); // VFALCO NOTE The hash for an open ledger is undefined so we use // something that is a reasonable substitute. - CanonicalTXSet set(app_.openLedger().current()->header().parentHash); + CanonicalTXSet set(app_.getOpenLedger().current()->header().parentHash); std::swap(mHeldTransactions, set); return set; }(); @@ -545,7 +545,7 @@ LedgerMaster::getValidatedRange(std::uint32_t& minVal, std::uint32_t& maxVal) // Remove from the validated range any ledger sequences that may not be // fully updated in the database yet - auto const pendingSaves = app_.pendingSaves().getSnapshot(); + auto const pendingSaves = app_.getPendingSaves().getSnapshot(); if (!pendingSaves.empty() && ((minVal != 0) || (maxVal != 0))) { @@ -687,7 +687,7 @@ LedgerMaster::getFetchPack(LedgerIndex missing, InboundLedger::Reason reason) std::shared_ptr target; { int maxScore = 0; - auto peerList = app_.overlay().getActivePeers(); + auto peerList = app_.getOverlay().getActivePeers(); for (auto const& peer : peerList) { if (peer->hasRange(missing, missing + 1)) @@ -849,10 +849,10 @@ LedgerMaster::checkAccept(uint256 const& hash, std::uint32_t seq) if (seq < mValidLedgerSeq) return; - auto validations = app_.validators().negativeUNLFilter( + auto validations = app_.getValidators().negativeUNLFilter( app_.getValidations().getTrustedForLedger(hash, seq)); valCount = validations.size(); - if (valCount >= app_.validators().quorum()) + if (valCount >= app_.getValidators().quorum()) { std::lock_guard ml(m_mutex); if (seq > mLastValidLedger.second) @@ -874,8 +874,8 @@ LedgerMaster::checkAccept(uint256 const& hash, std::uint32_t seq) if ((seq != 0) && (getValidLedgerIndex() == 0)) { // Set peers converged early if we can - if (valCount >= app_.validators().quorum()) - app_.overlay().checkTracking(seq); + if (valCount >= app_.getValidators().quorum()) + app_.getOverlay().checkTracking(seq); } // FIXME: We may not want to fetch a ledger with just one @@ -895,7 +895,7 @@ LedgerMaster::checkAccept(uint256 const& hash, std::uint32_t seq) std::size_t LedgerMaster::getNeededValidations() { - return standalone_ ? 0 : app_.validators().quorum(); + return standalone_ ? 0 : app_.getValidators().quorum(); } void @@ -914,7 +914,7 @@ LedgerMaster::checkAccept(std::shared_ptr const& ledger) return; auto const minVal = getNeededValidations(); - auto validations = app_.validators().negativeUNLFilter( + auto validations = app_.getValidators().negativeUNLFilter( app_.getValidations().getTrustedForLedger(ledger->header().hash, ledger->header().seq)); auto const tvc = validations.size(); if (tvc < minVal) // nothing we can do @@ -978,7 +978,7 @@ LedgerMaster::checkAccept(std::shared_ptr const& ledger) // before checking the version information to accumulate more validation // messages. - auto currentTime = app_.timeKeeper().now(); + auto currentTime = app_.getTimeKeeper().now(); bool needPrint = false; // The variable upgradeWarningPrevTime_ will be set when and only when @@ -1007,7 +1007,7 @@ LedgerMaster::checkAccept(std::shared_ptr const& ledger) { constexpr std::size_t reportingPercent = 90; constexpr std::size_t cutoffPercent = 60; - auto const unlSize{app_.validators().getQuorumKeys().second.size()}; + auto const unlSize{app_.getValidators().getQuorumKeys().second.size()}; needPrint = unlSize > 0 && calculatePercent(vals.size(), unlSize) >= reportingPercent && calculatePercent(higherVersionCount, rippledCount) >= cutoffPercent; @@ -1054,7 +1054,7 @@ LedgerMaster::consensusBuilt( if (ledger->header().seq <= mValidLedgerSeq) { - auto stream = app_.journal("LedgerConsensus").info(); + auto stream = app_.getJournal("LedgerConsensus").info(); JLOG(stream) << "Consensus built old ledger: " << ledger->header().seq << " <= " << mValidLedgerSeq; return; @@ -1065,7 +1065,7 @@ LedgerMaster::consensusBuilt( if (ledger->header().seq <= mValidLedgerSeq) { - auto stream = app_.journal("LedgerConsensus").debug(); + auto stream = app_.getJournal("LedgerConsensus").debug(); JLOG(stream) << "Consensus ledger fully validated"; return; } @@ -1073,7 +1073,8 @@ LedgerMaster::consensusBuilt( // This ledger cannot be the new fully-validated ledger, but // maybe we saved up validations for some other ledger that can be - auto validations = app_.validators().negativeUNLFilter(app_.getValidations().currentTrusted()); + auto validations = + app_.getValidators().negativeUNLFilter(app_.getValidations().currentTrusted()); // Track validation counts with sequence numbers class valSeq @@ -1130,7 +1131,7 @@ LedgerMaster::consensusBuilt( if (maxSeq > mValidLedgerSeq) { - auto stream = app_.journal("LedgerConsensus").debug(); + auto stream = app_.getJournal("LedgerConsensus").debug(); JLOG(stream) << "Consensus triggered check of ledger"; checkAccept(maxLedger, maxSeq); } @@ -1361,7 +1362,7 @@ LedgerMaster::updatePaths() } else if (mPathFindNewRequest) { // We have a new request but no new ledger - lastLedger = app_.openLedger().current(); + lastLedger = app_.getOpenLedger().current(); } else { // Nothing to do @@ -1375,7 +1376,7 @@ LedgerMaster::updatePaths() if (!standalone_) { // don't pathfind with a ledger that's more than 60 seconds old using namespace std::chrono; - auto age = time_point_cast(app_.timeKeeper().closeTime()) - + auto age = time_point_cast(app_.getTimeKeeper().closeTime()) - lastLedger->header().closeTime; if (age > 1min) { @@ -1389,7 +1390,7 @@ LedgerMaster::updatePaths() try { - auto& pathRequests = app_.getPathRequests(); + auto& pathRequests = app_.getPathRequestManager(); { std::lock_guard ml(m_mutex); if (!pathRequests.requestsPending()) @@ -1471,7 +1472,7 @@ LedgerMaster::newOrderBookDB() bool LedgerMaster::newPFWork(char const* name, std::unique_lock&) { - if (!app_.isStopping() && mPathFindThread < 2 && app_.getPathRequests().requestsPending()) + if (!app_.isStopping() && mPathFindThread < 2 && app_.getPathRequestManager().requestsPending()) { JLOG(m_journal.debug()) << "newPFWork: Creating job. path find threads: " << mPathFindThread; @@ -1495,7 +1496,7 @@ LedgerMaster::peekMutex() std::shared_ptr LedgerMaster::getCurrentLedger() { - return app_.openLedger().current(); + return app_.getOpenLedger().current(); } std::shared_ptr diff --git a/src/xrpld/app/ledger/detail/LedgerPersistence.cpp b/src/xrpld/app/ledger/detail/LedgerPersistence.cpp new file mode 100644 index 0000000000..91de010f1d --- /dev/null +++ b/src/xrpld/app/ledger/detail/LedgerPersistence.cpp @@ -0,0 +1,172 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace xrpl { + +static bool +saveValidatedLedger( + ServiceRegistry& registry, + std::shared_ptr const& ledger, + bool current) +{ + auto j = registry.getJournal("Ledger"); + auto seq = ledger->header().seq; + if (!registry.getPendingSaves().startWork(seq)) + { + // The save was completed synchronously + JLOG(j.debug()) << "Save aborted"; + return true; + } + + auto& db = registry.getRelationalDatabase(); + + auto const res = db.saveValidatedLedger(ledger, current); + + // Clients can now trust the database for + // information about this ledger sequence. + registry.getPendingSaves().finishWork(seq); + return res; +} + +bool +pendSaveValidated( + ServiceRegistry& registry, + std::shared_ptr const& ledger, + bool isSynchronous, + bool isCurrent) +{ + if (!registry.getHashRouter().setFlags(ledger->header().hash, HashRouterFlags::SAVED)) + { + // We have tried to save this ledger recently + auto stream = registry.getJournal("Ledger").debug(); + JLOG(stream) << "Double pend save for " << ledger->header().seq; + + if (!isSynchronous || !registry.getPendingSaves().pending(ledger->header().seq)) + { + // Either we don't need it to be finished + // or it is finished + return true; + } + } + + XRPL_ASSERT(ledger->isImmutable(), "xrpl::pendSaveValidated : immutable ledger"); + + if (!registry.getPendingSaves().shouldWork(ledger->header().seq, isSynchronous)) + { + auto stream = registry.getJournal("Ledger").debug(); + JLOG(stream) << "Pend save with seq in pending saves " << ledger->header().seq; + + return true; + } + + // See if we can use the JobQueue. + if (!isSynchronous && + registry.getJobQueue().addJob( + isCurrent ? jtPUBLEDGER : jtPUBOLDLEDGER, + "Pub" + std::to_string(ledger->seq()), + [®istry, ledger, isCurrent]() { saveValidatedLedger(registry, ledger, isCurrent); })) + { + return true; + } + + // The JobQueue won't do the Job. Do the save synchronously. + return saveValidatedLedger(registry, ledger, isCurrent); +} + +std::shared_ptr +loadLedgerHelper( + LedgerHeader const& info, + Rules const& rules, + Fees const& fees, + ServiceRegistry& registry, + bool acquire) +{ + bool loaded = false; + auto ledger = std::make_shared( + info, + loaded, + acquire, + rules, + fees, + registry.getNodeFamily(), + registry.getJournal("Ledger")); + + if (!loaded) + ledger.reset(); + + return ledger; +} + +static void +finishLoadByIndexOrHash(std::shared_ptr const& ledger, beast::Journal j) +{ + if (!ledger) + return; + + XRPL_ASSERT( + ledger->header().seq < XRP_LEDGER_EARLIEST_FEES || ledger->read(keylet::fees()), + "xrpl::finishLoadByIndexOrHash : valid ledger fees"); + ledger->setImmutable(); + + JLOG(j.trace()) << "Loaded ledger: " << to_string(ledger->header().hash); + + ledger->setFull(); +} + +std::tuple, std::uint32_t, uint256> +getLatestLedger(Rules const& rules, Fees const& fees, ServiceRegistry& registry) +{ + std::optional const info = registry.getRelationalDatabase().getNewestLedgerInfo(); + if (!info) + return {std::shared_ptr(), {}, {}}; + return {loadLedgerHelper(*info, rules, fees, registry, true), info->seq, info->hash}; +} + +std::shared_ptr +loadByIndex( + std::uint32_t ledgerIndex, + Rules const& rules, + Fees const& fees, + ServiceRegistry& registry, + bool acquire) +{ + if (std::optional info = + registry.getRelationalDatabase().getLedgerInfoByIndex(ledgerIndex)) + { + std::shared_ptr ledger = loadLedgerHelper(*info, rules, fees, registry, acquire); + finishLoadByIndexOrHash(ledger, registry.getJournal("Ledger")); + return ledger; + } + return {}; +} + +std::shared_ptr +loadByHash( + uint256 const& ledgerHash, + Rules const& rules, + Fees const& fees, + ServiceRegistry& registry, + bool acquire) +{ + if (std::optional info = + registry.getRelationalDatabase().getLedgerInfoByHash(ledgerHash)) + { + std::shared_ptr ledger = loadLedgerHelper(*info, rules, fees, registry, acquire); + finishLoadByIndexOrHash(ledger, registry.getJournal("Ledger")); + XRPL_ASSERT( + !ledger || ledger->header().hash == ledgerHash, + "xrpl::loadByHash : ledger hash match if loaded"); + return ledger; + } + return {}; +} + +} // namespace xrpl diff --git a/src/xrpld/app/ledger/detail/LedgerReplay.cpp b/src/xrpld/app/ledger/detail/LedgerReplay.cpp index d115402115..a02267e4a1 100644 --- a/src/xrpld/app/ledger/detail/LedgerReplay.cpp +++ b/src/xrpld/app/ledger/detail/LedgerReplay.cpp @@ -1,6 +1,7 @@ -#include #include +#include + namespace xrpl { LedgerReplay::LedgerReplay( diff --git a/src/xrpld/app/ledger/detail/LedgerReplayMsgHandler.cpp b/src/xrpld/app/ledger/detail/LedgerReplayMsgHandler.cpp index 93cf0e5cce..a212629d28 100644 --- a/src/xrpld/app/ledger/detail/LedgerReplayMsgHandler.cpp +++ b/src/xrpld/app/ledger/detail/LedgerReplayMsgHandler.cpp @@ -10,7 +10,7 @@ namespace xrpl { LedgerReplayMsgHandler::LedgerReplayMsgHandler(Application& app, LedgerReplayer& replayer) - : app_(app), replayer_(replayer), journal_(app.journal("LedgerReplayMsgHandler")) + : app_(app), replayer_(replayer), journal_(app.getJournal("LedgerReplayMsgHandler")) { } diff --git a/src/xrpld/app/ledger/detail/LedgerReplayTask.cpp b/src/xrpld/app/ledger/detail/LedgerReplayTask.cpp index b878c840dd..6db0cebf1a 100644 --- a/src/xrpld/app/ledger/detail/LedgerReplayTask.cpp +++ b/src/xrpld/app/ledger/detail/LedgerReplayTask.cpp @@ -73,7 +73,7 @@ LedgerReplayTask::LedgerReplayTask( parameter.finishHash_, LedgerReplayParameters::TASK_TIMEOUT, {jtREPLAY_TASK, "LedReplTask", LedgerReplayParameters::MAX_QUEUED_TASKS}, - app.journal("LedgerReplayTask")) + app.getJournal("LedgerReplayTask")) , inboundLedgers_(inboundLedgers) , replayer_(replayer) , parameter_(parameter) diff --git a/src/xrpld/app/ledger/detail/LedgerReplayer.cpp b/src/xrpld/app/ledger/detail/LedgerReplayer.cpp index 553ff91174..9161c05d9a 100644 --- a/src/xrpld/app/ledger/detail/LedgerReplayer.cpp +++ b/src/xrpld/app/ledger/detail/LedgerReplayer.cpp @@ -11,7 +11,7 @@ LedgerReplayer::LedgerReplayer( : app_(app) , inboundLedgers_(inboundLedgers) , peerSetBuilder_(std::move(peerSetBuilder)) - , j_(app.journal("LedgerReplayer")) + , j_(app.getJournal("LedgerReplayer")) { } diff --git a/src/xrpld/app/ledger/detail/LocalTxs.cpp b/src/xrpld/app/ledger/detail/LocalTxs.cpp index 8eb821a6c9..8f04da9c2d 100644 --- a/src/xrpld/app/ledger/detail/LocalTxs.cpp +++ b/src/xrpld/app/ledger/detail/LocalTxs.cpp @@ -1,6 +1,6 @@ -#include #include +#include #include /* diff --git a/src/xrpld/app/ledger/detail/OpenLedger.cpp b/src/xrpld/app/ledger/detail/OpenLedger.cpp index a26751bc64..da35a72bbc 100644 --- a/src/xrpld/app/ledger/detail/OpenLedger.cpp +++ b/src/xrpld/app/ledger/detail/OpenLedger.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -124,8 +125,8 @@ OpenLedger::accept( tx->add(s); msg.set_rawtransaction(s.data(), s.size()); msg.set_status(protocol::tsNEW); - msg.set_receivetimestamp(app.timeKeeper().now().time_since_epoch().count()); - app.overlay().relay(txId, msg, *toSkip); + msg.set_receivetimestamp(app.getTimeKeeper().now().time_since_epoch().count()); + app.getOverlay().relay(txId, msg, *toSkip); } } diff --git a/src/xrpld/app/ledger/detail/SkipListAcquire.cpp b/src/xrpld/app/ledger/detail/SkipListAcquire.cpp index 2191ef965a..3a60fbdc6d 100644 --- a/src/xrpld/app/ledger/detail/SkipListAcquire.cpp +++ b/src/xrpld/app/ledger/detail/SkipListAcquire.cpp @@ -16,7 +16,7 @@ SkipListAcquire::SkipListAcquire( ledgerHash, LedgerReplayParameters::SUB_TASK_TIMEOUT, {jtREPLAY_TASK, "SkipListAcq", LedgerReplayParameters::MAX_QUEUED_TASKS}, - app.journal("LedgerReplaySkipList")) + app.getJournal("LedgerReplaySkipList")) , inboundLedgers_(inboundLedgers) , peerSet_(std::move(peerSet)) { diff --git a/src/xrpld/app/ledger/detail/SkipListAcquire.h b/src/xrpld/app/ledger/detail/SkipListAcquire.h index 5a79e8ae5c..da62578d41 100644 --- a/src/xrpld/app/ledger/detail/SkipListAcquire.h +++ b/src/xrpld/app/ledger/detail/SkipListAcquire.h @@ -1,10 +1,10 @@ #pragma once #include -#include #include #include +#include #include namespace xrpl { diff --git a/src/xrpld/app/ledger/detail/TransactionAcquire.cpp b/src/xrpld/app/ledger/detail/TransactionAcquire.cpp index 18c5066064..9cf35b93dc 100644 --- a/src/xrpld/app/ledger/detail/TransactionAcquire.cpp +++ b/src/xrpld/app/ledger/detail/TransactionAcquire.cpp @@ -30,7 +30,7 @@ TransactionAcquire::TransactionAcquire( hash, TX_ACQUIRE_TIMEOUT, {jtTXN_DATA, "TxAcq", {}}, - app.journal("TransactionAcquire")) + app.getJournal("TransactionAcquire")) , mHaveRoot(false) , mPeerSet(std::move(peerSet)) { diff --git a/src/xrpld/app/ledger/detail/TransactionMaster.cpp b/src/xrpld/app/ledger/detail/TransactionMaster.cpp index e3ebd443f1..4be3c95993 100644 --- a/src/xrpld/app/ledger/detail/TransactionMaster.cpp +++ b/src/xrpld/app/ledger/detail/TransactionMaster.cpp @@ -15,7 +15,7 @@ TransactionMaster::TransactionMaster(Application& app) 65536, std::chrono::minutes{30}, stopwatch(), - mApp.journal("TaggedCache")) + mApp.getJournal("TaggedCache")) { } diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index 55ba09e49e..39bb4d5b22 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -3,11 +3,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -21,13 +21,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include #include @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -170,7 +171,7 @@ public: std::unique_ptr m_nodeStore; NodeFamily nodeFamily_; std::unique_ptr m_orderBookDB; - std::unique_ptr m_pathRequests; + std::unique_ptr m_pathRequestManager; std::unique_ptr m_ledgerMaster; std::unique_ptr ledgerCleaner_; std::unique_ptr m_inboundLedgers; @@ -330,8 +331,8 @@ public: , m_orderBookDB(make_OrderBookDB(*this, {config_->PATH_SEARCH_MAX, config_->standalone()})) - , m_pathRequests( - std::make_unique( + , m_pathRequestManager( + std::make_unique( *this, logs_->journal("PathRequest"), m_collectorManager->collector())) @@ -488,7 +489,7 @@ public: } Logs& - logs() override + getLogs() override { return *logs_; } @@ -512,7 +513,7 @@ public: } TimeKeeper& - timeKeeper() override + getTimeKeeper() override { return *timeKeeper_; } @@ -660,14 +661,14 @@ public: return *m_orderBookDB; } - PathRequests& - getPathRequests() override + PathRequestManager& + getPathRequestManager() override { - return *m_pathRequests; + return *m_pathRequestManager; } CachedSLEs& - cachedSLEs() override + getCachedSLEs() override { return cachedSLEs_; } @@ -703,37 +704,37 @@ public: } ValidatorList& - validators() override + getValidators() override { return *validators_; } ValidatorSite& - validatorSites() override + getValidatorSites() override { return *validatorSites_; } ManifestCache& - validatorManifests() override + getValidatorManifests() override { return *validatorManifests_; } ManifestCache& - publisherManifests() override + getPublisherManifests() override { return *publisherManifests_; } Cluster& - cluster() override + getCluster() override { return *cluster_; } PeerReservationTable& - peerReservations() override + getPeerReservations() override { return *peerReservations_; } @@ -745,25 +746,25 @@ public: } PendingSaves& - pendingSaves() override + getPendingSaves() override { return pendingSaves_; } OpenLedger& - openLedger() override + getOpenLedger() override { return *openLedger_; } OpenLedger const& - openLedger() const override + getOpenLedger() const override { return *openLedger_; } Overlay& - overlay() override + getOverlay() override { XRPL_ASSERT(overlay_, "xrpl::ApplicationImp::overlay : non-null overlay"); return *overlay_; @@ -797,7 +798,7 @@ public: serverOkay(std::string& reason) override; beast::Journal - journal(std::string const& name) override; + getJournal(std::string const& name) override; //-------------------------------------------------------------------------- @@ -1073,7 +1074,7 @@ public: } virtual std::optional const& - trapTxID() const override + getTrapTxID() const override { return trapTxID_; } @@ -1109,7 +1110,7 @@ private: setMaxDisallowedLedger(); Application& - app() override + getApp() override { return *this; } @@ -1430,7 +1431,7 @@ ApplicationImp::setup(boost::program_options::variables_map const& cmdline) Resource::Charge loadType = Resource::feeReferenceRPC; Resource::Consumer c; RPC::JsonContext context{ - {journal("RPCHandler"), + {getJournal("RPCHandler"), *this, loadType, getOPs(), @@ -1546,11 +1547,11 @@ ApplicationImp::run() // TODO Store manifests in manifests.sqlite instead of wallet.db validatorManifests_->save(getWalletDB(), "ValidatorManifests", [this](PublicKey const& pubKey) { - return validators().listed(pubKey); + return getValidators().listed(pubKey); }); publisherManifests_->save(getWalletDB(), "PublisherManifests", [this](PublicKey const& pubKey) { - return validators().trustedPublisher(pubKey); + return getValidators().trustedPublisher(pubKey); }); // The order of these stop calls is delicate. @@ -1639,11 +1640,15 @@ ApplicationImp::startGenesisLedger() ? m_amendmentTable->getDesired() : std::vector{}; - std::shared_ptr const genesis = - std::make_shared(create_genesis, *config_, initialAmendments, nodeFamily_); + std::shared_ptr const genesis = std::make_shared( + create_genesis, + Rules{config_->features}, + config_->FEES.toFees(), + initialAmendments, + nodeFamily_); m_ledgerMaster->storeLedger(genesis); - auto const next = std::make_shared(*genesis, timeKeeper().closeTime()); + auto const next = std::make_shared(*genesis, getTimeKeeper().closeTime()); next->updateSkipList(); XRPL_ASSERT( next->header().seq < XRP_LEDGER_EARLIEST_FEES || next->read(keylet::fees()), @@ -1657,11 +1662,12 @@ ApplicationImp::startGenesisLedger() std::shared_ptr ApplicationImp::getLastFullLedger() { - auto j = journal("Ledger"); + auto j = getJournal("Ledger"); try { - auto const [ledger, seq, hash] = getLatestLedger(*this); + auto const [ledger, seq, hash] = + getLatestLedger(Rules{config_->features}, config_->FEES.toFees(), *this); if (!ledger) return ledger; @@ -1729,7 +1735,7 @@ ApplicationImp::loadLedgerFromFile(std::string const& name) ledger = ledger.get()["ledger"]; std::uint32_t seq = 1; - auto closeTime = timeKeeper().closeTime(); + auto closeTime = getTimeKeeper().closeTime(); using namespace std::chrono_literals; auto closeTimeResolution = 30s; bool closeTimeEstimated = false; @@ -1772,7 +1778,8 @@ ApplicationImp::loadLedgerFromFile(std::string const& name) return nullptr; } - auto loadLedger = std::make_shared(seq, closeTime, *config_, nodeFamily_); + auto loadLedger = std::make_shared( + seq, closeTime, Rules{config_->features}, config_->FEES.toFees(), nodeFamily_); loadLedger->setTotalDrops(totalDrops); for (Json::UInt index = 0; index < ledger.get().size(); ++index) @@ -1852,7 +1859,8 @@ ApplicationImp::loadOldLedger( if (hash.parseHex(ledgerID)) { - loadLedger = loadByHash(hash, *this); + loadLedger = + loadByHash(hash, Rules{config_->features}, config_->FEES.toFees(), *this); if (!loadLedger) { @@ -1879,7 +1887,10 @@ ApplicationImp::loadOldLedger( std::uint32_t index = 0; if (beast::lexicalCastChecked(index, ledgerID)) - loadLedger = loadByIndex(index, *this); + { + loadLedger = + loadByIndex(index, Rules{config_->features}, config_->FEES.toFees(), *this); + } } if (!loadLedger) @@ -1894,7 +1905,11 @@ ApplicationImp::loadOldLedger( JLOG(m_journal.info()) << "Loading parent ledger"; - loadLedger = loadByHash(replayLedger->header().parentHash, *this); + loadLedger = loadByHash( + replayLedger->header().parentHash, + Rules{config_->features}, + config_->FEES.toFees(), + *this); if (!loadLedger) { JLOG(m_journal.info()) << "Loading parent ledger from node store"; @@ -1952,7 +1967,7 @@ ApplicationImp::loadOldLedger( // LCOV_EXCL_STOP } - if (!loadLedger->walkLedger(journal("Ledger"), true)) + if (!loadLedger->walkLedger(getJournal("Ledger"), true)) { // LCOV_EXCL_START JLOG(m_journal.fatal()) << "Ledger is missing nodes."; @@ -1963,10 +1978,13 @@ ApplicationImp::loadOldLedger( // LCOV_EXCL_STOP } - if (!loadLedger->assertSensible(journal("Ledger"))) + if (!loadLedger->isSensible()) { // LCOV_EXCL_START - JLOG(m_journal.fatal()) << "Ledger is not sensible."; + Json::Value j = getJson({*loadLedger, {}}); + j[jss::accountTreeHash] = to_string(loadLedger->header().accountHash); + j[jss::transTreeHash] = to_string(loadLedger->header().txHash); + JLOG(m_journal.fatal()) << "Ledger is not sensible: " << j; UNREACHABLE( "xrpl::ApplicationImp::loadOldLedger : ledger is not " "sensible"); @@ -2081,7 +2099,7 @@ ApplicationImp::serverOkay(std::string& reason) } beast::Journal -ApplicationImp::journal(std::string const& name) +ApplicationImp::getJournal(std::string const& name) { return logs_->journal(name); } diff --git a/src/xrpld/app/main/Application.h b/src/xrpld/app/main/Application.h index 0000ae010b..9c79aabb02 100644 --- a/src/xrpld/app/main/Application.h +++ b/src/xrpld/app/main/Application.h @@ -66,7 +66,7 @@ class NetworkOPs; class OpenLedger; class OrderBookDB; class Overlay; -class PathRequests; +class PathRequestManager; class PendingSaves; class PublicKey; class ServerHandler; diff --git a/src/xrpld/app/main/GRPCServer.cpp b/src/xrpld/app/main/GRPCServer.cpp index a9810ae22b..f95c20ba8c 100644 --- a/src/xrpld/app/main/GRPCServer.cpp +++ b/src/xrpld/app/main/GRPCServer.cpp @@ -120,7 +120,7 @@ GRPCServerImpl::CallData::process(std::shared_ptr::process(std::shared_ptr context{ - {app_.journal("gRPCServer"), + {app_.getJournal("gRPCServer"), app_, loadType, app_.getOPs(), @@ -285,7 +285,8 @@ GRPCServerImpl::CallData::getUsage() Throw("Failed to get client endpoint"); } -GRPCServerImpl::GRPCServerImpl(Application& app) : app_(app), journal_(app_.journal("gRPC Server")) +GRPCServerImpl::GRPCServerImpl(Application& app) + : app_(app), journal_(app_.getJournal("gRPC Server")) { // if present, get endpoint from config if (app_.config().exists(SECTION_PORT_GRPC)) diff --git a/src/xrpld/app/main/Main.cpp b/src/xrpld/app/main/Main.cpp index 88a335f843..e2bd4423d9 100644 --- a/src/xrpld/app/main/Main.cpp +++ b/src/xrpld/app/main/Main.cpp @@ -752,8 +752,6 @@ run(int argc, char** argv) // No arguments. Run server. if (!vm.contains("parameters")) { - // TODO: this comment can be removed in a future release - - // say 1.7 or higher if (config->had_trailing_comments()) { JLOG(logs->journal("Application").warn()) @@ -781,7 +779,7 @@ run(int argc, char** argv) // With our configuration parsed, ensure we have // enough file descriptors available: - if (!adjustDescriptorLimit(app->fdRequired(), app->logs().journal("Application"))) + if (!adjustDescriptorLimit(app->fdRequired(), app->getJournal("Application"))) return -1; // Start the server diff --git a/src/xrpld/app/misc/FeeVoteImpl.cpp b/src/xrpld/app/misc/FeeVoteImpl.cpp index 764a9564ad..450e53e86c 100644 --- a/src/xrpld/app/misc/FeeVoteImpl.cpp +++ b/src/xrpld/app/misc/FeeVoteImpl.cpp @@ -1,7 +1,8 @@ -#include #include +#include #include +#include #include #include @@ -272,7 +273,7 @@ FeeVoteImpl::doVoting( baseReserve.first.dropsAs(baseReserveVote.current()); obj[sfReserveIncrement] = incReserve.first.dropsAs(incReserveVote.current()); - obj[sfReferenceFeeUnits] = Config::FEE_UNITS_DEPRECATED; + obj[sfReferenceFeeUnits] = FEE_UNITS_DEPRECATED; } }); diff --git a/src/xrpld/app/misc/NegativeUNLVote.cpp b/src/xrpld/app/misc/NegativeUNLVote.cpp index 8f0ba5255a..fe031749bc 100644 --- a/src/xrpld/app/misc/NegativeUNLVote.cpp +++ b/src/xrpld/app/misc/NegativeUNLVote.cpp @@ -1,7 +1,7 @@ #include -#include #include +#include #include namespace xrpl { diff --git a/src/xrpld/app/misc/NegativeUNLVote.h b/src/xrpld/app/misc/NegativeUNLVote.h index 7ad460cbf1..2cc63cf8c5 100644 --- a/src/xrpld/app/misc/NegativeUNLVote.h +++ b/src/xrpld/app/misc/NegativeUNLVote.h @@ -1,8 +1,7 @@ #pragma once -#include - #include +#include #include #include #include diff --git a/src/xrpld/app/misc/NetworkOPs.cpp b/src/xrpld/app/misc/NetworkOPs.cpp index 5110534efc..d7b42076c7 100644 --- a/src/xrpld/app/misc/NetworkOPs.cpp +++ b/src/xrpld/app/misc/NetworkOPs.cpp @@ -227,16 +227,16 @@ public: , clusterTimer_(io_svc) , accountHistoryTxTimer_(io_svc) , mConsensus( - registry_.app(), + registry_.getApp(), make_FeeVote( - setup_FeeVote(registry_.app().config().section("voting")), - registry_.logs().journal("FeeVote")), + setup_FeeVote(registry_.getApp().config().section("voting")), + registry_.getJournal("FeeVote")), ledgerMaster, *m_localTX, registry.getInboundTransactions(), beast::get_abstract_clock(), validatorKeys, - registry_.logs().journal("LedgerConsensus")) + registry_.getJournal("LedgerConsensus")) , validatorPK_( validatorKeys.keys ? validatorKeys.keys->publicKey : decltype(validatorPK_){}) , validatorMasterPK_( @@ -877,7 +877,7 @@ NetworkOPsImp::getHostId(bool forAdmin) // For non-admin uses hash the node public key into a // single RFC1751 word: static std::string const shroudedHostId = [this]() { - auto const& id = registry_.app().nodeIdentity(); + auto const& id = registry_.getApp().nodeIdentity(); return RFC1751::getWordFromBlob(id.first.data(), id.first.size()); }(); @@ -891,7 +891,7 @@ NetworkOPsImp::setStateTimer() setHeartbeatTimer(); // Only do this work if a cluster is configured - if (registry_.cluster().size() != 0) + if (registry_.getCluster().size() != 0) setClusterTimer(); } @@ -969,13 +969,13 @@ NetworkOPsImp::processHeartbeatTimer() { RclConsensusLogger clog("Heartbeat Timer", mConsensus.validating(), m_journal); { - std::unique_lock lock{registry_.app().getMasterMutex()}; + std::unique_lock lock{registry_.getApp().getMasterMutex()}; // VFALCO NOTE This is for diagnosing a crash on exit LoadManager& mgr(registry_.getLoadManager()); mgr.heartbeat(); - std::size_t const numPeers = registry_.overlay().size(); + std::size_t const numPeers = registry_.getOverlay().size(); // do we have sufficient peers? If not, we are disconnected. if (numPeers < minPeerCount_) @@ -1031,7 +1031,7 @@ NetworkOPsImp::processHeartbeatTimer() CLOG(clog.ss()) << ". "; } - mConsensus.timerEntry(registry_.timeKeeper().closeTime(), clog.ss()); + mConsensus.timerEntry(registry_.getTimeKeeper().closeTime(), clog.ss()); CLOG(clog.ss()) << "consensus phase " << to_string(mLastConsensusPhase); ConsensusPhase const currPhase = mConsensus.phase(); @@ -1049,17 +1049,17 @@ NetworkOPsImp::processHeartbeatTimer() void NetworkOPsImp::processClusterTimer() { - if (registry_.cluster().size() == 0) + if (registry_.getCluster().size() == 0) return; using namespace std::chrono_literals; - bool const update = registry_.cluster().update( - registry_.app().nodeIdentity().first, + bool const update = registry_.getCluster().update( + registry_.getApp().nodeIdentity().first, "", (m_ledgerMaster.getValidatedLedgerAge() <= 4min) ? registry_.getFeeTrack().getLocalFee() : 0, - registry_.timeKeeper().now()); + registry_.getTimeKeeper().now()); if (!update) { @@ -1069,7 +1069,7 @@ NetworkOPsImp::processClusterTimer() } protocol::TMCluster cluster; - registry_.cluster().for_each([&cluster](ClusterNode const& node) { + registry_.getCluster().for_each([&cluster](ClusterNode const& node) { protocol::TMClusterNode& n = *cluster.add_clusternodes(); n.set_publickey(toBase58(TokenType::NodePublic, node.identity())); n.set_reporttime(node.getReportTime().time_since_epoch().count()); @@ -1085,7 +1085,7 @@ NetworkOPsImp::processClusterTimer() node.set_name(to_string(item.address)); node.set_cost(item.balance); } - registry_.overlay().foreach( + registry_.getOverlay().foreach( send_if(std::make_shared(cluster, protocol::mtCLUSTER), peer_in_cluster())); setClusterTimer(); } @@ -1159,7 +1159,7 @@ NetworkOPsImp::submitTransaction(std::shared_ptr const& iTrans) std::string reason; - auto tx = std::make_shared(trans, reason, registry_.app()); + auto tx = std::make_shared(trans, reason, registry_.getApp()); m_job_queue.addJob(jtTRANSACTION, "SubmitTxn", [this, tx]() { auto t = tx; @@ -1320,7 +1320,7 @@ NetworkOPsImp::processTransactionSet(CanonicalTXSet const& set) for (auto const& [_, tx] : set) { std::string reason; - auto transaction = std::make_shared(tx, reason, registry_.app()); + auto transaction = std::make_shared(tx, reason, registry_.getApp()); if (transaction->getStatus() == INVALID) { @@ -1406,13 +1406,13 @@ NetworkOPsImp::apply(std::unique_lock& batchLock) batchLock.unlock(); { - std::unique_lock masterLock{registry_.app().getMasterMutex(), std::defer_lock}; + std::unique_lock masterLock{registry_.getApp().getMasterMutex(), std::defer_lock}; bool changed = false; { std::unique_lock ledgerLock{m_ledgerMaster.peekMutex(), std::defer_lock}; std::lock(masterLock, ledgerLock); - registry_.openLedger().modify([&](OpenView& view, beast::Journal j) { + registry_.getOpenLedger().modify([&](OpenView& view, beast::Journal j) { for (TransactionStatus& e : transactions) { // we check before adding to the batch @@ -1424,7 +1424,7 @@ NetworkOPsImp::apply(std::unique_lock& batchLock) flags |= tapFAIL_HARD; auto const result = registry_.getTxQ().apply( - registry_.app(), view, e.transaction->getSTransaction(), flags, j); + registry_.getApp(), view, e.transaction->getSTransaction(), flags, j); e.result = result.ter; e.applied = result.applied; changed = changed || result.applied; @@ -1439,7 +1439,7 @@ NetworkOPsImp::apply(std::unique_lock& batchLock) if (auto const l = m_ledgerMaster.getValidatedLedger()) validatedLedgerIndex = l->header().seq; - auto newOL = registry_.openLedger().current(); + auto newOL = registry_.getOpenLedger().current(); for (TransactionStatus& e : transactions) { e.transaction->clearSubmitResult(); @@ -1488,7 +1488,7 @@ NetworkOPsImp::apply(std::unique_lock& batchLock) batchLock.lock(); std::string reason; auto const trans = sterilize(*txNext); - auto t = std::make_shared(trans, reason, registry_.app()); + auto t = std::make_shared(trans, reason, registry_.getApp()); if (t->getApplying()) break; submit_held.emplace_back(t, false, false, FailHard::no); @@ -1594,10 +1594,10 @@ NetworkOPsImp::apply(std::unique_lock& batchLock) tx.set_rawtransaction(s.data(), s.size()); tx.set_status(protocol::tsCURRENT); tx.set_receivetimestamp( - registry_.timeKeeper().now().time_since_epoch().count()); + registry_.getTimeKeeper().now().time_since_epoch().count()); tx.set_deferred(e.result == terQUEUED); // FIXME: This should be when we received it - registry_.overlay().relay(e.transaction->getID(), tx, *toSkip); + registry_.getOverlay().relay(e.transaction->getID(), tx, *toSkip); e.transaction->setBroadcast(); } } @@ -1874,7 +1874,7 @@ NetworkOPsImp::switchLastClosedLedger(std::shared_ptr const& newLC clearNeedNetworkLedger(); // Update fee computations. - registry_.getTxQ().processClosedLedger(registry_.app(), *newLCL, true); + registry_.getTxQ().processClosedLedger(registry_.getApp(), *newLCL, true); // Caller must own master lock { @@ -1886,14 +1886,14 @@ NetworkOPsImp::switchLastClosedLedger(std::shared_ptr const& newLC std::optional rules; if (lastVal) { - rules = makeRulesGivenLedger(*lastVal, registry_.app().config().features); + rules = makeRulesGivenLedger(*lastVal, registry_.getApp().config().features); } else { - rules.emplace(registry_.app().config().features); + rules.emplace(registry_.getApp().config().features); } - registry_.openLedger().accept( - registry_.app(), + registry_.getOpenLedger().accept( + registry_.getApp(), *rules, newLCL, OrderedTxs({}), @@ -1903,7 +1903,7 @@ NetworkOPsImp::switchLastClosedLedger(std::shared_ptr const& newLC "jump", [&](OpenView& view, beast::Journal j) { // Stuff the ledger with transactions from the queue. - return registry_.getTxQ().accept(registry_.app(), view); + return registry_.getTxQ().accept(registry_.getApp(), view); }); } @@ -1912,12 +1912,12 @@ NetworkOPsImp::switchLastClosedLedger(std::shared_ptr const& newLC protocol::TMStatusChange s; s.set_newevent(protocol::neSWITCHED_LEDGER); s.set_ledgerseq(newLCL->header().seq); - s.set_networktime(registry_.timeKeeper().now().time_since_epoch().count()); + s.set_networktime(registry_.getTimeKeeper().now().time_since_epoch().count()); s.set_ledgerhashprevious( newLCL->header().parentHash.begin(), newLCL->header().parentHash.size()); s.set_ledgerhash(newLCL->header().hash.begin(), newLCL->header().hash.size()); - registry_.overlay().foreach( + registry_.getOverlay().foreach( send_always(std::make_shared(s, protocol::mtSTATUS_CHANGE))); } @@ -1958,23 +1958,24 @@ NetworkOPsImp::beginConsensus( "xrpl::NetworkOPsImp::beginConsensus : closedLedger parent matches " "hash"); - registry_.validators().setNegativeUNL(prevLedger->negativeUNL()); - TrustChanges const changes = registry_.validators().updateTrusted( + registry_.getValidators().setNegativeUNL(prevLedger->negativeUNL()); + TrustChanges const changes = registry_.getValidators().updateTrusted( registry_.getValidations().getCurrentNodeIDs(), closingInfo.parentCloseTime, *this, - registry_.overlay(), + registry_.getOverlay(), registry_.getHashRouter()); if (!changes.added.empty() || !changes.removed.empty()) { registry_.getValidations().trustChanged(changes.added, changes.removed); // Update the AmendmentTable so it tracks the current validators. - registry_.getAmendmentTable().trustChanged(registry_.validators().getQuorumKeys().second); + registry_.getAmendmentTable().trustChanged( + registry_.getValidators().getQuorumKeys().second); } mConsensus.startRound( - registry_.timeKeeper().closeTime(), + registry_.getTimeKeeper().closeTime(), networkClosed, prevLedger, changes.removed, @@ -2014,7 +2015,7 @@ NetworkOPsImp::processTrustedProposal(RCLCxPeerPos peerPos) return false; } - return mConsensus.peerProposal(registry_.timeKeeper().closeTime(), peerPos); + return mConsensus.peerProposal(registry_.getTimeKeeper().closeTime(), peerPos); } void @@ -2028,11 +2029,12 @@ NetworkOPsImp::mapComplete(std::shared_ptr const& map, bool fromAcquire) protocol::TMHaveTransactionSet msg; msg.set_hash(map->getHash().as_uint256().begin(), 256 / 8); msg.set_status(protocol::tsHAVE); - registry_.overlay().foreach(send_always(std::make_shared(msg, protocol::mtHAVE_SET))); + registry_.getOverlay().foreach( + send_always(std::make_shared(msg, protocol::mtHAVE_SET))); // We acquired it because consensus asked us to if (fromAcquire) - mConsensus.gotTxSet(registry_.timeKeeper().closeTime(), RCLTxSet{map}); + mConsensus.gotTxSet(registry_.getTimeKeeper().closeTime(), RCLTxSet{map}); } void @@ -2040,7 +2042,7 @@ NetworkOPsImp::endConsensus(std::unique_ptr const& clog) { uint256 deadLedger = m_ledgerMaster.getClosedLedger()->header().parentHash; - for (auto const& it : registry_.overlay().getActivePeers()) + for (auto const& it : registry_.getOverlay().getActivePeers()) { if (it && (it->getClosedLedgerHash() == deadLedger)) { @@ -2050,7 +2052,8 @@ NetworkOPsImp::endConsensus(std::unique_ptr const& clog) } uint256 networkClosed; - bool ledgerChange = checkLastClosedLedger(registry_.overlay().getActivePeers(), networkClosed); + bool ledgerChange = + checkLastClosedLedger(registry_.getOverlay().getActivePeers(), networkClosed); if (networkClosed.isZero()) { @@ -2080,7 +2083,7 @@ NetworkOPsImp::endConsensus(std::unique_ptr const& clog) // Note: Do not go to FULL if we don't have the previous ledger // check if the ledger is bad enough to go to CONNECTED -- TODO auto current = m_ledgerMaster.getCurrentLedger(); - if (registry_.timeKeeper().now() < + if (registry_.getTimeKeeper().now() < (current->header().parentCloseTime + 2 * current->header().closeTimeResolution)) { setMode(OperatingMode::FULL); @@ -2188,8 +2191,8 @@ NetworkOPsImp::pubServer() Json::Value jvObj(Json::objectValue); ServerFeeSummary f{ - registry_.openLedger().current()->fees().base, - registry_.getTxQ().getMetrics(*registry_.openLedger().current()), + registry_.getOpenLedger().current()->fees().base, + registry_.getTxQ().getMetrics(*registry_.getOpenLedger().current()), registry_.getFeeTrack()}; jvObj[jss::type] = "serverStatus"; @@ -2295,7 +2298,7 @@ NetworkOPsImp::pubValidation(std::shared_ptr const& val) if (auto hash = (*val)[~sfValidatedHash]) jvObj[jss::validated_hash] = strHex(*hash); - auto const masterKey = registry_.validatorManifests().getMasterKey(signerPublic); + auto const masterKey = registry_.getValidatorManifests().getMasterKey(signerPublic); if (masterKey != signerPublic) jvObj[jss::master_key] = toBase58(TokenType::NodePublic, masterKey); @@ -2445,7 +2448,7 @@ NetworkOPsImp::recvValidation(std::shared_ptr const& val, std::str pendingValidations_.insert(val->getLedgerHash()); } scope_unlock unlock(lock); - handleNewValidation(registry_.app(), val, source, bypassAccept, m_journal); + handleNewValidation(registry_.getApp(), val, source, bypassAccept, m_journal); } catch (std::exception const& e) { @@ -2468,7 +2471,7 @@ NetworkOPsImp::recvValidation(std::shared_ptr const& val, std::str JLOG(m_journal.debug()) << [this, &val]() -> auto { std::stringstream ss; ss << "VALIDATION: " << val->render() << " master_key: "; - auto master = registry_.validators().getTrustedKey(val->getSignerPublic()); + auto master = registry_.getValidators().getTrustedKey(val->getSignerPublic()); if (master) { ss << toBase58(TokenType::NodePublic, *master); @@ -2482,7 +2485,7 @@ NetworkOPsImp::recvValidation(std::shared_ptr const& val, std::str // We will always relay trusted validations; if configured, we will // also relay all untrusted validations. - return registry_.app().config().RELAY_UNTRUSTED_VALIDATIONS == 1 || val->isTrusted(); + return registry_.getApp().config().RELAY_UNTRUSTED_VALIDATIONS == 1 || val->isTrusted(); } Json::Value @@ -2541,8 +2544,8 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) info[jss::hostid] = getHostId(admin); // domain: if configured with a domain, report it: - if (!registry_.app().config().SERVER_DOMAIN.empty()) - info[jss::server_domain] = registry_.app().config().SERVER_DOMAIN; + if (!registry_.getApp().config().SERVER_DOMAIN.empty()) + info[jss::server_domain] = registry_.getApp().config().SERVER_DOMAIN; info[jss::build_version] = BuildInfo::getVersionString(); @@ -2554,14 +2557,14 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) if (needNetworkLedger_) info[jss::network_ledger] = "waiting"; - info[jss::validation_quorum] = static_cast(registry_.validators().quorum()); + info[jss::validation_quorum] = static_cast(registry_.getValidators().quorum()); if (admin) { // Note: By default the node size is "tiny". When parsing it's an error if the final // NODE_SIZE is over 4 so below code should be safe. // NOLINTNEXTLINE(bugprone-switch-missing-default-case) - switch (registry_.app().config().NODE_SIZE) + switch (registry_.getApp().config().NODE_SIZE) { case 0: info[jss::node_size] = "tiny"; @@ -2580,7 +2583,7 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) break; } - auto when = registry_.validators().expires(); + auto when = registry_.getValidators().expires(); if (!human) { @@ -2598,7 +2601,7 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) { auto& x = (info[jss::validator_list] = Json::objectValue); - x[jss::count] = static_cast(registry_.validators().count()); + x[jss::count] = static_cast(registry_.getValidators().count()); if (when) { @@ -2611,7 +2614,7 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) { x[jss::expiration] = to_string(*when); - if (*when > registry_.timeKeeper().now()) + if (*when > registry_.getTimeKeeper().now()) { x[jss::status] = "active"; } @@ -2637,12 +2640,12 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) x[jss::branch] = xrpl::git::getBuildBranch(); } } - info[jss::io_latency_ms] = static_cast(registry_.app().getIOLatency().count()); + info[jss::io_latency_ms] = static_cast(registry_.getApp().getIOLatency().count()); if (admin) { - if (auto const localPubKey = registry_.validators().localPublicKey(); - localPubKey && registry_.app().getValidationPublicKey()) + if (auto const localPubKey = registry_.getValidators().localPublicKey(); + localPubKey && registry_.getApp().getValidationPublicKey()) { info[jss::pubkey_validator] = toBase58(TokenType::NodePublic, localPubKey.value()); } @@ -2662,7 +2665,8 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) info[jss::current_activities] = registry_.getPerfLog().currentJson(); } - info[jss::pubkey_node] = toBase58(TokenType::NodePublic, registry_.app().nodeIdentity().first); + info[jss::pubkey_node] = + toBase58(TokenType::NodePublic, registry_.getApp().nodeIdentity().first); info[jss::complete_ledgers] = registry_.getLedgerMaster().getCompleteLedgers(); @@ -2674,7 +2678,7 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) if (fp != 0) info[jss::fetch_pack] = Json::UInt(fp); - info[jss::peers] = Json::UInt(registry_.overlay().size()); + info[jss::peers] = Json::UInt(registry_.getOverlay().size()); Json::Value lastClose = Json::objectValue; lastClose[jss::proposers] = Json::UInt(mConsensus.prevProposers()); @@ -2696,10 +2700,11 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) if (admin) info[jss::load] = m_job_queue.getJson(); - if (auto const netid = registry_.overlay().networkID()) + if (auto const netid = registry_.getOverlay().networkID()) info[jss::network_id] = static_cast(*netid); - auto const escalationMetrics = registry_.getTxQ().getMetrics(*registry_.openLedger().current()); + auto const escalationMetrics = + registry_.getTxQ().getMetrics(*registry_.getOpenLedger().current()); auto const loadFactorServer = registry_.getFeeTrack().getLoadFactor(); auto const loadBaseServer = registry_.getFeeTrack().getLoadBase(); @@ -2797,7 +2802,7 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) l[jss::reserve_base_xrp] = lpClosed->fees().reserve.decimalXRP(); l[jss::reserve_inc_xrp] = lpClosed->fees().increment.decimalXRP(); - if (auto const closeOffset = registry_.timeKeeper().closeOffset(); + if (auto const closeOffset = registry_.getTimeKeeper().closeOffset(); std::abs(closeOffset.count()) >= 60) l[jss::close_time_offset] = static_cast(closeOffset.count()); @@ -2810,7 +2815,7 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) else { auto lCloseTime = lpClosed->header().closeTime; - auto closeTime = registry_.timeKeeper().closeTime(); + auto closeTime = registry_.getTimeKeeper().closeTime(); if (lCloseTime <= closeTime) { using namespace std::chrono_literals; @@ -2842,10 +2847,10 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) accounting_.json(info); info[jss::uptime] = UptimeClock::now().time_since_epoch().count(); - info[jss::jq_trans_overflow] = std::to_string(registry_.overlay().getJqTransOverflow()); - info[jss::peer_disconnects] = std::to_string(registry_.overlay().getPeerDisconnect()); + info[jss::jq_trans_overflow] = std::to_string(registry_.getOverlay().getJqTransOverflow()); + info[jss::peer_disconnects] = std::to_string(registry_.getOverlay().getPeerDisconnect()); info[jss::peer_disconnects_resources] = - std::to_string(registry_.overlay().getPeerDisconnectCharges()); + std::to_string(registry_.getOverlay().getPeerDisconnectCharges()); // This array must be sorted in increasing order. static constexpr std::array protocols{ @@ -2877,9 +2882,9 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) } } - if (registry_.app().config().exists(SECTION_PORT_GRPC)) + if (registry_.getApp().config().exists(SECTION_PORT_GRPC)) { - auto const& grpcSection = registry_.app().config().section(SECTION_PORT_GRPC); + auto const& grpcSection = registry_.getApp().config().section(SECTION_PORT_GRPC); auto const optPort = grpcSection.get("port"); if (optPort && grpcSection.get("ip")) { @@ -2985,7 +2990,7 @@ NetworkOPsImp::pubLedger(std::shared_ptr const& lpAccepted) jvObj[jss::network_id] = registry_.getNetworkIDService().getNetworkID(); if (!lpAccepted->rules().enabled(featureXRPFees)) - jvObj[jss::fee_ref] = Config::FEE_UNITS_DEPRECATED; + jvObj[jss::fee_ref] = FEE_UNITS_DEPRECATED; jvObj[jss::fee_base] = lpAccepted->fees().base.jsonClipped(); jvObj[jss::reserve_base] = lpAccepted->fees().reserve.jsonClipped(); jvObj[jss::reserve_inc] = lpAccepted->fees().increment.jsonClipped(); @@ -3066,8 +3071,8 @@ void NetworkOPsImp::reportFeeChange() { ServerFeeSummary f{ - registry_.openLedger().current()->fees().base, - registry_.getTxQ().getMetrics(*registry_.openLedger().current()), + registry_.getOpenLedger().current()->fees().base, + registry_.getTxQ().getMetrics(*registry_.getOpenLedger().current()), registry_.getFeeTrack()}; // only schedule the job if something has changed @@ -3168,8 +3173,8 @@ NetworkOPsImp::transJson( // If the offer create is not self funded then add the owner balance if (account != amount.issue().account) { - auto const ownerFunds = - accountFunds(*ledger, account, amount, fhIGNORE_FREEZE, registry_.journal("View")); + auto const ownerFunds = accountFunds( + *ledger, account, amount, fhIGNORE_FREEZE, registry_.getJournal("View")); jvObj[jss::transaction][jss::owner_funds] = ownerFunds.getText(); } } @@ -3994,7 +3999,7 @@ NetworkOPsImp::acceptLedger(std::optional consensusDe // FIXME Could we improve on this and remove the need for a specialized // API in Consensus? beginConsensus(m_ledgerMaster.getClosedLedger()->header().hash, {}); - mConsensus.simulate(registry_.timeKeeper().closeTime(), consensusDelay); + mConsensus.simulate(registry_.getTimeKeeper().closeTime(), consensusDelay); return m_ledgerMaster.getCurrentLedger()->header().seq; } @@ -4009,7 +4014,7 @@ NetworkOPsImp::subLedger(InfoSub::ref isrListener, Json::Value& jvResult) jvResult[jss::ledger_time] = Json::Value::UInt(lpClosed->header().closeTime.time_since_epoch().count()); if (!lpClosed->rules().enabled(featureXRPFees)) - jvResult[jss::fee_ref] = Config::FEE_UNITS_DEPRECATED; + jvResult[jss::fee_ref] = FEE_UNITS_DEPRECATED; jvResult[jss::fee_base] = lpClosed->fees().base.jsonClipped(); jvResult[jss::reserve_base] = lpClosed->fees().reserve.jsonClipped(); jvResult[jss::reserve_inc] = lpClosed->fees().increment.jsonClipped(); @@ -4084,7 +4089,7 @@ NetworkOPsImp::subServer(InfoSub::ref isrListener, Json::Value& jvResult, bool a jvResult[jss::load_factor] = feeTrack.getLoadFactor(); jvResult[jss::hostid] = getHostId(admin); jvResult[jss::pubkey_node] = - toBase58(TokenType::NodePublic, registry_.app().nodeIdentity().first); + toBase58(TokenType::NodePublic, registry_.getApp().nodeIdentity().first); std::lock_guard sl(mSubLock); return mStreamMaps[sServer].emplace(isrListener->getSeq(), isrListener).second; @@ -4271,7 +4276,7 @@ NetworkOPsImp::getBookPage( STAmount saDirRate; auto const rate = transferRate(view, book.out.account); - auto viewJ = registry_.journal("View"); + auto viewJ = registry_.getJournal("View"); while (!bDone && iLimit-- > 0) { diff --git a/src/xrpld/app/misc/SHAMapStore.h b/src/xrpld/app/misc/SHAMapStore.h index 67477593cb..b377538f62 100644 --- a/src/xrpld/app/misc/SHAMapStore.h +++ b/src/xrpld/app/misc/SHAMapStore.h @@ -1,7 +1,6 @@ #pragma once -#include - +#include #include #include diff --git a/src/xrpld/app/misc/SHAMapStoreImp.cpp b/src/xrpld/app/misc/SHAMapStoreImp.cpp index 2865f964de..6460d99686 100644 --- a/src/xrpld/app/misc/SHAMapStoreImp.cpp +++ b/src/xrpld/app/misc/SHAMapStoreImp.cpp @@ -158,7 +158,7 @@ SHAMapStoreImp::makeNodeStore(int readThreads) std::move(writableBackend), std::move(archiveBackend), nscfg, - app_.logs().journal(nodeStoreName_)); + app_.getJournal(nodeStoreName_)); fdRequired_ += dbr->fdRequired(); dbRotating_ = dbr.get(); db.reset(dynamic_cast(dbr.release())); @@ -170,7 +170,7 @@ SHAMapStoreImp::makeNodeStore(int readThreads) scheduler_, readThreads, nscfg, - app_.logs().journal(nodeStoreName_)); + app_.getJournal(nodeStoreName_)); fdRequired_ += db->fdRequired(); } return db; @@ -453,7 +453,7 @@ SHAMapStoreImp::makeBackendRotating(std::string path) section, megabytes(app_.config().getValueFor(SizedItem::burstSize, std::nullopt)), scheduler_, - app_.logs().journal(nodeStoreName_))}; + app_.getJournal(nodeStoreName_))}; backend->open(); return backend; } diff --git a/src/xrpld/app/misc/detail/AccountTxPaging.cpp b/src/xrpld/app/misc/detail/AccountTxPaging.cpp index 4e79b53ed0..bb0a09426a 100644 --- a/src/xrpld/app/misc/detail/AccountTxPaging.cpp +++ b/src/xrpld/app/misc/detail/AccountTxPaging.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/src/xrpld/app/misc/detail/Transaction.cpp b/src/xrpld/app/misc/detail/Transaction.cpp index 6eefd08369..f0cabf0fa6 100644 --- a/src/xrpld/app/misc/detail/Transaction.cpp +++ b/src/xrpld/app/misc/detail/Transaction.cpp @@ -16,7 +16,7 @@ Transaction::Transaction( std::shared_ptr const& stx, std::string& reason, Application& app) noexcept - : mTransaction(stx), mApp(app), j_(app.journal("Ledger")) + : mTransaction(stx), mApp(app), j_(app.getJournal("Ledger")) { try { diff --git a/src/xrpld/app/misc/detail/TxQ.cpp b/src/xrpld/app/misc/detail/TxQ.cpp index 78e8ccdba5..c03ef6872e 100644 --- a/src/xrpld/app/misc/detail/TxQ.cpp +++ b/src/xrpld/app/misc/detail/TxQ.cpp @@ -1770,7 +1770,7 @@ TxQ::getTxs() const Json::Value TxQ::doRPC(Application& app) const { - auto const view = app.openLedger().current(); + auto const view = app.getOpenLedger().current(); if (!view) { BOOST_ASSERT(false); diff --git a/src/xrpld/app/misc/detail/ValidatorSite.cpp b/src/xrpld/app/misc/detail/ValidatorSite.cpp index 8db29c0bb0..91352cb12d 100644 --- a/src/xrpld/app/misc/detail/ValidatorSite.cpp +++ b/src/xrpld/app/misc/detail/ValidatorSite.cpp @@ -72,7 +72,7 @@ ValidatorSite::ValidatorSite( std::optional j, std::chrono::seconds timeout) : app_{app} - , j_{j ? *j : app_.logs().journal("ValidatorSite")} + , j_{j ? *j : app_.getJournal("ValidatorSite")} , timer_{app_.getIOContext()} , fetching_{false} , pending_{false} @@ -101,7 +101,7 @@ ValidatorSite::~ValidatorSite() bool ValidatorSite::missingSite(std::lock_guard const& lock_sites) { - auto const sites = app_.validators().loadLists(); + auto const sites = app_.getValidators().loadLists(); return sites.empty() || load(sites, lock_sites); } @@ -394,8 +394,15 @@ ValidatorSite::parseJsonResponse( "xrpl::ValidatorSite::parseJsonResponse : version match"); auto const& uri = sites_[siteIdx].activeResource->uri; auto const hash = sha512Half(manifest, blobs, version); - auto const applyResult = app_.validators().applyListsAndBroadcast( - manifest, version, blobs, uri, hash, app_.overlay(), app_.getHashRouter(), app_.getOPs()); + auto const applyResult = app_.getValidators().applyListsAndBroadcast( + manifest, + version, + blobs, + uri, + hash, + app_.getOverlay(), + app_.getHashRouter(), + app_.getOPs()); sites_[siteIdx].lastRefreshStatus.emplace( Site::Status{clock_type::now(), applyResult.bestDisposition(), ""}); diff --git a/src/xrpld/app/rdb/backend/detail/Node.cpp b/src/xrpld/app/rdb/backend/detail/Node.cpp index 317c4e77a1..66b75e72de 100644 --- a/src/xrpld/app/rdb/backend/detail/Node.cpp +++ b/src/xrpld/app/rdb/backend/detail/Node.cpp @@ -1,7 +1,7 @@ #include #include +#include #include -#include #include #include @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -168,7 +169,7 @@ saveValidatedLedger( std::shared_ptr const& ledger, bool current) { - auto j = app.journal("Ledger"); + auto j = app.getJournal("Ledger"); auto seq = ledger->header().seq; // TODO(tom): Fix this hard-coded SQL! @@ -221,7 +222,7 @@ saveValidatedLedger( app.getLedgerMaster().failedSave(seq, ledger->header().hash); // Clients can now trust the database for information about this // ledger sequence. - app.pendingSaves().finishWork(seq); + app.getPendingSaves().finishWork(seq); return false; } @@ -1229,7 +1230,7 @@ getTransaction( } catch (std::exception& e) { - JLOG(app.journal("Ledger").warn()) + JLOG(app.getJournal("Ledger").warn()) << "Unable to deserialize transaction from raw SQL value. Error: " << e.what(); ec = rpcDB_DESERIALIZATION; diff --git a/src/xrpld/app/rdb/backend/detail/Node.h b/src/xrpld/app/rdb/backend/detail/Node.h index cb49a373bd..14eff07b94 100644 --- a/src/xrpld/app/rdb/backend/detail/Node.h +++ b/src/xrpld/app/rdb/backend/detail/Node.h @@ -1,8 +1,8 @@ #pragma once -#include #include +#include #include namespace xrpl { diff --git a/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp b/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp index 4f5365ea01..e271619b8e 100644 --- a/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp +++ b/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp @@ -178,7 +178,7 @@ SQLiteDatabase::saveValidatedLedger(std::shared_ptr const& ledger, { if (existsLedger()) { - if (!detail::saveValidatedLedger(*ledgerDb_, txdb_, registry_.app(), ledger, current)) + if (!detail::saveValidatedLedger(*ledgerDb_, txdb_, registry_.getApp(), ledger, current)) return false; } @@ -314,7 +314,7 @@ SQLiteDatabase::getTxHistory(LedgerIndex startIndex) if (existsTransaction()) { auto db = checkoutTransaction(); - auto const res = detail::getTxHistory(*db, registry_.app(), startIndex, 20).first; + auto const res = detail::getTxHistory(*db, registry_.getApp(), startIndex, 20).first; if (!res.empty()) return res; @@ -334,7 +334,8 @@ SQLiteDatabase::getOldestAccountTxs(AccountTxOptions const& options) if (existsTransaction()) { auto db = checkoutTransaction(); - return detail::getOldestAccountTxs(*db, registry_.app(), ledgerMaster, options, j_).first; + return detail::getOldestAccountTxs(*db, registry_.getApp(), ledgerMaster, options, j_) + .first; } return {}; @@ -351,7 +352,8 @@ SQLiteDatabase::getNewestAccountTxs(AccountTxOptions const& options) if (existsTransaction()) { auto db = checkoutTransaction(); - return detail::getNewestAccountTxs(*db, registry_.app(), ledgerMaster, options, j_).first; + return detail::getNewestAccountTxs(*db, registry_.getApp(), ledgerMaster, options, j_) + .first; } return {}; @@ -366,7 +368,7 @@ SQLiteDatabase::getOldestAccountTxsB(AccountTxOptions const& options) if (existsTransaction()) { auto db = checkoutTransaction(); - return detail::getOldestAccountTxsB(*db, registry_.app(), options, j_).first; + return detail::getOldestAccountTxsB(*db, registry_.getApp(), options, j_).first; } return {}; @@ -381,7 +383,7 @@ SQLiteDatabase::getNewestAccountTxsB(AccountTxOptions const& options) if (existsTransaction()) { auto db = checkoutTransaction(); - return detail::getNewestAccountTxsB(*db, registry_.app(), options, j_).first; + return detail::getNewestAccountTxsB(*db, registry_.getApp(), options, j_).first; } return {}; @@ -395,10 +397,10 @@ SQLiteDatabase::oldestAccountTxPage(AccountTxPageOptions const& options) static std::uint32_t const page_length(200); auto onUnsavedLedger = - std::bind(saveLedgerAsync, std::ref(registry_.app()), std::placeholders::_1); + std::bind(saveLedgerAsync, std::ref(registry_.getApp()), std::placeholders::_1); AccountTxs ret; auto onTransaction = - [&ret, &app = registry_.app()]( + [&ret, &app = registry_.getApp()]( std::uint32_t ledger_index, std::string const& status, Blob&& rawTxn, Blob&& rawMeta) { convertBlobsToTxResult( ret, ledger_index, status, std::move(rawTxn), std::move(rawMeta), app); @@ -424,10 +426,10 @@ SQLiteDatabase::newestAccountTxPage(AccountTxPageOptions const& options) static std::uint32_t const page_length(200); auto onUnsavedLedger = - std::bind(saveLedgerAsync, std::ref(registry_.app()), std::placeholders::_1); + std::bind(saveLedgerAsync, std::ref(registry_.getApp()), std::placeholders::_1); AccountTxs ret; auto onTransaction = - [&ret, &app = registry_.app()]( + [&ret, &app = registry_.getApp()]( std::uint32_t ledger_index, std::string const& status, Blob&& rawTxn, Blob&& rawMeta) { convertBlobsToTxResult( ret, ledger_index, status, std::move(rawTxn), std::move(rawMeta), app); @@ -453,7 +455,7 @@ SQLiteDatabase::oldestAccountTxPageB(AccountTxPageOptions const& options) static std::uint32_t const page_length(500); auto onUnsavedLedger = - std::bind(saveLedgerAsync, std::ref(registry_.app()), std::placeholders::_1); + std::bind(saveLedgerAsync, std::ref(registry_.getApp()), std::placeholders::_1); MetaTxsList ret; auto onTransaction = [&ret]( @@ -481,7 +483,7 @@ SQLiteDatabase::newestAccountTxPageB(AccountTxPageOptions const& options) static std::uint32_t const page_length(500); auto onUnsavedLedger = - std::bind(saveLedgerAsync, std::ref(registry_.app()), std::placeholders::_1); + std::bind(saveLedgerAsync, std::ref(registry_.getApp()), std::placeholders::_1); MetaTxsList ret; auto onTransaction = [&ret]( @@ -513,7 +515,7 @@ SQLiteDatabase::getTransaction( if (existsTransaction()) { auto db = checkoutTransaction(); - return detail::getTransaction(*db, registry_.app(), id, range, ec); + return detail::getTransaction(*db, registry_.getApp(), id, range, ec); } return TxSearched::unknown; @@ -604,10 +606,10 @@ SQLiteDatabase::closeTransactionDB() SQLiteDatabase::SQLiteDatabase(ServiceRegistry& registry, Config const& config, JobQueue& jobQueue) : registry_(registry) , useTxTables_(config.useTxTables()) - , j_(registry.journal("SQLiteDatabase")) + , j_(registry.getJournal("SQLiteDatabase")) { DatabaseCon::Setup const setup = setup_DatabaseCon(config, j_); - if (!makeLedgerDBs(config, setup, DatabaseCon::CheckpointerSetup{&jobQueue, ®istry_.logs()})) + if (!makeLedgerDBs(config, setup, DatabaseCon::CheckpointerSetup{&jobQueue, registry_})) { std::string_view constexpr error = "Failed to create ledger databases"; diff --git a/src/xrpld/consensus/Consensus.h b/src/xrpld/consensus/Consensus.h index 3c1e4e7dbf..2ed40cd2eb 100644 --- a/src/xrpld/consensus/Consensus.h +++ b/src/xrpld/consensus/Consensus.h @@ -4,12 +4,12 @@ #include #include #include -#include #include #include #include #include +#include #include #include diff --git a/src/xrpld/core/Config.h b/src/xrpld/core/Config.h index c40d13c83a..44509d2145 100644 --- a/src/xrpld/core/Config.h +++ b/src/xrpld/core/Config.h @@ -5,6 +5,7 @@ #include #include #include +#include #include // VFALCO Breaks levelization #include @@ -57,6 +58,13 @@ struct FeeSetup /* (Remember to update the example cfg files when changing any of these * values.) */ + + /** Convert to a Fees object for use with Ledger construction. */ + Fees + toFees() const + { + return Fees{reference_fee, account_reserve, owner_reserve}; + } }; // This entire derived class is deprecated. @@ -137,10 +145,6 @@ public: // Network parameters uint32_t NETWORK_ID = 0; - // DEPRECATED - Fee units for a reference transaction. - // Only provided for backwards compatibility in a couple of places - static constexpr std::uint32_t FEE_UNITS_DEPRECATED = 10; - // Note: The following parameters do not relate to the UNL or trust at all // Minimum number of nodes to consider the network present std::size_t NETWORK_QUORUM = 1; diff --git a/src/xrpld/overlay/Slot.h b/src/xrpld/overlay/Slot.h index ac3c3ad49e..11cbd09e36 100644 --- a/src/xrpld/overlay/Slot.h +++ b/src/xrpld/overlay/Slot.h @@ -536,14 +536,14 @@ class Slots final public: /** - * @param logs reference to the logger + * @param registry The service registry. * @param handler Squelch/unsquelch implementation * @param config reference to the global config */ - Slots(Logs& logs, SquelchHandler const& handler, Config const& config) + Slots(ServiceRegistry& registry, SquelchHandler const& handler, Config const& config) : handler_(handler) - , logs_(logs) - , journal_(logs.journal("Slots")) + , logs_(registry.getLogs()) + , journal_(registry.getJournal("Slots")) , baseSquelchEnabled_(config.VP_REDUCE_RELAY_BASE_SQUELCH_ENABLE) , maxSelectedPeers_(config.VP_REDUCE_RELAY_SQUELCH_MAX_SELECTED_PEERS) { diff --git a/src/xrpld/overlay/detail/ConnectAttempt.cpp b/src/xrpld/overlay/detail/ConnectAttempt.cpp index 78aee006f1..406370ff19 100644 --- a/src/xrpld/overlay/detail/ConnectAttempt.cpp +++ b/src/xrpld/overlay/detail/ConnectAttempt.cpp @@ -607,7 +607,7 @@ ConnectAttempt::processResponse() JLOG(journal_.debug()) << "Protocol: " << to_string(*negotiatedProtocol); JLOG(journal_.info()) << "Public Key: " << toBase58(TokenType::NodePublic, publicKey); - auto const member = app_.cluster().member(publicKey); + auto const member = app_.getCluster().member(publicKey); if (member) { JLOG(journal_.info()) << "Cluster name: " << *member; diff --git a/src/xrpld/overlay/detail/Handshake.cpp b/src/xrpld/overlay/detail/Handshake.cpp index e9ad25bcc4..0992d252b0 100644 --- a/src/xrpld/overlay/detail/Handshake.cpp +++ b/src/xrpld/overlay/detail/Handshake.cpp @@ -166,7 +166,7 @@ buildHandshake( h.insert("Network-ID", std::to_string(*networkID)); } - h.insert("Network-Time", std::to_string(app.timeKeeper().now().time_since_epoch().count())); + h.insert("Network-Time", std::to_string(app.getTimeKeeper().now().time_since_epoch().count())); h.insert("Public-Key", toBase58(TokenType::NodePublic, app.nodeIdentity().first)); @@ -235,7 +235,7 @@ verifyHandshake( using namespace std::chrono; - auto const ourTime = app.timeKeeper().now(); + auto const ourTime = app.getTimeKeeper().now(); auto const tolerance = 20s; // We can't blindly "return a-b;" because TimeKeeper::time_point diff --git a/src/xrpld/overlay/detail/OverlayImpl.cpp b/src/xrpld/overlay/detail/OverlayImpl.cpp index 57eddd8b2c..aa3441f389 100644 --- a/src/xrpld/overlay/detail/OverlayImpl.cpp +++ b/src/xrpld/overlay/detail/OverlayImpl.cpp @@ -114,20 +114,20 @@ OverlayImpl::OverlayImpl( , work_(std::in_place, boost::asio::make_work_guard(io_context_)) , strand_(boost::asio::make_strand(io_context_)) , setup_(setup) - , journal_(app_.journal("Overlay")) + , journal_(app_.getJournal("Overlay")) , serverHandler_(serverHandler) , m_resourceManager(resourceManager) , m_peerFinder( PeerFinder::make_Manager( io_context, stopwatch(), - app_.journal("PeerFinder"), + app_.getJournal("PeerFinder"), config, collector)) , m_resolver(resolver) , next_id_(1) , timer_count_(0) - , slots_(app.logs(), *this, app.config()) + , slots_(app, *this, app.config()) , m_stats( std::bind(&OverlayImpl::collect_metrics, this), collector, @@ -150,7 +150,8 @@ OverlayImpl::onHandoff( endpoint_type remote_endpoint) { auto const id = next_id_++; - beast::WrappedSink sink(app_.logs()["Peer"], makePrefix(id)); + auto peerJournal = app_.getJournal("Peer"); + beast::WrappedSink sink(peerJournal.sink(), makePrefix(id)); beast::Journal journal(sink); Handoff handoff; @@ -240,8 +241,8 @@ OverlayImpl::onHandoff( { // The node gets a reserved slot if it is in our cluster // or if it has a reservation. - bool const reserved = static_cast(app_.cluster().member(publicKey)) || - app_.peerReservations().contains(publicKey); + bool const reserved = static_cast(app_.getCluster().member(publicKey)) || + app_.getPeerReservations().contains(publicKey); auto const result = m_peerFinder->activate(slot, publicKey, reserved); if (result != PeerFinder::Result::success) { @@ -389,7 +390,7 @@ OverlayImpl::connect(beast::IP::Endpoint const& remote_endpoint) setup_.context, next_id_++, slot, - app_.journal("Peer"), + app_.getJournal("Peer"), *this); std::lock_guard lock(mutex_); @@ -612,7 +613,7 @@ OverlayImpl::onManifests( { auto const serialized = mo->serialized; - auto const result = app_.validatorManifests().applyManifest(std::move(*mo)); + auto const result = app_.getValidatorManifests().applyManifest(std::move(*mo)); if (result == ManifestDisposition::accepted) { @@ -629,7 +630,7 @@ OverlayImpl::onManifests( app_.getOPs().pubManifest(*mo); - if (app_.validators().listed(mo->masterKey)) + if (app_.getValidators().listed(mo->masterKey)) { auto db = app_.getWalletDB().checkoutDb(); addValidatorManifest(*db, serialized); @@ -758,7 +759,7 @@ OverlayImpl::getServerCounts() Json::Value OverlayImpl::getUnlInfo() { - Json::Value validators = app_.validators().getJson(); + Json::Value validators = app_.getValidators().getJson(); if (validators.isMember(jss::publisher_lists)) { @@ -774,7 +775,7 @@ OverlayImpl::getUnlInfo() validators.removeMember(jss::trusted_validator_keys); validators.removeMember(jss::validation_quorum); - Json::Value validatorSites = app_.validatorSites().getJson(); + Json::Value validatorSites = app_.getValidatorSites().getJson(); if (validatorSites.isMember(jss::validator_sites)) { @@ -875,7 +876,7 @@ OverlayImpl::processValidatorList(http_request_type const& req, Handoff& handoff return fail(boost::beast::http::status::bad_request); // find the list - auto vl = app_.validators().getAvailable(key, version); + auto vl = app_.getValidators().getAvailable(key, version); if (!vl) { @@ -1142,11 +1143,11 @@ OverlayImpl::getManifestsMessage() { std::lock_guard g(manifestLock_); - if (auto seq = app_.validatorManifests().sequence(); seq != manifestListSeq_) + if (auto seq = app_.getValidatorManifests().sequence(); seq != manifestListSeq_) { protocol::TMManifests tm; - app_.validatorManifests().for_each_manifest( + app_.getValidatorManifests().for_each_manifest( [&tm](std::size_t s) { tm.mutable_list()->Reserve(s); }, [&tm, &hr = app_.getHashRouter()](Manifest const& manifest) { tm.add_list()->set_stobject(manifest.serialized.data(), manifest.serialized.size()); diff --git a/src/xrpld/overlay/detail/PeerImp.cpp b/src/xrpld/overlay/detail/PeerImp.cpp index 767e8bfd20..92c5bcb221 100644 --- a/src/xrpld/overlay/detail/PeerImp.cpp +++ b/src/xrpld/overlay/detail/PeerImp.cpp @@ -65,8 +65,8 @@ PeerImp::PeerImp( , id_(id) , fingerprint_(getFingerprint(slot->remote_endpoint(), publicKey, to_string(id))) , prefix_(makePrefix(fingerprint_)) - , sink_(app_.journal("Peer"), prefix_) - , p_sink_(app_.journal("Protocol"), prefix_) + , sink_(app_.getJournal("Peer"), prefix_) + , p_sink_(app_.getJournal("Protocol"), prefix_) , journal_(sink_) , p_journal_(p_sink_) , stream_ptr_(std::move(stream_ptr)) @@ -83,7 +83,7 @@ PeerImp::PeerImp( , publicKey_(publicKey) , lastPingTime_(clock_type::now()) , creationTime_(clock_type::now()) - , squelch_(app_.journal("Squelch")) + , squelch_(app_.getJournal("Squelch")) , usage_(consumer) , fee_{Resource::feeTrivialPeer, ""} , slot_(slot) @@ -364,7 +364,7 @@ PeerImp::crawl() const bool PeerImp::cluster() const { - return static_cast(app_.cluster().member(publicKey_)); + return static_cast(app_.getCluster().member(publicKey_)); } std::string @@ -818,7 +818,7 @@ PeerImp::doAccept() JLOG(journal_.debug()) << "Protocol: " << to_string(protocol_); - if (auto member = app_.cluster().member(publicKey_)) + if (auto member = app_.getCluster().member(publicKey_)) { { std::unique_lock lock{nameMutex_}; @@ -908,7 +908,7 @@ PeerImp::doProtocolStart() // Send all the validator lists that have been loaded if (inbound_ && supportsFeature(ProtocolFeature::ValidatorListPropagation)) { - app_.validators().for_each_available( + app_.getValidators().for_each_available( [&](std::string const& manifest, std::uint32_t version, std::map const& blobInfos, @@ -1242,7 +1242,7 @@ PeerImp::onMessage(std::shared_ptr const& m) { auto const reportTime = NetClock::time_point{NetClock::duration{node.reporttime()}}; - app_.cluster().update(*publicKey, name, node.nodeload(), reportTime); + app_.getCluster().update(*publicKey, name, node.nodeload(), reportTime); } } @@ -1264,13 +1264,13 @@ PeerImp::onMessage(std::shared_ptr const& m) } // Calculate the cluster fee: - auto const thresh = app_.timeKeeper().now() - 90s; + auto const thresh = app_.getTimeKeeper().now() - 90s; std::uint32_t clusterFee = 0; std::vector fees; - fees.reserve(app_.cluster().size()); + fees.reserve(app_.getCluster().size()); - app_.cluster().for_each([&fees, thresh](ClusterNode const& status) { + app_.getCluster().for_each([&fees, thresh](ClusterNode const& status) { if (status.getReportTime() >= thresh) fees.push_back(status.getLoadFee()); }); @@ -1811,7 +1811,7 @@ PeerImp::onMessage(std::shared_ptr const& m) // suppression for 30 seconds to avoid doing a relatively expensive lookup // every time a spam packet is received PublicKey const publicKey{makeSlice(set.nodepubkey())}; - auto const isTrusted = app_.validators().trusted(publicKey); + auto const isTrusted = app_.getValidators().trusted(publicKey); // If the operator has specified that untrusted proposals be dropped then // this happens here I.e. before further wasting CPU verifying the signature @@ -1877,8 +1877,8 @@ PeerImp::onMessage(std::shared_ptr const& m) set.proposeseq(), proposeHash, closeTime, - app_.timeKeeper().closeTime(), - calcNodeID(app_.validatorManifests().getMasterKey(publicKey))}); + app_.getTimeKeeper().closeTime(), + calcNodeID(app_.getValidatorManifests().getMasterKey(publicKey))}); std::weak_ptr weak = shared_from_this(); app_.getJobQueue().addJob( @@ -1894,7 +1894,7 @@ PeerImp::onMessage(std::shared_ptr const& m) JLOG(p_journal_.trace()) << "Status: Change"; if (!m->has_networktime()) - m->set_networktime(app_.timeKeeper().now().time_since_epoch().count()); + m->set_networktime(app_.getTimeKeeper().now().time_since_epoch().count()); { std::lock_guard sl(recentLock_); @@ -2157,13 +2157,13 @@ PeerImp::onValidatorListMessage( return; } - auto const applyResult = app_.validators().applyListsAndBroadcast( + auto const applyResult = app_.getValidators().applyListsAndBroadcast( manifest, version, blobs, remote_address_.to_string(), hash, - app_.overlay(), + app_.getOverlay(), app_.getHashRouter(), app_.getOPs()); @@ -2390,7 +2390,7 @@ PeerImp::onMessage(std::shared_ptr const& m) try { - auto const closeTime = app_.timeKeeper().closeTime(); + auto const closeTime = app_.getTimeKeeper().closeTime(); std::shared_ptr val; { @@ -2398,7 +2398,7 @@ PeerImp::onMessage(std::shared_ptr const& m) val = std::make_shared( std::ref(sit), [this](PublicKey const& pk) { - return calcNodeID(app_.validatorManifests().getMasterKey(pk)); + return calcNodeID(app_.getValidatorManifests().getMasterKey(pk)); }, false); val->setSeen(closeTime); @@ -2406,7 +2406,7 @@ PeerImp::onMessage(std::shared_ptr const& m) if (!isCurrent( app_.getValidations().parms(), - app_.timeKeeper().closeTime(), + app_.getTimeKeeper().closeTime(), val->getSignTime(), val->getSeenTime())) { @@ -2418,7 +2418,7 @@ PeerImp::onMessage(std::shared_ptr const& m) // RH TODO: when isTrusted = false we should probably also cache a key // suppression for 30 seconds to avoid doing a relatively expensive // lookup every time a spam packet is received - auto const isTrusted = app_.validators().trusted(val->getSignerPublic()); + auto const isTrusted = app_.getValidators().trusted(val->getSignerPublic()); // If the operator has specified that untrusted validations be // dropped then this happens here I.e. before further wasting CPU @@ -2863,7 +2863,7 @@ PeerImp::doTransactions(std::shared_ptr const& pack sttx->add(s); tx->set_rawtransaction(s.data(), s.size()); tx->set_status(txn->getStatus() == INCLUDED ? protocol::tsCURRENT : protocol::tsNEW); - tx->set_receivetimestamp(app_.timeKeeper().now().time_since_epoch().count()); + tx->set_receivetimestamp(app_.getTimeKeeper().now().time_since_epoch().count()); tx->set_deferred(txn->getSubmitResult().queued); } @@ -2941,7 +2941,7 @@ PeerImp::checkTransaction( { JLOG(p_journal_.debug()) << "Passing skipped pseudo pseudo-transaction tx " << tx->getID(); - app_.overlay().relay(tx->getID(), {}, *toSkip); + app_.getOverlay().relay(tx->getID(), {}, *toSkip); } if (!batch) { @@ -3041,7 +3041,7 @@ PeerImp::checkPropose( // not be relayed to these peers. But the message must be counted // as part of the squelch logic. auto haveMessage = - app_.overlay().relay(*packet, peerPos.suppressionID(), peerPos.publicKey()); + app_.getOverlay().relay(*packet, peerPos.suppressionID(), peerPos.publicKey()); if (!haveMessage.empty()) { overlay_.updateSlotAndSquelch( diff --git a/src/xrpld/overlay/detail/PeerImp.h b/src/xrpld/overlay/detail/PeerImp.h index b4393ebd62..5a687a9b2a 100644 --- a/src/xrpld/overlay/detail/PeerImp.h +++ b/src/xrpld/overlay/detail/PeerImp.h @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -815,8 +814,8 @@ PeerImp::PeerImp( , id_(id) , fingerprint_(getFingerprint(slot->remote_endpoint(), publicKey, to_string(id_))) , prefix_(makePrefix(fingerprint_)) - , sink_(app_.journal("Peer"), prefix_) - , p_sink_(app_.journal("Protocol"), prefix_) + , sink_(app_.getJournal("Peer"), prefix_) + , p_sink_(app_.getJournal("Protocol"), prefix_) , journal_(sink_) , p_journal_(p_sink_) , stream_ptr_(std::move(stream_ptr)) @@ -833,7 +832,7 @@ PeerImp::PeerImp( , publicKey_(publicKey) , lastPingTime_(clock_type::now()) , creationTime_(clock_type::now()) - , squelch_(app_.journal("Squelch")) + , squelch_(app_.getJournal("Squelch")) , usage_(usage) , fee_{Resource::feeTrivialPeer} , slot_(std::move(slot)) diff --git a/src/xrpld/overlay/detail/PeerSet.cpp b/src/xrpld/overlay/detail/PeerSet.cpp index 1327d190c2..3329f67e7a 100644 --- a/src/xrpld/overlay/detail/PeerSet.cpp +++ b/src/xrpld/overlay/detail/PeerSet.cpp @@ -37,7 +37,7 @@ private: std::set peers_; }; -PeerSetImpl::PeerSetImpl(Application& app) : app_(app), journal_(app.journal("PeerSet")) +PeerSetImpl::PeerSetImpl(Application& app) : app_(app), journal_(app.getJournal("PeerSet")) { } @@ -49,7 +49,7 @@ PeerSetImpl::addPeers( { using ScoredPeer = std::pair>; - auto const& overlay = app_.overlay(); + auto const& overlay = app_.getOverlay(); std::vector pairs; pairs.reserve(overlay.size()); @@ -90,7 +90,7 @@ PeerSetImpl::sendRequest( for (auto id : peers_) { - if (auto p = app_.overlay().findPeerByShortID(id)) + if (auto p = app_.getOverlay().findPeerByShortID(id)) p->send(packet); } } @@ -127,7 +127,7 @@ make_PeerSetBuilder(Application& app) class DummyPeerSet : public PeerSet { public: - DummyPeerSet(Application& app) : j_(app.journal("DummyPeerSet")) + DummyPeerSet(Application& app) : j_(app.getJournal("DummyPeerSet")) { } diff --git a/src/xrpld/rpc/RPCCall.h b/src/xrpld/rpc/RPCCall.h index 54b73b65cf..6ab9f1d1fa 100644 --- a/src/xrpld/rpc/RPCCall.h +++ b/src/xrpld/rpc/RPCCall.h @@ -2,7 +2,7 @@ #include -#include +#include #include #include diff --git a/src/xrpld/rpc/RPCSub.h b/src/xrpld/rpc/RPCSub.h index e89f8f34e4..e96234ee02 100644 --- a/src/xrpld/rpc/RPCSub.h +++ b/src/xrpld/rpc/RPCSub.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -29,6 +30,6 @@ make_RPCSub( std::string const& strUrl, std::string const& strUsername, std::string const& strPassword, - Logs& logs); + ServiceRegistry& registry); } // namespace xrpl diff --git a/src/xrpld/app/paths/AccountCurrencies.cpp b/src/xrpld/rpc/detail/AccountCurrencies.cpp similarity index 97% rename from src/xrpld/app/paths/AccountCurrencies.cpp rename to src/xrpld/rpc/detail/AccountCurrencies.cpp index 92ba61e00e..c839b1475c 100644 --- a/src/xrpld/app/paths/AccountCurrencies.cpp +++ b/src/xrpld/rpc/detail/AccountCurrencies.cpp @@ -1,4 +1,4 @@ -#include +#include namespace xrpl { diff --git a/src/xrpld/app/paths/AccountCurrencies.h b/src/xrpld/rpc/detail/AccountCurrencies.h similarity index 89% rename from src/xrpld/app/paths/AccountCurrencies.h rename to src/xrpld/rpc/detail/AccountCurrencies.h index d8459de7f2..76c531cb9b 100644 --- a/src/xrpld/app/paths/AccountCurrencies.h +++ b/src/xrpld/rpc/detail/AccountCurrencies.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/src/xrpld/app/paths/PathRequest.cpp b/src/xrpld/rpc/detail/PathRequest.cpp similarity index 98% rename from src/xrpld/app/paths/PathRequest.cpp rename to src/xrpld/rpc/detail/PathRequest.cpp index 0e895e66d4..f02377381c 100644 --- a/src/xrpld/app/paths/PathRequest.cpp +++ b/src/xrpld/rpc/detail/PathRequest.cpp @@ -1,12 +1,11 @@ #include -#include -#include -#include -#include #include +#include +#include +#include +#include #include -#include #include #include #include @@ -24,7 +23,7 @@ PathRequest::PathRequest( Application& app, std::shared_ptr const& subscriber, int id, - PathRequests& owner, + PathRequestManager& owner, beast::Journal journal) : app_(app) , m_journal(journal) @@ -47,7 +46,7 @@ PathRequest::PathRequest( std::function const& completion, Resource::Consumer& consumer, int id, - PathRequests& owner, + PathRequestManager& owner, beast::Journal journal) : app_(app) , m_journal(journal) @@ -546,7 +545,7 @@ PathRequest::findPaths( *raSrcAccount, // --> Account sending from. ps, // --> Path set. domain, // --> Domain. - app_.logs(), + app_, &rcInput); if (!convert_all_ && !fullLiquidityPath.empty() && @@ -565,7 +564,7 @@ PathRequest::findPaths( *raSrcAccount, // --> Account sending from. ps, // --> Path set. domain, // --> Domain. - app_.logs()); + app_); if (!isTesSuccess(rc.result())) { diff --git a/src/xrpld/app/paths/PathRequest.h b/src/xrpld/rpc/detail/PathRequest.h similarity index 94% rename from src/xrpld/app/paths/PathRequest.h rename to src/xrpld/rpc/detail/PathRequest.h index 0ffc6c6e2c..db173e307b 100644 --- a/src/xrpld/app/paths/PathRequest.h +++ b/src/xrpld/rpc/detail/PathRequest.h @@ -1,11 +1,11 @@ #pragma once -#include -#include -#include +#include +#include #include #include +#include #include #include @@ -20,7 +20,7 @@ namespace xrpl { // The request issuer must maintain a strong pointer class RippleLineCache; -class PathRequests; +class PathRequestManager; // Return values from parseJson <0 = invalid, >0 = valid #define PFR_PJ_INVALID -1 @@ -43,7 +43,7 @@ public: Application& app, std::shared_ptr const& subscriber, int id, - PathRequests&, + PathRequestManager&, beast::Journal journal); // ripple_path_find semantics @@ -53,7 +53,7 @@ public: std::function const& completion, Resource::Consumer& consumer, int id, - PathRequests&, + PathRequestManager&, beast::Journal journal); ~PathRequest(); @@ -119,7 +119,7 @@ private: std::recursive_mutex mLock; - PathRequests& mOwner; + PathRequestManager& mOwner; std::weak_ptr wpSubscriber; // Who this request came from std::function fCompletion; diff --git a/src/xrpld/app/paths/PathRequests.cpp b/src/xrpld/rpc/detail/PathRequestManager.cpp similarity index 93% rename from src/xrpld/app/paths/PathRequests.cpp rename to src/xrpld/rpc/detail/PathRequestManager.cpp index 61db1e58ef..e953f1ca70 100644 --- a/src/xrpld/app/paths/PathRequests.cpp +++ b/src/xrpld/rpc/detail/PathRequestManager.cpp @@ -1,8 +1,7 @@ #include #include -#include +#include -#include #include #include #include @@ -16,7 +15,7 @@ namespace xrpl { Get the correct ledger to use. */ std::shared_ptr -PathRequests::getLineCache(std::shared_ptr const& ledger, bool authoritative) +PathRequestManager::getLineCache(std::shared_ptr const& ledger, bool authoritative) { std::lock_guard sl(mLock); @@ -37,13 +36,13 @@ PathRequests::getLineCache(std::shared_ptr const& ledger, bool a // weak_ptr, and will immediately discard it if there are no other // references. lineCache_ = lineCache = - std::make_shared(ledger, app_.journal("RippleLineCache")); + std::make_shared(ledger, app_.getJournal("RippleLineCache")); } return lineCache; } void -PathRequests::updateAll(std::shared_ptr const& inLedger) +PathRequestManager::updateAll(std::shared_ptr const& inLedger) { auto event = app_.getJobQueue().makeLoadEvent(jtPATH_FIND, "PathRequest::updateAll"); @@ -191,14 +190,14 @@ PathRequests::updateAll(std::shared_ptr const& inLedger) } bool -PathRequests::requestsPending() const +PathRequestManager::requestsPending() const { std::lock_guard sl(mLock); return !requests_.empty(); } void -PathRequests::insertPathRequest(PathRequest::pointer const& req) +PathRequestManager::insertPathRequest(PathRequest::pointer const& req) { std::lock_guard sl(mLock); @@ -216,7 +215,7 @@ PathRequests::insertPathRequest(PathRequest::pointer const& req) // Make a new-style path_find request Json::Value -PathRequests::makePathRequest( +PathRequestManager::makePathRequest( std::shared_ptr const& subscriber, std::shared_ptr const& inLedger, Json::Value const& requestJson) @@ -236,7 +235,7 @@ PathRequests::makePathRequest( // Make an old-style ripple_path_find request Json::Value -PathRequests::makeLegacyPathRequest( +PathRequestManager::makeLegacyPathRequest( PathRequest::pointer& req, std::function completion, Resource::Consumer& consumer, @@ -269,12 +268,12 @@ PathRequests::makeLegacyPathRequest( } Json::Value -PathRequests::doLegacyPathRequest( +PathRequestManager::doLegacyPathRequest( Resource::Consumer& consumer, std::shared_ptr const& inLedger, Json::Value const& request) { - auto cache = std::make_shared(inLedger, app_.journal("RippleLineCache")); + auto cache = std::make_shared(inLedger, app_.getJournal("RippleLineCache")); auto req = std::make_shared(app_, [] {}, consumer, ++mLastIdentifier, *this, mJournal); diff --git a/src/xrpld/app/paths/PathRequests.h b/src/xrpld/rpc/detail/PathRequestManager.h similarity index 94% rename from src/xrpld/app/paths/PathRequests.h rename to src/xrpld/rpc/detail/PathRequestManager.h index 98f4be9fd7..0f884de5f3 100644 --- a/src/xrpld/app/paths/PathRequests.h +++ b/src/xrpld/rpc/detail/PathRequestManager.h @@ -1,8 +1,8 @@ #pragma once #include -#include -#include +#include +#include #include #include @@ -10,11 +10,11 @@ namespace xrpl { -class PathRequests +class PathRequestManager { public: /** A collection of all PathRequest instances. */ - PathRequests( + PathRequestManager( Application& app, beast::Journal journal, beast::insight::Collector::ptr const& collector) diff --git a/src/xrpld/app/paths/Pathfinder.cpp b/src/xrpld/rpc/detail/Pathfinder.cpp similarity index 99% rename from src/xrpld/app/paths/Pathfinder.cpp rename to src/xrpld/rpc/detail/Pathfinder.cpp index 10d69fc040..176c7f9529 100644 --- a/src/xrpld/app/paths/Pathfinder.cpp +++ b/src/xrpld/rpc/detail/Pathfinder.cpp @@ -1,9 +1,8 @@ #include -#include -#include -#include +#include +#include +#include -#include #include #include #include @@ -167,7 +166,7 @@ Pathfinder::Pathfinder( , mLedger(cache->getLedger()) , mRLCache(cache) , app_(app) - , j_(app.journal("Pathfinder")) + , j_(app.getJournal("Pathfinder")) { XRPL_ASSERT( !uSrcIssuer || isXRP(uSrcCurrency) == isXRP(uSrcIssuer.value()), @@ -345,7 +344,7 @@ Pathfinder::getPathLiquidity( mSrcAccount, pathSet, mDomain, - app_.logs(), + app_, &rcInput); // If we can't get even the minimum liquidity requested, we're done. if (!isTesSuccess(rc.result())) @@ -366,7 +365,7 @@ Pathfinder::getPathLiquidity( mSrcAccount, pathSet, mDomain, - app_.logs(), + app_, &rcInput); // If we found further liquidity, add it into the result. @@ -404,7 +403,7 @@ Pathfinder::computePathRanks(int maxPaths, std::function const& cont mSrcAccount, STPathSet(), mDomain, - app_.logs(), + app_, &rcInput); if (rc.result() == tesSUCCESS) diff --git a/src/xrpld/app/paths/Pathfinder.h b/src/xrpld/rpc/detail/Pathfinder.h similarity index 98% rename from src/xrpld/app/paths/Pathfinder.h rename to src/xrpld/rpc/detail/Pathfinder.h index 03f2d6f038..5eaafd3370 100644 --- a/src/xrpld/app/paths/Pathfinder.h +++ b/src/xrpld/rpc/detail/Pathfinder.h @@ -1,10 +1,10 @@ #pragma once -#include -#include +#include #include #include +#include #include #include diff --git a/src/xrpld/app/paths/detail/PathfinderUtils.h b/src/xrpld/rpc/detail/PathfinderUtils.h similarity index 100% rename from src/xrpld/app/paths/detail/PathfinderUtils.h rename to src/xrpld/rpc/detail/PathfinderUtils.h diff --git a/src/xrpld/rpc/detail/RPCHelpers.cpp b/src/xrpld/rpc/detail/RPCHelpers.cpp index dd363c6d76..b4a0685bd6 100644 --- a/src/xrpld/rpc/detail/RPCHelpers.cpp +++ b/src/xrpld/rpc/detail/RPCHelpers.cpp @@ -1,8 +1,8 @@ #include -#include #include #include #include +#include #include #include diff --git a/src/xrpld/rpc/detail/RPCLedgerHelpers.cpp b/src/xrpld/rpc/detail/RPCLedgerHelpers.cpp index 0136d8af18..2216affa6f 100644 --- a/src/xrpld/rpc/detail/RPCLedgerHelpers.cpp +++ b/src/xrpld/rpc/detail/RPCLedgerHelpers.cpp @@ -411,7 +411,7 @@ getOrAcquireLedger(RPC::JsonContext const& context) if (ledgerIndex <= 0) return Unexpected(RPC::make_param_error("Ledger index too small")); - auto const j = context.app.journal("RPCHandler"); + auto const j = context.app.getJournal("RPCHandler"); // Try to get the hash of the desired ledger from the validated // ledger auto neededHash = hashOfSeq(*ledger, ledgerIndex, j); diff --git a/src/xrpld/rpc/detail/RPCLedgerHelpers.h b/src/xrpld/rpc/detail/RPCLedgerHelpers.h index c60b7bc6b2..6a04ab41d6 100644 --- a/src/xrpld/rpc/detail/RPCLedgerHelpers.h +++ b/src/xrpld/rpc/detail/RPCLedgerHelpers.h @@ -1,11 +1,11 @@ #pragma once -#include #include #include #include #include +#include #include #include #include diff --git a/src/xrpld/rpc/detail/RPCSub.cpp b/src/xrpld/rpc/detail/RPCSub.cpp index 233981001a..3aa5f75f6a 100644 --- a/src/xrpld/rpc/detail/RPCSub.cpp +++ b/src/xrpld/rpc/detail/RPCSub.cpp @@ -21,15 +21,15 @@ public: std::string const& strUrl, std::string const& strUsername, std::string const& strPassword, - Logs& logs) + ServiceRegistry& registry) : RPCSub(source) , m_io_context(io_context) , m_jobQueue(jobQueue) , mUrl(strUrl) , mUsername(strUsername) , mPassword(strPassword) - , j_(logs.journal("RPCSub")) - , logs_(logs) + , j_(registry.getJournal("RPCSub")) + , logs_(registry.getLogs()) { parsedURL pUrl; @@ -199,7 +199,7 @@ make_RPCSub( std::string const& strUrl, std::string const& strUsername, std::string const& strPassword, - Logs& logs) + ServiceRegistry& registry) { return std::make_shared( std::ref(source), @@ -208,7 +208,7 @@ make_RPCSub( strUrl, strUsername, strPassword, - logs); + registry); } } // namespace xrpl diff --git a/src/xrpld/app/paths/RippleLineCache.cpp b/src/xrpld/rpc/detail/RippleLineCache.cpp similarity index 98% rename from src/xrpld/app/paths/RippleLineCache.cpp rename to src/xrpld/rpc/detail/RippleLineCache.cpp index c45c20aca8..d6ed7b1478 100644 --- a/src/xrpld/app/paths/RippleLineCache.cpp +++ b/src/xrpld/rpc/detail/RippleLineCache.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include namespace xrpl { diff --git a/src/xrpld/app/paths/RippleLineCache.h b/src/xrpld/rpc/detail/RippleLineCache.h similarity index 97% rename from src/xrpld/app/paths/RippleLineCache.h rename to src/xrpld/rpc/detail/RippleLineCache.h index c4ddad6c81..65607f2d25 100644 --- a/src/xrpld/app/paths/RippleLineCache.h +++ b/src/xrpld/rpc/detail/RippleLineCache.h @@ -1,10 +1,10 @@ #pragma once -#include -#include +#include #include #include +#include #include #include diff --git a/src/xrpld/rpc/detail/ServerHandler.cpp b/src/xrpld/rpc/detail/ServerHandler.cpp index 917a9b7609..64c81ccc0a 100644 --- a/src/xrpld/rpc/detail/ServerHandler.cpp +++ b/src/xrpld/rpc/detail/ServerHandler.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -98,9 +97,9 @@ ServerHandler::ServerHandler( CollectorManager& cm) : app_(app) , m_resourceManager(resourceManager) - , m_journal(app_.journal("Server")) + , m_journal(app_.getJournal("Server")) , m_networkOPs(networkOPs) - , m_server(make_Server(*this, io_context, app_.journal("Server"))) + , m_server(make_Server(*this, io_context, app_.getJournal("Server"))) , m_jobQueue(jobQueue) { auto const& group(cm.group("rpc")); @@ -218,7 +217,7 @@ ServerHandler::onHandoff( } if (bundle && p.count("peer") > 0) - return app_.overlay().onHandoff(std::move(bundle), std::move(request), remote_address); + return app_.getOverlay().onHandoff(std::move(bundle), std::move(request), remote_address); if (is_ws && isStatusRequest(request)) return statusResponse(request); @@ -270,7 +269,7 @@ ServerHandler::onRequest(Session& session) // Make sure RPC is enabled on the port if (session.port().protocol.count("http") == 0 && session.port().protocol.count("https") == 0) { - HTTPReply(403, "Forbidden", makeOutput(session), app_.journal("RPC")); + HTTPReply(403, "Forbidden", makeOutput(session), app_.getJournal("RPC")); session.close(true); return; } @@ -278,7 +277,7 @@ ServerHandler::onRequest(Session& session) // Check user/password authorization if (!authorized(session.port(), build_map(session.request()))) { - HTTPReply(403, "Forbidden", makeOutput(session), app_.journal("RPC")); + HTTPReply(403, "Forbidden", makeOutput(session), app_.getJournal("RPC")); session.close(true); return; } @@ -291,7 +290,7 @@ ServerHandler::onRequest(Session& session) if (postResult == nullptr) { // The coroutine was rejected, probably because we're shutting down. - HTTPReply(503, "Service Unavailable", makeOutput(*detachedSession), app_.journal("RPC")); + HTTPReply(503, "Service Unavailable", makeOutput(*detachedSession), app_.getJournal("RPC")); detachedSession->close(true); return; } @@ -440,7 +439,7 @@ ServerHandler::processSession( else { RPC::JsonContext context{ - {app_.journal("RPCHandler"), + {app_.getJournal("RPCHandler"), app_, loadType, app_.getOPs(), @@ -574,7 +573,7 @@ ServerHandler::processRequest( std::string_view forwardedFor, std::string_view user) { - auto rpcJ = app_.journal("RPC"); + auto rpcJ = app_.getJournal("RPC"); Json::Value jsonOrig; { diff --git a/src/xrpld/rpc/detail/TransactionSign.cpp b/src/xrpld/rpc/detail/TransactionSign.cpp index 73385f62ef..1fb6fc291f 100644 --- a/src/xrpld/rpc/detail/TransactionSign.cpp +++ b/src/xrpld/rpc/detail/TransactionSign.cpp @@ -3,12 +3,11 @@ #include #include #include -#include #include +#include #include #include -#include #include #include #include @@ -258,10 +257,10 @@ checkPayment( STPathSet result; - if (auto ledger = app.openLedger().current()) + if (auto ledger = app.getOpenLedger().current()) { Pathfinder pf( - std::make_shared(ledger, app.journal("RippleLineCache")), + std::make_shared(ledger, app.getJournal("RippleLineCache")), srcAddressID, *dstAccountID, sendMax.issue().currency, @@ -280,7 +279,7 @@ checkPayment( } } - auto j = app.journal("RPCHandler"); + auto j = app.getJournal("RPCHandler"); JLOG(j.debug()) << "transactionSign: build_path: " << result.getJson(JsonOptions::none); if (!result.empty()) @@ -402,7 +401,7 @@ transactionPreProcessImpl( std::chrono::seconds validatedLedgerAge, Application& app) { - auto j = app.journal("RPCHandler"); + auto j = app.getJournal("RPCHandler"); Json::Value jvResult; std::optional> keyPair = keypairForSignature(params, jvResult); @@ -461,7 +460,7 @@ transactionPreProcessImpl( std::shared_ptr sle; if (verify) - sle = app.openLedger().current()->read(keylet::account(srcAddressID)); + sle = app.getOpenLedger().current()->read(keylet::account(srcAddressID)); if (verify && !sle) { @@ -565,7 +564,7 @@ transactionPreProcessImpl( auto delegatedAddressID = *ptrDelegatedAddressID; auto delegatedSle = - app.openLedger().current()->read(keylet::account(delegatedAddressID)); + app.getOpenLedger().current()->read(keylet::account(delegatedAddressID)); if (!delegatedSle) return rpcError(rpcDELEGATE_ACT_NOT_FOUND); @@ -765,7 +764,7 @@ transactionFormatResultImpl(Transaction::pointer tpTrans, unsigned apiVersion) [[nodiscard]] static XRPAmount getTxFee(Application const& app, Config const& config, Json::Value tx) { - auto const& ledger = app.openLedger().current(); + auto const& ledger = app.getOpenLedger().current(); // autofilling only needed in this function so that the `STParsedJSONObject` // parsing works properly it should not be modifying the actual `tx` object if (!tx.isMember(jss::Fee)) @@ -827,7 +826,7 @@ getTxFee(Application const& app, Config const& config, Json::Value tx) if (!passesLocalChecks(stTx, reason)) return config.FEES.reference_fee; - return calculateBaseFee(*app.openLedger().current(), stTx); + return calculateBaseFee(*app.getOpenLedger().current(), stTx); } catch (std::exception& e) { @@ -848,7 +847,7 @@ getCurrentNetworkFee( { XRPAmount const feeDefault = getTxFee(app, config, tx); - auto ledger = app.openLedger().current(); + auto ledger = app.getOpenLedger().current(); // Administrative and identified endpoints are exempt from local fees. XRPAmount const loadFee = scaleFeeLoad(feeDefault, feeTrack, ledger->fees(), isUnlimited(role)); XRPAmount fee = loadFee; @@ -950,7 +949,7 @@ transactionSign( { using namespace detail; - auto j = app.journal("RPCHandler"); + auto j = app.getJournal("RPCHandler"); JLOG(j.debug()) << "transactionSign: " << jvRequest; // Add and amend fields based on the transaction type. @@ -961,7 +960,7 @@ transactionSign( if (!preprocResult.second) return preprocResult.first; - std::shared_ptr ledger = app.openLedger().current(); + std::shared_ptr ledger = app.getOpenLedger().current(); // Make sure the STTx makes a legitimate Transaction. std::pair txn = transactionConstructImpl(preprocResult.second, ledger->rules(), app); @@ -985,8 +984,8 @@ transactionSubmit( { using namespace detail; - auto const& ledger = app.openLedger().current(); - auto j = app.journal("RPCHandler"); + auto const& ledger = app.getOpenLedger().current(); + auto j = app.getJournal("RPCHandler"); JLOG(j.debug()) << "transactionSubmit: " << jvRequest; // Add and amend fields based on the transaction type. @@ -1107,8 +1106,8 @@ transactionSignFor( std::chrono::seconds validatedLedgerAge, Application& app) { - auto const& ledger = app.openLedger().current(); - auto j = app.journal("RPCHandler"); + auto const& ledger = app.getOpenLedger().current(); + auto j = app.getJournal("RPCHandler"); JLOG(j.debug()) << "transactionSignFor: " << jvRequest; // Verify presence of the signer's account field. @@ -1219,8 +1218,8 @@ transactionSubmitMultiSigned( Application& app, ProcessTransactionFn const& processTransaction) { - auto const& ledger = app.openLedger().current(); - auto j = app.journal("RPCHandler"); + auto const& ledger = app.getOpenLedger().current(); + auto j = app.getJournal("RPCHandler"); JLOG(j.debug()) << "transactionSubmitMultiSigned: " << jvRequest; // When multi-signing, the "Sequence" and "SigningPubKey" fields must diff --git a/src/xrpld/app/paths/TrustLine.cpp b/src/xrpld/rpc/detail/TrustLine.cpp similarity index 98% rename from src/xrpld/app/paths/TrustLine.cpp rename to src/xrpld/rpc/detail/TrustLine.cpp index 963e1402be..c2bc152448 100644 --- a/src/xrpld/app/paths/TrustLine.cpp +++ b/src/xrpld/rpc/detail/TrustLine.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/xrpld/app/paths/TrustLine.h b/src/xrpld/rpc/detail/TrustLine.h similarity index 100% rename from src/xrpld/app/paths/TrustLine.h rename to src/xrpld/rpc/detail/TrustLine.h diff --git a/src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp b/src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp index 2ec1e20875..fe74c915f5 100644 --- a/src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp +++ b/src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp @@ -1,6 +1,6 @@ -#include #include #include +#include #include #include diff --git a/src/xrpld/rpc/handlers/AccountLines.cpp b/src/xrpld/rpc/handlers/AccountLines.cpp index b3b93c0eb1..396a09b082 100644 --- a/src/xrpld/rpc/handlers/AccountLines.cpp +++ b/src/xrpld/rpc/handlers/AccountLines.cpp @@ -1,7 +1,7 @@ -#include #include #include #include +#include #include #include diff --git a/src/xrpld/rpc/handlers/Connect.cpp b/src/xrpld/rpc/handlers/Connect.cpp index 292cd50cbb..fe3183484e 100644 --- a/src/xrpld/rpc/handlers/Connect.cpp +++ b/src/xrpld/rpc/handlers/Connect.cpp @@ -48,7 +48,7 @@ doConnect(RPC::JsonContext& context) auto ip = beast::IP::Endpoint::from_string(ip_str); if (!is_unspecified(ip)) - context.app.overlay().connect(ip.at_port(iPort)); + context.app.getOverlay().connect(ip.at_port(iPort)); return RPC::makeObjectValue( "attempting connection to IP:" + ip_str + " port: " + std::to_string(iPort)); diff --git a/src/xrpld/rpc/handlers/DoManifest.cpp b/src/xrpld/rpc/handlers/DoManifest.cpp index 5928947e21..ba3461033f 100644 --- a/src/xrpld/rpc/handlers/DoManifest.cpp +++ b/src/xrpld/rpc/handlers/DoManifest.cpp @@ -32,25 +32,25 @@ doManifest(RPC::JsonContext& context) // first attempt to use params as ephemeral key, // if this lookup succeeds master key will be returned, // else an unseated optional is returned - auto const mk = context.app.validatorManifests().getMasterKey(*pk); + auto const mk = context.app.getValidatorManifests().getMasterKey(*pk); - auto const ek = context.app.validatorManifests().getSigningKey(mk); + auto const ek = context.app.getValidatorManifests().getSigningKey(mk); // if ephemeral key not found, we don't have specified manifest if (!ek) return ret; - if (auto const manifest = context.app.validatorManifests().getManifest(mk)) + if (auto const manifest = context.app.getValidatorManifests().getManifest(mk)) ret[jss::manifest] = base64_encode(*manifest); Json::Value details; details[jss::master_key] = toBase58(TokenType::NodePublic, mk); details[jss::ephemeral_key] = toBase58(TokenType::NodePublic, *ek); - if (auto const seq = context.app.validatorManifests().getSequence(mk)) + if (auto const seq = context.app.getValidatorManifests().getSequence(mk)) details[jss::seq] = *seq; - if (auto const domain = context.app.validatorManifests().getDomain(mk)) + if (auto const domain = context.app.getValidatorManifests().getDomain(mk)) details[jss::domain] = *domain; ret[jss::details] = details; diff --git a/src/xrpld/rpc/handlers/GatewayBalances.cpp b/src/xrpld/rpc/handlers/GatewayBalances.cpp index f7acbc77e6..914725de60 100644 --- a/src/xrpld/rpc/handlers/GatewayBalances.cpp +++ b/src/xrpld/rpc/handlers/GatewayBalances.cpp @@ -1,7 +1,7 @@ #include -#include #include #include +#include #include #include diff --git a/src/xrpld/rpc/handlers/GetCounts.cpp b/src/xrpld/rpc/handlers/GetCounts.cpp index f5f953046d..09a952e114 100644 --- a/src/xrpld/rpc/handlers/GetCounts.cpp +++ b/src/xrpld/rpc/handlers/GetCounts.cpp @@ -80,7 +80,7 @@ getCountsJson(Application& app, int minObjectCount) ret[jss::write_load] = app.getNodeStore().getWriteLoad(); ret[jss::historical_perminute] = static_cast(app.getInboundLedgers().fetchRate()); - ret[jss::SLE_hit_rate] = app.cachedSLEs().rate(); + ret[jss::SLE_hit_rate] = app.getCachedSLEs().rate(); ret[jss::ledger_hit_rate] = app.getLedgerMaster().getCacheHitRate(); ret[jss::AL_size] = Json::UInt(app.getAcceptedLedgerCache().size()); ret[jss::AL_hit_rate] = app.getAcceptedLedgerCache().getHitRate(); diff --git a/src/xrpld/rpc/handlers/LogLevel.cpp b/src/xrpld/rpc/handlers/LogLevel.cpp index 2bc1beb7d4..a932dfb198 100644 --- a/src/xrpld/rpc/handlers/LogLevel.cpp +++ b/src/xrpld/rpc/handlers/LogLevel.cpp @@ -21,9 +21,9 @@ doLogLevel(RPC::JsonContext& context) Json::Value ret(Json::objectValue); Json::Value lev(Json::objectValue); - lev[jss::base] = Logs::toString(Logs::fromSeverity(context.app.logs().threshold())); + lev[jss::base] = Logs::toString(Logs::fromSeverity(context.app.getLogs().threshold())); std::vector> logTable( - context.app.logs().partition_severities()); + context.app.getLogs().partition_severities()); for (auto const& [k, v] : logTable) lev[k] = v; @@ -41,7 +41,7 @@ doLogLevel(RPC::JsonContext& context) if (!context.params.isMember(jss::partition)) { // set base log threshold - context.app.logs().threshold(severity); + context.app.getLogs().threshold(severity); return Json::objectValue; } @@ -53,11 +53,11 @@ doLogLevel(RPC::JsonContext& context) if (boost::iequals(partition, "base")) { - context.app.logs().threshold(severity); + context.app.getLogs().threshold(severity); } else { - context.app.logs().get(partition).threshold(severity); + context.app.getLogs().get(partition).threshold(severity); } return Json::objectValue; diff --git a/src/xrpld/rpc/handlers/LogRotate.cpp b/src/xrpld/rpc/handlers/LogRotate.cpp index 3d52dc6538..3cc7f35381 100644 --- a/src/xrpld/rpc/handlers/LogRotate.cpp +++ b/src/xrpld/rpc/handlers/LogRotate.cpp @@ -10,7 +10,7 @@ Json::Value doLogRotate(RPC::JsonContext& context) { context.app.getPerfLog().rotate(); - return RPC::makeObjectValue(context.app.logs().rotate()); + return RPC::makeObjectValue(context.app.getLogs().rotate()); } } // namespace xrpl diff --git a/src/xrpld/rpc/handlers/NoRippleCheck.cpp b/src/xrpld/rpc/handlers/NoRippleCheck.cpp index a0f797214d..7b780f3b16 100644 --- a/src/xrpld/rpc/handlers/NoRippleCheck.cpp +++ b/src/xrpld/rpc/handlers/NoRippleCheck.cpp @@ -1,8 +1,8 @@ #include -#include #include #include #include +#include #include #include diff --git a/src/xrpld/rpc/handlers/PathFind.cpp b/src/xrpld/rpc/handlers/PathFind.cpp index 357cd9b91e..1b180167ea 100644 --- a/src/xrpld/rpc/handlers/PathFind.cpp +++ b/src/xrpld/rpc/handlers/PathFind.cpp @@ -1,7 +1,7 @@ #include #include -#include #include +#include #include #include @@ -34,7 +34,7 @@ doPathFind(RPC::JsonContext& context) { context.loadType = Resource::feeHeavyBurdenRPC; context.infoSub->clearRequest(); - return context.app.getPathRequests().makePathRequest( + return context.app.getPathRequestManager().makePathRequest( context.infoSub, lpLedger, context.params); } diff --git a/src/xrpld/rpc/handlers/Peers.cpp b/src/xrpld/rpc/handlers/Peers.cpp index b21efc01fb..ddcb674b33 100644 --- a/src/xrpld/rpc/handlers/Peers.cpp +++ b/src/xrpld/rpc/handlers/Peers.cpp @@ -15,7 +15,7 @@ doPeers(RPC::JsonContext& context) { Json::Value jvResult(Json::objectValue); - jvResult[jss::peers] = context.app.overlay().json(); + jvResult[jss::peers] = context.app.getOverlay().json(); // Legacy support if (context.apiVersion == 1) @@ -38,13 +38,13 @@ doPeers(RPC::JsonContext& context) } } - auto const now = context.app.timeKeeper().now(); + auto const now = context.app.getTimeKeeper().now(); auto const self = context.app.nodeIdentity().first; Json::Value& cluster = (jvResult[jss::cluster] = Json::objectValue); std::uint32_t ref = context.app.getFeeTrack().getLoadBase(); - context.app.cluster().for_each([&cluster, now, ref, &self](ClusterNode const& node) { + context.app.getCluster().for_each([&cluster, now, ref, &self](ClusterNode const& node) { if (node.identity() == self) return; diff --git a/src/xrpld/rpc/handlers/Reservations.cpp b/src/xrpld/rpc/handlers/Reservations.cpp index 5d9c23d46e..fb874247ad 100644 --- a/src/xrpld/rpc/handlers/Reservations.cpp +++ b/src/xrpld/rpc/handlers/Reservations.cpp @@ -56,7 +56,7 @@ doPeerReservationsAdd(RPC::JsonContext& context) PublicKey const& nodeId = *optPk; auto const previous = - context.app.peerReservations().insert_or_assign(PeerReservation{nodeId, desc}); + context.app.getPeerReservations().insert_or_assign(PeerReservation{nodeId, desc}); Json::Value result{Json::objectValue}; if (previous) @@ -83,7 +83,7 @@ doPeerReservationsDel(RPC::JsonContext& context) return rpcError(rpcPUBLIC_MALFORMED); PublicKey const& nodeId = *optPk; - auto const previous = context.app.peerReservations().erase(nodeId); + auto const previous = context.app.getPeerReservations().erase(nodeId); Json::Value result{Json::objectValue}; if (previous) @@ -96,8 +96,8 @@ doPeerReservationsDel(RPC::JsonContext& context) Json::Value doPeerReservationsList(RPC::JsonContext& context) { - auto const& reservations = context.app.peerReservations().list(); - // Enumerate the reservations in context.app.peerReservations() + auto const& reservations = context.app.getPeerReservations().list(); + // Enumerate the reservations in context.app.getPeerReservations() // as a Json::Value. Json::Value result{Json::objectValue}; Json::Value& jaReservations = result[jss::reservations] = Json::arrayValue; diff --git a/src/xrpld/rpc/handlers/RipplePathFind.cpp b/src/xrpld/rpc/handlers/RipplePathFind.cpp index 5f73165287..cc695908fb 100644 --- a/src/xrpld/rpc/handlers/RipplePathFind.cpp +++ b/src/xrpld/rpc/handlers/RipplePathFind.cpp @@ -1,7 +1,7 @@ #include -#include #include #include +#include #include #include @@ -105,7 +105,7 @@ doRipplePathFind(RPC::JsonContext& context) // JobQueue before letting the thread continue. // // May 2017 - jvResult = context.app.getPathRequests().makeLegacyPathRequest( + jvResult = context.app.getPathRequestManager().makeLegacyPathRequest( request, [&context]() { // Copying the shared_ptr keeps the coroutine alive up @@ -144,7 +144,7 @@ doRipplePathFind(RPC::JsonContext& context) if (!lpf.isOk()) return rpcError(rpcTOO_BUSY); - auto result = context.app.getPathRequests().doLegacyPathRequest( + auto result = context.app.getPathRequestManager().doLegacyPathRequest( context.consumer, lpLedger, context.params); for (auto& fieldName : jvResult.getMemberNames()) diff --git a/src/xrpld/rpc/handlers/Simulate.cpp b/src/xrpld/rpc/handlers/Simulate.cpp index 1d46f72425..c1d6d7f334 100644 --- a/src/xrpld/rpc/handlers/Simulate.cpp +++ b/src/xrpld/rpc/handlers/Simulate.cpp @@ -39,10 +39,10 @@ getAutofillSequence(Json::Value const& tx_json, RPC::JsonContext& context) RPC::make_error(rpcSRC_ACT_MALFORMED, RPC::invalid_field_message("tx.Account"))); } std::shared_ptr const sle = - context.app.openLedger().current()->read(keylet::account(*srcAddressID)); + context.app.getOpenLedger().current()->read(keylet::account(*srcAddressID)); if (!hasTicketSeq && !sle) { - JLOG(context.app.journal("Simulate").debug()) + JLOG(context.app.getJournal("Simulate").debug()) << "Failed to find source account " << "in current ledger: " << toBase58(*srcAddressID); @@ -210,7 +210,7 @@ simulateTxn(RPC::JsonContext& context, std::shared_ptr transaction) { Json::Value jvResult; // Process the transaction - OpenView view = *context.app.openLedger().current(); + OpenView view = *context.app.getOpenLedger().current(); auto const result = context.app.getTxQ().apply( context.app, view, transaction->getSTransaction(), tapDRY_RUN, context.j); diff --git a/src/xrpld/rpc/handlers/Subscribe.cpp b/src/xrpld/rpc/handlers/Subscribe.cpp index 6e8d9dbaa3..fc5238b37b 100644 --- a/src/xrpld/rpc/handlers/Subscribe.cpp +++ b/src/xrpld/rpc/handlers/Subscribe.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -62,7 +61,7 @@ doSubscribe(RPC::JsonContext& context) strUrl, strUsername, strPassword, - context.app.logs()); + context.app); ispSub = context.netOps.addRpcSub(strUrl, std::dynamic_pointer_cast(rspSub)); } diff --git a/src/xrpld/rpc/handlers/TxReduceRelay.cpp b/src/xrpld/rpc/handlers/TxReduceRelay.cpp index d269ef448e..f24f0862ef 100644 --- a/src/xrpld/rpc/handlers/TxReduceRelay.cpp +++ b/src/xrpld/rpc/handlers/TxReduceRelay.cpp @@ -9,7 +9,7 @@ namespace xrpl { Json::Value doTxReduceRelay(RPC::JsonContext& context) { - return context.app.overlay().txMetrics(); + return context.app.getOverlay().txMetrics(); } } // namespace xrpl diff --git a/src/xrpld/rpc/handlers/UnlList.cpp b/src/xrpld/rpc/handlers/UnlList.cpp index 20fb692fbb..31f41b4a33 100644 --- a/src/xrpld/rpc/handlers/UnlList.cpp +++ b/src/xrpld/rpc/handlers/UnlList.cpp @@ -12,7 +12,7 @@ doUnlList(RPC::JsonContext& context) { Json::Value obj(Json::objectValue); - context.app.validators().for_each_listed( + context.app.getValidators().for_each_listed( [&unl = obj[jss::unl]](PublicKey const& publicKey, bool trusted) { Json::Value node(Json::objectValue); diff --git a/src/xrpld/rpc/handlers/ValidatorInfo.cpp b/src/xrpld/rpc/handlers/ValidatorInfo.cpp index 4b6663b68a..aec9dba4b4 100644 --- a/src/xrpld/rpc/handlers/ValidatorInfo.cpp +++ b/src/xrpld/rpc/handlers/ValidatorInfo.cpp @@ -21,7 +21,7 @@ doValidatorInfo(RPC::JsonContext& context) Json::Value ret; // assume validationPK is ephemeral key, get master key - auto const mk = context.app.validatorManifests().getMasterKey(*validationPK); + auto const mk = context.app.getValidatorManifests().getMasterKey(*validationPK); ret[jss::master_key] = toBase58(TokenType::NodePublic, mk); // validationPK is master key, this implies that there is no ephemeral @@ -31,13 +31,13 @@ doValidatorInfo(RPC::JsonContext& context) ret[jss::ephemeral_key] = toBase58(TokenType::NodePublic, *validationPK); - if (auto const manifest = context.app.validatorManifests().getManifest(mk)) + if (auto const manifest = context.app.getValidatorManifests().getManifest(mk)) ret[jss::manifest] = base64_encode(*manifest); - if (auto const seq = context.app.validatorManifests().getSequence(mk)) + if (auto const seq = context.app.getValidatorManifests().getSequence(mk)) ret[jss::seq] = *seq; - if (auto const domain = context.app.validatorManifests().getDomain(mk)) + if (auto const domain = context.app.getValidatorManifests().getDomain(mk)) ret[jss::domain] = *domain; return ret; diff --git a/src/xrpld/rpc/handlers/ValidatorListSites.cpp b/src/xrpld/rpc/handlers/ValidatorListSites.cpp index 7acaa27168..36e2064387 100644 --- a/src/xrpld/rpc/handlers/ValidatorListSites.cpp +++ b/src/xrpld/rpc/handlers/ValidatorListSites.cpp @@ -9,7 +9,7 @@ namespace xrpl { Json::Value doValidatorListSites(RPC::JsonContext& context) { - return context.app.validatorSites().getJson(); + return context.app.getValidatorSites().getJson(); } } // namespace xrpl diff --git a/src/xrpld/rpc/handlers/Validators.cpp b/src/xrpld/rpc/handlers/Validators.cpp index a83a6fe4b0..95e6de9e68 100644 --- a/src/xrpld/rpc/handlers/Validators.cpp +++ b/src/xrpld/rpc/handlers/Validators.cpp @@ -9,7 +9,7 @@ namespace xrpl { Json::Value doValidators(RPC::JsonContext& context) { - return context.app.validators().getJson(); + return context.app.getValidators().getJson(); } } // namespace xrpl diff --git a/src/xrpld/shamap/NodeFamily.cpp b/src/xrpld/shamap/NodeFamily.cpp index a0821ea202..ec5e9eb1b2 100644 --- a/src/xrpld/shamap/NodeFamily.cpp +++ b/src/xrpld/shamap/NodeFamily.cpp @@ -9,12 +9,12 @@ namespace xrpl { NodeFamily::NodeFamily(Application& app, CollectorManager& cm) : app_(app) , db_(app.getNodeStore()) - , j_(app.journal("NodeFamily")) + , j_(app.getJournal("NodeFamily")) , fbCache_( std::make_shared( "Node family full below cache", stopwatch(), - app.journal("NodeFamilyFulLBelowCache"), + app.getJournal("NodeFamilyFulLBelowCache"), cm.collector(), fullBelowTargetSize, fullBelowExpiration))