diff --git a/.clang-tidy b/.clang-tidy index d8a7cb1b6f..36b59f43e3 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,4 +1,6 @@ --- +# This entire group of checks was applied to all cpp files but not all header files. +# --- Checks: "-*, bugprone-argument-comment, bugprone-assert-side-effect, @@ -8,26 +10,26 @@ Checks: "-*, bugprone-chained-comparison, bugprone-compare-pointer-to-member-virtual-function, bugprone-copy-constructor-init, - bugprone-crtp-constructor-accessibility, + # bugprone-crtp-constructor-accessibility, # has issues bugprone-dangling-handle, bugprone-dynamic-static-initializers, - bugprone-empty-catch, + # bugprone-empty-catch, # has issues bugprone-fold-init-type, - bugprone-forward-declaration-namespace, - bugprone-inaccurate-erase, - bugprone-inc-dec-in-conditions, - bugprone-incorrect-enable-if, - bugprone-incorrect-roundings, - bugprone-infinite-loop, - bugprone-integer-division, + # bugprone-forward-declaration-namespace, # has issues + # bugprone-inaccurate-erase, + # bugprone-inc-dec-in-conditions, + # bugprone-incorrect-enable-if, + # bugprone-incorrect-roundings, + # bugprone-infinite-loop, + # bugprone-integer-division, bugprone-lambda-function-name, - bugprone-macro-parentheses, + # bugprone-macro-parentheses, # has issues bugprone-macro-repeated-side-effects, bugprone-misplaced-operator-in-strlen-in-alloc, bugprone-misplaced-pointer-arithmetic-in-alloc, bugprone-misplaced-widening-cast, bugprone-move-forwarding-reference, - bugprone-multi-level-implicit-pointer-conversion, + # bugprone-multi-level-implicit-pointer-conversion, # has issues bugprone-multiple-new-in-one-expression, bugprone-multiple-statement-macro, bugprone-no-escape, @@ -37,13 +39,13 @@ Checks: "-*, bugprone-pointer-arithmetic-on-polymorphic-object, bugprone-posix-return, bugprone-redundant-branch-condition, - bugprone-reserved-identifier, - bugprone-return-const-ref-from-parameter, + # bugprone-reserved-identifier, # has issues + # bugprone-return-const-ref-from-parameter, # has issues bugprone-shared-ptr-array-mismatch, bugprone-signal-handler, bugprone-signed-char-misuse, bugprone-sizeof-container, - bugprone-sizeof-expression, + # bugprone-sizeof-expression, # has issues bugprone-spuriously-wake-up-functions, bugprone-standalone-empty, bugprone-string-constructor, @@ -60,7 +62,7 @@ Checks: "-*, bugprone-suspicious-string-compare, bugprone-suspicious-stringview-data-usage, bugprone-swapped-arguments, - bugprone-switch-missing-default-case, + # bugprone-switch-missing-default-case, # has issues bugprone-terminating-continue, bugprone-throw-keyword-missing, bugprone-too-small-loop-variable, @@ -71,70 +73,75 @@ Checks: "-*, bugprone-unhandled-self-assignment, bugprone-unique-ptr-array-mismatch, bugprone-unsafe-functions, - bugprone-use-after-move, + # bugprone-use-after-move, # has issues bugprone-unused-raii, bugprone-unused-return-value, bugprone-unused-local-non-trivial-variable, bugprone-virtual-near-miss, - cppcoreguidelines-init-variables, - cppcoreguidelines-misleading-capture-default-by-value, + # cppcoreguidelines-init-variables, # has issues + # cppcoreguidelines-misleading-capture-default-by-value, # has issues cppcoreguidelines-no-suspend-with-lock, - cppcoreguidelines-pro-type-member-init, + # cppcoreguidelines-pro-type-member-init, # has issues cppcoreguidelines-pro-type-static-cast-downcast, - cppcoreguidelines-rvalue-reference-param-not-moved, - cppcoreguidelines-use-default-member-init, - cppcoreguidelines-virtual-class-destructor, + # cppcoreguidelines-rvalue-reference-param-not-moved, # has issues + # cppcoreguidelines-use-default-member-init, # has issues + # cppcoreguidelines-virtual-class-destructor, # has issues hicpp-ignored-remove-result, - misc-definitions-in-headers, + # misc-definitions-in-headers, # has issues misc-header-include-cycle, misc-misplaced-const, misc-static-assert, - misc-throw-by-value-catch-by-reference, + # misc-throw-by-value-catch-by-reference, # has issues misc-unused-alias-decls, misc-unused-using-decls, modernize-deprecated-headers, modernize-make-shared, modernize-make-unique, + performance-faster-string-find, + performance-for-range-copy, performance-implicit-conversion-in-loop, + performance-inefficient-vector-operation, + performance-move-const-arg, performance-move-constructor-init, + performance-no-automatic-move, performance-trivially-destructible, - readability-avoid-nested-conditional-operator, - readability-avoid-return-with-void-value, - readability-braces-around-statements, - readability-const-return-type, - readability-container-contains, - readability-container-size-empty, + # readability-avoid-nested-conditional-operator, # has issues + # readability-avoid-return-with-void-value, # has issues + # readability-braces-around-statements, # has issues + # readability-const-return-type, # has issues + # readability-container-contains, # has issues + # readability-container-size-empty, # has issues + # readability-convert-member-functions-to-static, # has issues readability-duplicate-include, - readability-else-after-return, - readability-enum-initial-value, - readability-make-member-function-const, + # readability-else-after-return, # has issues + # readability-enum-initial-value, # has issues + # readability-implicit-bool-conversion, # has issues + # readability-make-member-function-const, # has issues + # readability-math-missing-parentheses, # has issues readability-misleading-indentation, readability-non-const-parameter, - readability-redundant-casting, - readability-redundant-declaration, - readability-redundant-inline-specifier, - readability-redundant-member-init, + # readability-redundant-casting, # has issues + # readability-redundant-declaration, # has issues + # readability-redundant-inline-specifier, # has issues + # readability-redundant-member-init, # has issues readability-redundant-string-init, readability-reference-to-constructed-temporary, - readability-static-definition-in-anonymous-namespace, + # readability-simplify-boolean-expr, # has issues + # readability-static-definition-in-anonymous-namespace, # has issues + # readability-suspicious-call-argument, # has issues readability-use-std-min-max " # --- -# checks that have some issues that need to be resolved: +# other checks that have issues that need to be resolved: # # llvm-namespace-comment, # misc-const-correctness, # misc-include-cleaner, # misc-redundant-expression, # -# readability-convert-member-functions-to-static, -# readability-implicit-bool-conversion, -# readability-inconsistent-declaration-parameter-name, -# readability-identifier-naming, -# readability-math-missing-parentheses, -# readability-simplify-boolean-expr, -# readability-suspicious-call-argument, -# readability-static-accessed-through-instance, +# readability-inconsistent-declaration-parameter-name, # in this codebase this check will break a lot of arg names +# readability-static-accessed-through-instance, # this check is probably unnecessary. it makes the code less readable +# readability-identifier-naming, # https://github.com/XRPLF/rippled/pull/6571 # # modernize-concat-nested-namespaces, # modernize-pass-by-value, @@ -148,12 +155,6 @@ Checks: "-*, # modernize-use-starts-ends-with, # modernize-use-std-numbers, # modernize-use-using, -# -# performance-faster-string-find, -# performance-for-range-copy, -# performance-inefficient-vector-operation, -# performance-move-const-arg, -# performance-no-automatic-move, # --- # CheckOptions: @@ -195,5 +196,6 @@ CheckOptions: bugprone-unused-return-value.CheckedReturnTypes: ::std::error_code;::std::error_condition;::std::errc # misc-include-cleaner.IgnoreHeaders: '.*/(detail|impl)/.*;.*(expected|unexpected).*;.*ranges_lower_bound\.h;time.h;stdlib.h;__chrono/.*;fmt/chrono.h;boost/uuid/uuid_hash.hpp' # -# HeaderFilterRegex: '^.*/(src|tests)/.*\.(h|hpp)$' +HeaderFilterRegex: '^.*/(test|xrpl|xrpld)/.*\.(h|hpp)$' +ExcludeHeaderFilterRegex: '^.*/protocol_autogen/.*\.(h|hpp)$' WarningsAsErrors: "*" 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..7d40ff3363 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" @@ -82,13 +81,13 @@ jobs: cmake --build . --target docs --parallel ${BUILD_NPROC} - name: Create documentation artifact - if: ${{ github.event_name == 'push' }} + if: ${{ github.event.repository.visibility == 'public' && github.event_name == 'push' }} uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0 with: path: ${{ env.BUILD_DIR }}/docs/html deploy: - if: ${{ github.event_name == 'push' }} + if: ${{ github.event.repository.visibility == 'public' && github.event_name == 'push' }} needs: build runs-on: ubuntu-latest permissions: @@ -100,4 +99,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deploy - uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5 + uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0 diff --git a/.github/workflows/reusable-build-test-config.yml b/.github/workflows/reusable-build-test-config.yml index 02a47e169d..27dfa2fd6a 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 }} @@ -298,7 +298,7 @@ jobs: - name: Upload coverage report if: ${{ github.repository == 'XRPLF/rippled' && !inputs.build_only && env.COVERAGE_ENABLED == 'true' }} - uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2 + uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0 with: disable_search: true disable_telem: true 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/CONTRIBUTING.md b/CONTRIBUTING.md index 86bef765a5..8670b79db9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -259,6 +259,10 @@ There is a Continuous Integration job that runs clang-tidy on pull requests. The This ensures that configuration changes don't introduce new warnings across the codebase. +### Installing clang-tidy + +See the [environment setup guide](./docs/build/environment.md#clang-tidy) for platform-specific installation instructions. + ### Running clang-tidy locally Before running clang-tidy, you must build the project to generate required files (particularly protobuf headers). Refer to [`BUILD.md`](./BUILD.md) for build instructions. @@ -266,10 +270,15 @@ Before running clang-tidy, you must build the project to generate required files Then run clang-tidy on your local changes: ``` -run-clang-tidy -p build src tests +run-clang-tidy -p build src include tests ``` -This will check all source files in the `src` and `tests` directories using the compile commands from your `build` directory. +This will check all source files in the `src`, `include` and `tests` directories using the compile commands from your `build` directory. +If you wish to automatically fix whatever clang-tidy finds _and_ is capable of fixing, add `-fix` to the above command: + +``` +run-clang-tidy -p build -fix src include tests +``` ## Contracts and instrumentation 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 900d3526e1..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#3a61e95e220062ef32c48d019e9c81f7%1770306721.686", + "secp256k1/0.7.1#481881709eb0bdd0185a12b912bbe8ad%1770910500.329", "rocksdb/10.5.1#4a197eca381a3e5ae8adf8cffa5aacd0%1765850186.86", - "re2/20230301#ca3b241baec15bd31ea9187150e0b333%1765850148.103", - "protobuf/6.32.1#f481fd276fc23a33b85a3ed1e898b693%1765850161.038", - "openssl/3.5.5#05a4ac5b7323f7a329b2db1391d9941f%1769599205.414", + "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,27 +18,26 @@ "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#f244a57bff01e708c55a1100b12e1589%1765850193.734", + "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#99262a368bd01c0ccca8790dfced9719%1766517936.993" + "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#eea83308ad7e9023f7318c60d5a9e6cb%1770199879.083", - "m4/1.4.19#70dc8bbb33e981d119d2acc0175cf381%1763158052.846", - "cmake/4.2.0#ae0a44f44a1ef9ab68fd4b3e9a1f8671%1765850153.937", - "cmake/3.31.10#313d16a1aa16bbdb2ca0792467214b76%1765850153.479", - "b2/5.3.3#107c15377719889654eb9a162a673975%1765850144.355", + "msys2/cci.latest#d22fe7b2808f5fd34d0a7923ace9c54f%1770657326.649", + "m4/1.4.19#5d7a4994e5875d76faf7acf3ed056036%1774365463.87", + "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#99262a368bd01c0ccca8790dfced9719%1766517936.993" + "abseil/20250127.0#bb0baf1f362bc4a725a24eddd419b8f7%1774365460.196" ], "python_requires": [], "overrides": { @@ -46,14 +45,14 @@ null, "boost/1.90.0" ], - "protobuf/5.27.0": [ - "protobuf/6.32.1" + "protobuf/[>=5.27.0 <7]": [ + "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/docs/build/environment.md b/docs/build/environment.md index c67877a082..66bed06c26 100644 --- a/docs/build/environment.md +++ b/docs/build/environment.md @@ -109,3 +109,32 @@ Install CMake with Homebrew too: ``` brew install cmake ``` + +## Clang-tidy + +Clang-tidy is required to run static analysis checks locally (see [CONTRIBUTING.md](../../CONTRIBUTING.md)). +It is not required to build the project. Currently this project uses clang-tidy version 21. + +### Linux + +LLVM 21 is not available in the default Debian 12 (Bookworm) repositories. +Install it using the official LLVM apt installer: + +``` +wget https://apt.llvm.org/llvm.sh +chmod +x llvm.sh +sudo ./llvm.sh 21 +sudo apt install --yes clang-tidy-21 +``` + +Then use `run-clang-tidy-21` when running clang-tidy locally. + +### macOS + +Install LLVM 21 via Homebrew: + +``` +brew install llvm@21 +``` + +Then use `run-clang-tidy` from the LLVM 21 Homebrew prefix when running clang-tidy locally. diff --git a/include/xrpl/beast/utility/instrumentation.h b/include/xrpl/beast/utility/instrumentation.h index 106856514b..39b80bc438 100644 --- a/include/xrpl/beast/utility/instrumentation.h +++ b/include/xrpl/beast/utility/instrumentation.h @@ -15,7 +15,7 @@ #define ALWAYS_OR_UNREACHABLE(cond, message) assert((message) && (cond)) #define SOMETIMES(cond, message, ...) #define REACHABLE(message, ...) -#define UNREACHABLE(message, ...) assert((message) && false) +#define UNREACHABLE(message, ...) assert((message) && false) // NOLINT(misc-static-assert) #endif #define XRPL_ASSERT ALWAYS_OR_UNREACHABLE 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 f40a892173..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. */ @@ -316,7 +316,7 @@ private: // Returns the limit of running jobs for the given job type. // For jobs with no limit, we return the largest int. Hopefully that // will be enough. - int + static int getJobLimit(JobType type); }; @@ -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/include/xrpl/core/StartUpType.h b/include/xrpl/core/StartUpType.h index 74a1898806..46359ad7b6 100644 --- a/include/xrpl/core/StartUpType.h +++ b/include/xrpl/core/StartUpType.h @@ -5,7 +5,7 @@ namespace xrpl { -enum class StartUpType { FRESH, NORMAL, LOAD, LOAD_FILE, REPLAY, NETWORK }; +enum class StartUpType { Fresh, Normal, Load, LoadFile, Replay, Network }; inline std::ostream& operator<<(std::ostream& os, StartUpType const& type) 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/include/xrpl/ledger/Credit.h b/include/xrpl/ledger/Credit.h deleted file mode 100644 index 770b82a650..0000000000 --- a/include/xrpl/ledger/Credit.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace xrpl { - -/** Calculate the maximum amount of IOUs that an account can hold - @param ledger the ledger to check against. - @param account the account of interest. - @param issuer the issuer of the IOU. - @param currency the IOU to check. - @return The maximum amount that can be held. -*/ -/** @{ */ -STAmount -creditLimit( - ReadView const& view, - AccountID const& account, - AccountID const& issuer, - Currency const& currency); - -IOUAmount -creditLimit2(ReadView const& v, AccountID const& acc, AccountID const& iss, Currency const& cur); -/** @} */ - -/** Returns the amount of IOUs issued by issuer that are held by an account - @param ledger the ledger to check against. - @param account the account of interest. - @param issuer the issuer of the IOU. - @param currency the IOU to check. -*/ -/** @{ */ -STAmount -creditBalance( - ReadView const& view, - AccountID const& account, - AccountID const& issuer, - Currency const& currency); -/** @} */ - -} // namespace xrpl 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/include/xrpl/ledger/OrderBookDB.h b/include/xrpl/ledger/OrderBookDB.h index 3d689607bf..5bf66eb4ab 100644 --- a/include/xrpl/ledger/OrderBookDB.h +++ b/include/xrpl/ledger/OrderBookDB.h @@ -76,16 +76,33 @@ public: @return true if a book from this issue to XRP exists */ virtual bool - isBookToXRP(Issue const& issue, std::optional domain = std::nullopt) = 0; + isBookToXRP(Issue const& issue, std::optional const& domain = std::nullopt) = 0; + /** + * Process a transaction for order book tracking. + * @param ledger The ledger the transaction was applied to + * @param alTx The transaction to process + * @param jvObj The JSON object of the transaction + */ virtual void processTxn( std::shared_ptr const& ledger, AcceptedLedgerTx const& alTx, MultiApiJson const& jvObj) = 0; + /** + * Get the book listeners for a book. + * @param book The book to get the listeners for + * @return The book listeners for the book + */ virtual BookListeners::pointer getBookListeners(Book const&) = 0; + + /** + * Create a new book listeners for a book. + * @param book The book to create the listeners for + * @return The new book listeners for the book + */ virtual BookListeners::pointer makeBookListeners(Book const&) = 0; }; 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/ledger/View.h b/include/xrpl/ledger/View.h index cd23cf4978..55be01d677 100644 --- a/include/xrpl/ledger/View.h +++ b/include/xrpl/ledger/View.h @@ -2,26 +2,23 @@ #include #include -#include #include -#include -#include #include #include -#include #include -#include -#include +#include #include +#include #include -#include #include +#include +#include +#include #include namespace xrpl { -enum class WaiveTransferFee : bool { No = false, Yes }; enum class SkipEntry : bool { No = false, Yes }; //------------------------------------------------------------------------------ @@ -54,24 +51,6 @@ enum class SkipEntry : bool { No = false, Yes }; [[nodiscard]] bool hasExpired(ReadView const& view, std::optional const& exp); -/** Controls the treatment of frozen account balances */ -enum FreezeHandling { fhIGNORE_FREEZE, fhZERO_IF_FROZEN }; - -/** Controls the treatment of unauthorized MPT balances */ -enum AuthHandling { ahIGNORE_AUTH, ahZERO_IF_UNAUTHORIZED }; - -/** Controls whether to include the account's full spendable balance */ -enum SpendableHandling { shSIMPLE_BALANCE, shFULL_BALANCE }; - -[[nodiscard]] bool -isGlobalFrozen(ReadView const& view, AccountID const& issuer); - -[[nodiscard]] bool -isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue); - -[[nodiscard]] bool -isGlobalFrozen(ReadView const& view, Asset const& asset); - // Note, depth parameter is used to limit the recursion depth [[nodiscard]] bool isVaultPseudoAccountFrozen( @@ -80,175 +59,6 @@ isVaultPseudoAccountFrozen( MPTIssue const& mptShare, int depth); -[[nodiscard]] bool -isIndividualFrozen( - ReadView const& view, - AccountID const& account, - Currency const& currency, - AccountID const& issuer); - -[[nodiscard]] inline bool -isIndividualFrozen(ReadView const& view, AccountID const& account, Issue const& issue) -{ - return isIndividualFrozen(view, account, issue.currency, issue.account); -} - -[[nodiscard]] bool -isIndividualFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue); - -[[nodiscard]] inline bool -isIndividualFrozen(ReadView const& view, AccountID const& account, Asset const& asset) -{ - return std::visit( - [&](auto const& issue) { return isIndividualFrozen(view, account, issue); }, asset.value()); -} - -[[nodiscard]] bool -isFrozen( - ReadView const& view, - AccountID const& account, - Currency const& currency, - AccountID const& issuer); - -[[nodiscard]] inline bool -isFrozen(ReadView const& view, AccountID const& account, Issue const& issue, int = 0 /*ignored*/) -{ - return isFrozen(view, account, issue.currency, issue.account); -} - -[[nodiscard]] bool -isFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue, int depth = 0); - -/** - * isFrozen check is recursive for MPT shares in a vault, descending to - * assets in the vault, up to maxAssetCheckDepth recursion depth. This is - * purely defensive, as we currently do not allow such vaults to be created. - */ -[[nodiscard]] inline bool -isFrozen(ReadView const& view, AccountID const& account, Asset const& asset, int depth = 0) -{ - return std::visit( - [&](auto const& issue) { return isFrozen(view, account, issue, depth); }, asset.value()); -} - -[[nodiscard]] inline TER -checkFrozen(ReadView const& view, AccountID const& account, Issue const& issue) -{ - return isFrozen(view, account, issue) ? (TER)tecFROZEN : (TER)tesSUCCESS; -} - -[[nodiscard]] inline TER -checkFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue) -{ - return isFrozen(view, account, mptIssue) ? (TER)tecLOCKED : (TER)tesSUCCESS; -} - -[[nodiscard]] inline TER -checkFrozen(ReadView const& view, AccountID const& account, Asset const& asset) -{ - return std::visit( - [&](auto const& issue) { return checkFrozen(view, account, issue); }, asset.value()); -} - -[[nodiscard]] bool -isAnyFrozen( - ReadView const& view, - std::initializer_list const& accounts, - MPTIssue const& mptIssue, - int depth = 0); - -[[nodiscard]] inline bool -isAnyFrozen( - ReadView const& view, - std::initializer_list const& accounts, - Issue const& issue) -{ - for (auto const& account : accounts) - { - if (isFrozen(view, account, issue.currency, issue.account)) - return true; - } - return false; -} - -[[nodiscard]] inline bool -isAnyFrozen( - ReadView const& view, - std::initializer_list const& accounts, - Asset const& asset, - int depth = 0) -{ - return std::visit( - [&](TIss const& issue) { - if constexpr (std::is_same_v) - return isAnyFrozen(view, accounts, issue); - else - return isAnyFrozen(view, accounts, issue, depth); - }, - asset.value()); -} - -[[nodiscard]] bool -isDeepFrozen( - ReadView const& view, - AccountID const& account, - Currency const& currency, - AccountID const& issuer); - -[[nodiscard]] inline bool -isDeepFrozen( - ReadView const& view, - AccountID const& account, - Issue const& issue, - int = 0 /*ignored*/) -{ - return isDeepFrozen(view, account, issue.currency, issue.account); -} - -[[nodiscard]] inline bool -isDeepFrozen( - ReadView const& view, - AccountID const& account, - MPTIssue const& mptIssue, - int depth = 0) -{ - // Unlike IOUs, frozen / locked MPTs are not allowed to send or receive - // funds, so checking "deep frozen" is the same as checking "frozen". - return isFrozen(view, account, mptIssue, depth); -} - -/** - * isFrozen check is recursive for MPT shares in a vault, descending to - * assets in the vault, up to maxAssetCheckDepth recursion depth. This is - * purely defensive, as we currently do not allow such vaults to be created. - */ -[[nodiscard]] inline bool -isDeepFrozen(ReadView const& view, AccountID const& account, Asset const& asset, int depth = 0) -{ - return std::visit( - [&](auto const& issue) { return isDeepFrozen(view, account, issue, depth); }, - asset.value()); -} - -[[nodiscard]] inline TER -checkDeepFrozen(ReadView const& view, AccountID const& account, Issue const& issue) -{ - return isDeepFrozen(view, account, issue) ? (TER)tecFROZEN : (TER)tesSUCCESS; -} - -[[nodiscard]] inline TER -checkDeepFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue) -{ - return isDeepFrozen(view, account, mptIssue) ? (TER)tecLOCKED : (TER)tesSUCCESS; -} - -[[nodiscard]] inline TER -checkDeepFrozen(ReadView const& view, AccountID const& account, Asset const& asset) -{ - return std::visit( - [&](auto const& issue) { return checkDeepFrozen(view, account, issue); }, asset.value()); -} - [[nodiscard]] bool isLPTokenFrozen( ReadView const& view, @@ -256,159 +66,6 @@ isLPTokenFrozen( Issue const& asset, Issue const& asset2); -// Returns the amount an account can spend. -// -// If shSIMPLE_BALANCE is specified, this is the amount the account can spend -// without going into debt. -// -// If shFULL_BALANCE is specified, this is the amount the account can spend -// total. Specifically: -// * The account can go into debt if using a trust line, and the other side has -// a non-zero limit. -// * If the account is the asset issuer the limit is defined by the asset / -// issuance. -// -// <-- saAmount: amount of currency held by account. May be negative. -[[nodiscard]] STAmount -accountHolds( - ReadView const& view, - AccountID const& account, - Currency const& currency, - AccountID const& issuer, - FreezeHandling zeroIfFrozen, - beast::Journal j, - SpendableHandling includeFullBalance = shSIMPLE_BALANCE); - -[[nodiscard]] STAmount -accountHolds( - ReadView const& view, - AccountID const& account, - Issue const& issue, - FreezeHandling zeroIfFrozen, - beast::Journal j, - SpendableHandling includeFullBalance = shSIMPLE_BALANCE); - -[[nodiscard]] STAmount -accountHolds( - ReadView const& view, - AccountID const& account, - MPTIssue const& mptIssue, - FreezeHandling zeroIfFrozen, - AuthHandling zeroIfUnauthorized, - beast::Journal j, - SpendableHandling includeFullBalance = shSIMPLE_BALANCE); - -[[nodiscard]] STAmount -accountHolds( - ReadView const& view, - AccountID const& account, - Asset const& asset, - FreezeHandling zeroIfFrozen, - AuthHandling zeroIfUnauthorized, - beast::Journal j, - SpendableHandling includeFullBalance = shSIMPLE_BALANCE); - -// Returns the amount an account can spend of the currency type saDefault, or -// returns saDefault if this account is the issuer of the currency in -// question. Should be used in favor of accountHolds when questioning how much -// an account can spend while also allowing currency issuers to spend -// unlimited amounts of their own currency (since they can always issue more). -[[nodiscard]] STAmount -accountFunds( - ReadView const& view, - AccountID const& id, - STAmount const& saDefault, - FreezeHandling freezeHandling, - beast::Journal j); - -// Return the account's liquid (not reserved) XRP. Generally prefer -// calling accountHolds() over this interface. However, this interface -// allows the caller to temporarily adjust the owner count should that be -// necessary. -// -// @param ownerCountAdj positive to add to count, negative to reduce count. -[[nodiscard]] XRPAmount -xrpLiquid(ReadView const& view, AccountID const& id, std::int32_t ownerCountAdj, beast::Journal j); - -/** Iterate all items in the given directory. */ -void -forEachItem( - ReadView const& view, - Keylet const& root, - std::function const&)> const& f); - -/** Iterate all items after an item in the given directory. - @param after The key of the item to start after - @param hint The directory page containing `after` - @param limit The maximum number of items to return - @return `false` if the iteration failed -*/ -bool -forEachItemAfter( - ReadView const& view, - Keylet const& root, - uint256 const& after, - std::uint64_t const hint, - unsigned int limit, - std::function const&)> const& f); - -/** Iterate all items in an account's owner directory. */ -inline void -forEachItem( - ReadView const& view, - AccountID const& id, - std::function const&)> const& f) -{ - return forEachItem(view, keylet::ownerDir(id), f); -} - -/** Iterate all items after an item in an owner directory. - @param after The key of the item to start after - @param hint The directory page containing `after` - @param limit The maximum number of items to return - @return `false` if the iteration failed -*/ -inline bool -forEachItemAfter( - ReadView const& view, - AccountID const& id, - uint256 const& after, - std::uint64_t const hint, - unsigned int limit, - std::function const&)> const& f) -{ - return forEachItemAfter(view, keylet::ownerDir(id), after, hint, limit, f); -} - -/** Returns IOU issuer transfer fee as Rate. Rate specifies - * the fee as fractions of 1 billion. For example, 1% transfer rate - * is represented as 1,010,000,000. - * @param issuer The IOU issuer - */ -[[nodiscard]] Rate -transferRate(ReadView const& view, AccountID const& issuer); - -/** Returns MPT transfer fee as Rate. Rate specifies - * the fee as fractions of 1 billion. For example, 1% transfer rate - * is represented as 1,010,000,000. - * @param issuanceID MPTokenIssuanceID of MPTTokenIssuance object - */ -[[nodiscard]] Rate -transferRate(ReadView const& view, MPTID const& issuanceID); - -/** Returns the transfer fee as Rate based on the type of token - * @param view The ledger view - * @param amount The amount to transfer - */ -[[nodiscard]] Rate -transferRate(ReadView const& view, STAmount const& amount); - -/** Returns `true` if the directory is empty - @param key The key of the directory -*/ -[[nodiscard]] bool -dirIsEmpty(ReadView const& view, Keylet const& k); - // Return the list of enabled amendments [[nodiscard]] std::set getEnabledAmendments(ReadView const& view); @@ -474,81 +131,6 @@ areCompatible( // //------------------------------------------------------------------------------ -/** Adjust the owner count up or down. */ -void -adjustOwnerCount( - ApplyView& view, - std::shared_ptr const& sle, - std::int32_t amount, - beast::Journal j); - -/** @{ */ -/** Returns the first entry in the directory, advancing the index - - @deprecated These are legacy function that are considered deprecated - and will soon be replaced with an iterator-based model - that is easier to use. You should not use them in new code. - - @param view The view against which to operate - @param root The root (i.e. first page) of the directory to iterate - @param page The current page - @param index The index inside the current page - @param entry The entry at the current index - - @return true if the directory isn't empty; false otherwise - */ -bool -cdirFirst( - ReadView const& view, - uint256 const& root, - std::shared_ptr& page, - unsigned int& index, - uint256& entry); - -bool -dirFirst( - ApplyView& view, - uint256 const& root, - std::shared_ptr& page, - unsigned int& index, - uint256& entry); -/** @} */ - -/** @{ */ -/** Returns the next entry in the directory, advancing the index - - @deprecated These are legacy function that are considered deprecated - and will soon be replaced with an iterator-based model - that is easier to use. You should not use them in new code. - - @param view The view against which to operate - @param root The root (i.e. first page) of the directory to iterate - @param page The current page - @param index The index inside the current page - @param entry The entry at the current index - - @return true if the directory isn't empty; false otherwise - */ -bool -cdirNext( - ReadView const& view, - uint256 const& root, - std::shared_ptr& page, - unsigned int& index, - uint256& entry); - -bool -dirNext( - ApplyView& view, - uint256 const& root, - std::shared_ptr& page, - unsigned int& index, - uint256& entry); -/** @} */ - -[[nodiscard]] std::function -describeOwnerDir(AccountID const& account); - [[nodiscard]] TER dirLink( ApplyView& view, @@ -556,63 +138,6 @@ dirLink( std::shared_ptr& object, SF_UINT64 const& node = sfOwnerNode); -AccountID -pseudoAccountAddress(ReadView const& view, uint256 const& pseudoOwnerKey); - -/** - * - * Create pseudo-account, storing pseudoOwnerKey into ownerField. - * - * The list of valid ownerField is maintained in View.cpp and the caller to - * this function must perform necessary amendment check(s) before using a - * field. The amendment check is **not** performed in createPseudoAccount. - */ -[[nodiscard]] Expected, TER> -createPseudoAccount(ApplyView& view, uint256 const& pseudoOwnerKey, SField const& ownerField); - -// Returns true if and only if sleAcct is a pseudo-account or specific -// pseudo-accounts in pseudoFieldFilter. -// -// Returns false if sleAcct is -// * NOT a pseudo-account OR -// * NOT a ltACCOUNT_ROOT OR -// * null pointer -[[nodiscard]] bool -isPseudoAccount( - std::shared_ptr sleAcct, - std::set const& pseudoFieldFilter = {}); - -// Returns the list of fields that define an ACCOUNT_ROOT as a pseudo-account if -// set -// Pseudo-account designator fields MUST be maintained by including the -// SField::sMD_PseudoAccount flag in the SField definition. (Don't forget to -// "| SField::sMD_Default"!) The fields do NOT need to be amendment-gated, -// since a non-active amendment will not set any field, by definition. -// Specific properties of a pseudo-account are NOT checked here, that's what -// InvariantCheck is for. -[[nodiscard]] std::vector const& -getPseudoAccountFields(); - -[[nodiscard]] inline bool -isPseudoAccount( - ReadView const& view, - AccountID const& accountId, - std::set const& pseudoFieldFilter = {}) -{ - return isPseudoAccount(view.read(keylet::account(accountId)), pseudoFieldFilter); -} - -[[nodiscard]] TER -canAddHolding(ReadView const& view, Asset const& asset); - -/** Validates that the destination SLE and tag are valid - - - Checks that the SLE is not null. - - If the SLE requires a destination tag, checks that there is a tag. -*/ -[[nodiscard]] TER -checkDestinationAndTag(SLE::const_ref toSle, bool hasDestinationTag); - /** Checks that can withdraw funds from an object to itself or a destination. * * The receiver may be either the submitting account (sfAccount) or a different @@ -686,351 +211,6 @@ doWithdraw( STAmount const& amount, beast::Journal j); -/// Any transactors that call addEmptyHolding() in doApply must call -/// canAddHolding() in preflight with the same View and Asset -[[nodiscard]] TER -addEmptyHolding( - ApplyView& view, - AccountID const& accountID, - XRPAmount priorBalance, - Issue const& issue, - beast::Journal journal); - -[[nodiscard]] TER -addEmptyHolding( - ApplyView& view, - AccountID const& accountID, - XRPAmount priorBalance, - MPTIssue const& mptIssue, - beast::Journal journal); - -[[nodiscard]] inline TER -addEmptyHolding( - ApplyView& view, - AccountID const& accountID, - XRPAmount priorBalance, - Asset const& asset, - beast::Journal journal) -{ - return std::visit( - [&](TIss const& issue) -> TER { - return addEmptyHolding(view, accountID, priorBalance, issue, journal); - }, - asset.value()); -} - -[[nodiscard]] TER -authorizeMPToken( - ApplyView& view, - XRPAmount const& priorBalance, - MPTID const& mptIssuanceID, - AccountID const& account, - beast::Journal journal, - std::uint32_t flags = 0, - std::optional holderID = std::nullopt); - -// VFALCO NOTE Both STAmount parameters should just -// be "Amount", a unit-less number. -// -/** Create a trust line - - This can set an initial balance. -*/ -[[nodiscard]] TER -trustCreate( - ApplyView& view, - bool const bSrcHigh, - AccountID const& uSrcAccountID, - AccountID const& uDstAccountID, - uint256 const& uIndex, // --> ripple state entry - SLE::ref sleAccount, // --> the account being set. - bool const bAuth, // --> authorize account. - bool const bNoRipple, // --> others cannot ripple through - bool const bFreeze, // --> funds cannot leave - bool bDeepFreeze, // --> can neither receive nor send funds - STAmount const& saBalance, // --> balance of account being set. - // Issuer should be noAccount() - STAmount const& saLimit, // --> limit for account being set. - // Issuer should be the account being set. - std::uint32_t uSrcQualityIn, - std::uint32_t uSrcQualityOut, - beast::Journal j); - -[[nodiscard]] TER -removeEmptyHolding( - ApplyView& view, - AccountID const& accountID, - Issue const& issue, - beast::Journal journal); - -[[nodiscard]] TER -removeEmptyHolding( - ApplyView& view, - AccountID const& accountID, - MPTIssue const& mptIssue, - beast::Journal journal); - -[[nodiscard]] inline TER -removeEmptyHolding( - ApplyView& view, - AccountID const& accountID, - Asset const& asset, - beast::Journal journal) -{ - return std::visit( - [&](TIss const& issue) -> TER { - return removeEmptyHolding(view, accountID, issue, journal); - }, - asset.value()); -} - -[[nodiscard]] TER -trustDelete( - ApplyView& view, - std::shared_ptr const& sleRippleState, - AccountID const& uLowAccountID, - AccountID const& uHighAccountID, - beast::Journal j); - -/** Delete an offer. - - Requirements: - The passed `sle` be obtained from a prior - call to view.peek() -*/ -// [[nodiscard]] // nodiscard commented out so Flow, BookTip and others compile. -TER -offerDelete(ApplyView& view, std::shared_ptr const& sle, beast::Journal j); - -//------------------------------------------------------------------------------ - -// -// Money Transfers -// - -// Direct send w/o fees: -// - Redeeming IOUs and/or sending sender's own IOUs. -// - Create trust line of needed. -// --> bCheckIssuer : normally require issuer to be involved. -// [[nodiscard]] // nodiscard commented out so DirectStep.cpp compiles. - -/** Calls static rippleCreditIOU if saAmount represents Issue. - * Calls static rippleCreditMPT if saAmount represents MPTIssue. - */ -TER -rippleCredit( - ApplyView& view, - AccountID const& uSenderID, - AccountID const& uReceiverID, - STAmount const& saAmount, - bool bCheckIssuer, - beast::Journal j); - -TER -rippleLockEscrowMPT( - ApplyView& view, - AccountID const& uGrantorID, - STAmount const& saAmount, - beast::Journal j); - -TER -rippleUnlockEscrowMPT( - ApplyView& view, - AccountID const& uGrantorID, - AccountID const& uGranteeID, - STAmount const& netAmount, - STAmount const& grossAmount, - beast::Journal j); - -/** Calls static accountSendIOU if saAmount represents Issue. - * Calls static accountSendMPT if saAmount represents MPTIssue. - */ -[[nodiscard]] TER -accountSend( - ApplyView& view, - AccountID const& from, - AccountID const& to, - STAmount const& saAmount, - beast::Journal j, - WaiveTransferFee waiveFee = WaiveTransferFee::No); - -using MultiplePaymentDestinations = std::vector>; -/** Like accountSend, except one account is sending multiple payments (with the - * same asset!) simultaneously - * - * Calls static accountSendMultiIOU if saAmount represents Issue. - * Calls static accountSendMultiMPT if saAmount represents MPTIssue. - */ -[[nodiscard]] TER -accountSendMulti( - ApplyView& view, - AccountID const& senderID, - Asset const& asset, - MultiplePaymentDestinations const& receivers, - beast::Journal j, - WaiveTransferFee waiveFee = WaiveTransferFee::No); - -[[nodiscard]] TER -issueIOU( - ApplyView& view, - AccountID const& account, - STAmount const& amount, - Issue const& issue, - beast::Journal j); - -[[nodiscard]] TER -redeemIOU( - ApplyView& view, - AccountID const& account, - STAmount const& amount, - Issue const& issue, - beast::Journal j); - -[[nodiscard]] TER -transferXRP( - ApplyView& view, - AccountID const& from, - AccountID const& to, - STAmount const& amount, - beast::Journal j); - -/* Check if MPToken (for MPT) or trust line (for IOU) exists: - * - StrongAuth - before checking if authorization is required - * - WeakAuth - * for MPT - after checking lsfMPTRequireAuth flag - * for IOU - do not check if trust line exists - * - Legacy - * for MPT - before checking lsfMPTRequireAuth flag i.e. same as StrongAuth - * for IOU - do not check if trust line exists i.e. same as WeakAuth - */ -enum class AuthType { StrongAuth, WeakAuth, Legacy }; - -/** Check if the account lacks required authorization. - * - * Return tecNO_AUTH or tecNO_LINE if it does - * and tesSUCCESS otherwise. - * - * If StrongAuth then return tecNO_LINE if the RippleState doesn't exist. Return - * tecNO_AUTH if lsfRequireAuth is set on the issuer's AccountRoot, and the - * RippleState does exist, and the RippleState is not authorized. - * - * If WeakAuth then return tecNO_AUTH if lsfRequireAuth is set, and the - * RippleState exists, and is not authorized. Return tecNO_LINE if - * lsfRequireAuth is set and the RippleState doesn't exist. Consequently, if - * WeakAuth and lsfRequireAuth is *not* set, this function will return - * tesSUCCESS even if RippleState does *not* exist. - * - * The default "Legacy" auth type is equivalent to WeakAuth. - */ -[[nodiscard]] TER -requireAuth( - ReadView const& view, - Issue const& issue, - AccountID const& account, - AuthType authType = AuthType::Legacy); - -/** Check if the account lacks required authorization. - * - * This will also check for expired credentials. If it is called directly - * from preclaim, the user should convert result tecEXPIRED to tesSUCCESS and - * proceed to also check permissions with enforceMPTokenAuthorization inside - * doApply. This will ensure that any expired credentials are deleted. - * - * requireAuth check is recursive for MPT shares in a vault, descending to - * assets in the vault, up to maxAssetCheckDepth recursion depth. This is - * purely defensive, as we currently do not allow such vaults to be created. - * - * If StrongAuth then return tecNO_AUTH if MPToken doesn't exist or - * lsfMPTRequireAuth is set and MPToken is not authorized. Vault and LoanBroker - * pseudo-accounts are implicitly authorized. - * - * If WeakAuth then return tecNO_AUTH if lsfMPTRequireAuth is set and MPToken - * doesn't exist or is not authorized (explicitly or via credentials, if - * DomainID is set in MPTokenIssuance). Consequently, if WeakAuth and - * lsfMPTRequireAuth is *not* set, this function will return true even if - * MPToken does *not* exist. - * - * The default "Legacy" auth type is equivalent to StrongAuth. - */ -[[nodiscard]] TER -requireAuth( - ReadView const& view, - MPTIssue const& mptIssue, - AccountID const& account, - AuthType authType = AuthType::Legacy, - int depth = 0); - -[[nodiscard]] TER inline requireAuth( - ReadView const& view, - Asset const& asset, - AccountID const& account, - AuthType authType = AuthType::Legacy) -{ - return std::visit( - [&](TIss const& issue_) { - return requireAuth(view, issue_, account, authType); - }, - asset.value()); -} - -/** Enforce account has MPToken to match its authorization. - * - * Called from doApply - it will check for expired (and delete if found any) - * credentials matching DomainID set in MPTokenIssuance. Must be called if - * requireAuth(...MPTIssue...) returned tesSUCCESS or tecEXPIRED in preclaim, - * which implies that preclaim should replace `tecEXPIRED` with `tesSUCCESS` - * in order for the transactor to proceed to doApply. - * - * This function will create MPToken (if needed) on the basis of any - * non-expired credentials and will delete any expired credentials, indirectly - * via verifyValidDomain, as per DomainID (if set in MPTokenIssuance). - * - * The caller does NOT need to ensure that DomainID is actually set - this - * function handles gracefully both cases when DomainID is set and when not. - * - * The caller does NOT need to look for existing MPToken to match - * mptIssue/account - this function checks lsfMPTAuthorized of an existing - * MPToken iff DomainID is not set. - * - * Do not use for accounts which hold implied permission e.g. object owners or - * if MPTokenIssuance does not require authorization. In both cases use - * MPTokenAuthorize::authorize if MPToken does not yet exist. - */ -[[nodiscard]] TER -enforceMPTokenAuthorization( - ApplyView& view, - MPTID const& mptIssuanceID, - AccountID const& account, - XRPAmount const& priorBalance, - beast::Journal j); - -/** Check if the destination account is allowed - * to receive MPT. Return tecNO_AUTH if it doesn't - * and tesSUCCESS otherwise. - */ -[[nodiscard]] TER -canTransfer( - ReadView const& view, - MPTIssue const& mptIssue, - AccountID const& from, - AccountID const& to); - -[[nodiscard]] TER -canTransfer(ReadView const& view, Issue const& issue, AccountID const& from, AccountID const& to); - -[[nodiscard]] TER inline canTransfer( - ReadView const& view, - Asset const& asset, - AccountID const& from, - AccountID const& to) -{ - return std::visit( - [&](TIss const& issue) -> TER { - return canTransfer(view, issue, from, to); - }, - asset.value()); -} - /** Deleter function prototype. Returns the status of the entry deletion * (if should not be skipped) and if the entry should be skipped. The status * is always tesSUCCESS if the entry should be skipped. @@ -1052,57 +232,6 @@ cleanupOnAccountDelete( beast::Journal j, std::optional maxNodesToDelete = std::nullopt); -/** Delete trustline to AMM. The passed `sle` must be obtained from a prior - * call to view.peek(). Fail if neither side of the trustline is AMM or - * if ammAccountID is seated and is not one of the trustline's side. - */ -[[nodiscard]] TER -deleteAMMTrustLine( - ApplyView& view, - std::shared_ptr sleState, - std::optional const& ammAccountID, - beast::Journal j); - -// From the perspective of a vault, return the number of shares to give the -// depositor when they deposit a fixed amount of assets. Since shares are MPT -// this number is integral and always truncated in this calculation. -[[nodiscard]] std::optional -assetsToSharesDeposit( - std::shared_ptr const& vault, - std::shared_ptr const& issuance, - STAmount const& assets); - -// From the perspective of a vault, return the number of assets to take from -// depositor when they receive a fixed amount of shares. Note, since shares are -// MPT, they are always an integral number. -[[nodiscard]] std::optional -sharesToAssetsDeposit( - std::shared_ptr const& vault, - std::shared_ptr const& issuance, - STAmount const& shares); - -enum class TruncateShares : bool { no = false, yes = true }; - -// From the perspective of a vault, return the number of shares to demand from -// the depositor when they ask to withdraw a fixed amount of assets. Since -// shares are MPT this number is integral, and it will be rounded to nearest -// unless explicitly requested to be truncated instead. -[[nodiscard]] std::optional -assetsToSharesWithdraw( - std::shared_ptr const& vault, - std::shared_ptr const& issuance, - STAmount const& assets, - TruncateShares truncate = TruncateShares::no); - -// From the perspective of a vault, return the number of assets to give the -// depositor when they redeem a fixed amount of shares. Note, since shares are -// MPT, they are always an integral number. -[[nodiscard]] std::optional -sharesToAssetsWithdraw( - std::shared_ptr const& vault, - std::shared_ptr const& issuance, - STAmount const& shares); - /** Has the specified time passed? @param now the current time diff --git a/include/xrpl/ledger/helpers/AccountRootHelpers.h b/include/xrpl/ledger/helpers/AccountRootHelpers.h new file mode 100644 index 0000000000..353c27fe41 --- /dev/null +++ b/include/xrpl/ledger/helpers/AccountRootHelpers.h @@ -0,0 +1,112 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace xrpl { + +/** Check if the issuer has the global freeze flag set. + @param issuer The account to check + @return true if the account has global freeze set +*/ +[[nodiscard]] bool +isGlobalFrozen(ReadView const& view, AccountID const& issuer); + +// Calculate liquid XRP balance for an account. +// This function may be used to calculate the amount of XRP that +// the holder is able to freely spend. It subtracts reserve requirements. +// +// ownerCountAdj adjusts the owner count in case the caller calculates +// before ledger entries are added or removed. Positive to add, negative +// to subtract. +// +// @param ownerCountAdj positive to add to count, negative to reduce count. +[[nodiscard]] XRPAmount +xrpLiquid(ReadView const& view, AccountID const& id, std::int32_t ownerCountAdj, beast::Journal j); + +/** Adjust the owner count up or down. */ +void +adjustOwnerCount( + ApplyView& view, + std::shared_ptr const& sle, + std::int32_t amount, + beast::Journal j); + +/** Returns IOU issuer transfer fee as Rate. Rate specifies + * the fee as fractions of 1 billion. For example, 1% transfer rate + * is represented as 1,010,000,000. + * @param issuer The IOU issuer + */ +[[nodiscard]] Rate +transferRate(ReadView const& view, AccountID const& issuer); + +/** Generate a pseudo-account address from a pseudo owner key. + @param pseudoOwnerKey The key to generate the address from + @return The generated account ID +*/ +AccountID +pseudoAccountAddress(ReadView const& view, uint256 const& pseudoOwnerKey); + +/** Returns the list of fields that define an ACCOUNT_ROOT as a pseudo-account + if set. + + The list is constructed during initialization and is const after that. + Pseudo-account designator fields MUST be maintained by including the + SField::sMD_PseudoAccount flag in the SField definition. +*/ +[[nodiscard]] std::vector const& +getPseudoAccountFields(); + +/** Returns true if and only if sleAcct is a pseudo-account or specific + pseudo-accounts in pseudoFieldFilter. + + Returns false if sleAcct is: + - NOT a pseudo-account OR + - NOT a ltACCOUNT_ROOT OR + - null pointer +*/ +[[nodiscard]] bool +isPseudoAccount( + std::shared_ptr sleAcct, + std::set const& pseudoFieldFilter = {}); + +/** Convenience overload that reads the account from the view. */ +[[nodiscard]] inline bool +isPseudoAccount( + ReadView const& view, + AccountID const& accountId, + std::set const& pseudoFieldFilter = {}) +{ + return isPseudoAccount(view.read(keylet::account(accountId)), pseudoFieldFilter); +} + +/** + * Create pseudo-account, storing pseudoOwnerKey into ownerField. + * + * The list of valid ownerField is maintained in AccountRootHelpers.cpp and + * the caller to this function must perform necessary amendment check(s) + * before using a field. The amendment check is **not** performed in + * createPseudoAccount. + */ +[[nodiscard]] Expected, TER> +createPseudoAccount(ApplyView& view, uint256 const& pseudoOwnerKey, SField const& ownerField); + +/** Checks the destination and tag. + + - Checks that the SLE is not null. + - If the SLE requires a destination tag, checks that there is a tag. +*/ +[[nodiscard]] TER +checkDestinationAndTag(SLE::const_ref toSle, bool hasDestinationTag); + +} // namespace xrpl diff --git a/include/xrpl/ledger/CredentialHelpers.h b/include/xrpl/ledger/helpers/CredentialHelpers.h similarity index 100% rename from include/xrpl/ledger/CredentialHelpers.h rename to include/xrpl/ledger/helpers/CredentialHelpers.h diff --git a/include/xrpl/ledger/helpers/DirectoryHelpers.h b/include/xrpl/ledger/helpers/DirectoryHelpers.h new file mode 100644 index 0000000000..189dfcd263 --- /dev/null +++ b/include/xrpl/ledger/helpers/DirectoryHelpers.h @@ -0,0 +1,223 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace xrpl { + +namespace detail { + +template < + class V, + class N, + class = std::enable_if_t< + std::is_same_v, SLE> && std::is_base_of_v>> +bool +internalDirNext( + V& view, + uint256 const& root, + std::shared_ptr& page, + unsigned int& index, + uint256& entry) +{ + auto const& svIndexes = page->getFieldV256(sfIndexes); + XRPL_ASSERT(index <= svIndexes.size(), "xrpl::detail::internalDirNext : index inside range"); + + if (index >= svIndexes.size()) + { + auto const next = page->getFieldU64(sfIndexNext); + + if (!next) + { + entry.zero(); + return false; + } + + if constexpr (std::is_const_v) + { + page = view.read(keylet::page(root, next)); + } + else + { + page = view.peek(keylet::page(root, next)); + } + + XRPL_ASSERT(page, "xrpl::detail::internalDirNext : non-null root"); + + if (!page) + return false; + + index = 0; + + return internalDirNext(view, root, page, index, entry); + } + + entry = svIndexes[index++]; + return true; +} + +template < + class V, + class N, + class = std::enable_if_t< + std::is_same_v, SLE> && std::is_base_of_v>> +bool +internalDirFirst( + V& view, + uint256 const& root, + std::shared_ptr& page, + unsigned int& index, + uint256& entry) +{ + if constexpr (std::is_const_v) + { + page = view.read(keylet::page(root)); + } + else + { + page = view.peek(keylet::page(root)); + } + + if (!page) + return false; + + index = 0; + + return internalDirNext(view, root, page, index, entry); +} + +} // namespace detail + +/** @{ */ +/** Returns the first entry in the directory, advancing the index + + @deprecated These are legacy function that are considered deprecated + and will soon be replaced with an iterator-based model + that is easier to use. You should not use them in new code. + + @param view The view against which to operate + @param root The root (i.e. first page) of the directory to iterate + @param page The current page + @param index The index inside the current page + @param entry The entry at the current index + + @return true if the directory isn't empty; false otherwise + */ +bool +cdirFirst( + ReadView const& view, + uint256 const& root, + std::shared_ptr& page, + unsigned int& index, + uint256& entry); + +bool +dirFirst( + ApplyView& view, + uint256 const& root, + std::shared_ptr& page, + unsigned int& index, + uint256& entry); +/** @} */ + +/** @{ */ +/** Returns the next entry in the directory, advancing the index + + @deprecated These are legacy function that are considered deprecated + and will soon be replaced with an iterator-based model + that is easier to use. You should not use them in new code. + + @param view The view against which to operate + @param root The root (i.e. first page) of the directory to iterate + @param page The current page + @param index The index inside the current page + @param entry The entry at the current index + + @return true if the directory isn't empty; false otherwise + */ +bool +cdirNext( + ReadView const& view, + uint256 const& root, + std::shared_ptr& page, + unsigned int& index, + uint256& entry); + +bool +dirNext( + ApplyView& view, + uint256 const& root, + std::shared_ptr& page, + unsigned int& index, + uint256& entry); +/** @} */ + +/** Iterate all items in the given directory. */ +void +forEachItem( + ReadView const& view, + Keylet const& root, + std::function const&)> const& f); + +/** Iterate all items after an item in the given directory. + @param after The key of the item to start after + @param hint The directory page containing `after` + @param limit The maximum number of items to return + @return `false` if the iteration failed +*/ +bool +forEachItemAfter( + ReadView const& view, + Keylet const& root, + uint256 const& after, + std::uint64_t const hint, + unsigned int limit, + std::function const&)> const& f); + +/** Iterate all items in an account's owner directory. */ +inline void +forEachItem( + ReadView const& view, + AccountID const& id, + std::function const&)> const& f) +{ + return forEachItem(view, keylet::ownerDir(id), f); +} + +/** Iterate all items after an item in an owner directory. + @param after The key of the item to start after + @param hint The directory page containing `after` + @param limit The maximum number of items to return + @return `false` if the iteration failed +*/ +inline bool +forEachItemAfter( + ReadView const& view, + AccountID const& id, + uint256 const& after, + std::uint64_t const hint, + unsigned int limit, + std::function const&)> const& f) +{ + return forEachItemAfter(view, keylet::ownerDir(id), after, hint, limit, f); +} + +/** Returns `true` if the directory is empty + @param key The key of the directory +*/ +[[nodiscard]] bool +dirIsEmpty(ReadView const& view, Keylet const& k); + +/** Returns a function that sets the owner on a directory SLE */ +[[nodiscard]] std::function +describeOwnerDir(AccountID const& account); + +} // namespace xrpl diff --git a/include/xrpl/ledger/helpers/MPTokenHelpers.h b/include/xrpl/ledger/helpers/MPTokenHelpers.h new file mode 100644 index 0000000000..ab487280b9 --- /dev/null +++ b/include/xrpl/ledger/helpers/MPTokenHelpers.h @@ -0,0 +1,160 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace xrpl { + +//------------------------------------------------------------------------------ +// +// Freeze checking (MPT-specific) +// +//------------------------------------------------------------------------------ + +[[nodiscard]] bool +isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue); + +[[nodiscard]] bool +isIndividualFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue); + +[[nodiscard]] bool +isFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue, int depth = 0); + +[[nodiscard]] bool +isAnyFrozen( + ReadView const& view, + std::initializer_list const& accounts, + MPTIssue const& mptIssue, + int depth = 0); + +//------------------------------------------------------------------------------ +// +// Transfer rate (MPT-specific) +// +//------------------------------------------------------------------------------ + +/** Returns MPT transfer fee as Rate. Rate specifies + * the fee as fractions of 1 billion. For example, 1% transfer rate + * is represented as 1,010,000,000. + * @param issuanceID MPTokenIssuanceID of MPTTokenIssuance object + */ +[[nodiscard]] Rate +transferRate(ReadView const& view, MPTID const& issuanceID); + +//------------------------------------------------------------------------------ +// +// Holding checks (MPT-specific) +// +//------------------------------------------------------------------------------ + +[[nodiscard]] TER +canAddHolding(ReadView const& view, MPTIssue const& mptIssue); + +//------------------------------------------------------------------------------ +// +// Authorization (MPT-specific) +// +//------------------------------------------------------------------------------ + +[[nodiscard]] TER +authorizeMPToken( + ApplyView& view, + XRPAmount const& priorBalance, + MPTID const& mptIssuanceID, + AccountID const& account, + beast::Journal journal, + std::uint32_t flags = 0, + std::optional holderID = std::nullopt); + +/** Check if the account lacks required authorization for MPT. + * + * requireAuth check is recursive for MPT shares in a vault, descending to + * assets in the vault, up to maxAssetCheckDepth recursion depth. This is + * purely defensive, as we currently do not allow such vaults to be created. + */ +[[nodiscard]] TER +requireAuth( + ReadView const& view, + MPTIssue const& mptIssue, + AccountID const& account, + AuthType authType = AuthType::Legacy, + int depth = 0); + +/** Enforce account has MPToken to match its authorization. + * + * Called from doApply - it will check for expired (and delete if found any) + * credentials matching DomainID set in MPTokenIssuance. Must be called if + * requireAuth(...MPTIssue...) returned tesSUCCESS or tecEXPIRED in preclaim. + */ +[[nodiscard]] TER +enforceMPTokenAuthorization( + ApplyView& view, + MPTID const& mptIssuanceID, + AccountID const& account, + XRPAmount const& priorBalance, + beast::Journal j); + +/** Check if the destination account is allowed + * to receive MPT. Return tecNO_AUTH if it doesn't + * and tesSUCCESS otherwise. + */ +[[nodiscard]] TER +canTransfer( + ReadView const& view, + MPTIssue const& mptIssue, + AccountID const& from, + AccountID const& to); + +//------------------------------------------------------------------------------ +// +// Empty holding operations (MPT-specific) +// +//------------------------------------------------------------------------------ + +[[nodiscard]] TER +addEmptyHolding( + ApplyView& view, + AccountID const& accountID, + XRPAmount priorBalance, + MPTIssue const& mptIssue, + beast::Journal journal); + +[[nodiscard]] TER +removeEmptyHolding( + ApplyView& view, + AccountID const& accountID, + MPTIssue const& mptIssue, + beast::Journal journal); + +//------------------------------------------------------------------------------ +// +// Escrow operations (MPT-specific) +// +//------------------------------------------------------------------------------ + +TER +rippleLockEscrowMPT( + ApplyView& view, + AccountID const& uGrantorID, + STAmount const& saAmount, + beast::Journal j); + +TER +rippleUnlockEscrowMPT( + ApplyView& view, + AccountID const& uGrantorID, + AccountID const& uGranteeID, + STAmount const& netAmount, + STAmount const& grossAmount, + beast::Journal j); + +} // namespace xrpl diff --git a/include/xrpl/ledger/helpers/OfferHelpers.h b/include/xrpl/ledger/helpers/OfferHelpers.h new file mode 100644 index 0000000000..9096071811 --- /dev/null +++ b/include/xrpl/ledger/helpers/OfferHelpers.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include + +#include + +namespace xrpl { + +/** Delete an offer. + + Requirements: + The offer must exist. + The caller must have already checked permissions. + + @param view The ApplyView to modify. + @param sle The offer to delete. + @param j Journal for logging. + + @return tesSUCCESS on success, otherwise an error code. +*/ +// [[nodiscard]] // nodiscard commented out so Flow, BookTip and others compile. +TER +offerDelete(ApplyView& view, std::shared_ptr const& sle, beast::Journal j); + +} // namespace xrpl diff --git a/include/xrpl/ledger/helpers/RippleStateHelpers.h b/include/xrpl/ledger/helpers/RippleStateHelpers.h new file mode 100644 index 0000000000..3feba59d1f --- /dev/null +++ b/include/xrpl/ledger/helpers/RippleStateHelpers.h @@ -0,0 +1,255 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//------------------------------------------------------------------------------ +// +// RippleState (Trustline) helpers +// +//------------------------------------------------------------------------------ + +namespace xrpl { + +//------------------------------------------------------------------------------ +// +// Credit functions (from Credit.h) +// +//------------------------------------------------------------------------------ + +/** Calculate the maximum amount of IOUs that an account can hold + @param view the ledger to check against. + @param account the account of interest. + @param issuer the issuer of the IOU. + @param currency the IOU to check. + @return The maximum amount that can be held. +*/ +/** @{ */ +STAmount +creditLimit( + ReadView const& view, + AccountID const& account, + AccountID const& issuer, + Currency const& currency); + +IOUAmount +creditLimit2(ReadView const& v, AccountID const& acc, AccountID const& iss, Currency const& cur); +/** @} */ + +/** Returns the amount of IOUs issued by issuer that are held by an account + @param view the ledger to check against. + @param account the account of interest. + @param issuer the issuer of the IOU. + @param currency the IOU to check. +*/ +/** @{ */ +STAmount +creditBalance( + ReadView const& view, + AccountID const& account, + AccountID const& issuer, + Currency const& currency); +/** @} */ + +//------------------------------------------------------------------------------ +// +// Freeze checking (IOU-specific) +// +//------------------------------------------------------------------------------ + +[[nodiscard]] bool +isIndividualFrozen( + ReadView const& view, + AccountID const& account, + Currency const& currency, + AccountID const& issuer); + +[[nodiscard]] inline bool +isIndividualFrozen(ReadView const& view, AccountID const& account, Issue const& issue) +{ + return isIndividualFrozen(view, account, issue.currency, issue.account); +} + +[[nodiscard]] bool +isFrozen( + ReadView const& view, + AccountID const& account, + Currency const& currency, + AccountID const& issuer); + +[[nodiscard]] inline bool +isFrozen(ReadView const& view, AccountID const& account, Issue const& issue) +{ + return isFrozen(view, account, issue.currency, issue.account); +} + +// Overload with depth parameter for uniformity with MPTIssue version. +// The depth parameter is ignored for IOUs since they don't have vault recursion. +[[nodiscard]] inline bool +isFrozen(ReadView const& view, AccountID const& account, Issue const& issue, int /*depth*/) +{ + return isFrozen(view, account, issue); +} + +[[nodiscard]] bool +isDeepFrozen( + ReadView const& view, + AccountID const& account, + Currency const& currency, + AccountID const& issuer); + +[[nodiscard]] inline bool +isDeepFrozen( + ReadView const& view, + AccountID const& account, + Issue const& issue, + int = 0 /*ignored*/) +{ + return isDeepFrozen(view, account, issue.currency, issue.account); +} + +[[nodiscard]] inline TER +checkDeepFrozen(ReadView const& view, AccountID const& account, Issue const& issue) +{ + return isDeepFrozen(view, account, issue) ? (TER)tecFROZEN : (TER)tesSUCCESS; +} + +//------------------------------------------------------------------------------ +// +// Trust line operations +// +//------------------------------------------------------------------------------ + +/** Create a trust line + + This can set an initial balance. +*/ +[[nodiscard]] TER +trustCreate( + ApplyView& view, + bool const bSrcHigh, + AccountID const& uSrcAccountID, + AccountID const& uDstAccountID, + uint256 const& uIndex, // --> ripple state entry + SLE::ref sleAccount, // --> the account being set. + bool const bAuth, // --> authorize account. + bool const bNoRipple, // --> others cannot ripple through + bool const bFreeze, // --> funds cannot leave + bool bDeepFreeze, // --> can neither receive nor send funds + STAmount const& saBalance, // --> balance of account being set. + // Issuer should be noAccount() + STAmount const& saLimit, // --> limit for account being set. + // Issuer should be the account being set. + std::uint32_t uQualityIn, + std::uint32_t uQualityOut, + beast::Journal j); + +[[nodiscard]] TER +trustDelete( + ApplyView& view, + std::shared_ptr const& sleRippleState, + AccountID const& uLowAccountID, + AccountID const& uHighAccountID, + beast::Journal j); + +//------------------------------------------------------------------------------ +// +// IOU issuance/redemption +// +//------------------------------------------------------------------------------ + +[[nodiscard]] TER +issueIOU( + ApplyView& view, + AccountID const& account, + STAmount const& amount, + Issue const& issue, + beast::Journal j); + +[[nodiscard]] TER +redeemIOU( + ApplyView& view, + AccountID const& account, + STAmount const& amount, + Issue const& issue, + beast::Journal j); + +//------------------------------------------------------------------------------ +// +// Authorization and transfer checks (IOU-specific) +// +//------------------------------------------------------------------------------ + +/** Check if the account lacks required authorization. + * + * Return tecNO_AUTH or tecNO_LINE if it does + * and tesSUCCESS otherwise. + * + * If StrongAuth then return tecNO_LINE if the RippleState doesn't exist. Return + * tecNO_AUTH if lsfRequireAuth is set on the issuer's AccountRoot, and the + * RippleState does exist, and the RippleState is not authorized. + * + * If WeakAuth then return tecNO_AUTH if lsfRequireAuth is set, and the + * RippleState exists, and is not authorized. Return tecNO_LINE if + * lsfRequireAuth is set and the RippleState doesn't exist. Consequently, if + * WeakAuth and lsfRequireAuth is *not* set, this function will return + * tesSUCCESS even if RippleState does *not* exist. + * + * The default "Legacy" auth type is equivalent to WeakAuth. + */ +[[nodiscard]] TER +requireAuth( + ReadView const& view, + Issue const& issue, + AccountID const& account, + AuthType authType = AuthType::Legacy); + +/** Check if the destination account is allowed + * to receive IOU. Return terNO_RIPPLE if rippling is + * disabled on both sides and tesSUCCESS otherwise. + */ +[[nodiscard]] TER +canTransfer(ReadView const& view, Issue const& issue, AccountID const& from, AccountID const& to); + +//------------------------------------------------------------------------------ +// +// Empty holding operations (IOU-specific) +// +//------------------------------------------------------------------------------ + +/// Any transactors that call addEmptyHolding() in doApply must call +/// canAddHolding() in preflight with the same View and Asset +[[nodiscard]] TER +addEmptyHolding( + ApplyView& view, + AccountID const& accountID, + XRPAmount priorBalance, + Issue const& issue, + beast::Journal journal); + +[[nodiscard]] TER +removeEmptyHolding( + ApplyView& view, + AccountID const& accountID, + Issue const& issue, + beast::Journal journal); + +/** Delete trustline to AMM. The passed `sle` must be obtained from a prior + * call to view.peek(). Fail if neither side of the trustline is AMM or + * if ammAccountID is seated and is not one of the trustline's side. + */ +[[nodiscard]] TER +deleteAMMTrustLine( + ApplyView& view, + std::shared_ptr sleState, + std::optional const& ammAccountID, + beast::Journal j); + +} // namespace xrpl diff --git a/include/xrpl/ledger/helpers/TokenHelpers.h b/include/xrpl/ledger/helpers/TokenHelpers.h new file mode 100644 index 0000000000..74d1e4848e --- /dev/null +++ b/include/xrpl/ledger/helpers/TokenHelpers.h @@ -0,0 +1,286 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace xrpl { + +//------------------------------------------------------------------------------ +// +// Enums for token handling +// +//------------------------------------------------------------------------------ + +/** Controls the treatment of frozen account balances */ +enum FreezeHandling { fhIGNORE_FREEZE, fhZERO_IF_FROZEN }; + +/** Controls the treatment of unauthorized MPT balances */ +enum AuthHandling { ahIGNORE_AUTH, ahZERO_IF_UNAUTHORIZED }; + +/** Controls whether to include the account's full spendable balance */ +enum SpendableHandling { shSIMPLE_BALANCE, shFULL_BALANCE }; + +enum class WaiveTransferFee : bool { No = false, Yes }; + +/* Check if MPToken (for MPT) or trust line (for IOU) exists: + * - StrongAuth - before checking if authorization is required + * - WeakAuth + * for MPT - after checking lsfMPTRequireAuth flag + * for IOU - do not check if trust line exists + * - Legacy + * for MPT - before checking lsfMPTRequireAuth flag i.e. same as StrongAuth + * for IOU - do not check if trust line exists i.e. same as WeakAuth + */ +enum class AuthType { StrongAuth, WeakAuth, Legacy }; + +//------------------------------------------------------------------------------ +// +// Freeze checking (Asset-based dispatchers) +// +//------------------------------------------------------------------------------ + +[[nodiscard]] bool +isGlobalFrozen(ReadView const& view, Asset const& asset); + +[[nodiscard]] bool +isIndividualFrozen(ReadView const& view, AccountID const& account, Asset const& asset); + +/** + * isFrozen check is recursive for MPT shares in a vault, descending to + * assets in the vault, up to maxAssetCheckDepth recursion depth. This is + * purely defensive, as we currently do not allow such vaults to be created. + */ +[[nodiscard]] bool +isFrozen(ReadView const& view, AccountID const& account, Asset const& asset, int depth = 0); + +[[nodiscard]] TER +checkFrozen(ReadView const& view, AccountID const& account, Issue const& issue); + +[[nodiscard]] TER +checkFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue); + +[[nodiscard]] TER +checkFrozen(ReadView const& view, AccountID const& account, Asset const& asset); + +[[nodiscard]] bool +isAnyFrozen( + ReadView const& view, + std::initializer_list const& accounts, + Issue const& issue); + +[[nodiscard]] bool +isAnyFrozen( + ReadView const& view, + std::initializer_list const& accounts, + Asset const& asset, + int depth = 0); + +[[nodiscard]] bool +isDeepFrozen( + ReadView const& view, + AccountID const& account, + MPTIssue const& mptIssue, + int depth = 0); + +/** + * isFrozen check is recursive for MPT shares in a vault, descending to + * assets in the vault, up to maxAssetCheckDepth recursion depth. This is + * purely defensive, as we currently do not allow such vaults to be created. + */ +[[nodiscard]] bool +isDeepFrozen(ReadView const& view, AccountID const& account, Asset const& asset, int depth = 0); + +[[nodiscard]] TER +checkDeepFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue); + +[[nodiscard]] TER +checkDeepFrozen(ReadView const& view, AccountID const& account, Asset const& asset); + +//------------------------------------------------------------------------------ +// +// Account balance functions (Asset-based dispatchers) +// +//------------------------------------------------------------------------------ + +// Returns the amount an account can spend. +// +// If shSIMPLE_BALANCE is specified, this is the amount the account can spend +// without going into debt. +// +// If shFULL_BALANCE is specified, this is the amount the account can spend +// total. Specifically: +// * The account can go into debt if using a trust line, and the other side has +// a non-zero limit. +// * If the account is the asset issuer the limit is defined by the asset / +// issuance. +// +// <-- saAmount: amount of currency held by account. May be negative. +[[nodiscard]] STAmount +accountHolds( + ReadView const& view, + AccountID const& account, + Currency const& currency, + AccountID const& issuer, + FreezeHandling zeroIfFrozen, + beast::Journal j, + SpendableHandling includeFullBalance = shSIMPLE_BALANCE); + +[[nodiscard]] STAmount +accountHolds( + ReadView const& view, + AccountID const& account, + Issue const& issue, + FreezeHandling zeroIfFrozen, + beast::Journal j, + SpendableHandling includeFullBalance = shSIMPLE_BALANCE); + +[[nodiscard]] STAmount +accountHolds( + ReadView const& view, + AccountID const& account, + MPTIssue const& mptIssue, + FreezeHandling zeroIfFrozen, + AuthHandling zeroIfUnauthorized, + beast::Journal j, + SpendableHandling includeFullBalance = shSIMPLE_BALANCE); + +[[nodiscard]] STAmount +accountHolds( + ReadView const& view, + AccountID const& account, + Asset const& asset, + FreezeHandling zeroIfFrozen, + AuthHandling zeroIfUnauthorized, + beast::Journal j, + SpendableHandling includeFullBalance = shSIMPLE_BALANCE); + +// Returns the amount an account can spend of the currency type saDefault, or +// returns saDefault if this account is the issuer of the currency in +// question. Should be used in favor of accountHolds when questioning how much +// an account can spend while also allowing currency issuers to spend +// unlimited amounts of their own currency (since they can always issue more). +[[nodiscard]] STAmount +accountFunds( + ReadView const& view, + AccountID const& id, + STAmount const& saDefault, + FreezeHandling freezeHandling, + beast::Journal j); + +/** Returns the transfer fee as Rate based on the type of token + * @param view The ledger view + * @param amount The amount to transfer + */ +[[nodiscard]] Rate +transferRate(ReadView const& view, STAmount const& amount); + +//------------------------------------------------------------------------------ +// +// Holding operations (Asset-based dispatchers) +// +//------------------------------------------------------------------------------ + +[[nodiscard]] TER +canAddHolding(ReadView const& view, Asset const& asset); + +[[nodiscard]] TER +addEmptyHolding( + ApplyView& view, + AccountID const& accountID, + XRPAmount priorBalance, + Asset const& asset, + beast::Journal journal); + +[[nodiscard]] TER +removeEmptyHolding( + ApplyView& view, + AccountID const& accountID, + Asset const& asset, + beast::Journal journal); + +//------------------------------------------------------------------------------ +// +// Authorization and transfer checks (Asset-based dispatchers) +// +//------------------------------------------------------------------------------ + +[[nodiscard]] TER +requireAuth( + ReadView const& view, + Asset const& asset, + AccountID const& account, + AuthType authType = AuthType::Legacy); + +[[nodiscard]] TER +canTransfer(ReadView const& view, Asset const& asset, AccountID const& from, AccountID const& to); + +//------------------------------------------------------------------------------ +// +// Money Transfers (Asset-based dispatchers) +// +//------------------------------------------------------------------------------ + +// Direct send w/o fees: +// - Redeeming IOUs and/or sending sender's own IOUs. +// - Create trust line of needed. +// --> bCheckIssuer : normally require issuer to be involved. +// [[nodiscard]] // nodiscard commented out so DirectStep.cpp compiles. + +/** Calls static rippleCreditIOU if saAmount represents Issue. + * Calls static rippleCreditMPT if saAmount represents MPTIssue. + */ +TER +rippleCredit( + ApplyView& view, + AccountID const& uSenderID, + AccountID const& uReceiverID, + STAmount const& saAmount, + bool bCheckIssuer, + beast::Journal j); + +/** Calls static accountSendIOU if saAmount represents Issue. + * Calls static accountSendMPT if saAmount represents MPTIssue. + */ +[[nodiscard]] TER +accountSend( + ApplyView& view, + AccountID const& from, + AccountID const& to, + STAmount const& saAmount, + beast::Journal j, + WaiveTransferFee waiveFee = WaiveTransferFee::No); + +using MultiplePaymentDestinations = std::vector>; +/** Like accountSend, except one account is sending multiple payments (with the + * same asset!) simultaneously + * + * Calls static accountSendMultiIOU if saAmount represents Issue. + * Calls static accountSendMultiMPT if saAmount represents MPTIssue. + */ +[[nodiscard]] TER +accountSendMulti( + ApplyView& view, + AccountID const& senderID, + Asset const& asset, + MultiplePaymentDestinations const& receivers, + beast::Journal j, + WaiveTransferFee waiveFee = WaiveTransferFee::No); + +[[nodiscard]] TER +transferXRP( + ApplyView& view, + AccountID const& from, + AccountID const& to, + STAmount const& amount, + beast::Journal j); + +} // namespace xrpl diff --git a/include/xrpl/ledger/helpers/VaultHelpers.h b/include/xrpl/ledger/helpers/VaultHelpers.h new file mode 100644 index 0000000000..8aef30aa27 --- /dev/null +++ b/include/xrpl/ledger/helpers/VaultHelpers.h @@ -0,0 +1,81 @@ +#pragma once + +#include +#include + +#include +#include + +namespace xrpl { + +/** From the perspective of a vault, return the number of shares to give + depositor when they offer a fixed amount of assets. Note, since shares are + MPT, this number is integral and always truncated in this calculation. + + @param vault The vault SLE. + @param issuance The MPTokenIssuance SLE for the vault's shares. + @param assets The amount of assets to convert. + + @return The number of shares, or nullopt on error. +*/ +[[nodiscard]] std::optional +assetsToSharesDeposit( + std::shared_ptr const& vault, + std::shared_ptr const& issuance, + STAmount const& assets); + +/** From the perspective of a vault, return the number of assets to take from + depositor when they receive a fixed amount of shares. Note, since shares are + MPT, they are always an integral number. + + @param vault The vault SLE. + @param issuance The MPTokenIssuance SLE for the vault's shares. + @param shares The amount of shares to convert. + + @return The number of assets, or nullopt on error. +*/ +[[nodiscard]] std::optional +sharesToAssetsDeposit( + std::shared_ptr const& vault, + std::shared_ptr const& issuance, + STAmount const& shares); + +/** Controls whether to truncate shares instead of rounding. */ +enum class TruncateShares : bool { no = false, yes = true }; + +/** From the perspective of a vault, return the number of shares to demand from + the depositor when they ask to withdraw a fixed amount of assets. Since + shares are MPT this number is integral, and it will be rounded to nearest + unless explicitly requested to be truncated instead. + + @param vault The vault SLE. + @param issuance The MPTokenIssuance SLE for the vault's shares. + @param assets The amount of assets to convert. + @param truncate Whether to truncate instead of rounding. + + @return The number of shares, or nullopt on error. +*/ +[[nodiscard]] std::optional +assetsToSharesWithdraw( + std::shared_ptr const& vault, + std::shared_ptr const& issuance, + STAmount const& assets, + TruncateShares truncate = TruncateShares::no); + +/** From the perspective of a vault, return the number of assets to give the + depositor when they redeem a fixed amount of shares. Note, since shares are + MPT, they are always an integral number. + + @param vault The vault SLE. + @param issuance The MPTokenIssuance SLE for the vault's shares. + @param shares The amount of shares to convert. + + @return The number of assets, or nullopt on error. +*/ +[[nodiscard]] std::optional +sharesToAssetsWithdraw( + std::shared_ptr const& vault, + std::shared_ptr const& issuance, + STAmount const& shares); + +} // namespace xrpl 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/Permissions.h b/include/xrpl/protocol/Permissions.h index 65861addc7..0ec4f04f1a 100644 --- a/include/xrpl/protocol/Permissions.h +++ b/include/xrpl/protocol/Permissions.h @@ -72,12 +72,12 @@ public: isDelegable(std::uint32_t const& permissionValue, Rules const& rules) const; // for tx level permission, permission value is equal to tx type plus one - uint32_t - txToPermissionType(TxType const& type) const; + static uint32_t + txToPermissionType(TxType const& type); // tx type value is permission value minus one - TxType - permissionToTxType(uint32_t const& value) const; + static TxType + permissionToTxType(uint32_t const& value); }; } // namespace xrpl diff --git a/include/xrpl/protocol/STVector256.h b/include/xrpl/protocol/STVector256.h index dd77067b7c..815224def2 100644 --- a/include/xrpl/protocol/STVector256.h +++ b/include/xrpl/protocol/STVector256.h @@ -69,9 +69,6 @@ public: std::vector::iterator insert(std::vector::const_iterator pos, uint256 const& value); - std::vector::iterator - insert(std::vector::const_iterator pos, uint256&& value); - void push_back(uint256 const& v); @@ -184,12 +181,6 @@ STVector256::insert(std::vector::const_iterator pos, uint256 const& val return mValue.insert(pos, value); } -inline std::vector::iterator -STVector256::insert(std::vector::const_iterator pos, uint256&& value) -{ - return mValue.insert(pos, std::move(value)); -} - inline void STVector256::push_back(uint256 const& v) { diff --git a/include/xrpl/protocol/Serializer.h b/include/xrpl/protocol/Serializer.h index 98cefb4d08..75f5dbdf96 100644 --- a/include/xrpl/protocol/Serializer.h +++ b/include/xrpl/protocol/Serializer.h @@ -336,7 +336,7 @@ public: static_assert(N > 0, ""); } - std::size_t + [[nodiscard]] bool empty() const noexcept { return remain_ == 0; diff --git a/include/xrpl/protocol/TxSearched.h b/include/xrpl/protocol/TxSearched.h index e085bff315..71bd75005b 100644 --- a/include/xrpl/protocol/TxSearched.h +++ b/include/xrpl/protocol/TxSearched.h @@ -2,6 +2,6 @@ namespace xrpl { -enum class TxSearched { all, some, unknown }; +enum class TxSearched { All, Some, Unknown }; } 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..bd7b9ca803 100644 --- a/include/xrpl/rdb/DatabaseCon.h +++ b/include/xrpl/rdb/DatabaseCon.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -69,7 +70,7 @@ public: { explicit Setup() = default; - StartUpType startUp = StartUpType::NORMAL; + StartUpType startUp = StartUpType::Normal; bool standAlone = false; boost::filesystem::path dataDir; // Indicates whether or not to return the `globalPragma` @@ -94,7 +95,7 @@ public: struct CheckpointerSetup { JobQueue* jobQueue; - Logs* logs; + std::reference_wrapper registry; }; template @@ -106,9 +107,8 @@ public: beast::Journal journal) // Use temporary files or regular DB files? : DatabaseCon( - setup.standAlone && setup.startUp != StartUpType::LOAD && - setup.startUp != StartUpType::LOAD_FILE && - setup.startUp != StartUpType::REPLAY + setup.standAlone && setup.startUp != StartUpType::Load && + setup.startUp != StartUpType::LoadFile && setup.startUp != StartUpType::Replay ? "" : (setup.dataDir / dbName), setup.commonPragma(), @@ -129,7 +129,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 +154,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 +177,7 @@ public: private: void - setupCheckpointing(JobQueue*, Logs&); + setupCheckpointing(JobQueue*, ServiceRegistry&); template DatabaseCon( diff --git a/include/xrpl/rdb/RelationalDatabase.h b/include/xrpl/rdb/RelationalDatabase.h index e728e518aa..56c20e4263 100644 --- a/include/xrpl/rdb/RelationalDatabase.h +++ b/include/xrpl/rdb/RelationalDatabase.h @@ -49,8 +49,9 @@ public: struct AccountTxOptions { AccountID const& account; - std::uint32_t minLedger; - std::uint32_t maxLedger; + /// Ledger sequence range to search. A value of 0 for min or max + /// means unbounded in that direction (no constraint applied). + LedgerRange ledgerRange; std::uint32_t offset; std::uint32_t limit; bool bUnlimited; @@ -59,8 +60,7 @@ public: struct AccountTxPageOptions { AccountID const& account; - std::uint32_t minLedger; - std::uint32_t maxLedger; + LedgerRange ledgerRange; std::optional marker; std::uint32_t limit; bool bAdmin; @@ -247,7 +247,7 @@ public: * @return Struct CountMinMax which contains the minimum sequence, * maximum sequence and number of ledgers. */ - virtual struct CountMinMax + virtual CountMinMax getLedgerCountMinMax() = 0; /** @@ -405,10 +405,10 @@ public: * @param id Hash of the transaction. * @param range Range of ledgers to check, if present. * @param ec Default error code value. - * @return Transaction and its metadata if found, otherwise TxSearched::all + * @return Transaction and its metadata if found, otherwise TxSearched::All * if a range is provided and all ledgers from the range are present - * in the database, TxSearched::some if a range is provided and not - * all ledgers are present, TxSearched::unknown if the range is not + * in the database, TxSearched::Some if a range is provided and not + * all ledgers are present, TxSearched::Unknown if the range is not * provided or a deserializing error occurred. In the last case the * error code is returned via the ec parameter, in other cases the * default error code is not changed. @@ -455,9 +455,10 @@ public: closeTransactionDB() = 0; }; -template +template T rangeCheckedCast(C c) + requires(std::is_arithmetic_v && std::is_arithmetic_v && std::convertible_to) { if ((c > std::numeric_limits::max()) || (!std::numeric_limits::is_signed && c < 0) || (std::numeric_limits::is_signed && std::numeric_limits::is_signed && 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/shamap/SHAMap.h b/include/xrpl/shamap/SHAMap.h index 2c0910a830..213e7ce0ce 100644 --- a/include/xrpl/shamap/SHAMap.h +++ b/include/xrpl/shamap/SHAMap.h @@ -520,7 +520,7 @@ private: // getMissingNodes helper functions void gmn_ProcessNodes(MissingNodes&, MissingNodes::StackEntry& node); - void + static void gmn_ProcessDeferredReads(MissingNodes&); // fetch from DB helper function diff --git a/include/xrpl/tx/ApplyContext.h b/include/xrpl/tx/ApplyContext.h index 9e382556c2..6341c0bcc5 100644 --- a/include/xrpl/tx/ApplyContext.h +++ b/include/xrpl/tx/ApplyContext.h @@ -37,7 +37,7 @@ public: XRPL_ASSERT((flags & tapBATCH) == 0, "Batch apply flag should not be set"); } - ServiceRegistry& registry; + std::reference_wrapper registry; STTx const& tx; TER const preclaimResult; XRPAmount const baseFee; @@ -111,7 +111,7 @@ public: checkInvariants(TER const result, XRPAmount const fee); private: - TER + static TER failInvariantCheck(TER const result); template diff --git a/include/xrpl/tx/Transactor.h b/include/xrpl/tx/Transactor.h index 86ba6f4d1f..0e89a5aca8 100644 --- a/include/xrpl/tx/Transactor.h +++ b/include/xrpl/tx/Transactor.h @@ -13,7 +13,7 @@ namespace xrpl { struct PreflightContext { public: - ServiceRegistry& registry; + std::reference_wrapper registry; STTx const& tx; Rules const rules; ApplyFlags flags; @@ -56,7 +56,7 @@ public: struct PreclaimContext { public: - ServiceRegistry& registry; + std::reference_wrapper registry; ReadView const& view; TER preflightResult; ApplyFlags flags; diff --git a/include/xrpl/tx/invariants/FreezeInvariant.h b/include/xrpl/tx/invariants/FreezeInvariant.h index ac9d83166e..645f444462 100644 --- a/include/xrpl/tx/invariants/FreezeInvariant.h +++ b/include/xrpl/tx/invariants/FreezeInvariant.h @@ -48,7 +48,7 @@ private: bool isValidEntry(std::shared_ptr const& before, std::shared_ptr const& after); - STAmount + static STAmount calculateBalanceChange( std::shared_ptr const& before, std::shared_ptr const& after, @@ -63,7 +63,7 @@ private: std::shared_ptr findIssuer(AccountID const& issuerID, ReadView const& view); - bool + static bool validateIssuerChanges( std::shared_ptr const& issuer, IssuerChanges const& changes, @@ -71,7 +71,7 @@ private: beast::Journal const& j, bool enforce); - bool + static bool validateFrozenState( BalanceChange const& change, bool high, diff --git a/include/xrpl/tx/invariants/InvariantCheck.h b/include/xrpl/tx/invariants/InvariantCheck.h index e0ad65f14c..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 @@ -111,7 +112,7 @@ public: void visitEntry(bool, std::shared_ptr const&, std::shared_ptr const&); - bool + static bool finalize(STTx const&, TER const, XRPAmount const, ReadView const&, beast::Journal const&); }; 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 be771cd582..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_; - - bool - goodZeroDirectory(ReadView const& view, SLE::const_ref dir, beast::Journal const& j) const; - -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 98% rename from src/xrpld/app/paths/AMMOffer.h rename to include/xrpl/tx/paths/AMMOffer.h index ebaa7311c0..aa6132dfce 100644 --- a/src/xrpld/app/paths/AMMOffer.h +++ b/include/xrpl/tx/paths/AMMOffer.h @@ -2,6 +2,7 @@ #include #include +#include #include #include 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/include/xrpl/tx/paths/detail/StrandFlow.h b/include/xrpl/tx/paths/detail/StrandFlow.h index 67e333f2e6..2a94b9b968 100644 --- a/include/xrpl/tx/paths/detail/StrandFlow.h +++ b/include/xrpl/tx/paths/detail/StrandFlow.h @@ -1,7 +1,9 @@ #pragma once #include -#include +#include +#include +#include #include #include #include diff --git a/include/xrpl/tx/transactors/dex/AMMHelpers.h b/include/xrpl/tx/transactors/dex/AMMHelpers.h index e2735ea80f..6e3957769f 100644 --- a/include/xrpl/tx/transactors/dex/AMMHelpers.h +++ b/include/xrpl/tx/transactors/dex/AMMHelpers.h @@ -203,7 +203,7 @@ getAMMOfferStartWithTakerGets( // Try to reduce the offer size to improve the quality. // The quality might still not match the targetQuality for a tiny offer. - if (auto const amounts = getAmounts(*nTakerGets); Quality{amounts} < targetQuality) + if (auto amounts = getAmounts(*nTakerGets); Quality{amounts} < targetQuality) return getAmounts(detail::reduceOffer(amounts.out)); else return amounts; @@ -270,7 +270,7 @@ getAMMOfferStartWithTakerPays( // Try to reduce the offer size to improve the quality. // The quality might still not match the targetQuality for a tiny offer. - if (auto const amounts = getAmounts(*nTakerPays); Quality{amounts} < targetQuality) + if (auto amounts = getAmounts(*nTakerPays); Quality{amounts} < targetQuality) return getAmounts(detail::reduceOffer(amounts.in)); else return amounts; @@ -335,8 +335,7 @@ changeSpotPriceQuality( } auto const takerPays = toAmount(getIssue(pool.in), nTakerPays, Number::upward); // should not fail - if (auto const amounts = - TAmounts{takerPays, swapAssetIn(pool, takerPays, tfee)}; + if (auto amounts = TAmounts{takerPays, swapAssetIn(pool, takerPays, tfee)}; Quality{amounts} < quality && !withinRelativeDistance(Quality{amounts}, quality, Number(1, -7))) { @@ -362,7 +361,7 @@ changeSpotPriceQuality( // Generate the offer starting with XRP side. Return seated offer amounts // if the offer can be generated, otherwise nullopt. - auto const amounts = [&]() { + auto amounts = [&]() { if (isXRP(getIssue(pool.out))) return getAMMOfferStartWithTakerGets(pool, quality, tfee); return getAMMOfferStartWithTakerPays(pool, quality, tfee); diff --git a/include/xrpl/tx/transactors/dex/AMMUtils.h b/include/xrpl/tx/transactors/dex/AMMUtils.h index 18db7e6555..77ad18106e 100644 --- a/include/xrpl/tx/transactors/dex/AMMUtils.h +++ b/include/xrpl/tx/transactors/dex/AMMUtils.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include diff --git a/include/xrpl/tx/transactors/dex/AMMWithdraw.h b/include/xrpl/tx/transactors/dex/AMMWithdraw.h index 9da17c828d..e8cd558227 100644 --- a/include/xrpl/tx/transactors/dex/AMMWithdraw.h +++ b/include/xrpl/tx/transactors/dex/AMMWithdraw.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include namespace xrpl { diff --git a/src/libxrpl/basics/FileUtilities.cpp b/src/libxrpl/basics/FileUtilities.cpp index 0f636276da..73f2c2f10d 100644 --- a/src/libxrpl/basics/FileUtilities.cpp +++ b/src/libxrpl/basics/FileUtilities.cpp @@ -45,7 +45,7 @@ getFileContents( return {}; } - std::string const result{ + std::string result{ std::istreambuf_iterator{fileStream}, std::istreambuf_iterator{}}; if (fileStream.bad()) diff --git a/src/libxrpl/basics/Number.cpp b/src/libxrpl/basics/Number.cpp index b520261ffe..f0655cd8a9 100644 --- a/src/libxrpl/basics/Number.cpp +++ b/src/libxrpl/basics/Number.cpp @@ -981,7 +981,7 @@ root(Number f, unsigned d) auto ex = [e = e, di = di]() // Euclidean remainder of e/d { int k = (e >= 0 ? e : e - (di - 1)) / di; - int k2 = e - k * di; + int k2 = e - (k * di); if (k2 == 0) return 0; return di - k2; @@ -998,7 +998,7 @@ root(Number f, unsigned d) } // Quadratic least squares curve fit of f^(1/d) in the range [0, 1] - auto const D = ((6 * di + 11) * di + 6) * di + 1; + auto const D = (((6 * di + 11) * di + 6) * di) + 1; auto const a0 = 3 * di * ((2 * di - 3) * di + 1); auto const a1 = 24 * di * (2 * di - 1); auto const a2 = -30 * (di - 1) * di; diff --git a/src/libxrpl/basics/ResolverAsio.cpp b/src/libxrpl/basics/ResolverAsio.cpp index b746092645..aa1cb1470d 100644 --- a/src/libxrpl/basics/ResolverAsio.cpp +++ b/src/libxrpl/basics/ResolverAsio.cpp @@ -169,7 +169,7 @@ public: XRPL_ASSERT(m_stopped == true, "xrpl::ResolverAsioImpl::start : stopped"); XRPL_ASSERT(m_stop_called == false, "xrpl::ResolverAsioImpl::start : not stopping"); - if (m_stopped.exchange(false) == true) + if (m_stopped.exchange(false)) { { std::lock_guard lk{m_mut}; @@ -182,7 +182,7 @@ public: void stop_async() override { - if (m_stop_called.exchange(true) == false) + if (!m_stop_called.exchange(true)) { boost::asio::dispatch( m_io_context, @@ -229,7 +229,7 @@ public: { XRPL_ASSERT(m_stop_called == true, "xrpl::ResolverAsioImpl::do_stop : stopping"); - if (m_stopped.exchange(true) == false) + if (!m_stopped.exchange(true)) { m_work.clear(); m_resolver.cancel(); @@ -271,7 +271,7 @@ public: m_strand, std::bind(&ResolverAsioImpl::do_work, this, CompletionCounter(this)))); } - HostAndPort + static HostAndPort parseName(std::string const& str) { // first attempt to parse as an endpoint (IP addr + port). @@ -319,7 +319,7 @@ public: void do_work(CompletionCounter) { - if (m_stop_called == true) + if (m_stop_called) return; // We don't have any work to do at this time @@ -367,7 +367,7 @@ public: { XRPL_ASSERT(!names.empty(), "xrpl::ResolverAsioImpl::do_resolve : names non-empty"); - if (m_stop_called == false) + if (!m_stop_called) { m_work.emplace_back(names, handler); diff --git a/src/libxrpl/basics/StringUtilities.cpp b/src/libxrpl/basics/StringUtilities.cpp index 0dd466c9b4..c47618db82 100644 --- a/src/libxrpl/basics/StringUtilities.cpp +++ b/src/libxrpl/basics/StringUtilities.cpp @@ -24,7 +24,7 @@ sqlBlobLiteral(Blob const& blob) { std::string j; - j.reserve(blob.size() * 2 + 3); + j.reserve((blob.size() * 2) + 3); j.push_back('X'); j.push_back('\''); boost::algorithm::hex(blob.begin(), blob.end(), std::back_inserter(j)); diff --git a/src/libxrpl/basics/base64.cpp b/src/libxrpl/basics/base64.cpp index 31888ec99c..a510fbf6c9 100644 --- a/src/libxrpl/basics/base64.cpp +++ b/src/libxrpl/basics/base64.cpp @@ -107,7 +107,7 @@ encode(void* dest, void const* src, std::size_t len) char const* in = static_cast(src); auto const tab = base64::get_alphabet(); - for (auto n = len / 3; n--;) + for (auto n = len / 3; n != 0u; --n) { *out++ = tab[(in[0] & 0xfc) >> 2]; *out++ = tab[((in[0] & 0x03) << 4) + ((in[1] & 0xf0) >> 4)]; @@ -162,7 +162,7 @@ decode(void* dest, char const* src, std::size_t len) auto const inverse = base64::get_inverse(); - while (len-- && *in != '=') + while (((len--) != 0u) && *in != '=') { auto const v = inverse[*in]; if (v == -1) @@ -181,7 +181,7 @@ decode(void* dest, char const* src, std::size_t len) } } - if (i) + if (i != 0) { c3[0] = (c4[0] << 2) + ((c4[1] & 0x30) >> 4); c3[1] = ((c4[1] & 0xf) << 4) + ((c4[2] & 0x3c) >> 2); diff --git a/src/libxrpl/basics/make_SSLContext.cpp b/src/libxrpl/basics/make_SSLContext.cpp index 74aab709d8..de16e8c6cf 100644 --- a/src/libxrpl/basics/make_SSLContext.cpp +++ b/src/libxrpl/basics/make_SSLContext.cpp @@ -253,7 +253,7 @@ initAuthenticated( // VFALCO Replace fopen() with RAII FILE* f = fopen(chain_file.c_str(), "r"); - if (!f) + if (f == nullptr) { LogicError( "Problem opening SSL chain file" + diff --git a/src/libxrpl/beast/insight/StatsDCollector.cpp b/src/libxrpl/beast/insight/StatsDCollector.cpp index cc3bbf2861..83fc65e92c 100644 --- a/src/libxrpl/beast/insight/StatsDCollector.cpp +++ b/src/libxrpl/beast/insight/StatsDCollector.cpp @@ -352,7 +352,7 @@ public: } } - void + static void log(std::vector const& buffers) { (void)buffers; diff --git a/src/libxrpl/beast/net/IPAddressV6.cpp b/src/libxrpl/beast/net/IPAddressV6.cpp index a261002ed3..30e2eefb96 100644 --- a/src/libxrpl/beast/net/IPAddressV6.cpp +++ b/src/libxrpl/beast/net/IPAddressV6.cpp @@ -10,7 +10,7 @@ bool is_private(AddressV6 const& addr) { return ( - (addr.to_bytes()[0] & 0xfd) || // TODO fc00::/8 too ? + ((addr.to_bytes()[0] & 0xfd) != 0) || // TODO fc00::/8 too ? (addr.is_v4_mapped() && is_private(boost::asio::ip::make_address_v4(boost::asio::ip::v4_mapped, addr)))); } diff --git a/src/libxrpl/beast/net/IPEndpoint.cpp b/src/libxrpl/beast/net/IPEndpoint.cpp index f8352f4318..70e7bff2c5 100644 --- a/src/libxrpl/beast/net/IPEndpoint.cpp +++ b/src/libxrpl/beast/net/IPEndpoint.cpp @@ -57,7 +57,7 @@ Endpoint::to_string() const if (port() != 0 && address().is_v6()) s += '['; s += address().to_string(); - if (port()) + if (port() != 0u) { if (address().is_v6()) s += ']'; @@ -111,7 +111,7 @@ operator>>(std::istream& is, Endpoint& endpoint) // so we continue to honor that here by assuming we are at the end // of the address portion if we hit a space (or the separator // we were expecting to see) - if (isspace(static_cast(i)) || (readTo && i == readTo)) + if ((isspace(static_cast(i)) != 0) || ((readTo != 0) && i == readTo)) break; if ((i == '.') || (i >= '0' && i <= ':') || (i >= 'a' && i <= 'f') || @@ -121,13 +121,13 @@ operator>>(std::istream& is, Endpoint& endpoint) // don't exceed a reasonable length... if (addrStr.size() == INET6_ADDRSTRLEN || - (readTo && readTo == ':' && addrStr.size() > 15)) + ((readTo != 0) && readTo == ':' && addrStr.size() > 15)) { is.setstate(std::ios_base::failbit); return is; } - if (!readTo && (i == '.' || i == ':')) + if ((readTo == 0) && (i == '.' || i == ':')) { // if we see a dot first, must be IPv4 // otherwise must be non-bracketed IPv6 @@ -145,7 +145,7 @@ operator>>(std::istream& is, Endpoint& endpoint) if (readTo == ']' && is.rdbuf()->in_avail() > 0) { is.get(i); - if (!(isspace(static_cast(i)) || i == ':')) + if ((isspace(static_cast(i)) == 0) && i != ':') { is.unget(); is.setstate(std::ios_base::failbit); diff --git a/src/libxrpl/core/detail/JobQueue.cpp b/src/libxrpl/core/detail/JobQueue.cpp index 9adbf6312b..2fe5a5b0fd 100644 --- a/src/libxrpl/core/detail/JobQueue.cpp +++ b/src/libxrpl/core/detail/JobQueue.cpp @@ -84,8 +84,7 @@ JobQueue::addRefCountedJob(JobType type, std::string const& name, JobFunction co JobType const type(job.getType()); XRPL_ASSERT(type != jtINVALID, "xrpl::JobQueue::addRefCountedJob : has valid job type"); - XRPL_ASSERT( - m_jobSet.find(job) != m_jobSet.end(), "xrpl::JobQueue::addRefCountedJob : job found"); + XRPL_ASSERT(m_jobSet.contains(job), "xrpl::JobQueue::addRefCountedJob : job found"); perfLog_.jobQueue(type); JobTypeData& data(getJobTypeData(type)); diff --git a/src/libxrpl/core/detail/LoadMonitor.cpp b/src/libxrpl/core/detail/LoadMonitor.cpp index 89a364ca30..9891bdb8b8 100644 --- a/src/libxrpl/core/detail/LoadMonitor.cpp +++ b/src/libxrpl/core/detail/LoadMonitor.cpp @@ -141,7 +141,7 @@ LoadMonitor::isOver() update(); if (mLatencyEvents == 0) - return 0; + return false; return isOverTarget( mLatencyMSAvg / (mLatencyEvents * 4), mLatencyMSPeak / (mLatencyEvents * 4)); diff --git a/src/libxrpl/core/detail/Workers.cpp b/src/libxrpl/core/detail/Workers.cpp index c037169a29..21bf75b958 100644 --- a/src/libxrpl/core/detail/Workers.cpp +++ b/src/libxrpl/core/detail/Workers.cpp @@ -47,7 +47,7 @@ Workers::setNumberOfThreads(int numberOfThreads) if (m_numberOfThreads == numberOfThreads) return; - if (perfLog_) + if (perfLog_ != nullptr) perfLog_->resizeJobs(numberOfThreads); if (numberOfThreads > m_numberOfThreads) diff --git a/src/libxrpl/crypto/RFC1751.cpp b/src/libxrpl/crypto/RFC1751.cpp index f7c1e675cb..becd0aab8d 100644 --- a/src/libxrpl/crypto/RFC1751.cpp +++ b/src/libxrpl/crypto/RFC1751.cpp @@ -210,8 +210,8 @@ RFC1751::extract(char const* s, int start, int length) int const shiftR = 24 - (length + (start % 8)); cl = s[start / 8]; // get components - cc = (shiftR < 16) ? s[start / 8 + 1] : 0; - cr = (shiftR < 8) ? s[start / 8 + 2] : 0; + cc = (shiftR < 16) ? s[(start / 8) + 1] : 0; + cr = (shiftR < 8) ? s[(start / 8) + 2] : 0; x = ((long)(cl << 8 | cc) << 8 | cr); // Put bits together x = x >> shiftR; // Right justify number @@ -265,13 +265,13 @@ RFC1751::insert(char* s, int x, int start, int length) if (shift + length > 16) { s[start / 8] |= cl; - s[start / 8 + 1] |= cc; - s[start / 8 + 2] |= cr; + s[(start / 8) + 1] |= cc; + s[(start / 8) + 2] |= cr; } else if (shift + length > 8) { s[start / 8] |= cc; - s[start / 8 + 1] |= cr; + s[(start / 8) + 1] |= cr; } else { @@ -284,7 +284,7 @@ RFC1751::standard(std::string& strWord) { for (auto& letter : strWord) { - if (islower(static_cast(letter))) + if (islower(static_cast(letter)) != 0) { letter = toupper(static_cast(letter)); } @@ -312,10 +312,10 @@ RFC1751::wsrch(std::string const& strWord, int iMin, int iMax) while (iResult < 0 && iMin != iMax) { // Have a range to search. - int iMid = iMin + (iMax - iMin) / 2; + int iMid = iMin + ((iMax - iMin) / 2); int iDir = strWord.compare(s_dictionary[iMid]); - if (!iDir) + if (iDir == 0) { iResult = iMid; // Found it. } diff --git a/src/libxrpl/json/Writer.cpp b/src/libxrpl/json/Writer.cpp index 6ff5a130dd..796ec35dfd 100644 --- a/src/libxrpl/json/Writer.cpp +++ b/src/libxrpl/json/Writer.cpp @@ -152,7 +152,7 @@ public: #ifndef NDEBUG // Make sure we haven't already seen this tag. auto& tags = stack_.top().tags; - check(tags.find(tag) == tags.end(), "Already seen tag " + tag); + check(!tags.contains(tag), "Already seen tag " + tag); tags.insert(tag); #endif diff --git a/src/libxrpl/json/json_reader.cpp b/src/libxrpl/json/json_reader.cpp index 4c2a27400f..6475a5b68b 100644 --- a/src/libxrpl/json/json_reader.cpp +++ b/src/libxrpl/json/json_reader.cpp @@ -296,7 +296,7 @@ Reader::match(Location pattern, int patternLength) int index = patternLength; - while (index--) + while ((index--) != 0) { if (current_[index] != pattern[index]) return false; @@ -362,7 +362,7 @@ Reader::readNumber() while (current_ != end_) { - if (!std::isdigit(static_cast(*current_))) + if (std::isdigit(static_cast(*current_)) == 0) { auto ret = std::find(std::begin(extended_tokens), std::end(extended_tokens), *current_); @@ -913,7 +913,7 @@ Reader::getFormattedErrorMessages() const formattedMessage += "* " + getLocationLineAndColumn(error.token_.start_) + "\n"; formattedMessage += " " + error.message_ + "\n"; - if (error.extra_) + if (error.extra_ != nullptr) formattedMessage += "See " + getLocationLineAndColumn(error.extra_) + " for detail.\n"; } diff --git a/src/libxrpl/json/json_value.cpp b/src/libxrpl/json/json_value.cpp index 94b077d224..988a25a3ff 100644 --- a/src/libxrpl/json/json_value.cpp +++ b/src/libxrpl/json/json_value.cpp @@ -40,10 +40,10 @@ public: // return 0; if (length == unknown) - length = value ? (unsigned int)strlen(value) : 0; + length = (value != nullptr) ? (unsigned int)strlen(value) : 0; char* newString = static_cast(malloc(length + 1)); - if (value) + if (value != nullptr) memcpy(newString, value, length); newString[length] = 0; return newString; @@ -52,7 +52,7 @@ public: void releaseStringValue(char* value) override { - if (value) + if (value != nullptr) free(value); } }; @@ -108,14 +108,14 @@ Value::CZString::CZString(CZString const& other) Value::CZString::~CZString() { - if (cstr_ && index_ == duplicate) + if ((cstr_ != nullptr) && index_ == duplicate) valueAllocator()->releaseMemberName(const_cast(cstr_)); } bool Value::CZString::operator<(CZString const& other) const { - if (cstr_ && other.cstr_) + if ((cstr_ != nullptr) && (other.cstr_ != nullptr)) return strcmp(cstr_, other.cstr_) < 0; return index_ < other.index_; @@ -124,7 +124,7 @@ Value::CZString::operator<(CZString const& other) const bool Value::CZString::operator==(CZString const& other) const { - if (cstr_ && other.cstr_) + if ((cstr_ != nullptr) && (other.cstr_ != nullptr)) return strcmp(cstr_, other.cstr_) == 0; return index_ == other.index_; @@ -251,7 +251,7 @@ Value::Value(Value const& other) : type_(other.type_) break; case stringValue: - if (other.value_.string_) + if (other.value_.string_ != nullptr) { value_.string_ = valueAllocator()->duplicateStringValue(other.value_.string_); allocated_ = true; @@ -294,7 +294,7 @@ Value::~Value() case arrayValue: case objectValue: - if (value_.map_) + if (value_.map_ != nullptr) delete value_.map_; break; @@ -392,11 +392,11 @@ operator<(Value const& x, Value const& y) return x.value_.real_ < y.value_.real_; case booleanValue: - return x.value_.bool_ < y.value_.bool_; + return static_cast(x.value_.bool_) < static_cast(y.value_.bool_); case stringValue: - return (x.value_.string_ == 0 && y.value_.string_) || - (y.value_.string_ && x.value_.string_ && + return (x.value_.string_ == 0 && (y.value_.string_ != nullptr)) || + ((y.value_.string_ != nullptr) && (x.value_.string_ != nullptr) && strcmp(x.value_.string_, y.value_.string_) < 0); case arrayValue: @@ -413,7 +413,7 @@ operator<(Value const& x, Value const& y) // LCOV_EXCL_STOP } - return 0; // unreachable + return false; // unreachable } bool @@ -422,9 +422,9 @@ operator==(Value const& x, Value const& y) if (x.type_ != y.type_) { if (x.type_ == intValue && y.type_ == uintValue) - return !integerCmp(x.value_.int_, y.value_.uint_); + return integerCmp(x.value_.int_, y.value_.uint_) == 0; if (x.type_ == uintValue && y.type_ == intValue) - return !integerCmp(y.value_.int_, x.value_.uint_); + return integerCmp(y.value_.int_, x.value_.uint_) == 0; return false; } @@ -447,8 +447,8 @@ operator==(Value const& x, Value const& y) case stringValue: return x.value_.string_ == y.value_.string_ || - (y.value_.string_ && x.value_.string_ && - !strcmp(x.value_.string_, y.value_.string_)); + ((y.value_.string_ != nullptr) && (x.value_.string_ != nullptr) && + (strcmp(x.value_.string_, y.value_.string_) == 0)); case arrayValue: case objectValue: @@ -461,7 +461,7 @@ operator==(Value const& x, Value const& y) // LCOV_EXCL_STOP } - return 0; // unreachable + return false; // unreachable } char const* @@ -480,7 +480,7 @@ Value::asString() const return ""; case stringValue: - return value_.string_ ? value_.string_ : ""; + return (value_.string_ != nullptr) ? value_.string_ : ""; case booleanValue: return value_.bool_ ? "true" : "false"; @@ -525,7 +525,7 @@ Value::asInt() const case realValue: JSON_ASSERT_MESSAGE( - value_.real_ >= minInt && value_.real_ <= maxInt, + (value_.real_ >= minInt && value_.real_ <= maxInt), "Real out of signed integer range"); return Int(value_.real_); @@ -533,7 +533,7 @@ Value::asInt() const return value_.bool_ ? 1 : 0; case stringValue: { - char const* const str{value_.string_ ? value_.string_ : ""}; + char const* const str{(value_.string_ != nullptr) ? value_.string_ : ""}; return beast::lexicalCastThrow(str); } @@ -584,7 +584,7 @@ Value::asAbsUInt() const return value_.bool_ ? 1 : 0; case stringValue: { - char const* const str{value_.string_ ? value_.string_ : ""}; + char const* const str{(value_.string_ != nullptr) ? value_.string_ : ""}; auto const temp = beast::lexicalCastThrow(str); if (temp < 0) { @@ -626,14 +626,15 @@ Value::asUInt() const case realValue: JSON_ASSERT_MESSAGE( - value_.real_ >= 0 && value_.real_ <= maxUInt, "Real out of unsigned integer range"); + (value_.real_ >= 0 && value_.real_ <= maxUInt), + "Real out of unsigned integer range"); return UInt(value_.real_); case booleanValue: return value_.bool_ ? 1 : 0; case stringValue: { - char const* const str{value_.string_ ? value_.string_ : ""}; + char const* const str{(value_.string_ != nullptr) ? value_.string_ : ""}; return beast::lexicalCastThrow(str); } @@ -703,7 +704,7 @@ Value::asBool() const return value_.bool_; case stringValue: - return value_.string_ && value_.string_[0] != 0; + return (value_.string_ != nullptr) && value_.string_[0] != 0; case arrayValue: case objectValue: @@ -745,13 +746,13 @@ Value::isConvertibleTo(ValueType other) const other == realValue || other == stringValue || other == booleanValue; case booleanValue: - return (other == nullValue && value_.bool_ == false) || other == intValue || + return (other == nullValue && !value_.bool_) || other == intValue || other == uintValue || other == realValue || other == stringValue || other == booleanValue; case stringValue: return other == stringValue || - (other == nullValue && (!value_.string_ || value_.string_[0] == 0)); + (other == nullValue && ((value_.string_ == nullptr) || value_.string_[0] == 0)); case arrayValue: return other == arrayValue || (other == nullValue && value_.map_->empty()); @@ -813,10 +814,10 @@ operator bool() const if (isString()) { auto s = asCString(); - return s && s[0]; + return (s != nullptr) && (s[0] != 0); } - return !(isArray() || isObject()) || size(); + return !(isArray() || isObject()) || (size() != 0u); } void @@ -1139,7 +1140,7 @@ Value::begin() const { case arrayValue: case objectValue: - if (value_.map_) + if (value_.map_ != nullptr) return const_iterator(value_.map_->begin()); break; @@ -1157,7 +1158,7 @@ Value::end() const { case arrayValue: case objectValue: - if (value_.map_) + if (value_.map_ != nullptr) return const_iterator(value_.map_->end()); break; @@ -1175,7 +1176,7 @@ Value::begin() { case arrayValue: case objectValue: - if (value_.map_) + if (value_.map_ != nullptr) return iterator(value_.map_->begin()); break; default: @@ -1192,7 +1193,7 @@ Value::end() { case arrayValue: case objectValue: - if (value_.map_) + if (value_.map_ != nullptr) return iterator(value_.map_->end()); break; default: diff --git a/src/libxrpl/json/json_valueiterator.cpp b/src/libxrpl/json/json_valueiterator.cpp index e49ad50f9a..b3cf7e6538 100644 --- a/src/libxrpl/json/json_valueiterator.cpp +++ b/src/libxrpl/json/json_valueiterator.cpp @@ -89,7 +89,7 @@ ValueIteratorBase::key() const { Value::CZString const czString = (*current_).first; - if (czString.c_str()) + if (czString.c_str() != nullptr) { if (czString.isStaticString()) return Value(StaticString(czString.c_str())); @@ -105,7 +105,7 @@ ValueIteratorBase::index() const { Value::CZString const czString = (*current_).first; - if (!czString.c_str()) + if (czString.c_str() == nullptr) return czString.index(); return Value::UInt(-1); @@ -115,7 +115,7 @@ char const* ValueIteratorBase::memberName() const { char const* name = (*current_).first.c_str(); - return name ? name : ""; + return (name != nullptr) ? name : ""; } // ////////////////////////////////////////////////////////////////// diff --git a/src/libxrpl/json/json_writer.cpp b/src/libxrpl/json/json_writer.cpp index 66507f0111..b51da5bb68 100644 --- a/src/libxrpl/json/json_writer.cpp +++ b/src/libxrpl/json/json_writer.cpp @@ -23,7 +23,7 @@ isControlCharacter(char ch) static bool containsControlCharacter(char const* str) { - while (*str) + while (*str != 0) { if (isControlCharacter(*(str++))) return true; @@ -106,7 +106,7 @@ valueToQuotedString(char const* value) // We have to walk value and escape any special characters. // Appending to std::string is not efficient, but this should be rare. // (Note: forward slashes are *not* rare, but I am not escaping them.) - unsigned maxsize = strlen(value) * 2 + 3; // all-escaped+quotes+NULL + unsigned maxsize = (strlen(value) * 2) + 3; // all-escaped+quotes+NULL std::string result; result.reserve(maxsize); // to avoid lots of mallocs result += "\""; @@ -416,7 +416,7 @@ StyledWriter::isMultilineArray(Value const& value) { childValues_.reserve(size); addChildValues_ = true; - int lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]' + int lineLength = 4 + ((size - 1) * 2); // '[ ' + ', '*n + ' ]' for (int index = 0; index < size; ++index) { @@ -651,7 +651,7 @@ StyledStreamWriter::isMultilineArray(Value const& value) { childValues_.reserve(size); addChildValues_ = true; - int lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]' + int lineLength = 4 + ((size - 1) * 2); // '[ ' + ', '*n + ' ]' for (int index = 0; index < size; ++index) { diff --git a/src/libxrpl/ledger/AcceptedLedgerTx.cpp b/src/libxrpl/ledger/AcceptedLedgerTx.cpp index f0d243f9b6..005d48e6f6 100644 --- a/src/libxrpl/ledger/AcceptedLedgerTx.cpp +++ b/src/libxrpl/ledger/AcceptedLedgerTx.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include diff --git a/src/libxrpl/ledger/ApplyStateTable.cpp b/src/libxrpl/ledger/ApplyStateTable.cpp index a0074c0b53..a48c3910e1 100644 --- a/src/libxrpl/ledger/ApplyStateTable.cpp +++ b/src/libxrpl/ledger/ApplyStateTable.cpp @@ -275,9 +275,7 @@ ApplyStateTable::exists(ReadView const& base, Keylet const& k) const case Action::modify: break; } - if (!k.check(*sle)) - return false; - return true; + return k.check(*sle); } auto diff --git a/src/libxrpl/ledger/ApplyView.cpp b/src/libxrpl/ledger/ApplyView.cpp index 463b2ba538..fe2e046b26 100644 --- a/src/libxrpl/ledger/ApplyView.cpp +++ b/src/libxrpl/ledger/ApplyView.cpp @@ -36,7 +36,7 @@ findPreviousPage(ApplyView& view, Keylet const& directory, SLE::ref start) auto node = start; - if (page) + if (page != 0u) { node = view.peek(keylet::page(directory, page)); if (!node) diff --git a/src/libxrpl/ledger/BookDirs.cpp b/src/libxrpl/ledger/BookDirs.cpp index 699d6c2879..2bdf6ac9a5 100644 --- a/src/libxrpl/ledger/BookDirs.cpp +++ b/src/libxrpl/ledger/BookDirs.cpp @@ -1,5 +1,6 @@ #include #include +#include #include namespace xrpl { 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/libxrpl/ledger/Credit.cpp b/src/libxrpl/ledger/Credit.cpp deleted file mode 100644 index 0a0283c3b8..0000000000 --- a/src/libxrpl/ledger/Credit.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include -#include -#include - -namespace xrpl { - -STAmount -creditLimit( - ReadView const& view, - AccountID const& account, - AccountID const& issuer, - Currency const& currency) -{ - STAmount result(Issue{currency, account}); - - auto sleRippleState = view.read(keylet::line(account, issuer, currency)); - - if (sleRippleState) - { - result = sleRippleState->getFieldAmount(account < issuer ? sfLowLimit : sfHighLimit); - result.setIssuer(account); - } - - XRPL_ASSERT(result.getIssuer() == account, "xrpl::creditLimit : result issuer match"); - XRPL_ASSERT(result.getCurrency() == currency, "xrpl::creditLimit : result currency match"); - return result; -} - -IOUAmount -creditLimit2(ReadView const& v, AccountID const& acc, AccountID const& iss, Currency const& cur) -{ - return toAmount(creditLimit(v, acc, iss, cur)); -} - -STAmount -creditBalance( - ReadView const& view, - AccountID const& account, - AccountID const& issuer, - Currency const& currency) -{ - STAmount result(Issue{currency, account}); - - auto sleRippleState = view.read(keylet::line(account, issuer, currency)); - - if (sleRippleState) - { - result = sleRippleState->getFieldAmount(sfBalance); - if (account < issuer) - result.negate(); - result.setIssuer(account); - } - - XRPL_ASSERT(result.getIssuer() == account, "xrpl::creditBalance : result issuer match"); - XRPL_ASSERT(result.getCurrency() == currency, "xrpl::creditBalance : result currency match"); - return result; -} - -} // 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..87f6350ce1 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 @@ -108,8 +80,7 @@ public: txs_iter_impl(txs_iter_impl const&) = default; - txs_iter_impl(bool metadata, SHAMap::const_iterator iter) - : metadata_(metadata), iter_(std::move(iter)) + txs_iter_impl(bool metadata, SHAMap::const_iterator iter) : metadata_(metadata), iter_(iter) { } @@ -138,8 +109,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 +118,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 +155,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 +180,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 +210,6 @@ Ledger::Ledger( txMap_.setImmutable(); stateMap_.setImmutable(); - defaultFees(config); if (!setup()) loaded = false; @@ -275,11 +249,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 +263,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 +325,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 +611,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 { @@ -732,7 +693,7 @@ Ledger::updateNegativeUNL() if (sle->isFieldPresent(sfDisabledValidators)) { auto const& oldNUnl = sle->getFieldArray(sfDisabledValidators); - for (auto v : oldNUnl) + for (auto const& v : oldNUnl) { if (hasToReEnable && v.isFieldPresent(sfPublicKey) && v.getFieldVL(sfPublicKey) == sle->getFieldVL(sfValidatorToReEnable)) @@ -816,27 +777,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 +876,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 +889,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/PaymentSandbox.cpp b/src/libxrpl/ledger/PaymentSandbox.cpp index 1f84da1dcb..a56d730b5a 100644 --- a/src/libxrpl/ledger/PaymentSandbox.cpp +++ b/src/libxrpl/ledger/PaymentSandbox.cpp @@ -164,7 +164,7 @@ PaymentSandbox::balanceHook( auto delta = amount.zeroed(); auto lastBal = amount; auto minBal = amount; - for (auto curSB = this; curSB; curSB = curSB->ps_) + for (auto curSB = this; curSB != nullptr; curSB = curSB->ps_) { if (auto adj = curSB->tab_.adjustments(account, issuer, currency)) { @@ -198,7 +198,7 @@ std::uint32_t PaymentSandbox::ownerCountHook(AccountID const& account, std::uint32_t count) const { std::uint32_t result = count; - for (auto curSB = this; curSB; curSB = curSB->ps_) + for (auto curSB = this; curSB != nullptr; curSB = curSB->ps_) { if (auto adj = curSB->tab_.ownerCount(account)) result = std::max(result, *adj); diff --git a/src/libxrpl/ledger/View.cpp b/src/libxrpl/ledger/View.cpp index d5c94a9981..227eafbec8 100644 --- a/src/libxrpl/ledger/View.cpp +++ b/src/libxrpl/ledger/View.cpp @@ -2,10 +2,12 @@ #include #include #include -#include -#include #include #include +#include +#include +#include +#include #include #include #include @@ -22,133 +24,6 @@ namespace xrpl { -namespace detail { - -template < - class V, - class N, - class = std::enable_if_t< - std::is_same_v, SLE> && std::is_base_of_v>> -bool -internalDirNext( - V& view, - uint256 const& root, - std::shared_ptr& page, - unsigned int& index, - uint256& entry) -{ - auto const& svIndexes = page->getFieldV256(sfIndexes); - XRPL_ASSERT(index <= svIndexes.size(), "xrpl::detail::internalDirNext : index inside range"); - - if (index >= svIndexes.size()) - { - auto const next = page->getFieldU64(sfIndexNext); - - if (!next) - { - entry.zero(); - return false; - } - - if constexpr (std::is_const_v) - { - page = view.read(keylet::page(root, next)); - } - else - { - page = view.peek(keylet::page(root, next)); - } - - XRPL_ASSERT(page, "xrpl::detail::internalDirNext : non-null root"); - - if (!page) - return false; - - index = 0; - - return internalDirNext(view, root, page, index, entry); - } - - entry = svIndexes[index++]; - return true; -} - -template < - class V, - class N, - class = std::enable_if_t< - std::is_same_v, SLE> && std::is_base_of_v>> -bool -internalDirFirst( - V& view, - uint256 const& root, - std::shared_ptr& page, - unsigned int& index, - uint256& entry) -{ - if constexpr (std::is_const_v) - { - page = view.read(keylet::page(root)); - } - else - { - page = view.peek(keylet::page(root)); - } - - if (!page) - return false; - - index = 0; - - return internalDirNext(view, root, page, index, entry); -} - -} // namespace detail - -bool -dirFirst( - ApplyView& view, - uint256 const& root, - std::shared_ptr& page, - unsigned int& index, - uint256& entry) -{ - return detail::internalDirFirst(view, root, page, index, entry); -} - -bool -dirNext( - ApplyView& view, - uint256 const& root, - std::shared_ptr& page, - unsigned int& index, - uint256& entry) -{ - return detail::internalDirNext(view, root, page, index, entry); -} - -bool -cdirFirst( - ReadView const& view, - uint256 const& root, - std::shared_ptr& page, - unsigned int& index, - uint256& entry) -{ - return detail::internalDirFirst(view, root, page, index, entry); -} - -bool -cdirNext( - ReadView const& view, - uint256 const& root, - std::shared_ptr& page, - unsigned int& index, - uint256& entry) -{ - return detail::internalDirNext(view, root, page, index, entry); -} - //------------------------------------------------------------------------------ // // Observers @@ -164,124 +39,6 @@ hasExpired(ReadView const& view, std::optional const& exp) return exp && (view.parentCloseTime() >= tp{d{*exp}}); } -bool -isGlobalFrozen(ReadView const& view, AccountID const& issuer) -{ - if (isXRP(issuer)) - return false; - if (auto const sle = view.read(keylet::account(issuer))) - return sle->isFlag(lsfGlobalFreeze); - return false; -} - -bool -isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue) -{ - if (auto const sle = view.read(keylet::mptIssuance(mptIssue.getMptID()))) - return sle->isFlag(lsfMPTLocked); - return false; -} - -bool -isGlobalFrozen(ReadView const& view, Asset const& asset) -{ - return std::visit( - [&](TIss const& issue) { - if constexpr (std::is_same_v) - { - return isGlobalFrozen(view, issue.getIssuer()); - } - else - { - return isGlobalFrozen(view, issue); - } - }, - asset.value()); -} - -bool -isIndividualFrozen( - ReadView const& view, - AccountID const& account, - Currency const& currency, - AccountID const& issuer) -{ - if (isXRP(currency)) - return false; - if (issuer != account) - { - // Check if the issuer froze the line - auto const sle = view.read(keylet::line(account, issuer, currency)); - if (sle && sle->isFlag((issuer > account) ? lsfHighFreeze : lsfLowFreeze)) - return true; - } - return false; -} - -bool -isIndividualFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue) -{ - if (auto const sle = view.read(keylet::mptoken(mptIssue.getMptID(), account))) - return sle->isFlag(lsfMPTLocked); - return false; -} - -// Can the specified account spend the specified currency issued by -// the specified issuer or does the freeze flag prohibit it? -bool -isFrozen( - ReadView const& view, - AccountID const& account, - Currency const& currency, - AccountID const& issuer) -{ - if (isXRP(currency)) - return false; - auto sle = view.read(keylet::account(issuer)); - if (sle && sle->isFlag(lsfGlobalFreeze)) - return true; - if (issuer != account) - { - // Check if the issuer froze the line - sle = view.read(keylet::line(account, issuer, currency)); - if (sle && sle->isFlag((issuer > account) ? lsfHighFreeze : lsfLowFreeze)) - return true; - } - return false; -} - -bool -isFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue, int depth) -{ - return isGlobalFrozen(view, mptIssue) || isIndividualFrozen(view, account, mptIssue) || - isVaultPseudoAccountFrozen(view, account, mptIssue, depth); -} - -[[nodiscard]] bool -isAnyFrozen( - ReadView const& view, - std::initializer_list const& accounts, - MPTIssue const& mptIssue, - int depth) -{ - if (isGlobalFrozen(view, mptIssue)) - return true; - - for (auto const& account : accounts) - { - if (isIndividualFrozen(view, account, mptIssue)) - return true; - } - - for (auto const& account : accounts) - { - if (isVaultPseudoAccountFrozen(view, account, mptIssue, depth)) - return true; - } - - return false; -} - bool isVaultPseudoAccountFrozen( ReadView const& view, @@ -323,32 +80,6 @@ isVaultPseudoAccountFrozen( return isAnyFrozen(view, {issuer, account}, vault->at(sfAsset), depth + 1); } -bool -isDeepFrozen( - ReadView const& view, - AccountID const& account, - Currency const& currency, - AccountID const& issuer) -{ - if (isXRP(currency)) - { - return false; - } - - if (issuer == account) - { - return false; - } - - auto const sle = view.read(keylet::line(account, issuer, currency)); - if (!sle) - { - return false; - } - - return sle->isFlag(lsfHighDeepFreeze) || sle->isFlag(lsfLowDeepFreeze); -} - bool isLPTokenFrozen( ReadView const& view, @@ -360,468 +91,6 @@ isLPTokenFrozen( isFrozen(view, account, asset2.currency, asset2.account); } -static SLE::const_pointer -getLineIfUsable( - ReadView const& view, - AccountID const& account, - Currency const& currency, - AccountID const& issuer, - FreezeHandling zeroIfFrozen, - beast::Journal j) -{ - auto const sle = view.read(keylet::line(account, issuer, currency)); - - if (!sle) - { - return nullptr; - } - - if (zeroIfFrozen == fhZERO_IF_FROZEN) - { - if (isFrozen(view, account, currency, issuer) || - isDeepFrozen(view, account, currency, issuer)) - { - return nullptr; - } - - // when fixFrozenLPTokenTransfer is enabled, if currency is lptoken, - // we need to check if the associated assets have been frozen - if (view.rules().enabled(fixFrozenLPTokenTransfer)) - { - auto const sleIssuer = view.read(keylet::account(issuer)); - if (!sleIssuer) - { - return nullptr; // LCOV_EXCL_LINE - } - if (sleIssuer->isFieldPresent(sfAMMID)) - { - auto const sleAmm = view.read(keylet::amm((*sleIssuer)[sfAMMID])); - - if (!sleAmm || - isLPTokenFrozen( - view, - account, - (*sleAmm)[sfAsset].get(), - (*sleAmm)[sfAsset2].get())) - { - return nullptr; - } - } - } - } - - return sle; -} - -static STAmount -getTrustLineBalance( - ReadView const& view, - SLE::const_ref sle, - AccountID const& account, - Currency const& currency, - AccountID const& issuer, - bool includeOppositeLimit, - beast::Journal j) -{ - STAmount amount; - if (sle) - { - amount = sle->getFieldAmount(sfBalance); - bool const accountHigh = account > issuer; - auto const& oppositeField = accountHigh ? sfLowLimit : sfHighLimit; - if (accountHigh) - { - // Put balance in account terms. - amount.negate(); - } - if (includeOppositeLimit) - { - amount += sle->getFieldAmount(oppositeField); - } - amount.setIssuer(issuer); - } - else - { - amount.clear(Issue{currency, issuer}); - } - - JLOG(j.trace()) << "getTrustLineBalance:" << " account=" << to_string(account) - << " amount=" << amount.getFullText(); - - return view.balanceHook(account, issuer, amount); -} - -STAmount -accountHolds( - ReadView const& view, - AccountID const& account, - Currency const& currency, - AccountID const& issuer, - FreezeHandling zeroIfFrozen, - beast::Journal j, - SpendableHandling includeFullBalance) -{ - STAmount amount; - if (isXRP(currency)) - { - return {xrpLiquid(view, account, 0, j)}; - } - - bool const returnSpendable = (includeFullBalance == shFULL_BALANCE); - if (returnSpendable && account == issuer) - { - // If the account is the issuer, then their limit is effectively - // infinite - return STAmount{Issue{currency, issuer}, STAmount::cMaxValue, STAmount::cMaxOffset}; - } - - // IOU: Return balance on trust line modulo freeze - SLE::const_pointer const sle = - getLineIfUsable(view, account, currency, issuer, zeroIfFrozen, j); - - return getTrustLineBalance(view, sle, account, currency, issuer, returnSpendable, j); -} - -STAmount -accountHolds( - ReadView const& view, - AccountID const& account, - Issue const& issue, - FreezeHandling zeroIfFrozen, - beast::Journal j, - SpendableHandling includeFullBalance) -{ - return accountHolds( - view, account, issue.currency, issue.account, zeroIfFrozen, j, includeFullBalance); -} - -STAmount -accountHolds( - ReadView const& view, - AccountID const& account, - MPTIssue const& mptIssue, - FreezeHandling zeroIfFrozen, - AuthHandling zeroIfUnauthorized, - beast::Journal j, - SpendableHandling includeFullBalance) -{ - bool const returnSpendable = (includeFullBalance == shFULL_BALANCE); - - if (returnSpendable && account == mptIssue.getIssuer()) - { - // if the account is the issuer, and the issuance exists, their limit is - // the issuance limit minus the outstanding value - auto const issuance = view.read(keylet::mptIssuance(mptIssue.getMptID())); - - if (!issuance) - { - return STAmount{mptIssue}; - } - return STAmount{ - mptIssue, - issuance->at(~sfMaximumAmount).value_or(maxMPTokenAmount) - - issuance->at(sfOutstandingAmount)}; - } - - STAmount amount; - - auto const sleMpt = view.read(keylet::mptoken(mptIssue.getMptID(), account)); - - if (!sleMpt) - { - amount.clear(mptIssue); - } - else if (zeroIfFrozen == fhZERO_IF_FROZEN && isFrozen(view, account, mptIssue)) - { - amount.clear(mptIssue); - } - else - { - amount = STAmount{mptIssue, sleMpt->getFieldU64(sfMPTAmount)}; - - // Only if auth check is needed, as it needs to do an additional read - // operation. Note featureSingleAssetVault will affect error codes. - if (zeroIfUnauthorized == ahZERO_IF_UNAUTHORIZED && - view.rules().enabled(featureSingleAssetVault)) - { - if (auto const err = requireAuth(view, mptIssue, account, AuthType::StrongAuth); - !isTesSuccess(err)) - amount.clear(mptIssue); - } - else if (zeroIfUnauthorized == ahZERO_IF_UNAUTHORIZED) - { - auto const sleIssuance = view.read(keylet::mptIssuance(mptIssue.getMptID())); - - // if auth is enabled on the issuance and mpt is not authorized, - // clear amount - if (sleIssuance && sleIssuance->isFlag(lsfMPTRequireAuth) && - !sleMpt->isFlag(lsfMPTAuthorized)) - amount.clear(mptIssue); - } - } - - return amount; -} - -[[nodiscard]] STAmount -accountHolds( - ReadView const& view, - AccountID const& account, - Asset const& asset, - FreezeHandling zeroIfFrozen, - AuthHandling zeroIfUnauthorized, - beast::Journal j, - SpendableHandling includeFullBalance) -{ - return std::visit( - [&](TIss const& value) { - if constexpr (std::is_same_v) - { - return accountHolds(view, account, value, zeroIfFrozen, j, includeFullBalance); - } - else if constexpr (std::is_same_v) - { - return accountHolds( - view, account, value, zeroIfFrozen, zeroIfUnauthorized, j, includeFullBalance); - } - }, - asset.value()); -} - -STAmount -accountFunds( - ReadView const& view, - AccountID const& id, - STAmount const& saDefault, - FreezeHandling freezeHandling, - beast::Journal j) -{ - if (!saDefault.native() && saDefault.getIssuer() == id) - return saDefault; - - return accountHolds( - view, id, saDefault.getCurrency(), saDefault.getIssuer(), freezeHandling, j); -} - -// Prevent ownerCount from wrapping under error conditions. -// -// adjustment allows the ownerCount to be adjusted up or down in multiple steps. -// If id != std::nullopt, then do error reporting. -// -// Returns adjusted owner count. -static std::uint32_t -confineOwnerCount( - std::uint32_t current, - std::int32_t adjustment, - std::optional const& id = std::nullopt, - beast::Journal j = beast::Journal{beast::Journal::getNullSink()}) -{ - std::uint32_t adjusted{current + adjustment}; - if (adjustment > 0) - { - // Overflow is well defined on unsigned - if (adjusted < current) - { - if (id) - { - JLOG(j.fatal()) << "Account " << *id << " owner count exceeds max!"; - } - adjusted = std::numeric_limits::max(); - } - } - else - { - // Underflow is well defined on unsigned - if (adjusted > current) - { - if (id) - { - JLOG(j.fatal()) << "Account " << *id << " owner count set below 0!"; - } - adjusted = 0; - XRPL_ASSERT(!id, "xrpl::confineOwnerCount : id is not set"); - } - } - return adjusted; -} - -XRPAmount -xrpLiquid(ReadView const& view, AccountID const& id, std::int32_t ownerCountAdj, beast::Journal j) -{ - auto const sle = view.read(keylet::account(id)); - if (sle == nullptr) - return beast::zero; - - // Return balance minus reserve - std::uint32_t const ownerCount = - confineOwnerCount(view.ownerCountHook(id, sle->getFieldU32(sfOwnerCount)), ownerCountAdj); - - // Pseudo-accounts have no reserve requirement - auto const reserve = - isPseudoAccount(sle) ? XRPAmount{0} : view.fees().accountReserve(ownerCount); - - auto const fullBalance = sle->getFieldAmount(sfBalance); - - auto const balance = view.balanceHook(id, xrpAccount(), fullBalance); - - STAmount const amount = (balance < reserve) ? STAmount{0} : balance - reserve; - - JLOG(j.trace()) << "accountHolds:" << " account=" << to_string(id) - << " amount=" << amount.getFullText() - << " fullBalance=" << fullBalance.getFullText() - << " balance=" << balance.getFullText() << " reserve=" << reserve - << " ownerCount=" << ownerCount << " ownerCountAdj=" << ownerCountAdj; - - return amount.xrp(); -} - -void -forEachItem( - ReadView const& view, - Keylet const& root, - std::function const&)> const& f) -{ - XRPL_ASSERT(root.type == ltDIR_NODE, "xrpl::forEachItem : valid root type"); - - if (root.type != ltDIR_NODE) - return; - - auto pos = root; - - while (true) - { - auto sle = view.read(pos); - if (!sle) - return; - for (auto const& key : sle->getFieldV256(sfIndexes)) - f(view.read(keylet::child(key))); - auto const next = sle->getFieldU64(sfIndexNext); - if (!next) - return; - pos = keylet::page(root, next); - } -} - -bool -forEachItemAfter( - ReadView const& view, - Keylet const& root, - uint256 const& after, - std::uint64_t const hint, - unsigned int limit, - std::function const&)> const& f) -{ - XRPL_ASSERT(root.type == ltDIR_NODE, "xrpl::forEachItemAfter : valid root type"); - - if (root.type != ltDIR_NODE) - return false; - - auto currentIndex = root; - - // If startAfter is not zero try jumping to that page using the hint - if (after.isNonZero()) - { - auto const hintIndex = keylet::page(root, hint); - - if (auto hintDir = view.read(hintIndex)) - { - for (auto const& key : hintDir->getFieldV256(sfIndexes)) - { - if (key == after) - { - // We found the hint, we can start here - currentIndex = hintIndex; - break; - } - } - } - - bool found = false; - for (;;) - { - auto const ownerDir = view.read(currentIndex); - if (!ownerDir) - return found; - for (auto const& key : ownerDir->getFieldV256(sfIndexes)) - { - if (!found) - { - if (key == after) - found = true; - } - else if (f(view.read(keylet::child(key))) && limit-- <= 1) - { - return found; - } - } - - auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext); - if (uNodeNext == 0) - return found; - currentIndex = keylet::page(root, uNodeNext); - } - } - else - { - for (;;) - { - auto const ownerDir = view.read(currentIndex); - if (!ownerDir) - return true; - for (auto const& key : ownerDir->getFieldV256(sfIndexes)) - { - if (f(view.read(keylet::child(key))) && limit-- <= 1) - return true; - } - auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext); - if (uNodeNext == 0) - return true; - currentIndex = keylet::page(root, uNodeNext); - } - } -} - -Rate -transferRate(ReadView const& view, AccountID const& issuer) -{ - auto const sle = view.read(keylet::account(issuer)); - - if (sle && sle->isFieldPresent(sfTransferRate)) - return Rate{sle->getFieldU32(sfTransferRate)}; - - return parityRate; -} - -Rate -transferRate(ReadView const& view, MPTID const& issuanceID) -{ - // fee is 0-50,000 (0-50%), rate is 1,000,000,000-2,000,000,000 - // For example, if transfer fee is 50% then 10,000 * 50,000 = 500,000 - // which represents 50% of 1,000,000,000 - if (auto const sle = view.read(keylet::mptIssuance(issuanceID)); - sle && sle->isFieldPresent(sfTransferFee)) - return Rate{1'000'000'000u + 10'000 * sle->getFieldU16(sfTransferFee)}; - - return parityRate; -} - -Rate -transferRate(ReadView const& view, STAmount const& amount) -{ - return std::visit( - [&](TIss const& issue) { - if constexpr (std::is_same_v) - { - return transferRate(view, issue.getIssuer()); - } - else - { - return transferRate(view, issue.getMptID()); - } - }, - amount.asset().value()); -} - bool areCompatible( ReadView const& validLedger, @@ -920,20 +189,6 @@ areCompatible( return ret; } -bool -dirIsEmpty(ReadView const& view, Keylet const& k) -{ - auto const sleNode = view.read(k); - if (!sleNode) - return true; - if (!sleNode->getFieldV256(sfIndexes).empty()) - return false; - // The first page of a directory may legitimately be empty even if there - // are other pages (the first page is the anchor page) so check to see if - // there is another page. If there is, the directory isn't empty. - return sleNode->getFieldU64(sfIndexNext) == 0; -} - std::set getEnabledAmendments(ReadView const& view) { @@ -1037,30 +292,6 @@ hashOfSeq(ReadView const& ledger, LedgerIndex seq, beast::Journal journal) // //------------------------------------------------------------------------------ -void -adjustOwnerCount( - ApplyView& view, - std::shared_ptr const& sle, - std::int32_t amount, - beast::Journal j) -{ - if (!sle) - return; - XRPL_ASSERT(amount, "xrpl::adjustOwnerCount : nonzero amount input"); - std::uint32_t const current{sle->getFieldU32(sfOwnerCount)}; - AccountID const id = (*sle)[sfAccount]; - std::uint32_t const adjusted = confineOwnerCount(current, amount, id, j); - view.adjustOwnerCountHook(id, current, adjusted); - sle->at(sfOwnerCount) = adjusted; - view.update(sle); -} - -std::function -describeOwnerDir(AccountID const& account) -{ - return [account](std::shared_ptr const& sle) { (*sle)[sfOwner] = account; }; -} - TER dirLink( ApplyView& view, @@ -1076,168 +307,6 @@ dirLink( return tesSUCCESS; } -AccountID -pseudoAccountAddress(ReadView const& view, uint256 const& pseudoOwnerKey) -{ - // This number must not be changed without an amendment - constexpr std::uint16_t maxAccountAttempts = 256; - for (std::uint16_t i = 0; i < maxAccountAttempts; ++i) - { - ripesha_hasher rsh; - auto const hash = sha512Half(i, view.header().parentHash, pseudoOwnerKey); - rsh(hash.data(), hash.size()); - AccountID const ret{static_cast(rsh)}; - if (!view.read(keylet::account(ret))) - return ret; - } - return beast::zero; -} - -// Pseudo-account designator fields MUST be maintained by including the -// SField::sMD_PseudoAccount flag in the SField definition. (Don't forget to -// "| SField::sMD_Default"!) The fields do NOT need to be amendment-gated, -// since a non-active amendment will not set any field, by definition. -// Specific properties of a pseudo-account are NOT checked here, that's what -// InvariantCheck is for. -[[nodiscard]] std::vector const& -getPseudoAccountFields() -{ - static std::vector const pseudoFields = []() { - auto const ar = LedgerFormats::getInstance().findByType(ltACCOUNT_ROOT); - if (!ar) - { - // LCOV_EXCL_START - LogicError( - "xrpl::getPseudoAccountFields : unable to find account root " - "ledger format"); - // LCOV_EXCL_STOP - } - auto const& soTemplate = ar->getSOTemplate(); - - std::vector pseudoFields; - for (auto const& field : soTemplate) - { - if (field.sField().shouldMeta(SField::sMD_PseudoAccount)) - pseudoFields.emplace_back(&field.sField()); - } - return pseudoFields; - }(); - return pseudoFields; -} - -[[nodiscard]] bool -isPseudoAccount( - std::shared_ptr sleAcct, - std::set const& pseudoFieldFilter) -{ - auto const& fields = getPseudoAccountFields(); - - // Intentionally use defensive coding here because it's cheap and makes the - // semantics of true return value clean. - return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT && - std::count_if( - fields.begin(), fields.end(), [&sleAcct, &pseudoFieldFilter](SField const* sf) -> bool { - return sleAcct->isFieldPresent(*sf) && - (pseudoFieldFilter.empty() || pseudoFieldFilter.contains(sf)); - }) > 0; -} - -Expected, TER> -createPseudoAccount(ApplyView& view, uint256 const& pseudoOwnerKey, SField const& ownerField) -{ - [[maybe_unused]] - auto const& fields = getPseudoAccountFields(); - XRPL_ASSERT( - std::count_if( - fields.begin(), - fields.end(), - [&ownerField](SField const* sf) -> bool { return *sf == ownerField; }) == 1, - "xrpl::createPseudoAccount : valid owner field"); - - auto const accountId = pseudoAccountAddress(view, pseudoOwnerKey); - if (accountId == beast::zero) - return Unexpected(tecDUPLICATE); - - // Create pseudo-account. - auto account = std::make_shared(keylet::account(accountId)); - account->setAccountID(sfAccount, accountId); - account->setFieldAmount(sfBalance, STAmount{}); - - // Pseudo-accounts can't submit transactions, so set the sequence number - // to 0 to make them easier to spot and verify, and add an extra level - // of protection. - std::uint32_t const seqno = // - view.rules().enabled(featureSingleAssetVault) || // - view.rules().enabled(featureLendingProtocol) // - ? 0 // - : view.seq(); - account->setFieldU32(sfSequence, seqno); - // Ignore reserves requirement, disable the master key, allow default - // rippling, and enable deposit authorization to prevent payments into - // pseudo-account. - account->setFieldU32(sfFlags, lsfDisableMaster | lsfDefaultRipple | lsfDepositAuth); - // Link the pseudo-account with its owner object. - account->setFieldH256(ownerField, pseudoOwnerKey); - - view.insert(account); - - return account; -} - -[[nodiscard]] TER -canAddHolding(ReadView const& view, Issue const& issue) -{ - if (issue.native()) - return tesSUCCESS; // No special checks for XRP - - auto const issuer = view.read(keylet::account(issue.getIssuer())); - if (!issuer) - { - return terNO_ACCOUNT; - } - if (!issuer->isFlag(lsfDefaultRipple)) - { - return terNO_RIPPLE; - } - - return tesSUCCESS; -} - -[[nodiscard]] TER -canAddHolding(ReadView const& view, MPTIssue const& mptIssue) -{ - auto mptID = mptIssue.getMptID(); - auto issuance = view.read(keylet::mptIssuance(mptID)); - if (!issuance) - return tecOBJECT_NOT_FOUND; - if (!issuance->isFlag(lsfMPTCanTransfer)) - return tecNO_AUTH; - - return tesSUCCESS; -} - -[[nodiscard]] TER -canAddHolding(ReadView const& view, Asset const& asset) -{ - return std::visit( - [&](TIss const& issue) -> TER { return canAddHolding(view, issue); }, - asset.value()); -} - -[[nodiscard]] TER -checkDestinationAndTag(SLE::const_ref toSle, bool hasDestinationTag) -{ - if (toSle == nullptr) - return tecNO_DST; - - // The tag is basically account-specific information we don't - // understand, but we can require someone to fill it in. - if (toSle->isFlag(lsfRequireDestTag) && !hasDestinationTag) - return tecDST_TAG_NEEDED; // Cannot send without a tag - - return tesSUCCESS; -} - /* * Checks if a withdrawal amount into the destination account exceeds * any applicable receiving limit. @@ -1364,8 +433,7 @@ doWithdraw( j) < amount) { // LCOV_EXCL_START - JLOG(j.error()) << "LoanBrokerCoverWithdraw: negative balance of " - "broker cover assets."; + JLOG(j.error()) << "doWithdraw: negative balance of broker cover assets."; return tefINTERNAL; // LCOV_EXCL_STOP } @@ -1375,1837 +443,6 @@ doWithdraw( return accountSend(view, sourceAcct, dstAcct, amount, j, WaiveTransferFee::Yes); } -[[nodiscard]] TER -addEmptyHolding( - ApplyView& view, - AccountID const& accountID, - XRPAmount priorBalance, - Issue const& issue, - beast::Journal journal) -{ - // Every account can hold XRP. An issuer can issue directly. - if (issue.native() || accountID == issue.getIssuer()) - return tesSUCCESS; - - auto const& issuerId = issue.getIssuer(); - auto const& currency = issue.currency; - if (isGlobalFrozen(view, issuerId)) - return tecFROZEN; // LCOV_EXCL_LINE - - auto const& srcId = issuerId; - auto const& dstId = accountID; - auto const high = srcId > dstId; - auto const index = keylet::line(srcId, dstId, currency); - auto const sleSrc = view.peek(keylet::account(srcId)); - auto const sleDst = view.peek(keylet::account(dstId)); - if (!sleDst || !sleSrc) - return tefINTERNAL; // LCOV_EXCL_LINE - if (!sleSrc->isFlag(lsfDefaultRipple)) - return tecINTERNAL; // LCOV_EXCL_LINE - // If the line already exists, don't create it again. - if (view.read(index)) - return tecDUPLICATE; - - // Can the account cover the trust line reserve ? - std::uint32_t const ownerCount = sleDst->at(sfOwnerCount); - if (priorBalance < view.fees().accountReserve(ownerCount + 1)) - return tecNO_LINE_INSUF_RESERVE; - - return trustCreate( - view, - high, - srcId, - dstId, - index.key, - sleDst, - /*bAuth=*/false, - /*bNoRipple=*/true, - /*bFreeze=*/false, - /*deepFreeze*/ false, - /*saBalance=*/STAmount{Issue{currency, noAccount()}}, - /*saLimit=*/STAmount{Issue{currency, dstId}}, - /*uSrcQualityIn=*/0, - /*uSrcQualityOut=*/0, - journal); -} - -[[nodiscard]] TER -addEmptyHolding( - ApplyView& view, - AccountID const& accountID, - XRPAmount priorBalance, - MPTIssue const& mptIssue, - beast::Journal journal) -{ - auto const& mptID = mptIssue.getMptID(); - auto const mpt = view.peek(keylet::mptIssuance(mptID)); - if (!mpt) - return tefINTERNAL; // LCOV_EXCL_LINE - if (mpt->isFlag(lsfMPTLocked)) - return tefINTERNAL; // LCOV_EXCL_LINE - if (view.peek(keylet::mptoken(mptID, accountID))) - return tecDUPLICATE; - if (accountID == mptIssue.getIssuer()) - return tesSUCCESS; - - return authorizeMPToken(view, priorBalance, mptID, accountID, journal); -} - -[[nodiscard]] TER -authorizeMPToken( - ApplyView& view, - XRPAmount const& priorBalance, - MPTID const& mptIssuanceID, - AccountID const& account, - beast::Journal journal, - std::uint32_t flags, - std::optional holderID) -{ - auto const sleAcct = view.peek(keylet::account(account)); - if (!sleAcct) - return tecINTERNAL; // LCOV_EXCL_LINE - - // If the account that submitted the tx is a holder - // Note: `account_` is holder's account - // `holderID` is NOT used - if (!holderID) - { - // When a holder wants to unauthorize/delete a MPT, the ledger must - // - delete mptokenKey from owner directory - // - delete the MPToken - if (flags & tfMPTUnauthorize) - { - auto const mptokenKey = keylet::mptoken(mptIssuanceID, account); - auto const sleMpt = view.peek(mptokenKey); - if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0) - return tecINTERNAL; // LCOV_EXCL_LINE - - if (!view.dirRemove( - keylet::ownerDir(account), (*sleMpt)[sfOwnerNode], sleMpt->key(), false)) - return tecINTERNAL; // LCOV_EXCL_LINE - - adjustOwnerCount(view, sleAcct, -1, journal); - - view.erase(sleMpt); - return tesSUCCESS; - } - - // A potential holder wants to authorize/hold a mpt, the ledger must: - // - add the new mptokenKey to the owner directory - // - create the MPToken object for the holder - - // The reserve that is required to create the MPToken. Note - // that although the reserve increases with every item - // an account owns, in the case of MPTokens we only - // *enforce* a reserve if the user owns more than two - // items. This is similar to the reserve requirements of trust lines. - std::uint32_t const uOwnerCount = sleAcct->getFieldU32(sfOwnerCount); - XRPAmount const reserveCreate( - (uOwnerCount < 2) ? XRPAmount(beast::zero) - : view.fees().accountReserve(uOwnerCount + 1)); - - if (priorBalance < reserveCreate) - return tecINSUFFICIENT_RESERVE; - - // Defensive check before we attempt to create MPToken for the issuer - auto const mpt = view.read(keylet::mptIssuance(mptIssuanceID)); - if (!mpt || mpt->getAccountID(sfIssuer) == account) - { - // LCOV_EXCL_START - UNREACHABLE("xrpl::authorizeMPToken : invalid issuance or issuers token"); - if (view.rules().enabled(featureLendingProtocol)) - return tecINTERNAL; - // LCOV_EXCL_STOP - } - - auto const mptokenKey = keylet::mptoken(mptIssuanceID, account); - auto mptoken = std::make_shared(mptokenKey); - if (auto ter = dirLink(view, account, mptoken)) - return ter; // LCOV_EXCL_LINE - - (*mptoken)[sfAccount] = account; - (*mptoken)[sfMPTokenIssuanceID] = mptIssuanceID; - (*mptoken)[sfFlags] = 0; - view.insert(mptoken); - - // Update owner count. - adjustOwnerCount(view, sleAcct, 1, journal); - - return tesSUCCESS; - } - - auto const sleMptIssuance = view.read(keylet::mptIssuance(mptIssuanceID)); - if (!sleMptIssuance) - return tecINTERNAL; // LCOV_EXCL_LINE - - // If the account that submitted this tx is the issuer of the MPT - // Note: `account_` is issuer's account - // `holderID` is holder's account - if (account != (*sleMptIssuance)[sfIssuer]) - return tecINTERNAL; // LCOV_EXCL_LINE - - auto const sleMpt = view.peek(keylet::mptoken(mptIssuanceID, *holderID)); - if (!sleMpt) - return tecINTERNAL; // LCOV_EXCL_LINE - - std::uint32_t const flagsIn = sleMpt->getFieldU32(sfFlags); - std::uint32_t flagsOut = flagsIn; - - // Issuer wants to unauthorize the holder, unset lsfMPTAuthorized on - // their MPToken - if (flags & tfMPTUnauthorize) - { - flagsOut &= ~lsfMPTAuthorized; - } - // Issuer wants to authorize a holder, set lsfMPTAuthorized on their - // MPToken - else - { - flagsOut |= lsfMPTAuthorized; - } - - if (flagsIn != flagsOut) - sleMpt->setFieldU32(sfFlags, flagsOut); - - view.update(sleMpt); - return tesSUCCESS; -} - -TER -trustCreate( - ApplyView& view, - bool const bSrcHigh, - AccountID const& uSrcAccountID, - AccountID const& uDstAccountID, - uint256 const& uIndex, // --> ripple state entry - SLE::ref sleAccount, // --> the account being set. - bool const bAuth, // --> authorize account. - bool const bNoRipple, // --> others cannot ripple through - bool const bFreeze, // --> funds cannot leave - bool bDeepFreeze, // --> can neither receive nor send funds - STAmount const& saBalance, // --> balance of account being set. - // Issuer should be noAccount() - STAmount const& saLimit, // --> limit for account being set. - // Issuer should be the account being set. - std::uint32_t uQualityIn, - std::uint32_t uQualityOut, - beast::Journal j) -{ - JLOG(j.trace()) << "trustCreate: " << to_string(uSrcAccountID) << ", " - << to_string(uDstAccountID) << ", " << saBalance.getFullText(); - - auto const& uLowAccountID = !bSrcHigh ? uSrcAccountID : uDstAccountID; - auto const& uHighAccountID = bSrcHigh ? uSrcAccountID : uDstAccountID; - if (uLowAccountID == uHighAccountID) - { - // LCOV_EXCL_START - UNREACHABLE("xrpl::trustCreate : trust line to self"); - if (view.rules().enabled(featureLendingProtocol)) - return tecINTERNAL; - // LCOV_EXCL_STOP - } - - auto const sleRippleState = std::make_shared(ltRIPPLE_STATE, uIndex); - view.insert(sleRippleState); - - auto lowNode = view.dirInsert( - keylet::ownerDir(uLowAccountID), sleRippleState->key(), describeOwnerDir(uLowAccountID)); - - if (!lowNode) - return tecDIR_FULL; // LCOV_EXCL_LINE - - auto highNode = view.dirInsert( - keylet::ownerDir(uHighAccountID), sleRippleState->key(), describeOwnerDir(uHighAccountID)); - - if (!highNode) - return tecDIR_FULL; // LCOV_EXCL_LINE - - bool const bSetDst = saLimit.getIssuer() == uDstAccountID; - bool const bSetHigh = bSrcHigh ^ bSetDst; - - XRPL_ASSERT(sleAccount, "xrpl::trustCreate : non-null SLE"); - if (!sleAccount) - return tefINTERNAL; // LCOV_EXCL_LINE - - XRPL_ASSERT( - sleAccount->getAccountID(sfAccount) == (bSetHigh ? uHighAccountID : uLowAccountID), - "xrpl::trustCreate : matching account ID"); - auto const slePeer = view.peek(keylet::account(bSetHigh ? uLowAccountID : uHighAccountID)); - if (!slePeer) - return tecNO_TARGET; - - // Remember deletion hints. - sleRippleState->setFieldU64(sfLowNode, *lowNode); - sleRippleState->setFieldU64(sfHighNode, *highNode); - - sleRippleState->setFieldAmount(bSetHigh ? sfHighLimit : sfLowLimit, saLimit); - sleRippleState->setFieldAmount( - bSetHigh ? sfLowLimit : sfHighLimit, - STAmount(Issue{saBalance.getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID})); - - if (uQualityIn) - sleRippleState->setFieldU32(bSetHigh ? sfHighQualityIn : sfLowQualityIn, uQualityIn); - - if (uQualityOut) - sleRippleState->setFieldU32(bSetHigh ? sfHighQualityOut : sfLowQualityOut, uQualityOut); - - std::uint32_t uFlags = bSetHigh ? lsfHighReserve : lsfLowReserve; - - if (bAuth) - { - uFlags |= (bSetHigh ? lsfHighAuth : lsfLowAuth); - } - if (bNoRipple) - { - uFlags |= (bSetHigh ? lsfHighNoRipple : lsfLowNoRipple); - } - if (bFreeze) - { - uFlags |= (bSetHigh ? lsfHighFreeze : lsfLowFreeze); - } - if (bDeepFreeze) - { - uFlags |= (bSetHigh ? lsfHighDeepFreeze : lsfLowDeepFreeze); - } - - if ((slePeer->getFlags() & lsfDefaultRipple) == 0) - { - // The other side's default is no rippling - uFlags |= (bSetHigh ? lsfLowNoRipple : lsfHighNoRipple); - } - - sleRippleState->setFieldU32(sfFlags, uFlags); - adjustOwnerCount(view, sleAccount, 1, j); - - // ONLY: Create ripple balance. - sleRippleState->setFieldAmount(sfBalance, bSetHigh ? -saBalance : saBalance); - - view.creditHook(uSrcAccountID, uDstAccountID, saBalance, saBalance.zeroed()); - - return tesSUCCESS; -} - -[[nodiscard]] TER -removeEmptyHolding( - ApplyView& view, - AccountID const& accountID, - Issue const& issue, - beast::Journal journal) -{ - if (issue.native()) - { - auto const sle = view.read(keylet::account(accountID)); - if (!sle) - return tecINTERNAL; // LCOV_EXCL_LINE - - auto const balance = sle->getFieldAmount(sfBalance); - if (balance.xrp() != 0) - return tecHAS_OBLIGATIONS; - - return tesSUCCESS; - } - - // `asset` is an IOU. - // If the account is the issuer, then no line should exist. Check anyway. If - // a line does exist, it will get deleted. If not, return success. - bool const accountIsIssuer = accountID == issue.account; - auto const line = view.peek(keylet::line(accountID, issue)); - if (!line) - return accountIsIssuer ? (TER)tesSUCCESS : (TER)tecOBJECT_NOT_FOUND; - if (!accountIsIssuer && line->at(sfBalance)->iou() != beast::zero) - return tecHAS_OBLIGATIONS; - - // Adjust the owner count(s) - if (line->isFlag(lsfLowReserve)) - { - // Clear reserve for low account. - auto sleLowAccount = view.peek(keylet::account(line->at(sfLowLimit)->getIssuer())); - if (!sleLowAccount) - return tecINTERNAL; // LCOV_EXCL_LINE - - adjustOwnerCount(view, sleLowAccount, -1, journal); - // It's not really necessary to clear the reserve flag, since the line - // is about to be deleted, but this will make the metadata reflect an - // accurate state at the time of deletion. - line->clearFlag(lsfLowReserve); - } - - if (line->isFlag(lsfHighReserve)) - { - // Clear reserve for high account. - auto sleHighAccount = view.peek(keylet::account(line->at(sfHighLimit)->getIssuer())); - if (!sleHighAccount) - return tecINTERNAL; // LCOV_EXCL_LINE - - adjustOwnerCount(view, sleHighAccount, -1, journal); - // It's not really necessary to clear the reserve flag, since the line - // is about to be deleted, but this will make the metadata reflect an - // accurate state at the time of deletion. - line->clearFlag(lsfHighReserve); - } - - return trustDelete( - view, line, line->at(sfLowLimit)->getIssuer(), line->at(sfHighLimit)->getIssuer(), journal); -} - -[[nodiscard]] TER -removeEmptyHolding( - ApplyView& view, - AccountID const& accountID, - MPTIssue const& mptIssue, - beast::Journal journal) -{ - // If the account is the issuer, then no token should exist. MPTs do not - // have the legacy ability to create such a situation, but check anyway. If - // a token does exist, it will get deleted. If not, return success. - bool const accountIsIssuer = accountID == mptIssue.getIssuer(); - auto const& mptID = mptIssue.getMptID(); - auto const mptoken = view.peek(keylet::mptoken(mptID, accountID)); - if (!mptoken) - return accountIsIssuer ? (TER)tesSUCCESS : (TER)tecOBJECT_NOT_FOUND; - // Unlike a trust line, if the account is the issuer, and the token has a - // balance, it can not just be deleted, because that will throw the issuance - // accounting out of balance, so fail. Since this should be impossible - // anyway, I'm not going to put any effort into it. - if (mptoken->at(sfMPTAmount) != 0) - return tecHAS_OBLIGATIONS; - - return authorizeMPToken( - view, - {}, // priorBalance - mptID, - accountID, - journal, - tfMPTUnauthorize // flags - ); -} - -TER -trustDelete( - ApplyView& view, - std::shared_ptr const& sleRippleState, - AccountID const& uLowAccountID, - AccountID const& uHighAccountID, - beast::Journal j) -{ - // Detect legacy dirs. - std::uint64_t uLowNode = sleRippleState->getFieldU64(sfLowNode); - std::uint64_t uHighNode = sleRippleState->getFieldU64(sfHighNode); - - JLOG(j.trace()) << "trustDelete: Deleting ripple line: low"; - - if (!view.dirRemove(keylet::ownerDir(uLowAccountID), uLowNode, sleRippleState->key(), false)) - { - return tefBAD_LEDGER; // LCOV_EXCL_LINE - } - - JLOG(j.trace()) << "trustDelete: Deleting ripple line: high"; - - if (!view.dirRemove(keylet::ownerDir(uHighAccountID), uHighNode, sleRippleState->key(), false)) - { - return tefBAD_LEDGER; // LCOV_EXCL_LINE - } - - JLOG(j.trace()) << "trustDelete: Deleting ripple line: state"; - view.erase(sleRippleState); - - return tesSUCCESS; -} - -TER -offerDelete(ApplyView& view, std::shared_ptr const& sle, beast::Journal j) -{ - if (!sle) - return tesSUCCESS; - auto offerIndex = sle->key(); - auto owner = sle->getAccountID(sfAccount); - - // Detect legacy directories. - uint256 uDirectory = sle->getFieldH256(sfBookDirectory); - - if (!view.dirRemove(keylet::ownerDir(owner), sle->getFieldU64(sfOwnerNode), offerIndex, false)) - { - return tefBAD_LEDGER; // LCOV_EXCL_LINE - } - - if (!view.dirRemove(keylet::page(uDirectory), sle->getFieldU64(sfBookNode), offerIndex, false)) - { - return tefBAD_LEDGER; // LCOV_EXCL_LINE - } - - if (sle->isFieldPresent(sfAdditionalBooks)) - { - XRPL_ASSERT( - sle->isFlag(lsfHybrid) && sle->isFieldPresent(sfDomainID), - "xrpl::offerDelete : should be a hybrid domain offer"); - - auto const& additionalBookDirs = sle->getFieldArray(sfAdditionalBooks); - - for (auto const& bookDir : additionalBookDirs) - { - auto const& dirIndex = bookDir.getFieldH256(sfBookDirectory); - auto const& dirNode = bookDir.getFieldU64(sfBookNode); - - if (!view.dirRemove(keylet::page(dirIndex), dirNode, offerIndex, false)) - { - return tefBAD_LEDGER; // LCOV_EXCL_LINE - } - } - } - - adjustOwnerCount(view, view.peek(keylet::account(owner)), -1, j); - - view.erase(sle); - - return tesSUCCESS; -} - -// Direct send w/o fees: -// - Redeeming IOUs and/or sending sender's own IOUs. -// - Create trust line if needed. -// --> bCheckIssuer : normally require issuer to be involved. -static TER -rippleCreditIOU( - ApplyView& view, - AccountID const& uSenderID, - AccountID const& uReceiverID, - STAmount const& saAmount, - bool bCheckIssuer, - beast::Journal j) -{ - AccountID const& issuer = saAmount.getIssuer(); - Currency const& currency = saAmount.getCurrency(); - - // Make sure issuer is involved. - XRPL_ASSERT( - !bCheckIssuer || uSenderID == issuer || uReceiverID == issuer, - "xrpl::rippleCreditIOU : matching issuer or don't care"); - (void)issuer; - - // Disallow sending to self. - XRPL_ASSERT(uSenderID != uReceiverID, "xrpl::rippleCreditIOU : sender is not receiver"); - - bool const bSenderHigh = uSenderID > uReceiverID; - auto const index = keylet::line(uSenderID, uReceiverID, currency); - - XRPL_ASSERT( - !isXRP(uSenderID) && uSenderID != noAccount(), "xrpl::rippleCreditIOU : sender is not XRP"); - XRPL_ASSERT( - !isXRP(uReceiverID) && uReceiverID != noAccount(), - "xrpl::rippleCreditIOU : receiver is not XRP"); - - // If the line exists, modify it accordingly. - if (auto const sleRippleState = view.peek(index)) - { - STAmount saBalance = sleRippleState->getFieldAmount(sfBalance); - - if (bSenderHigh) - saBalance.negate(); // Put balance in sender terms. - - view.creditHook(uSenderID, uReceiverID, saAmount, saBalance); - - STAmount const saBefore = saBalance; - - saBalance -= saAmount; - - JLOG(j.trace()) << "rippleCreditIOU: " << to_string(uSenderID) << " -> " - << to_string(uReceiverID) << " : before=" << saBefore.getFullText() - << " amount=" << saAmount.getFullText() - << " after=" << saBalance.getFullText(); - - std::uint32_t const uFlags(sleRippleState->getFieldU32(sfFlags)); - bool bDelete = false; - - // FIXME This NEEDS to be cleaned up and simplified. It's impossible - // for anyone to understand. - if (saBefore > beast::zero - // Sender balance was positive. - && saBalance <= beast::zero - // Sender is zero or negative. - && (uFlags & (!bSenderHigh ? lsfLowReserve : lsfHighReserve)) - // Sender reserve is set. - && static_cast(uFlags & (!bSenderHigh ? lsfLowNoRipple : lsfHighNoRipple)) != - static_cast( - view.read(keylet::account(uSenderID))->getFlags() & lsfDefaultRipple) && - !(uFlags & (!bSenderHigh ? lsfLowFreeze : lsfHighFreeze)) && - !sleRippleState->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit) - // Sender trust limit is 0. - && !sleRippleState->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn) - // Sender quality in is 0. - && !sleRippleState->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut)) - // Sender quality out is 0. - { - // Clear the reserve of the sender, possibly delete the line! - adjustOwnerCount(view, view.peek(keylet::account(uSenderID)), -1, j); - - // Clear reserve flag. - sleRippleState->setFieldU32( - sfFlags, uFlags & (!bSenderHigh ? ~lsfLowReserve : ~lsfHighReserve)); - - // Balance is zero, receiver reserve is clear. - bDelete = !saBalance // Balance is zero. - && !(uFlags & (bSenderHigh ? lsfLowReserve : lsfHighReserve)); - // Receiver reserve is clear. - } - - if (bSenderHigh) - saBalance.negate(); - - // Want to reflect balance to zero even if we are deleting line. - sleRippleState->setFieldAmount(sfBalance, saBalance); - // ONLY: Adjust ripple balance. - - if (bDelete) - { - return trustDelete( - view, - sleRippleState, - bSenderHigh ? uReceiverID : uSenderID, - !bSenderHigh ? uReceiverID : uSenderID, - j); - } - - view.update(sleRippleState); - return tesSUCCESS; - } - - STAmount const saReceiverLimit(Issue{currency, uReceiverID}); - STAmount saBalance{saAmount}; - - saBalance.setIssuer(noAccount()); - - JLOG(j.debug()) << "rippleCreditIOU: " - "create line: " - << to_string(uSenderID) << " -> " << to_string(uReceiverID) << " : " - << saAmount.getFullText(); - - auto const sleAccount = view.peek(keylet::account(uReceiverID)); - if (!sleAccount) - return tefINTERNAL; // LCOV_EXCL_LINE - - bool const noRipple = (sleAccount->getFlags() & lsfDefaultRipple) == 0; - - return trustCreate( - view, - bSenderHigh, - uSenderID, - uReceiverID, - index.key, - sleAccount, - false, - noRipple, - false, - false, - saBalance, - saReceiverLimit, - 0, - 0, - j); -} - -// Send regardless of limits. -// --> saAmount: Amount/currency/issuer to deliver to receiver. -// <-- saActual: Amount actually cost. Sender pays fees. -static TER -rippleSendIOU( - ApplyView& view, - AccountID const& uSenderID, - AccountID const& uReceiverID, - STAmount const& saAmount, - STAmount& saActual, - beast::Journal j, - WaiveTransferFee waiveFee) -{ - auto const& issuer = saAmount.getIssuer(); - - XRPL_ASSERT( - !isXRP(uSenderID) && !isXRP(uReceiverID), - "xrpl::rippleSendIOU : neither sender nor receiver is XRP"); - XRPL_ASSERT(uSenderID != uReceiverID, "xrpl::rippleSendIOU : sender is not receiver"); - - if (uSenderID == issuer || uReceiverID == issuer || issuer == noAccount()) - { - // Direct send: redeeming IOUs and/or sending own IOUs. - auto const ter = rippleCreditIOU(view, uSenderID, uReceiverID, saAmount, false, j); - if (!isTesSuccess(ter)) - return ter; - saActual = saAmount; - return tesSUCCESS; - } - - // Sending 3rd party IOUs: transit. - - // Calculate the amount to transfer accounting - // for any transfer fees if the fee is not waived: - saActual = (waiveFee == WaiveTransferFee::Yes) ? saAmount - : multiply(saAmount, transferRate(view, issuer)); - - JLOG(j.debug()) << "rippleSendIOU> " << to_string(uSenderID) << " - > " - << to_string(uReceiverID) << " : deliver=" << saAmount.getFullText() - << " cost=" << saActual.getFullText(); - - TER terResult = rippleCreditIOU(view, issuer, uReceiverID, saAmount, true, j); - - if (tesSUCCESS == terResult) - terResult = rippleCreditIOU(view, uSenderID, issuer, saActual, true, j); - - return terResult; -} - -// Send regardless of limits. -// --> receivers: Amount/currency/issuer to deliver to receivers. -// <-- saActual: Amount actually cost to sender. Sender pays fees. -static TER -rippleSendMultiIOU( - ApplyView& view, - AccountID const& senderID, - Issue const& issue, - MultiplePaymentDestinations const& receivers, - STAmount& actual, - beast::Journal j, - WaiveTransferFee waiveFee) -{ - auto const& issuer = issue.getIssuer(); - - XRPL_ASSERT(!isXRP(senderID), "xrpl::rippleSendMultiIOU : sender is not XRP"); - - // These may diverge - STAmount takeFromSender{issue}; - actual = takeFromSender; - - // Failures return immediately. - for (auto const& r : receivers) - { - auto const& receiverID = r.first; - STAmount amount{issue, r.second}; - - /* If we aren't sending anything or if the sender is the same as the - * receiver then we don't need to do anything. - */ - if (!amount || (senderID == receiverID)) - continue; - - XRPL_ASSERT(!isXRP(receiverID), "xrpl::rippleSendMultiIOU : receiver is not XRP"); - - if (senderID == issuer || receiverID == issuer || issuer == noAccount()) - { - // Direct send: redeeming IOUs and/or sending own IOUs. - if (auto const ter = rippleCreditIOU(view, senderID, receiverID, amount, false, j)) - return ter; - actual += amount; - // Do not add amount to takeFromSender, because rippleCreditIOU took - // it. - - continue; - } - - // Sending 3rd party IOUs: transit. - - // Calculate the amount to transfer accounting - // for any transfer fees if the fee is not waived: - STAmount actualSend = (waiveFee == WaiveTransferFee::Yes) - ? amount - : multiply(amount, transferRate(view, issuer)); - actual += actualSend; - takeFromSender += actualSend; - - JLOG(j.debug()) << "rippleSendMultiIOU> " << to_string(senderID) << " - > " - << to_string(receiverID) << " : deliver=" << amount.getFullText() - << " cost=" << actual.getFullText(); - - if (TER const terResult = rippleCreditIOU(view, issuer, receiverID, amount, true, j)) - return terResult; - } - - if (senderID != issuer && takeFromSender) - { - if (TER const terResult = rippleCreditIOU(view, senderID, issuer, takeFromSender, true, j)) - return terResult; - } - - return tesSUCCESS; -} - -static TER -accountSendIOU( - ApplyView& view, - AccountID const& uSenderID, - AccountID const& uReceiverID, - STAmount const& saAmount, - beast::Journal j, - WaiveTransferFee waiveFee) -{ - if (view.rules().enabled(fixAMMv1_1)) - { - if (saAmount < beast::zero || saAmount.holds()) - { - return tecINTERNAL; // LCOV_EXCL_LINE - } - } - else - { - // LCOV_EXCL_START - XRPL_ASSERT( - saAmount >= beast::zero && !saAmount.holds(), - "xrpl::accountSendIOU : minimum amount and not MPT"); - // LCOV_EXCL_STOP - } - - /* If we aren't sending anything or if the sender is the same as the - * receiver then we don't need to do anything. - */ - if (!saAmount || (uSenderID == uReceiverID)) - return tesSUCCESS; - - if (!saAmount.native()) - { - STAmount saActual; - - JLOG(j.trace()) << "accountSendIOU: " << to_string(uSenderID) << " -> " - << to_string(uReceiverID) << " : " << saAmount.getFullText(); - - return rippleSendIOU(view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee); - } - - /* XRP send which does not check reserve and can do pure adjustment. - * Note that sender or receiver may be null and this not a mistake; this - * setup is used during pathfinding and it is carefully controlled to - * ensure that transfers are balanced. - */ - TER terResult(tesSUCCESS); - - SLE::pointer sender = - uSenderID != beast::zero ? view.peek(keylet::account(uSenderID)) : SLE::pointer(); - SLE::pointer receiver = - uReceiverID != beast::zero ? view.peek(keylet::account(uReceiverID)) : SLE::pointer(); - - if (auto stream = j.trace()) - { - std::string sender_bal("-"); - std::string receiver_bal("-"); - - if (sender) - sender_bal = sender->getFieldAmount(sfBalance).getFullText(); - - if (receiver) - receiver_bal = receiver->getFieldAmount(sfBalance).getFullText(); - - stream << "accountSendIOU> " << to_string(uSenderID) << " (" << sender_bal << ") -> " - << to_string(uReceiverID) << " (" << receiver_bal - << ") : " << saAmount.getFullText(); - } - - if (sender) - { - if (sender->getFieldAmount(sfBalance) < saAmount) - { - // VFALCO Its laborious to have to mutate the - // TER based on params everywhere - // LCOV_EXCL_START - terResult = view.open() ? TER{telFAILED_PROCESSING} : TER{tecFAILED_PROCESSING}; - // LCOV_EXCL_STOP - } - else - { - auto const sndBal = sender->getFieldAmount(sfBalance); - view.creditHook(uSenderID, xrpAccount(), saAmount, sndBal); - - // Decrement XRP balance. - sender->setFieldAmount(sfBalance, sndBal - saAmount); - view.update(sender); - } - } - - if (tesSUCCESS == terResult && receiver) - { - // Increment XRP balance. - auto const rcvBal = receiver->getFieldAmount(sfBalance); - receiver->setFieldAmount(sfBalance, rcvBal + saAmount); - view.creditHook(xrpAccount(), uReceiverID, saAmount, -rcvBal); - - view.update(receiver); - } - - if (auto stream = j.trace()) - { - std::string sender_bal("-"); - std::string receiver_bal("-"); - - if (sender) - sender_bal = sender->getFieldAmount(sfBalance).getFullText(); - - if (receiver) - receiver_bal = receiver->getFieldAmount(sfBalance).getFullText(); - - stream << "accountSendIOU< " << to_string(uSenderID) << " (" << sender_bal << ") -> " - << to_string(uReceiverID) << " (" << receiver_bal - << ") : " << saAmount.getFullText(); - } - - return terResult; -} - -static TER -accountSendMultiIOU( - ApplyView& view, - AccountID const& senderID, - Issue const& issue, - MultiplePaymentDestinations const& receivers, - beast::Journal j, - WaiveTransferFee waiveFee) -{ - XRPL_ASSERT_PARTS( - receivers.size() > 1, "xrpl::accountSendMultiIOU", "multiple recipients provided"); - - if (!issue.native()) - { - STAmount actual; - JLOG(j.trace()) << "accountSendMultiIOU: " << to_string(senderID) << " sending " - << receivers.size() << " IOUs"; - - return rippleSendMultiIOU(view, senderID, issue, receivers, actual, j, waiveFee); - } - - /* XRP send which does not check reserve and can do pure adjustment. - * Note that sender or receiver may be null and this not a mistake; this - * setup could be used during pathfinding and it is carefully controlled to - * ensure that transfers are balanced. - */ - - SLE::pointer sender = - senderID != beast::zero ? view.peek(keylet::account(senderID)) : SLE::pointer(); - - if (auto stream = j.trace()) - { - std::string sender_bal("-"); - - if (sender) - sender_bal = sender->getFieldAmount(sfBalance).getFullText(); - - stream << "accountSendMultiIOU> " << to_string(senderID) << " (" << sender_bal << ") -> " - << receivers.size() << " receivers."; - } - - // Failures return immediately. - STAmount takeFromSender{issue}; - for (auto const& r : receivers) - { - auto const& receiverID = r.first; - STAmount amount{issue, r.second}; - - if (amount < beast::zero) - { - return tecINTERNAL; // LCOV_EXCL_LINE - } - - /* If we aren't sending anything or if the sender is the same as the - * receiver then we don't need to do anything. - */ - if (!amount || (senderID == receiverID)) - continue; - - SLE::pointer receiver = - receiverID != beast::zero ? view.peek(keylet::account(receiverID)) : SLE::pointer(); - - if (auto stream = j.trace()) - { - std::string receiver_bal("-"); - - if (receiver) - receiver_bal = receiver->getFieldAmount(sfBalance).getFullText(); - - stream << "accountSendMultiIOU> " << to_string(senderID) << " -> " - << to_string(receiverID) << " (" << receiver_bal - << ") : " << amount.getFullText(); - } - - if (receiver) - { - // Increment XRP balance. - auto const rcvBal = receiver->getFieldAmount(sfBalance); - receiver->setFieldAmount(sfBalance, rcvBal + amount); - view.creditHook(xrpAccount(), receiverID, amount, -rcvBal); - - view.update(receiver); - - // Take what is actually sent - takeFromSender += amount; - } - - if (auto stream = j.trace()) - { - std::string receiver_bal("-"); - - if (receiver) - receiver_bal = receiver->getFieldAmount(sfBalance).getFullText(); - - stream << "accountSendMultiIOU< " << to_string(senderID) << " -> " - << to_string(receiverID) << " (" << receiver_bal - << ") : " << amount.getFullText(); - } - } - - if (sender) - { - if (sender->getFieldAmount(sfBalance) < takeFromSender) - { - return TER{tecFAILED_PROCESSING}; - } - - auto const sndBal = sender->getFieldAmount(sfBalance); - view.creditHook(senderID, xrpAccount(), takeFromSender, sndBal); - - // Decrement XRP balance. - sender->setFieldAmount(sfBalance, sndBal - takeFromSender); - view.update(sender); - } - - if (auto stream = j.trace()) - { - std::string sender_bal("-"); - - if (sender) - sender_bal = sender->getFieldAmount(sfBalance).getFullText(); - - stream << "accountSendMultiIOU< " << to_string(senderID) << " (" << sender_bal << ") -> " - << receivers.size() << " receivers."; - } - return tesSUCCESS; -} - -static TER -rippleCreditMPT( - ApplyView& view, - AccountID const& uSenderID, - AccountID const& uReceiverID, - STAmount const& saAmount, - beast::Journal j) -{ - // Do not check MPT authorization here - it must have been checked earlier - auto const mptID = keylet::mptIssuance(saAmount.get().getMptID()); - auto const& issuer = saAmount.getIssuer(); - auto sleIssuance = view.peek(mptID); - if (!sleIssuance) - return tecOBJECT_NOT_FOUND; - if (uSenderID == issuer) - { - (*sleIssuance)[sfOutstandingAmount] += saAmount.mpt().value(); - view.update(sleIssuance); - } - else - { - auto const mptokenID = keylet::mptoken(mptID.key, uSenderID); - if (auto sle = view.peek(mptokenID)) - { - auto const amt = sle->getFieldU64(sfMPTAmount); - auto const pay = saAmount.mpt().value(); - if (amt < pay) - return tecINSUFFICIENT_FUNDS; - (*sle)[sfMPTAmount] = amt - pay; - view.update(sle); - } - else - { - return tecNO_AUTH; - } - } - - if (uReceiverID == issuer) - { - auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount); - auto const redeem = saAmount.mpt().value(); - if (outstanding >= redeem) - { - sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem); - view.update(sleIssuance); - } - else - { - return tecINTERNAL; // LCOV_EXCL_LINE - } - } - else - { - auto const mptokenID = keylet::mptoken(mptID.key, uReceiverID); - if (auto sle = view.peek(mptokenID)) - { - (*sle)[sfMPTAmount] += saAmount.mpt().value(); - view.update(sle); - } - else - { - return tecNO_AUTH; - } - } - - return tesSUCCESS; -} - -static TER -rippleSendMPT( - ApplyView& view, - AccountID const& uSenderID, - AccountID const& uReceiverID, - STAmount const& saAmount, - STAmount& saActual, - beast::Journal j, - WaiveTransferFee waiveFee) -{ - XRPL_ASSERT(uSenderID != uReceiverID, "xrpl::rippleSendMPT : sender is not receiver"); - - // Safe to get MPT since rippleSendMPT is only called by accountSendMPT - auto const& issuer = saAmount.getIssuer(); - - auto const sle = view.read(keylet::mptIssuance(saAmount.get().getMptID())); - if (!sle) - return tecOBJECT_NOT_FOUND; - - if (uSenderID == issuer || uReceiverID == issuer) - { - // if sender is issuer, check that the new OutstandingAmount will not - // exceed MaximumAmount - if (uSenderID == issuer) - { - auto const sendAmount = saAmount.mpt().value(); - auto const maximumAmount = sle->at(~sfMaximumAmount).value_or(maxMPTokenAmount); - if (sendAmount > maximumAmount || - sle->getFieldU64(sfOutstandingAmount) > maximumAmount - sendAmount) - return tecPATH_DRY; - } - - // Direct send: redeeming MPTs and/or sending own MPTs. - auto const ter = rippleCreditMPT(view, uSenderID, uReceiverID, saAmount, j); - if (!isTesSuccess(ter)) - return ter; - saActual = saAmount; - return tesSUCCESS; - } - - // Sending 3rd party MPTs: transit. - saActual = (waiveFee == WaiveTransferFee::Yes) - ? saAmount - : multiply(saAmount, transferRate(view, saAmount.get().getMptID())); - - JLOG(j.debug()) << "rippleSendMPT> " << to_string(uSenderID) << " - > " - << to_string(uReceiverID) << " : deliver=" << saAmount.getFullText() - << " cost=" << saActual.getFullText(); - - if (auto const terResult = rippleCreditMPT(view, issuer, uReceiverID, saAmount, j); - !isTesSuccess(terResult)) - return terResult; - - return rippleCreditMPT(view, uSenderID, issuer, saActual, j); -} - -static TER -rippleSendMultiMPT( - ApplyView& view, - AccountID const& senderID, - MPTIssue const& mptIssue, - MultiplePaymentDestinations const& receivers, - STAmount& actual, - beast::Journal j, - WaiveTransferFee waiveFee) -{ - // Safe to get MPT since rippleSendMultiMPT is only called by - // accountSendMultiMPT - auto const& issuer = mptIssue.getIssuer(); - - auto const sle = view.read(keylet::mptIssuance(mptIssue.getMptID())); - if (!sle) - return tecOBJECT_NOT_FOUND; - - // These may diverge - STAmount takeFromSender{mptIssue}; - actual = takeFromSender; - - for (auto const& r : receivers) - { - auto const& receiverID = r.first; - STAmount amount{mptIssue, r.second}; - - if (amount < beast::zero) - { - return tecINTERNAL; // LCOV_EXCL_LINE - } - - /* If we aren't sending anything or if the sender is the same as the - * receiver then we don't need to do anything. - */ - if (!amount || (senderID == receiverID)) - continue; - - if (senderID == issuer || receiverID == issuer) - { - // if sender is issuer, check that the new OutstandingAmount will - // not exceed MaximumAmount - if (senderID == issuer) - { - XRPL_ASSERT_PARTS( - takeFromSender == beast::zero, - "rippler::rippleSendMultiMPT", - "sender == issuer, takeFromSender == zero"); - auto const sendAmount = amount.mpt().value(); - auto const maximumAmount = sle->at(~sfMaximumAmount).value_or(maxMPTokenAmount); - if (sendAmount > maximumAmount || - sle->getFieldU64(sfOutstandingAmount) > maximumAmount - sendAmount) - return tecPATH_DRY; - } - - // Direct send: redeeming MPTs and/or sending own MPTs. - if (auto const ter = rippleCreditMPT(view, senderID, receiverID, amount, j)) - return ter; - actual += amount; - // Do not add amount to takeFromSender, because rippleCreditMPT took - // it - - continue; - } - - // Sending 3rd party MPTs: transit. - STAmount actualSend = (waiveFee == WaiveTransferFee::Yes) - ? amount - : multiply(amount, transferRate(view, amount.get().getMptID())); - actual += actualSend; - takeFromSender += actualSend; - - JLOG(j.debug()) << "rippleSendMultiMPT> " << to_string(senderID) << " - > " - << to_string(receiverID) << " : deliver=" << amount.getFullText() - << " cost=" << actualSend.getFullText(); - - if (auto const terResult = rippleCreditMPT(view, issuer, receiverID, amount, j)) - return terResult; - } - if (senderID != issuer && takeFromSender) - { - if (TER const terResult = rippleCreditMPT(view, senderID, issuer, takeFromSender, j)) - return terResult; - } - - return tesSUCCESS; -} - -static TER -accountSendMPT( - ApplyView& view, - AccountID const& uSenderID, - AccountID const& uReceiverID, - STAmount const& saAmount, - beast::Journal j, - WaiveTransferFee waiveFee) -{ - XRPL_ASSERT( - saAmount >= beast::zero && saAmount.holds(), - "xrpl::accountSendMPT : minimum amount and MPT"); - - /* If we aren't sending anything or if the sender is the same as the - * receiver then we don't need to do anything. - */ - if (!saAmount || (uSenderID == uReceiverID)) - return tesSUCCESS; - - STAmount saActual{saAmount.asset()}; - - return rippleSendMPT(view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee); -} - -static TER -accountSendMultiMPT( - ApplyView& view, - AccountID const& senderID, - MPTIssue const& mptIssue, - MultiplePaymentDestinations const& receivers, - beast::Journal j, - WaiveTransferFee waiveFee) -{ - STAmount actual; - - return rippleSendMultiMPT(view, senderID, mptIssue, receivers, actual, j, waiveFee); -} - -TER -accountSend( - ApplyView& view, - AccountID const& uSenderID, - AccountID const& uReceiverID, - STAmount const& saAmount, - beast::Journal j, - WaiveTransferFee waiveFee) -{ - return std::visit( - [&](TIss const& issue) { - if constexpr (std::is_same_v) - { - return accountSendIOU(view, uSenderID, uReceiverID, saAmount, j, waiveFee); - } - else - { - return accountSendMPT(view, uSenderID, uReceiverID, saAmount, j, waiveFee); - } - }, - saAmount.asset().value()); -} - -TER -accountSendMulti( - ApplyView& view, - AccountID const& senderID, - Asset const& asset, - MultiplePaymentDestinations const& receivers, - beast::Journal j, - WaiveTransferFee waiveFee) -{ - XRPL_ASSERT_PARTS( - receivers.size() > 1, "xrpl::accountSendMulti", "multiple recipients provided"); - return std::visit( - [&](TIss const& issue) { - if constexpr (std::is_same_v) - { - return accountSendMultiIOU(view, senderID, issue, receivers, j, waiveFee); - } - else - { - return accountSendMultiMPT(view, senderID, issue, receivers, j, waiveFee); - } - }, - asset.value()); -} - -static bool -updateTrustLine( - ApplyView& view, - SLE::pointer state, - bool bSenderHigh, - AccountID const& sender, - STAmount const& before, - STAmount const& after, - beast::Journal j) -{ - if (!state) - return false; - std::uint32_t const flags(state->getFieldU32(sfFlags)); - - auto sle = view.peek(keylet::account(sender)); - if (!sle) - return false; - - // YYY Could skip this if rippling in reverse. - if (before > beast::zero - // Sender balance was positive. - && after <= beast::zero - // Sender is zero or negative. - && (flags & (!bSenderHigh ? lsfLowReserve : lsfHighReserve)) - // Sender reserve is set. - && static_cast(flags & (!bSenderHigh ? lsfLowNoRipple : lsfHighNoRipple)) != - static_cast(sle->getFlags() & lsfDefaultRipple) && - !(flags & (!bSenderHigh ? lsfLowFreeze : lsfHighFreeze)) && - !state->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit) - // Sender trust limit is 0. - && !state->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn) - // Sender quality in is 0. - && !state->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut)) - // Sender quality out is 0. - { - // VFALCO Where is the line being deleted? - // Clear the reserve of the sender, possibly delete the line! - adjustOwnerCount(view, sle, -1, j); - - // Clear reserve flag. - state->setFieldU32(sfFlags, flags & (!bSenderHigh ? ~lsfLowReserve : ~lsfHighReserve)); - - // Balance is zero, receiver reserve is clear. - if (!after // Balance is zero. - && !(flags & (bSenderHigh ? lsfLowReserve : lsfHighReserve))) - return true; - } - return false; -} - -TER -issueIOU( - ApplyView& view, - AccountID const& account, - STAmount const& amount, - Issue const& issue, - beast::Journal j) -{ - XRPL_ASSERT( - !isXRP(account) && !isXRP(issue.account), - "xrpl::issueIOU : neither account nor issuer is XRP"); - - // Consistency check - XRPL_ASSERT(issue == amount.issue(), "xrpl::issueIOU : matching issue"); - - // Can't send to self! - XRPL_ASSERT(issue.account != account, "xrpl::issueIOU : not issuer account"); - - JLOG(j.trace()) << "issueIOU: " << to_string(account) << ": " << amount.getFullText(); - - bool bSenderHigh = issue.account > account; - - auto const index = keylet::line(issue.account, account, issue.currency); - - if (auto state = view.peek(index)) - { - STAmount final_balance = state->getFieldAmount(sfBalance); - - if (bSenderHigh) - final_balance.negate(); // Put balance in sender terms. - - STAmount const start_balance = final_balance; - - final_balance -= amount; - - auto const must_delete = updateTrustLine( - view, state, bSenderHigh, issue.account, start_balance, final_balance, j); - - view.creditHook(issue.account, account, amount, start_balance); - - if (bSenderHigh) - final_balance.negate(); - - // Adjust the balance on the trust line if necessary. We do this even if - // we are going to delete the line to reflect the correct balance at the - // time of deletion. - state->setFieldAmount(sfBalance, final_balance); - if (must_delete) - { - return trustDelete( - view, - state, - bSenderHigh ? account : issue.account, - bSenderHigh ? issue.account : account, - j); - } - - view.update(state); - - return tesSUCCESS; - } - - // NIKB TODO: The limit uses the receiver's account as the issuer and - // this is unnecessarily inefficient as copying which could be avoided - // is now required. Consider available options. - STAmount const limit(Issue{issue.currency, account}); - STAmount final_balance = amount; - - final_balance.setIssuer(noAccount()); - - auto const receiverAccount = view.peek(keylet::account(account)); - if (!receiverAccount) - return tefINTERNAL; // LCOV_EXCL_LINE - - bool noRipple = (receiverAccount->getFlags() & lsfDefaultRipple) == 0; - - return trustCreate( - view, - bSenderHigh, - issue.account, - account, - index.key, - receiverAccount, - false, - noRipple, - false, - false, - final_balance, - limit, - 0, - 0, - j); -} - -TER -redeemIOU( - ApplyView& view, - AccountID const& account, - STAmount const& amount, - Issue const& issue, - beast::Journal j) -{ - XRPL_ASSERT( - !isXRP(account) && !isXRP(issue.account), - "xrpl::redeemIOU : neither account nor issuer is XRP"); - - // Consistency check - XRPL_ASSERT(issue == amount.issue(), "xrpl::redeemIOU : matching issue"); - - // Can't send to self! - XRPL_ASSERT(issue.account != account, "xrpl::redeemIOU : not issuer account"); - - JLOG(j.trace()) << "redeemIOU: " << to_string(account) << ": " << amount.getFullText(); - - bool bSenderHigh = account > issue.account; - - if (auto state = view.peek(keylet::line(account, issue.account, issue.currency))) - { - STAmount final_balance = state->getFieldAmount(sfBalance); - - if (bSenderHigh) - final_balance.negate(); // Put balance in sender terms. - - STAmount const start_balance = final_balance; - - final_balance -= amount; - - auto const must_delete = - updateTrustLine(view, state, bSenderHigh, account, start_balance, final_balance, j); - - view.creditHook(account, issue.account, amount, start_balance); - - if (bSenderHigh) - final_balance.negate(); - - // Adjust the balance on the trust line if necessary. We do this even if - // we are going to delete the line to reflect the correct balance at the - // time of deletion. - state->setFieldAmount(sfBalance, final_balance); - - if (must_delete) - { - return trustDelete( - view, - state, - bSenderHigh ? issue.account : account, - bSenderHigh ? account : issue.account, - j); - } - - view.update(state); - return tesSUCCESS; - } - - // In order to hold an IOU, a trust line *MUST* exist to track the - // balance. If it doesn't, then something is very wrong. Don't try - // to continue. - // LCOV_EXCL_START - JLOG(j.fatal()) << "redeemIOU: " << to_string(account) << " attempts to redeem " - << amount.getFullText() << " but no trust line exists!"; - - return tefINTERNAL; - // LCOV_EXCL_STOP -} - -TER -transferXRP( - ApplyView& view, - AccountID const& from, - AccountID const& to, - STAmount const& amount, - beast::Journal j) -{ - XRPL_ASSERT(from != beast::zero, "xrpl::transferXRP : nonzero from account"); - XRPL_ASSERT(to != beast::zero, "xrpl::transferXRP : nonzero to account"); - XRPL_ASSERT(from != to, "xrpl::transferXRP : sender is not receiver"); - XRPL_ASSERT(amount.native(), "xrpl::transferXRP : amount is XRP"); - - SLE::pointer const sender = view.peek(keylet::account(from)); - SLE::pointer const receiver = view.peek(keylet::account(to)); - if (!sender || !receiver) - return tefINTERNAL; // LCOV_EXCL_LINE - - JLOG(j.trace()) << "transferXRP: " << to_string(from) << " -> " << to_string(to) - << ") : " << amount.getFullText(); - - if (sender->getFieldAmount(sfBalance) < amount) - { - // VFALCO Its unfortunate we have to keep - // mutating these TER everywhere - // FIXME: this logic should be moved to callers maybe? - // LCOV_EXCL_START - return view.open() ? TER{telFAILED_PROCESSING} : TER{tecFAILED_PROCESSING}; - // LCOV_EXCL_STOP - } - - // Decrement XRP balance. - sender->setFieldAmount(sfBalance, sender->getFieldAmount(sfBalance) - amount); - view.update(sender); - - receiver->setFieldAmount(sfBalance, receiver->getFieldAmount(sfBalance) + amount); - view.update(receiver); - - return tesSUCCESS; -} - -TER -requireAuth(ReadView const& view, Issue const& issue, AccountID const& account, AuthType authType) -{ - if (isXRP(issue) || issue.account == account) - return tesSUCCESS; - - auto const trustLine = view.read(keylet::line(account, issue.account, issue.currency)); - // If account has no line, and this is a strong check, fail - if (!trustLine && authType == AuthType::StrongAuth) - return tecNO_LINE; - - // 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) - { - if (trustLine) - { - return ((*trustLine)[sfFlags] & ((account > issue.account) ? lsfLowAuth : lsfHighAuth)) - ? tesSUCCESS - : TER{tecNO_AUTH}; - } - return TER{tecNO_LINE}; - } - - return tesSUCCESS; -} - -TER -requireAuth( - ReadView const& view, - MPTIssue const& mptIssue, - AccountID const& account, - AuthType authType, - int depth) -{ - auto const mptID = keylet::mptIssuance(mptIssue.getMptID()); - auto const sleIssuance = view.read(mptID); - if (!sleIssuance) - return tecOBJECT_NOT_FOUND; - - auto const mptIssuer = sleIssuance->getAccountID(sfIssuer); - - // issuer is always "authorized" - if (mptIssuer == account) // Issuer won't have MPToken - return tesSUCCESS; - - bool const featureSAVEnabled = view.rules().enabled(featureSingleAssetVault); - - if (featureSAVEnabled) - { - if (depth >= maxAssetCheckDepth) - return tecINTERNAL; // LCOV_EXCL_LINE - - // requireAuth is recursive if the issuer is a vault pseudo-account - auto const sleIssuer = view.read(keylet::account(mptIssuer)); - if (!sleIssuer) - return tefINTERNAL; // LCOV_EXCL_LINE - - if (sleIssuer->isFieldPresent(sfVaultID)) - { - auto const sleVault = view.read(keylet::vault(sleIssuer->getFieldH256(sfVaultID))); - if (!sleVault) - return tefINTERNAL; // LCOV_EXCL_LINE - - auto const asset = sleVault->at(sfAsset); - if (auto const err = std::visit( - [&](TIss const& issue) { - if constexpr (std::is_same_v) - { - return requireAuth(view, issue, account, authType); - } - else - { - return requireAuth(view, issue, account, authType, depth + 1); - } - }, - asset.value()); - !isTesSuccess(err)) - return err; - } - } - - auto const mptokenID = keylet::mptoken(mptID.key, account); - auto const sleToken = view.read(mptokenID); - - // if account has no MPToken, fail - if (!sleToken && (authType == AuthType::StrongAuth || authType == AuthType::Legacy)) - return tecNO_AUTH; - - // Note, this check is not amendment-gated because DomainID will be always - // empty **unless** writing to it has been enabled by an amendment - auto const maybeDomainID = sleIssuance->at(~sfDomainID); - if (maybeDomainID) - { - XRPL_ASSERT( - sleIssuance->getFieldU32(sfFlags) & lsfMPTRequireAuth, - "xrpl::requireAuth : issuance requires authorization"); - // ter = tefINTERNAL | tecOBJECT_NOT_FOUND | tecNO_AUTH | tecEXPIRED - auto const ter = credentials::validDomain(view, *maybeDomainID, account); - if (isTesSuccess(ter)) - { - return ter; // Note: sleToken might be null - } - if (!sleToken) - { - return ter; - } - // We ignore error from validDomain if we found sleToken, as it could - // belong to someone who is explicitly authorized e.g. a vault owner. - } - - if (featureSAVEnabled) - { - // Implicitly authorize Vault and LoanBroker pseudo-accounts - if (isPseudoAccount(view, account, {&sfVaultID, &sfLoanBrokerID})) - return tesSUCCESS; - } - - // mptoken must be authorized if issuance enabled requireAuth - if (sleIssuance->isFlag(lsfMPTRequireAuth) && - (!sleToken || !sleToken->isFlag(lsfMPTAuthorized))) - return tecNO_AUTH; - - return tesSUCCESS; // Note: sleToken might be null -} - -[[nodiscard]] TER -enforceMPTokenAuthorization( - ApplyView& view, - MPTID const& mptIssuanceID, - AccountID const& account, - XRPAmount const& priorBalance, // for MPToken authorization - beast::Journal j) -{ - auto const sleIssuance = view.read(keylet::mptIssuance(mptIssuanceID)); - if (!sleIssuance) - return tefINTERNAL; // LCOV_EXCL_LINE - - XRPL_ASSERT( - sleIssuance->isFlag(lsfMPTRequireAuth), - "xrpl::enforceMPTokenAuthorization : authorization required"); - - if (account == sleIssuance->at(sfIssuer)) - return tefINTERNAL; // LCOV_EXCL_LINE - - auto const keylet = keylet::mptoken(mptIssuanceID, account); - auto const sleToken = view.read(keylet); // NOTE: might be null - auto const maybeDomainID = sleIssuance->at(~sfDomainID); - bool expired = false; - bool const authorizedByDomain = [&]() -> bool { - // NOTE: defensive here, should be checked in preclaim - if (!maybeDomainID.has_value()) - return false; // LCOV_EXCL_LINE - - auto const ter = verifyValidDomain(view, account, *maybeDomainID, j); - if (isTesSuccess(ter)) - return true; - if (ter == tecEXPIRED) - expired = true; - return false; - }(); - - if (!authorizedByDomain && sleToken == nullptr) - { - // Could not find MPToken and won't create one, could be either of: - // - // 1. Field sfDomainID not set in MPTokenIssuance or - // 2. Account has no matching and accepted credentials or - // 3. Account has all expired credentials (deleted in verifyValidDomain) - // - // Either way, return tecNO_AUTH and there is nothing else to do - return expired ? tecEXPIRED : tecNO_AUTH; - } - if (!authorizedByDomain && maybeDomainID.has_value()) - { - // Found an MPToken but the account is not authorized and we expect - // it to have been authorized by the domain. This could be because the - // credentials used to create the MPToken have expired or been deleted. - return expired ? tecEXPIRED : tecNO_AUTH; - } - if (!authorizedByDomain) - { - // We found an MPToken, but sfDomainID is not set, so this is a classic - // MPToken which requires authorization by the token issuer. - XRPL_ASSERT( - sleToken != nullptr && !maybeDomainID.has_value(), - "xrpl::enforceMPTokenAuthorization : found MPToken"); - if (sleToken->isFlag(lsfMPTAuthorized)) - return tesSUCCESS; - - return tecNO_AUTH; - } - if (authorizedByDomain && sleToken != nullptr) - { - // Found an MPToken, authorized by the domain. Ignore authorization flag - // lsfMPTAuthorized because it is meaningless. Return tesSUCCESS - XRPL_ASSERT( - maybeDomainID.has_value(), - "xrpl::enforceMPTokenAuthorization : found MPToken for domain"); - return tesSUCCESS; - } - if (authorizedByDomain) - { - // Could not find MPToken but there should be one because we are - // authorized by domain. Proceed to create it, then return tesSUCCESS - XRPL_ASSERT( - maybeDomainID.has_value() && sleToken == nullptr, - "xrpl::enforceMPTokenAuthorization : new MPToken for domain"); - if (auto const err = authorizeMPToken( - view, - priorBalance, // priorBalance - mptIssuanceID, // mptIssuanceID - account, // account - j); - !isTesSuccess(err)) - return err; - - return tesSUCCESS; - } - - // LCOV_EXCL_START - UNREACHABLE("xrpl::enforceMPTokenAuthorization : condition list is incomplete"); - return tefINTERNAL; - // LCOV_EXCL_STOP -} - -TER -canTransfer( - ReadView const& view, - MPTIssue const& mptIssue, - AccountID const& from, - AccountID const& to) -{ - auto const mptID = keylet::mptIssuance(mptIssue.getMptID()); - auto const sleIssuance = view.read(mptID); - if (!sleIssuance) - return tecOBJECT_NOT_FOUND; - - if (!(sleIssuance->getFieldU32(sfFlags) & lsfMPTCanTransfer)) - { - if (from != (*sleIssuance)[sfIssuer] && to != (*sleIssuance)[sfIssuer]) - return TER{tecNO_AUTH}; - } - return tesSUCCESS; -} - -[[nodiscard]] TER -canTransfer(ReadView const& view, Issue const& issue, AccountID const& from, AccountID const& to) -{ - if (issue.native()) - return tesSUCCESS; - - auto const& issuerId = issue.getIssuer(); - if (issuerId == from || issuerId == to) - return tesSUCCESS; - auto const sleIssuer = view.read(keylet::account(issuerId)); - if (sleIssuer == nullptr) - return tefINTERNAL; // LCOV_EXCL_LINE - - auto const isRippleDisabled = [&](AccountID account) -> bool { - // Line might not exist, but some transfers can create it. If this - // is the case, just check the default ripple on the issuer account. - auto const line = view.read(keylet::line(account, issue)); - if (line) - { - bool const issuerHigh = issuerId > account; - return line->isFlag(issuerHigh ? lsfHighNoRipple : lsfLowNoRipple); - } - return sleIssuer->isFlag(lsfDefaultRipple) == false; - }; - - // Fail if rippling disabled on both trust lines - if (isRippleDisabled(from) && isRippleDisabled(to)) - return terNO_RIPPLE; - - return tesSUCCESS; -} - TER cleanupOnAccountDelete( ApplyView& view, @@ -3234,7 +471,7 @@ cleanupOnAccountDelete( { // Directory node has an invalid index. Bail out. // LCOV_EXCL_START - JLOG(j.fatal()) << "AccountDelete: Directory node in ledger " << view.seq() + JLOG(j.fatal()) << "DeleteAccount: Directory node in ledger " << view.seq() << " has index to object that is missing: " << to_string(dirEntry); return tefBAD_LEDGER; // LCOV_EXCL_STOP @@ -3269,7 +506,7 @@ cleanupOnAccountDelete( if (uDirEntry == 0) { // LCOV_EXCL_START - JLOG(j.error()) << "AccountDelete iterator re-validation failed."; + JLOG(j.error()) << "DeleteAccount iterator re-validation failed."; return tefBAD_LEDGER; // LCOV_EXCL_STOP } @@ -3282,447 +519,6 @@ cleanupOnAccountDelete( return tesSUCCESS; } -TER -deleteAMMTrustLine( - ApplyView& view, - std::shared_ptr sleState, - std::optional const& ammAccountID, - beast::Journal j) -{ - if (!sleState || sleState->getType() != ltRIPPLE_STATE) - return tecINTERNAL; // LCOV_EXCL_LINE - - auto const& [low, high] = std::minmax( - sleState->getFieldAmount(sfLowLimit).getIssuer(), - sleState->getFieldAmount(sfHighLimit).getIssuer()); - auto sleLow = view.peek(keylet::account(low)); - auto sleHigh = view.peek(keylet::account(high)); - if (!sleLow || !sleHigh) - return tecINTERNAL; // LCOV_EXCL_LINE - - bool const ammLow = sleLow->isFieldPresent(sfAMMID); - bool const ammHigh = sleHigh->isFieldPresent(sfAMMID); - - // can't both be AMM - if (ammLow && ammHigh) - return tecINTERNAL; // LCOV_EXCL_LINE - - // at least one must be - if (!ammLow && !ammHigh) - return terNO_AMM; - - // one must be the target amm - if (ammAccountID && (low != *ammAccountID && high != *ammAccountID)) - return terNO_AMM; - - if (auto const ter = trustDelete(view, sleState, low, high, j); !isTesSuccess(ter)) - { - JLOG(j.error()) << "deleteAMMTrustLine: failed to delete the trustline."; - return ter; - } - - auto const uFlags = !ammLow ? lsfLowReserve : lsfHighReserve; - if (!(sleState->getFlags() & uFlags)) - return tecINTERNAL; // LCOV_EXCL_LINE - - adjustOwnerCount(view, !ammLow ? sleLow : sleHigh, -1, j); - - return tesSUCCESS; -} - -TER -rippleCredit( - ApplyView& view, - AccountID const& uSenderID, - AccountID const& uReceiverID, - STAmount const& saAmount, - bool bCheckIssuer, - beast::Journal j) -{ - return std::visit( - [&](TIss const& issue) { - if constexpr (std::is_same_v) - { - return rippleCreditIOU(view, uSenderID, uReceiverID, saAmount, bCheckIssuer, j); - } - else - { - XRPL_ASSERT(!bCheckIssuer, "xrpl::rippleCredit : not checking issuer"); - return rippleCreditMPT(view, uSenderID, uReceiverID, saAmount, j); - } - }, - saAmount.asset().value()); -} - -[[nodiscard]] std::optional -assetsToSharesDeposit( - std::shared_ptr const& vault, - std::shared_ptr const& issuance, - STAmount const& assets) -{ - XRPL_ASSERT(!assets.negative(), "xrpl::assetsToSharesDeposit : non-negative assets"); - XRPL_ASSERT( - assets.asset() == vault->at(sfAsset), - "xrpl::assetsToSharesDeposit : assets and vault match"); - if (assets.negative() || assets.asset() != vault->at(sfAsset)) - return std::nullopt; // LCOV_EXCL_LINE - - Number const assetTotal = vault->at(sfAssetsTotal); - STAmount shares{vault->at(sfShareMPTID)}; - if (assetTotal == 0) - { - return STAmount{ - shares.asset(), - Number(assets.mantissa(), assets.exponent() + vault->at(sfScale)).truncate()}; - } - - Number const shareTotal = issuance->at(sfOutstandingAmount); - shares = ((shareTotal * assets) / assetTotal).truncate(); - return shares; -} - -[[nodiscard]] std::optional -sharesToAssetsDeposit( - std::shared_ptr const& vault, - std::shared_ptr const& issuance, - STAmount const& shares) -{ - XRPL_ASSERT(!shares.negative(), "xrpl::sharesToAssetsDeposit : non-negative shares"); - XRPL_ASSERT( - shares.asset() == vault->at(sfShareMPTID), - "xrpl::sharesToAssetsDeposit : shares and vault match"); - if (shares.negative() || shares.asset() != vault->at(sfShareMPTID)) - return std::nullopt; // LCOV_EXCL_LINE - - Number const assetTotal = vault->at(sfAssetsTotal); - STAmount assets{vault->at(sfAsset)}; - if (assetTotal == 0) - { - return STAmount{ - assets.asset(), shares.mantissa(), shares.exponent() - vault->at(sfScale), false}; - } - - Number const shareTotal = issuance->at(sfOutstandingAmount); - assets = (assetTotal * shares) / shareTotal; - return assets; -} - -[[nodiscard]] std::optional -assetsToSharesWithdraw( - std::shared_ptr const& vault, - std::shared_ptr const& issuance, - STAmount const& assets, - TruncateShares truncate) -{ - XRPL_ASSERT(!assets.negative(), "xrpl::assetsToSharesDeposit : non-negative assets"); - XRPL_ASSERT( - assets.asset() == vault->at(sfAsset), - "xrpl::assetsToSharesWithdraw : assets and vault match"); - if (assets.negative() || assets.asset() != vault->at(sfAsset)) - return std::nullopt; // LCOV_EXCL_LINE - - Number assetTotal = vault->at(sfAssetsTotal); - assetTotal -= vault->at(sfLossUnrealized); - STAmount shares{vault->at(sfShareMPTID)}; - if (assetTotal == 0) - return shares; - Number const shareTotal = issuance->at(sfOutstandingAmount); - Number result = (shareTotal * assets) / assetTotal; - if (truncate == TruncateShares::yes) - result = result.truncate(); - shares = result; - return shares; -} - -[[nodiscard]] std::optional -sharesToAssetsWithdraw( - std::shared_ptr const& vault, - std::shared_ptr const& issuance, - STAmount const& shares) -{ - XRPL_ASSERT(!shares.negative(), "xrpl::sharesToAssetsDeposit : non-negative shares"); - XRPL_ASSERT( - shares.asset() == vault->at(sfShareMPTID), - "xrpl::sharesToAssetsWithdraw : shares and vault match"); - if (shares.negative() || shares.asset() != vault->at(sfShareMPTID)) - return std::nullopt; // LCOV_EXCL_LINE - - Number assetTotal = vault->at(sfAssetsTotal); - assetTotal -= vault->at(sfLossUnrealized); - STAmount assets{vault->at(sfAsset)}; - if (assetTotal == 0) - return assets; - Number const shareTotal = issuance->at(sfOutstandingAmount); - assets = (assetTotal * shares) / shareTotal; - return assets; -} - -TER -rippleLockEscrowMPT( - ApplyView& view, - AccountID const& sender, - STAmount const& amount, - beast::Journal j) -{ - auto const mptIssue = amount.get(); - auto const mptID = keylet::mptIssuance(mptIssue.getMptID()); - auto sleIssuance = view.peek(mptID); - if (!sleIssuance) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleLockEscrowMPT: MPT issuance not found for " - << mptIssue.getMptID(); - return tecOBJECT_NOT_FOUND; - } // LCOV_EXCL_STOP - - if (amount.getIssuer() == sender) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleLockEscrowMPT: sender is the issuer, cannot lock MPTs."; - return tecINTERNAL; - } // LCOV_EXCL_STOP - - // 1. Decrease the MPT Holder MPTAmount - // 2. Increase the MPT Holder EscrowedAmount - { - auto const mptokenID = keylet::mptoken(mptID.key, sender); - auto sle = view.peek(mptokenID); - if (!sle) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleLockEscrowMPT: MPToken not found for " << sender; - return tecOBJECT_NOT_FOUND; - } // LCOV_EXCL_STOP - - auto const amt = sle->getFieldU64(sfMPTAmount); - auto const pay = amount.mpt().value(); - - // Underflow check for subtraction - if (!canSubtract(STAmount(mptIssue, amt), STAmount(mptIssue, pay))) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleLockEscrowMPT: insufficient MPTAmount for " - << to_string(sender) << ": " << amt << " < " << pay; - return tecINTERNAL; - } // LCOV_EXCL_STOP - - (*sle)[sfMPTAmount] = amt - pay; - - // Overflow check for addition - uint64_t const locked = (*sle)[~sfLockedAmount].value_or(0); - - if (!canAdd(STAmount(mptIssue, locked), STAmount(mptIssue, pay))) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleLockEscrowMPT: overflow on locked amount for " - << to_string(sender) << ": " << locked << " + " << pay; - return tecINTERNAL; - } // LCOV_EXCL_STOP - - if (sle->isFieldPresent(sfLockedAmount)) - { - (*sle)[sfLockedAmount] += pay; - } - else - { - sle->setFieldU64(sfLockedAmount, pay); - } - - view.update(sle); - } - - // 1. Increase the Issuance EscrowedAmount - // 2. DO NOT change the Issuance OutstandingAmount - { - uint64_t const issuanceEscrowed = (*sleIssuance)[~sfLockedAmount].value_or(0); - auto const pay = amount.mpt().value(); - - // Overflow check for addition - if (!canAdd(STAmount(mptIssue, issuanceEscrowed), STAmount(mptIssue, pay))) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleLockEscrowMPT: overflow on issuance " - "locked amount for " - << mptIssue.getMptID() << ": " << issuanceEscrowed << " + " << pay; - return tecINTERNAL; - } // LCOV_EXCL_STOP - - if (sleIssuance->isFieldPresent(sfLockedAmount)) - { - (*sleIssuance)[sfLockedAmount] += pay; - } - else - { - sleIssuance->setFieldU64(sfLockedAmount, pay); - } - - view.update(sleIssuance); - } - return tesSUCCESS; -} - -TER -rippleUnlockEscrowMPT( - ApplyView& view, - AccountID const& sender, - AccountID const& receiver, - STAmount const& netAmount, - STAmount const& grossAmount, - beast::Journal j) -{ - if (!view.rules().enabled(fixTokenEscrowV1)) - { - XRPL_ASSERT( - netAmount == grossAmount, "xrpl::rippleUnlockEscrowMPT : netAmount == grossAmount"); - } - - auto const& issuer = netAmount.getIssuer(); - auto const& mptIssue = netAmount.get(); - auto const mptID = keylet::mptIssuance(mptIssue.getMptID()); - auto sleIssuance = view.peek(mptID); - if (!sleIssuance) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleUnlockEscrowMPT: MPT issuance not found for " - << mptIssue.getMptID(); - return tecOBJECT_NOT_FOUND; - } // LCOV_EXCL_STOP - - // Decrease the Issuance EscrowedAmount - { - if (!sleIssuance->isFieldPresent(sfLockedAmount)) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleUnlockEscrowMPT: no locked amount in issuance for " - << mptIssue.getMptID(); - return tecINTERNAL; - } // LCOV_EXCL_STOP - - auto const locked = sleIssuance->getFieldU64(sfLockedAmount); - auto const redeem = grossAmount.mpt().value(); - - // Underflow check for subtraction - if (!canSubtract(STAmount(mptIssue, locked), STAmount(mptIssue, redeem))) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleUnlockEscrowMPT: insufficient locked amount for " - << mptIssue.getMptID() << ": " << locked << " < " << redeem; - return tecINTERNAL; - } // LCOV_EXCL_STOP - - auto const newLocked = locked - redeem; - if (newLocked == 0) - { - sleIssuance->makeFieldAbsent(sfLockedAmount); - } - else - { - sleIssuance->setFieldU64(sfLockedAmount, newLocked); - } - view.update(sleIssuance); - } - - if (issuer != receiver) - { - // Increase the MPT Holder MPTAmount - auto const mptokenID = keylet::mptoken(mptID.key, receiver); - auto sle = view.peek(mptokenID); - if (!sle) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleUnlockEscrowMPT: MPToken not found for " << receiver; - return tecOBJECT_NOT_FOUND; - } // LCOV_EXCL_STOP - - auto current = sle->getFieldU64(sfMPTAmount); - auto delta = netAmount.mpt().value(); - - // Overflow check for addition - if (!canAdd(STAmount(mptIssue, current), STAmount(mptIssue, delta))) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleUnlockEscrowMPT: overflow on MPTAmount for " - << to_string(receiver) << ": " << current << " + " << delta; - return tecINTERNAL; - } // LCOV_EXCL_STOP - - (*sle)[sfMPTAmount] += delta; - view.update(sle); - } - else - { - // Decrease the Issuance OutstandingAmount - auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount); - auto const redeem = netAmount.mpt().value(); - - // Underflow check for subtraction - if (!canSubtract(STAmount(mptIssue, outstanding), STAmount(mptIssue, redeem))) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleUnlockEscrowMPT: insufficient outstanding amount for " - << mptIssue.getMptID() << ": " << outstanding << " < " << redeem; - return tecINTERNAL; - } // LCOV_EXCL_STOP - - sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem); - view.update(sleIssuance); - } - - if (issuer == sender) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleUnlockEscrowMPT: sender is the issuer, " - "cannot unlock MPTs."; - return tecINTERNAL; - } // LCOV_EXCL_STOP - - // Decrease the MPT Holder EscrowedAmount - auto const mptokenID = keylet::mptoken(mptID.key, sender); - auto sle = view.peek(mptokenID); - if (!sle) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleUnlockEscrowMPT: MPToken not found for " << sender; - return tecOBJECT_NOT_FOUND; - } // LCOV_EXCL_STOP - - if (!sle->isFieldPresent(sfLockedAmount)) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleUnlockEscrowMPT: no locked amount in MPToken for " - << to_string(sender); - return tecINTERNAL; - } // LCOV_EXCL_STOP - - auto const locked = sle->getFieldU64(sfLockedAmount); - auto const delta = grossAmount.mpt().value(); - - // Underflow check for subtraction - if (!canSubtract(STAmount(mptIssue, locked), STAmount(mptIssue, delta))) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleUnlockEscrowMPT: insufficient locked amount for " - << to_string(sender) << ": " << locked << " < " << delta; - return tecINTERNAL; - } // LCOV_EXCL_STOP - - auto const newLocked = locked - delta; - if (newLocked == 0) - { - sle->makeFieldAbsent(sfLockedAmount); - } - else - { - sle->setFieldU64(sfLockedAmount, newLocked); - } - view.update(sle); - - // Note: The gross amount is the amount that was locked, the net - // amount is the amount that is being unlocked. The difference is the fee - // that was charged for the transfer. If this difference is greater than - // zero, we need to update the outstanding amount. - auto const diff = grossAmount.mpt().value() - netAmount.mpt().value(); - if (diff != 0) - { - auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount); - // Underflow check for subtraction - if (!canSubtract(STAmount(mptIssue, outstanding), STAmount(mptIssue, diff))) - { // LCOV_EXCL_START - JLOG(j.error()) << "rippleUnlockEscrowMPT: insufficient outstanding amount for " - << mptIssue.getMptID() << ": " << outstanding << " < " << diff; - return tecINTERNAL; - } // LCOV_EXCL_STOP - - sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - diff); - view.update(sleIssuance); - } - return tesSUCCESS; -} - bool after(NetClock::time_point now, std::uint32_t mark) { diff --git a/src/libxrpl/ledger/helpers/AccountRootHelpers.cpp b/src/libxrpl/ledger/helpers/AccountRootHelpers.cpp new file mode 100644 index 0000000000..399494bc5f --- /dev/null +++ b/src/libxrpl/ledger/helpers/AccountRootHelpers.cpp @@ -0,0 +1,247 @@ +#include +// +#include +#include +#include +#include +#include + +#include +#include + +namespace xrpl { + +bool +isGlobalFrozen(ReadView const& view, AccountID const& issuer) +{ + if (isXRP(issuer)) + return false; + if (auto const sle = view.read(keylet::account(issuer))) + return sle->isFlag(lsfGlobalFreeze); + return false; +} + +// An owner count cannot be negative. If adjustment would cause a negative +// owner count, clamp the owner count at 0. Similarly for overflow. This +// adjustment allows the ownerCount to be adjusted up or down in multiple steps. +// If id != std::nullopt, then do error reporting. +// +// Returns adjusted owner count. +static std::uint32_t +confineOwnerCount( + std::uint32_t current, + std::int32_t adjustment, + std::optional const& id = std::nullopt, + beast::Journal j = beast::Journal{beast::Journal::getNullSink()}) +{ + std::uint32_t adjusted{current + adjustment}; + if (adjustment > 0) + { + // Overflow is well defined on unsigned + if (adjusted < current) + { + if (id) + { + JLOG(j.fatal()) << "Account " << *id << " owner count exceeds max!"; + } + adjusted = std::numeric_limits::max(); + } + } + else + { + // Underflow is well defined on unsigned + if (adjusted > current) + { + if (id) + { + JLOG(j.fatal()) << "Account " << *id << " owner count set below 0!"; + } + adjusted = 0; + XRPL_ASSERT(!id, "xrpl::confineOwnerCount : id is not set"); + } + } + return adjusted; +} + +XRPAmount +xrpLiquid(ReadView const& view, AccountID const& id, std::int32_t ownerCountAdj, beast::Journal j) +{ + auto const sle = view.read(keylet::account(id)); + if (sle == nullptr) + return beast::zero; + + // Return balance minus reserve + std::uint32_t const ownerCount = + confineOwnerCount(view.ownerCountHook(id, sle->getFieldU32(sfOwnerCount)), ownerCountAdj); + + // Pseudo-accounts have no reserve requirement + auto const reserve = + isPseudoAccount(sle) ? XRPAmount{0} : view.fees().accountReserve(ownerCount); + + auto const fullBalance = sle->getFieldAmount(sfBalance); + + auto const balance = view.balanceHook(id, xrpAccount(), fullBalance); + + STAmount const amount = (balance < reserve) ? STAmount{0} : balance - reserve; + + JLOG(j.trace()) << "accountHolds:" << " account=" << to_string(id) + << " amount=" << amount.getFullText() + << " fullBalance=" << fullBalance.getFullText() + << " balance=" << balance.getFullText() << " reserve=" << reserve + << " ownerCount=" << ownerCount << " ownerCountAdj=" << ownerCountAdj; + + return amount.xrp(); +} + +Rate +transferRate(ReadView const& view, AccountID const& issuer) +{ + auto const sle = view.read(keylet::account(issuer)); + + if (sle && sle->isFieldPresent(sfTransferRate)) + return Rate{sle->getFieldU32(sfTransferRate)}; + + return parityRate; +} + +void +adjustOwnerCount( + ApplyView& view, + std::shared_ptr const& sle, + std::int32_t amount, + beast::Journal j) +{ + if (!sle) + return; + XRPL_ASSERT(amount, "xrpl::adjustOwnerCount : nonzero amount input"); + std::uint32_t const current{sle->getFieldU32(sfOwnerCount)}; + AccountID const id = (*sle)[sfAccount]; + std::uint32_t const adjusted = confineOwnerCount(current, amount, id, j); + view.adjustOwnerCountHook(id, current, adjusted); + sle->at(sfOwnerCount) = adjusted; + view.update(sle); +} + +AccountID +pseudoAccountAddress(ReadView const& view, uint256 const& pseudoOwnerKey) +{ + // This number must not be changed without an amendment + constexpr std::uint16_t maxAccountAttempts = 256; + for (std::uint16_t i = 0; i < maxAccountAttempts; ++i) + { + ripesha_hasher rsh; + auto const hash = sha512Half(i, view.header().parentHash, pseudoOwnerKey); + rsh(hash.data(), hash.size()); + AccountID const ret{static_cast(rsh)}; + if (!view.read(keylet::account(ret))) + return ret; + } + return beast::zero; +} + +// Pseudo-account designator fields MUST be maintained by including the +// SField::sMD_PseudoAccount flag in the SField definition. (Don't forget to +// "| SField::sMD_Default"!) The fields do NOT need to be amendment-gated, +// since a non-active amendment will not set any field, by definition. +// Specific properties of a pseudo-account are NOT checked here, that's what +// InvariantCheck is for. +[[nodiscard]] std::vector const& +getPseudoAccountFields() +{ + static std::vector const pseudoFields = []() { + auto const ar = LedgerFormats::getInstance().findByType(ltACCOUNT_ROOT); + if (!ar) + { + // LCOV_EXCL_START + LogicError( + "xrpl::getPseudoAccountFields : unable to find account root " + "ledger format"); + // LCOV_EXCL_STOP + } + auto const& soTemplate = ar->getSOTemplate(); + + std::vector pseudoFields; + for (auto const& field : soTemplate) + { + if (field.sField().shouldMeta(SField::sMD_PseudoAccount)) + pseudoFields.emplace_back(&field.sField()); + } + return pseudoFields; + }(); + return pseudoFields; +} + +[[nodiscard]] bool +isPseudoAccount( + std::shared_ptr sleAcct, + std::set const& pseudoFieldFilter) +{ + auto const& fields = getPseudoAccountFields(); + + // Intentionally use defensive coding here because it's cheap and makes the + // semantics of true return value clean. + return sleAcct && sleAcct->getType() == ltACCOUNT_ROOT && + std::count_if( + fields.begin(), fields.end(), [&sleAcct, &pseudoFieldFilter](SField const* sf) -> bool { + return sleAcct->isFieldPresent(*sf) && + (pseudoFieldFilter.empty() || pseudoFieldFilter.contains(sf)); + }) > 0; +} + +Expected, TER> +createPseudoAccount(ApplyView& view, uint256 const& pseudoOwnerKey, SField const& ownerField) +{ + [[maybe_unused]] + auto const& fields = getPseudoAccountFields(); + XRPL_ASSERT( + std::count_if( + fields.begin(), + fields.end(), + [&ownerField](SField const* sf) -> bool { return *sf == ownerField; }) == 1, + "xrpl::createPseudoAccount : valid owner field"); + + auto const accountId = pseudoAccountAddress(view, pseudoOwnerKey); + if (accountId == beast::zero) + return Unexpected(tecDUPLICATE); + + // Create pseudo-account. + auto account = std::make_shared(keylet::account(accountId)); + account->setAccountID(sfAccount, accountId); + account->setFieldAmount(sfBalance, STAmount{}); + + // Pseudo-accounts can't submit transactions, so set the sequence number + // to 0 to make them easier to spot and verify, and add an extra level + // of protection. + std::uint32_t const seqno = // + view.rules().enabled(featureSingleAssetVault) || // + view.rules().enabled(featureLendingProtocol) // + ? 0 // + : view.seq(); + account->setFieldU32(sfSequence, seqno); + // Ignore reserves requirement, disable the master key, allow default + // rippling, and enable deposit authorization to prevent payments into + // pseudo-account. + account->setFieldU32(sfFlags, lsfDisableMaster | lsfDefaultRipple | lsfDepositAuth); + // Link the pseudo-account with its owner object. + account->setFieldH256(ownerField, pseudoOwnerKey); + + view.insert(account); + + return account; +} + +[[nodiscard]] TER +checkDestinationAndTag(SLE::const_ref toSle, bool hasDestinationTag) +{ + if (toSle == nullptr) + return tecNO_DST; + + // The tag is basically account-specific information we don't + // understand, but we can require someone to fill it in. + if (toSle->isFlag(lsfRequireDestTag) && !hasDestinationTag) + return tecDST_TAG_NEEDED; // Cannot send without a tag + + return tesSUCCESS; +} + +} // namespace xrpl diff --git a/src/libxrpl/ledger/CredentialHelpers.cpp b/src/libxrpl/ledger/helpers/CredentialHelpers.cpp similarity index 96% rename from src/libxrpl/ledger/CredentialHelpers.cpp rename to src/libxrpl/ledger/helpers/CredentialHelpers.cpp index 0782eda67d..32db285f1e 100644 --- a/src/libxrpl/ledger/CredentialHelpers.cpp +++ b/src/libxrpl/ledger/helpers/CredentialHelpers.cpp @@ -1,5 +1,7 @@ -#include +#include +// #include +#include #include #include @@ -76,7 +78,7 @@ deleteSLE(ApplyView& view, std::shared_ptr const& sleCredential, beast::Jou auto const issuer = sleCredential->getAccountID(sfIssuer); auto const subject = sleCredential->getAccountID(sfSubject); - bool const accepted = sleCredential->getFlags() & lsfAccepted; + bool const accepted = (sleCredential->getFlags() & lsfAccepted) != 0u; auto err = delSLE(issuer, sfIssuerNode, !accepted || (subject == issuer)); if (!isTesSuccess(err)) @@ -145,7 +147,7 @@ valid(STTx const& tx, ReadView const& view, AccountID const& src, beast::Journal return tecBAD_CREDENTIALS; } - if (!(sleCred->getFlags() & lsfAccepted)) + if ((sleCred->getFlags() & lsfAccepted) == 0u) { JLOG(j.trace()) << "Credential isn't accepted. Cred: " << h; return tecBAD_CREDENTIALS; @@ -186,7 +188,7 @@ validDomain(ReadView const& view, uint256 domainID, AccountID const& subject) foundExpired = true; continue; } - if (sleCredential->getFlags() & lsfAccepted) + if ((sleCredential->getFlags() & lsfAccepted) != 0u) { return tesSUCCESS; } @@ -307,7 +309,7 @@ verifyValidDomain(ApplyView& view, AccountID const& account, uint256 domainID, b if (!sleCredential) continue; // expired, i.e. deleted in credentials::removeExpired - if (sleCredential->getFlags() & lsfAccepted) + if ((sleCredential->getFlags() & lsfAccepted) != 0u) return tesSUCCESS; } @@ -334,7 +336,7 @@ verifyDepositPreauth( if (credentialsPresent && credentials::removeExpired(view, tx.getFieldV256(sfCredentialIDs), j)) return tecEXPIRED; - if (sleDst && (sleDst->getFlags() & lsfDepositAuth)) + if (sleDst && ((sleDst->getFlags() & lsfDepositAuth) != 0u)) { if (src != dst) { diff --git a/src/libxrpl/ledger/helpers/DirectoryHelpers.cpp b/src/libxrpl/ledger/helpers/DirectoryHelpers.cpp new file mode 100644 index 0000000000..dba71e0acd --- /dev/null +++ b/src/libxrpl/ledger/helpers/DirectoryHelpers.cpp @@ -0,0 +1,177 @@ +#include +// +#include + +namespace xrpl { + +bool +dirFirst( + ApplyView& view, + uint256 const& root, + std::shared_ptr& page, + unsigned int& index, + uint256& entry) +{ + return detail::internalDirFirst(view, root, page, index, entry); +} + +bool +dirNext( + ApplyView& view, + uint256 const& root, + std::shared_ptr& page, + unsigned int& index, + uint256& entry) +{ + return detail::internalDirNext(view, root, page, index, entry); +} + +bool +cdirFirst( + ReadView const& view, + uint256 const& root, + std::shared_ptr& page, + unsigned int& index, + uint256& entry) +{ + return detail::internalDirFirst(view, root, page, index, entry); +} + +bool +cdirNext( + ReadView const& view, + uint256 const& root, + std::shared_ptr& page, + unsigned int& index, + uint256& entry) +{ + return detail::internalDirNext(view, root, page, index, entry); +} + +void +forEachItem( + ReadView const& view, + Keylet const& root, + std::function const&)> const& f) +{ + XRPL_ASSERT(root.type == ltDIR_NODE, "xrpl::forEachItem : valid root type"); + + if (root.type != ltDIR_NODE) + return; + + auto pos = root; + + while (true) + { + auto sle = view.read(pos); + if (!sle) + return; + for (auto const& key : sle->getFieldV256(sfIndexes)) + f(view.read(keylet::child(key))); + auto const next = sle->getFieldU64(sfIndexNext); + if (next == 0u) + return; + pos = keylet::page(root, next); + } +} + +bool +forEachItemAfter( + ReadView const& view, + Keylet const& root, + uint256 const& after, + std::uint64_t const hint, + unsigned int limit, + std::function const&)> const& f) +{ + XRPL_ASSERT(root.type == ltDIR_NODE, "xrpl::forEachItemAfter : valid root type"); + + if (root.type != ltDIR_NODE) + return false; + + auto currentIndex = root; + + // If startAfter is not zero try jumping to that page using the hint + if (after.isNonZero()) + { + auto const hintIndex = keylet::page(root, hint); + + if (auto hintDir = view.read(hintIndex)) + { + for (auto const& key : hintDir->getFieldV256(sfIndexes)) + { + if (key == after) + { + // We found the hint, we can start here + currentIndex = hintIndex; + break; + } + } + } + + bool found = false; + for (;;) + { + auto const ownerDir = view.read(currentIndex); + if (!ownerDir) + return found; + for (auto const& key : ownerDir->getFieldV256(sfIndexes)) + { + if (!found) + { + if (key == after) + found = true; + } + else if (f(view.read(keylet::child(key))) && limit-- <= 1) + { + return found; + } + } + + auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext); + if (uNodeNext == 0) + return found; + currentIndex = keylet::page(root, uNodeNext); + } + } + else + { + for (;;) + { + auto const ownerDir = view.read(currentIndex); + if (!ownerDir) + return true; + for (auto const& key : ownerDir->getFieldV256(sfIndexes)) + { + if (f(view.read(keylet::child(key))) && limit-- <= 1) + return true; + } + auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext); + if (uNodeNext == 0) + return true; + currentIndex = keylet::page(root, uNodeNext); + } + } +} + +bool +dirIsEmpty(ReadView const& view, Keylet const& k) +{ + auto const sleNode = view.read(k); + if (!sleNode) + return true; + if (!sleNode->getFieldV256(sfIndexes).empty()) + return false; + // The first page of a directory may legitimately be empty even if there + // are other pages (the first page is the anchor page) so check to see if + // there is another page. If there is, the directory isn't empty. + return sleNode->getFieldU64(sfIndexNext) == 0; +} + +std::function +describeOwnerDir(AccountID const& account) +{ + return [account](std::shared_ptr const& sle) { (*sle)[sfOwner] = account; }; +} + +} // namespace xrpl diff --git a/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp b/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp new file mode 100644 index 0000000000..31c1d543f5 --- /dev/null +++ b/src/libxrpl/ledger/helpers/MPTokenHelpers.cpp @@ -0,0 +1,752 @@ +#include +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace xrpl { + +bool +isGlobalFrozen(ReadView const& view, MPTIssue const& mptIssue) +{ + if (auto const sle = view.read(keylet::mptIssuance(mptIssue.getMptID()))) + return sle->isFlag(lsfMPTLocked); + return false; +} + +bool +isIndividualFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue) +{ + if (auto const sle = view.read(keylet::mptoken(mptIssue.getMptID(), account))) + return sle->isFlag(lsfMPTLocked); + return false; +} + +bool +isFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue, int depth) +{ + return isGlobalFrozen(view, mptIssue) || isIndividualFrozen(view, account, mptIssue) || + isVaultPseudoAccountFrozen(view, account, mptIssue, depth); +} + +[[nodiscard]] bool +isAnyFrozen( + ReadView const& view, + std::initializer_list const& accounts, + MPTIssue const& mptIssue, + int depth) +{ + if (isGlobalFrozen(view, mptIssue)) + return true; + + for (auto const& account : accounts) + { + if (isIndividualFrozen(view, account, mptIssue)) + return true; + } + + for (auto const& account : accounts) + { + if (isVaultPseudoAccountFrozen(view, account, mptIssue, depth)) + return true; + } + + return false; +} + +Rate +transferRate(ReadView const& view, MPTID const& issuanceID) +{ + // fee is 0-50,000 (0-50%), rate is 1,000,000,000-2,000,000,000 + // For example, if transfer fee is 50% then 10,000 * 50,000 = 500,000 + // which represents 50% of 1,000,000,000 + if (auto const sle = view.read(keylet::mptIssuance(issuanceID)); + sle && sle->isFieldPresent(sfTransferFee)) + return Rate{1'000'000'000u + (10'000 * sle->getFieldU16(sfTransferFee))}; + + return parityRate; +} + +[[nodiscard]] TER +canAddHolding(ReadView const& view, MPTIssue const& mptIssue) +{ + auto mptID = mptIssue.getMptID(); + auto issuance = view.read(keylet::mptIssuance(mptID)); + if (!issuance) + { + return tecOBJECT_NOT_FOUND; + } + if (!issuance->isFlag(lsfMPTCanTransfer)) + { + return tecNO_AUTH; + } + + return tesSUCCESS; +} + +[[nodiscard]] TER +addEmptyHolding( + ApplyView& view, + AccountID const& accountID, + XRPAmount priorBalance, + MPTIssue const& mptIssue, + beast::Journal journal) +{ + auto const& mptID = mptIssue.getMptID(); + auto const mpt = view.peek(keylet::mptIssuance(mptID)); + if (!mpt) + return tefINTERNAL; // LCOV_EXCL_LINE + if (mpt->isFlag(lsfMPTLocked)) + return tefINTERNAL; // LCOV_EXCL_LINE + if (view.peek(keylet::mptoken(mptID, accountID))) + return tecDUPLICATE; + if (accountID == mptIssue.getIssuer()) + return tesSUCCESS; + + return authorizeMPToken(view, priorBalance, mptID, accountID, journal); +} + +[[nodiscard]] TER +authorizeMPToken( + ApplyView& view, + XRPAmount const& priorBalance, + MPTID const& mptIssuanceID, + AccountID const& account, + beast::Journal journal, + std::uint32_t flags, + std::optional holderID) +{ + auto const sleAcct = view.peek(keylet::account(account)); + if (!sleAcct) + return tecINTERNAL; // LCOV_EXCL_LINE + + // If the account that submitted the tx is a holder + // Note: `account_` is holder's account + // `holderID` is NOT used + if (!holderID) + { + // When a holder wants to unauthorize/delete a MPT, the ledger must + // - delete mptokenKey from owner directory + // - delete the MPToken + if ((flags & tfMPTUnauthorize) != 0) + { + auto const mptokenKey = keylet::mptoken(mptIssuanceID, account); + auto const sleMpt = view.peek(mptokenKey); + if (!sleMpt || (*sleMpt)[sfMPTAmount] != 0) + return tecINTERNAL; // LCOV_EXCL_LINE + + if (!view.dirRemove( + keylet::ownerDir(account), (*sleMpt)[sfOwnerNode], sleMpt->key(), false)) + return tecINTERNAL; // LCOV_EXCL_LINE + + adjustOwnerCount(view, sleAcct, -1, journal); + + view.erase(sleMpt); + return tesSUCCESS; + } + + // A potential holder wants to authorize/hold a mpt, the ledger must: + // - add the new mptokenKey to the owner directory + // - create the MPToken object for the holder + + // The reserve that is required to create the MPToken. Note + // that although the reserve increases with every item + // an account owns, in the case of MPTokens we only + // *enforce* a reserve if the user owns more than two + // items. This is similar to the reserve requirements of trust lines. + std::uint32_t const uOwnerCount = sleAcct->getFieldU32(sfOwnerCount); + XRPAmount const reserveCreate( + (uOwnerCount < 2) ? XRPAmount(beast::zero) + : view.fees().accountReserve(uOwnerCount + 1)); + + if (priorBalance < reserveCreate) + return tecINSUFFICIENT_RESERVE; + + // Defensive check before we attempt to create MPToken for the issuer + auto const mpt = view.read(keylet::mptIssuance(mptIssuanceID)); + if (!mpt || mpt->getAccountID(sfIssuer) == account) + { + // LCOV_EXCL_START + UNREACHABLE("xrpl::authorizeMPToken : invalid issuance or issuers token"); + if (view.rules().enabled(featureLendingProtocol)) + return tecINTERNAL; + // LCOV_EXCL_STOP + } + + auto const mptokenKey = keylet::mptoken(mptIssuanceID, account); + auto mptoken = std::make_shared(mptokenKey); + if (auto ter = dirLink(view, account, mptoken)) + return ter; // LCOV_EXCL_LINE + + (*mptoken)[sfAccount] = account; + (*mptoken)[sfMPTokenIssuanceID] = mptIssuanceID; + (*mptoken)[sfFlags] = 0; + view.insert(mptoken); + + // Update owner count. + adjustOwnerCount(view, sleAcct, 1, journal); + + return tesSUCCESS; + } + + auto const sleMptIssuance = view.read(keylet::mptIssuance(mptIssuanceID)); + if (!sleMptIssuance) + return tecINTERNAL; // LCOV_EXCL_LINE + + // If the account that submitted this tx is the issuer of the MPT + // Note: `account_` is issuer's account + // `holderID` is holder's account + if (account != (*sleMptIssuance)[sfIssuer]) + return tecINTERNAL; // LCOV_EXCL_LINE + + auto const sleMpt = view.peek(keylet::mptoken(mptIssuanceID, *holderID)); + if (!sleMpt) + return tecINTERNAL; // LCOV_EXCL_LINE + + std::uint32_t const flagsIn = sleMpt->getFieldU32(sfFlags); + std::uint32_t flagsOut = flagsIn; + + // Issuer wants to unauthorize the holder, unset lsfMPTAuthorized on + // their MPToken + if ((flags & tfMPTUnauthorize) != 0) + { + flagsOut &= ~lsfMPTAuthorized; + } + // Issuer wants to authorize a holder, set lsfMPTAuthorized on their + // MPToken + else + { + flagsOut |= lsfMPTAuthorized; + } + + if (flagsIn != flagsOut) + sleMpt->setFieldU32(sfFlags, flagsOut); + + view.update(sleMpt); + return tesSUCCESS; +} + +[[nodiscard]] TER +removeEmptyHolding( + ApplyView& view, + AccountID const& accountID, + MPTIssue const& mptIssue, + beast::Journal journal) +{ + // If the account is the issuer, then no token should exist. MPTs do not + // have the legacy ability to create such a situation, but check anyway. If + // a token does exist, it will get deleted. If not, return success. + bool const accountIsIssuer = accountID == mptIssue.getIssuer(); + auto const& mptID = mptIssue.getMptID(); + auto const mptoken = view.peek(keylet::mptoken(mptID, accountID)); + if (!mptoken) + return accountIsIssuer ? (TER)tesSUCCESS : (TER)tecOBJECT_NOT_FOUND; + // Unlike a trust line, if the account is the issuer, and the token has a + // balance, it can not just be deleted, because that will throw the issuance + // accounting out of balance, so fail. Since this should be impossible + // anyway, I'm not going to put any effort into it. + if (mptoken->at(sfMPTAmount) != 0) + return tecHAS_OBLIGATIONS; + + return authorizeMPToken( + view, + {}, // priorBalance + mptID, + accountID, + journal, + tfMPTUnauthorize // flags + ); +} + +[[nodiscard]] TER +requireAuth( + ReadView const& view, + MPTIssue const& mptIssue, + AccountID const& account, + AuthType authType, + int depth) +{ + auto const mptID = keylet::mptIssuance(mptIssue.getMptID()); + auto const sleIssuance = view.read(mptID); + if (!sleIssuance) + return tecOBJECT_NOT_FOUND; + + auto const mptIssuer = sleIssuance->getAccountID(sfIssuer); + + // issuer is always "authorized" + if (mptIssuer == account) // Issuer won't have MPToken + return tesSUCCESS; + + bool const featureSAVEnabled = view.rules().enabled(featureSingleAssetVault); + + if (featureSAVEnabled) + { + if (depth >= maxAssetCheckDepth) + return tecINTERNAL; // LCOV_EXCL_LINE + + // requireAuth is recursive if the issuer is a vault pseudo-account + auto const sleIssuer = view.read(keylet::account(mptIssuer)); + if (!sleIssuer) + return tefINTERNAL; // LCOV_EXCL_LINE + + if (sleIssuer->isFieldPresent(sfVaultID)) + { + auto const sleVault = view.read(keylet::vault(sleIssuer->getFieldH256(sfVaultID))); + if (!sleVault) + return tefINTERNAL; // LCOV_EXCL_LINE + + auto const asset = sleVault->at(sfAsset); + if (auto const err = std::visit( + [&](TIss const& issue) { + if constexpr (std::is_same_v) + { + return requireAuth(view, issue, account, authType); + } + else + { + return requireAuth(view, issue, account, authType, depth + 1); + } + }, + asset.value()); + !isTesSuccess(err)) + return err; + } + } + + auto const mptokenID = keylet::mptoken(mptID.key, account); + auto const sleToken = view.read(mptokenID); + + // if account has no MPToken, fail + if (!sleToken && (authType == AuthType::StrongAuth || authType == AuthType::Legacy)) + return tecNO_AUTH; + + // Note, this check is not amendment-gated because DomainID will be always + // empty **unless** writing to it has been enabled by an amendment + auto const maybeDomainID = sleIssuance->at(~sfDomainID); + if (maybeDomainID) + { + XRPL_ASSERT( + sleIssuance->getFieldU32(sfFlags) & lsfMPTRequireAuth, + "xrpl::requireAuth : issuance requires authorization"); + // ter = tefINTERNAL | tecOBJECT_NOT_FOUND | tecNO_AUTH | tecEXPIRED + auto const ter = credentials::validDomain(view, *maybeDomainID, account); + if (isTesSuccess(ter)) + { + return ter; // Note: sleToken might be null + } + if (!sleToken) + { + return ter; + } + // We ignore error from validDomain if we found sleToken, as it could + // belong to someone who is explicitly authorized e.g. a vault owner. + } + + if (featureSAVEnabled) + { + // Implicitly authorize Vault and LoanBroker pseudo-accounts + if (isPseudoAccount(view, account, {&sfVaultID, &sfLoanBrokerID})) + return tesSUCCESS; + } + + // mptoken must be authorized if issuance enabled requireAuth + if (sleIssuance->isFlag(lsfMPTRequireAuth) && + (!sleToken || !sleToken->isFlag(lsfMPTAuthorized))) + return tecNO_AUTH; + + return tesSUCCESS; // Note: sleToken might be null +} + +[[nodiscard]] TER +enforceMPTokenAuthorization( + ApplyView& view, + MPTID const& mptIssuanceID, + AccountID const& account, + XRPAmount const& priorBalance, // for MPToken authorization + beast::Journal j) +{ + auto const sleIssuance = view.read(keylet::mptIssuance(mptIssuanceID)); + if (!sleIssuance) + return tefINTERNAL; // LCOV_EXCL_LINE + + XRPL_ASSERT( + sleIssuance->isFlag(lsfMPTRequireAuth), + "xrpl::enforceMPTokenAuthorization : authorization required"); + + if (account == sleIssuance->at(sfIssuer)) + return tefINTERNAL; // LCOV_EXCL_LINE + + auto const keylet = keylet::mptoken(mptIssuanceID, account); + auto const sleToken = view.read(keylet); // NOTE: might be null + auto const maybeDomainID = sleIssuance->at(~sfDomainID); + bool expired = false; + bool const authorizedByDomain = [&]() -> bool { + // NOTE: defensive here, should be checked in preclaim + if (!maybeDomainID.has_value()) + return false; // LCOV_EXCL_LINE + + auto const ter = verifyValidDomain(view, account, *maybeDomainID, j); + if (isTesSuccess(ter)) + return true; + if (ter == tecEXPIRED) + expired = true; + return false; + }(); + + if (!authorizedByDomain && sleToken == nullptr) + { + // Could not find MPToken and won't create one, could be either of: + // + // 1. Field sfDomainID not set in MPTokenIssuance or + // 2. Account has no matching and accepted credentials or + // 3. Account has all expired credentials (deleted in verifyValidDomain) + // + // Either way, return tecNO_AUTH and there is nothing else to do + return expired ? tecEXPIRED : tecNO_AUTH; + } + if (!authorizedByDomain && maybeDomainID.has_value()) + { + // Found an MPToken but the account is not authorized and we expect + // it to have been authorized by the domain. This could be because the + // credentials used to create the MPToken have expired or been deleted. + return expired ? tecEXPIRED : tecNO_AUTH; + } + if (!authorizedByDomain) + { + // We found an MPToken, but sfDomainID is not set, so this is a classic + // MPToken which requires authorization by the token issuer. + XRPL_ASSERT( + sleToken != nullptr && !maybeDomainID.has_value(), + "xrpl::enforceMPTokenAuthorization : found MPToken"); + if (sleToken->isFlag(lsfMPTAuthorized)) + return tesSUCCESS; + + return tecNO_AUTH; + } + if (authorizedByDomain && sleToken != nullptr) + { + // Found an MPToken, authorized by the domain. Ignore authorization flag + // lsfMPTAuthorized because it is meaningless. Return tesSUCCESS + XRPL_ASSERT( + maybeDomainID.has_value(), + "xrpl::enforceMPTokenAuthorization : found MPToken for domain"); + return tesSUCCESS; + } + if (authorizedByDomain) + { + // Could not find MPToken but there should be one because we are + // authorized by domain. Proceed to create it, then return tesSUCCESS + XRPL_ASSERT( + maybeDomainID.has_value() && sleToken == nullptr, + "xrpl::enforceMPTokenAuthorization : new MPToken for domain"); + if (auto const err = authorizeMPToken( + view, + priorBalance, // priorBalance + mptIssuanceID, // mptIssuanceID + account, // account + j); + !isTesSuccess(err)) + return err; + + return tesSUCCESS; + } + + // LCOV_EXCL_START + UNREACHABLE("xrpl::enforceMPTokenAuthorization : condition list is incomplete"); + return tefINTERNAL; + // LCOV_EXCL_STOP +} + +TER +canTransfer( + ReadView const& view, + MPTIssue const& mptIssue, + AccountID const& from, + AccountID const& to) +{ + auto const mptID = keylet::mptIssuance(mptIssue.getMptID()); + auto const sleIssuance = view.read(mptID); + if (!sleIssuance) + return tecOBJECT_NOT_FOUND; + + if (!sleIssuance->isFlag(lsfMPTCanTransfer)) + { + if (from != (*sleIssuance)[sfIssuer] && to != (*sleIssuance)[sfIssuer]) + return TER{tecNO_AUTH}; + } + return tesSUCCESS; +} + +TER +rippleLockEscrowMPT( + ApplyView& view, + AccountID const& sender, + STAmount const& amount, + beast::Journal j) +{ + auto const mptIssue = amount.get(); + auto const mptID = keylet::mptIssuance(mptIssue.getMptID()); + auto sleIssuance = view.peek(mptID); + if (!sleIssuance) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleLockEscrowMPT: MPT issuance not found for " + << mptIssue.getMptID(); + return tecOBJECT_NOT_FOUND; + } // LCOV_EXCL_STOP + + if (amount.getIssuer() == sender) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleLockEscrowMPT: sender is the issuer, cannot lock MPTs."; + return tecINTERNAL; + } // LCOV_EXCL_STOP + + // 1. Decrease the MPT Holder MPTAmount + // 2. Increase the MPT Holder EscrowedAmount + { + auto const mptokenID = keylet::mptoken(mptID.key, sender); + auto sle = view.peek(mptokenID); + if (!sle) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleLockEscrowMPT: MPToken not found for " << sender; + return tecOBJECT_NOT_FOUND; + } // LCOV_EXCL_STOP + + auto const amt = sle->getFieldU64(sfMPTAmount); + auto const pay = amount.mpt().value(); + + // Underflow check for subtraction + if (!canSubtract(STAmount(mptIssue, amt), STAmount(mptIssue, pay))) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleLockEscrowMPT: insufficient MPTAmount for " + << to_string(sender) << ": " << amt << " < " << pay; + return tecINTERNAL; + } // LCOV_EXCL_STOP + + (*sle)[sfMPTAmount] = amt - pay; + + // Overflow check for addition + uint64_t const locked = (*sle)[~sfLockedAmount].value_or(0); + + if (!canAdd(STAmount(mptIssue, locked), STAmount(mptIssue, pay))) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleLockEscrowMPT: overflow on locked amount for " + << to_string(sender) << ": " << locked << " + " << pay; + return tecINTERNAL; + } // LCOV_EXCL_STOP + + if (sle->isFieldPresent(sfLockedAmount)) + { + (*sle)[sfLockedAmount] += pay; + } + else + { + sle->setFieldU64(sfLockedAmount, pay); + } + + view.update(sle); + } + + // 1. Increase the Issuance EscrowedAmount + // 2. DO NOT change the Issuance OutstandingAmount + { + uint64_t const issuanceEscrowed = (*sleIssuance)[~sfLockedAmount].value_or(0); + auto const pay = amount.mpt().value(); + + // Overflow check for addition + if (!canAdd(STAmount(mptIssue, issuanceEscrowed), STAmount(mptIssue, pay))) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleLockEscrowMPT: overflow on issuance " + "locked amount for " + << mptIssue.getMptID() << ": " << issuanceEscrowed << " + " << pay; + return tecINTERNAL; + } // LCOV_EXCL_STOP + + if (sleIssuance->isFieldPresent(sfLockedAmount)) + { + (*sleIssuance)[sfLockedAmount] += pay; + } + else + { + sleIssuance->setFieldU64(sfLockedAmount, pay); + } + + view.update(sleIssuance); + } + return tesSUCCESS; +} + +TER +rippleUnlockEscrowMPT( + ApplyView& view, + AccountID const& sender, + AccountID const& receiver, + STAmount const& netAmount, + STAmount const& grossAmount, + beast::Journal j) +{ + if (!view.rules().enabled(fixTokenEscrowV1)) + { + XRPL_ASSERT( + netAmount == grossAmount, "xrpl::rippleUnlockEscrowMPT : netAmount == grossAmount"); + } + + auto const& issuer = netAmount.getIssuer(); + auto const& mptIssue = netAmount.get(); + auto const mptID = keylet::mptIssuance(mptIssue.getMptID()); + auto sleIssuance = view.peek(mptID); + if (!sleIssuance) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleUnlockEscrowMPT: MPT issuance not found for " + << mptIssue.getMptID(); + return tecOBJECT_NOT_FOUND; + } // LCOV_EXCL_STOP + + // Decrease the Issuance EscrowedAmount + { + if (!sleIssuance->isFieldPresent(sfLockedAmount)) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleUnlockEscrowMPT: no locked amount in issuance for " + << mptIssue.getMptID(); + return tecINTERNAL; + } // LCOV_EXCL_STOP + + auto const locked = sleIssuance->getFieldU64(sfLockedAmount); + auto const redeem = grossAmount.mpt().value(); + + // Underflow check for subtraction + if (!canSubtract(STAmount(mptIssue, locked), STAmount(mptIssue, redeem))) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleUnlockEscrowMPT: insufficient locked amount for " + << mptIssue.getMptID() << ": " << locked << " < " << redeem; + return tecINTERNAL; + } // LCOV_EXCL_STOP + + auto const newLocked = locked - redeem; + if (newLocked == 0) + { + sleIssuance->makeFieldAbsent(sfLockedAmount); + } + else + { + sleIssuance->setFieldU64(sfLockedAmount, newLocked); + } + view.update(sleIssuance); + } + + if (issuer != receiver) + { + // Increase the MPT Holder MPTAmount + auto const mptokenID = keylet::mptoken(mptID.key, receiver); + auto sle = view.peek(mptokenID); + if (!sle) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleUnlockEscrowMPT: MPToken not found for " << receiver; + return tecOBJECT_NOT_FOUND; + } // LCOV_EXCL_STOP + + auto current = sle->getFieldU64(sfMPTAmount); + auto delta = netAmount.mpt().value(); + + // Overflow check for addition + if (!canAdd(STAmount(mptIssue, current), STAmount(mptIssue, delta))) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleUnlockEscrowMPT: overflow on MPTAmount for " + << to_string(receiver) << ": " << current << " + " << delta; + return tecINTERNAL; + } // LCOV_EXCL_STOP + + (*sle)[sfMPTAmount] += delta; + view.update(sle); + } + else + { + // Decrease the Issuance OutstandingAmount + auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount); + auto const redeem = netAmount.mpt().value(); + + // Underflow check for subtraction + if (!canSubtract(STAmount(mptIssue, outstanding), STAmount(mptIssue, redeem))) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleUnlockEscrowMPT: insufficient outstanding amount for " + << mptIssue.getMptID() << ": " << outstanding << " < " << redeem; + return tecINTERNAL; + } // LCOV_EXCL_STOP + + sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem); + view.update(sleIssuance); + } + + if (issuer == sender) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleUnlockEscrowMPT: sender is the issuer, " + "cannot unlock MPTs."; + return tecINTERNAL; + } // LCOV_EXCL_STOP + // Decrease the MPT Holder EscrowedAmount + auto const mptokenID = keylet::mptoken(mptID.key, sender); + auto sle = view.peek(mptokenID); + if (!sle) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleUnlockEscrowMPT: MPToken not found for " << sender; + return tecOBJECT_NOT_FOUND; + } // LCOV_EXCL_STOP + + if (!sle->isFieldPresent(sfLockedAmount)) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleUnlockEscrowMPT: no locked amount in MPToken for " + << to_string(sender); + return tecINTERNAL; + } // LCOV_EXCL_STOP + + auto const locked = sle->getFieldU64(sfLockedAmount); + auto const delta = grossAmount.mpt().value(); + + // Underflow check for subtraction + if (!canSubtract(STAmount(mptIssue, locked), STAmount(mptIssue, delta))) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleUnlockEscrowMPT: insufficient locked amount for " + << to_string(sender) << ": " << locked << " < " << delta; + return tecINTERNAL; + } // LCOV_EXCL_STOP + + auto const newLocked = locked - delta; + if (newLocked == 0) + { + sle->makeFieldAbsent(sfLockedAmount); + } + else + { + sle->setFieldU64(sfLockedAmount, newLocked); + } + view.update(sle); + + // Note: The gross amount is the amount that was locked, the net + // amount is the amount that is being unlocked. The difference is the fee + // that was charged for the transfer. If this difference is greater than + // zero, we need to update the outstanding amount. + auto const diff = grossAmount.mpt().value() - netAmount.mpt().value(); + if (diff != 0) + { + auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount); + // Underflow check for subtraction + if (!canSubtract(STAmount(mptIssue, outstanding), STAmount(mptIssue, diff))) + { // LCOV_EXCL_START + JLOG(j.error()) << "rippleUnlockEscrowMPT: insufficient outstanding amount for " + << mptIssue.getMptID() << ": " << outstanding << " < " << diff; + return tecINTERNAL; + } // LCOV_EXCL_STOP + + sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - diff); + view.update(sleIssuance); + } + return tesSUCCESS; +} + +} // namespace xrpl diff --git a/src/libxrpl/ledger/helpers/OfferHelpers.cpp b/src/libxrpl/ledger/helpers/OfferHelpers.cpp new file mode 100644 index 0000000000..9422153b10 --- /dev/null +++ b/src/libxrpl/ledger/helpers/OfferHelpers.cpp @@ -0,0 +1,58 @@ +#include +// +#include +#include +#include +#include + +namespace xrpl { + +TER +offerDelete(ApplyView& view, std::shared_ptr const& sle, beast::Journal j) +{ + if (!sle) + return tesSUCCESS; + auto offerIndex = sle->key(); + auto owner = sle->getAccountID(sfAccount); + + // Detect legacy directories. + uint256 uDirectory = sle->getFieldH256(sfBookDirectory); + + if (!view.dirRemove(keylet::ownerDir(owner), sle->getFieldU64(sfOwnerNode), offerIndex, false)) + { + return tefBAD_LEDGER; // LCOV_EXCL_LINE + } + + if (!view.dirRemove(keylet::page(uDirectory), sle->getFieldU64(sfBookNode), offerIndex, false)) + { + return tefBAD_LEDGER; // LCOV_EXCL_LINE + } + + if (sle->isFieldPresent(sfAdditionalBooks)) + { + XRPL_ASSERT( + sle->isFlag(lsfHybrid) && sle->isFieldPresent(sfDomainID), + "xrpl::offerDelete : should be a hybrid domain offer"); + + auto const& additionalBookDirs = sle->getFieldArray(sfAdditionalBooks); + + for (auto const& bookDir : additionalBookDirs) + { + auto const& dirIndex = bookDir.getFieldH256(sfBookDirectory); + auto const& dirNode = bookDir.getFieldU64(sfBookNode); + + if (!view.dirRemove(keylet::page(dirIndex), dirNode, offerIndex, false)) + { + return tefBAD_LEDGER; // LCOV_EXCL_LINE + } + } + } + + adjustOwnerCount(view, view.peek(keylet::account(owner)), -1, j); + + view.erase(sle); + + return tesSUCCESS; +} + +} // namespace xrpl diff --git a/src/libxrpl/ledger/helpers/RippleStateHelpers.cpp b/src/libxrpl/ledger/helpers/RippleStateHelpers.cpp new file mode 100644 index 0000000000..22a0967939 --- /dev/null +++ b/src/libxrpl/ledger/helpers/RippleStateHelpers.cpp @@ -0,0 +1,760 @@ +#include +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace xrpl { + +//------------------------------------------------------------------------------ +// +// Credit functions (from Credit.cpp) +// +//------------------------------------------------------------------------------ + +STAmount +creditLimit( + ReadView const& view, + AccountID const& account, + AccountID const& issuer, + Currency const& currency) +{ + STAmount result(Issue{currency, account}); + + auto sleRippleState = view.read(keylet::line(account, issuer, currency)); + + if (sleRippleState) + { + result = sleRippleState->getFieldAmount(account < issuer ? sfLowLimit : sfHighLimit); + result.setIssuer(account); + } + + XRPL_ASSERT(result.getIssuer() == account, "xrpl::creditLimit : result issuer match"); + XRPL_ASSERT(result.getCurrency() == currency, "xrpl::creditLimit : result currency match"); + return result; +} + +IOUAmount +creditLimit2(ReadView const& v, AccountID const& acc, AccountID const& iss, Currency const& cur) +{ + return toAmount(creditLimit(v, acc, iss, cur)); +} + +STAmount +creditBalance( + ReadView const& view, + AccountID const& account, + AccountID const& issuer, + Currency const& currency) +{ + STAmount result(Issue{currency, account}); + + auto sleRippleState = view.read(keylet::line(account, issuer, currency)); + + if (sleRippleState) + { + result = sleRippleState->getFieldAmount(sfBalance); + if (account < issuer) + result.negate(); + result.setIssuer(account); + } + + XRPL_ASSERT(result.getIssuer() == account, "xrpl::creditBalance : result issuer match"); + XRPL_ASSERT(result.getCurrency() == currency, "xrpl::creditBalance : result currency match"); + return result; +} + +//------------------------------------------------------------------------------ +// +// Freeze checking (IOU-specific) +// +//------------------------------------------------------------------------------ + +bool +isIndividualFrozen( + ReadView const& view, + AccountID const& account, + Currency const& currency, + AccountID const& issuer) +{ + if (isXRP(currency)) + return false; + if (issuer != account) + { + // Check if the issuer froze the line + auto const sle = view.read(keylet::line(account, issuer, currency)); + if (sle && sle->isFlag((issuer > account) ? lsfHighFreeze : lsfLowFreeze)) + return true; + } + return false; +} + +// Can the specified account spend the specified currency issued by +// the specified issuer or does the freeze flag prohibit it? +bool +isFrozen( + ReadView const& view, + AccountID const& account, + Currency const& currency, + AccountID const& issuer) +{ + if (isXRP(currency)) + return false; + auto sle = view.read(keylet::account(issuer)); + if (sle && sle->isFlag(lsfGlobalFreeze)) + return true; + if (issuer != account) + { + // Check if the issuer froze the line + sle = view.read(keylet::line(account, issuer, currency)); + if (sle && sle->isFlag((issuer > account) ? lsfHighFreeze : lsfLowFreeze)) + return true; + } + return false; +} + +bool +isDeepFrozen( + ReadView const& view, + AccountID const& account, + Currency const& currency, + AccountID const& issuer) +{ + if (isXRP(currency)) + { + return false; + } + + if (issuer == account) + { + return false; + } + + auto const sle = view.read(keylet::line(account, issuer, currency)); + if (!sle) + { + return false; + } + + return sle->isFlag(lsfHighDeepFreeze) || sle->isFlag(lsfLowDeepFreeze); +} + +//------------------------------------------------------------------------------ +// +// Trust line operations +// +//------------------------------------------------------------------------------ + +TER +trustCreate( + ApplyView& view, + bool const bSrcHigh, + AccountID const& uSrcAccountID, + AccountID const& uDstAccountID, + uint256 const& uIndex, // --> ripple state entry + SLE::ref sleAccount, // --> the account being set. + bool const bAuth, // --> authorize account. + bool const bNoRipple, // --> others cannot ripple through + bool const bFreeze, // --> funds cannot leave + bool bDeepFreeze, // --> can neither receive nor send funds + STAmount const& saBalance, // --> balance of account being set. + // Issuer should be noAccount() + STAmount const& saLimit, // --> limit for account being set. + // Issuer should be the account being set. + std::uint32_t uQualityIn, + std::uint32_t uQualityOut, + beast::Journal j) +{ + JLOG(j.trace()) << "trustCreate: " << to_string(uSrcAccountID) << ", " + << to_string(uDstAccountID) << ", " << saBalance.getFullText(); + + auto const& uLowAccountID = !bSrcHigh ? uSrcAccountID : uDstAccountID; + auto const& uHighAccountID = bSrcHigh ? uSrcAccountID : uDstAccountID; + if (uLowAccountID == uHighAccountID) + { + // LCOV_EXCL_START + UNREACHABLE("xrpl::trustCreate : trust line to self"); + if (view.rules().enabled(featureLendingProtocol)) + return tecINTERNAL; + // LCOV_EXCL_STOP + } + + auto const sleRippleState = std::make_shared(ltRIPPLE_STATE, uIndex); + view.insert(sleRippleState); + + auto lowNode = view.dirInsert( + keylet::ownerDir(uLowAccountID), sleRippleState->key(), describeOwnerDir(uLowAccountID)); + + if (!lowNode) + return tecDIR_FULL; // LCOV_EXCL_LINE + + auto highNode = view.dirInsert( + keylet::ownerDir(uHighAccountID), sleRippleState->key(), describeOwnerDir(uHighAccountID)); + + if (!highNode) + return tecDIR_FULL; // LCOV_EXCL_LINE + + bool const bSetDst = saLimit.getIssuer() == uDstAccountID; + bool const bSetHigh = bSrcHigh ^ bSetDst; + + XRPL_ASSERT(sleAccount, "xrpl::trustCreate : non-null SLE"); + if (!sleAccount) + return tefINTERNAL; // LCOV_EXCL_LINE + + XRPL_ASSERT( + sleAccount->getAccountID(sfAccount) == (bSetHigh ? uHighAccountID : uLowAccountID), + "xrpl::trustCreate : matching account ID"); + auto const slePeer = view.peek(keylet::account(bSetHigh ? uLowAccountID : uHighAccountID)); + if (!slePeer) + return tecNO_TARGET; + + // Remember deletion hints. + sleRippleState->setFieldU64(sfLowNode, *lowNode); + sleRippleState->setFieldU64(sfHighNode, *highNode); + + sleRippleState->setFieldAmount(bSetHigh ? sfHighLimit : sfLowLimit, saLimit); + sleRippleState->setFieldAmount( + bSetHigh ? sfLowLimit : sfHighLimit, + STAmount(Issue{saBalance.getCurrency(), bSetDst ? uSrcAccountID : uDstAccountID})); + + if (uQualityIn != 0u) + sleRippleState->setFieldU32(bSetHigh ? sfHighQualityIn : sfLowQualityIn, uQualityIn); + + if (uQualityOut != 0u) + sleRippleState->setFieldU32(bSetHigh ? sfHighQualityOut : sfLowQualityOut, uQualityOut); + + std::uint32_t uFlags = bSetHigh ? lsfHighReserve : lsfLowReserve; + + if (bAuth) + { + uFlags |= (bSetHigh ? lsfHighAuth : lsfLowAuth); + } + if (bNoRipple) + { + uFlags |= (bSetHigh ? lsfHighNoRipple : lsfLowNoRipple); + } + if (bFreeze) + { + uFlags |= (bSetHigh ? lsfHighFreeze : lsfLowFreeze); + } + if (bDeepFreeze) + { + uFlags |= (bSetHigh ? lsfHighDeepFreeze : lsfLowDeepFreeze); + } + + if ((slePeer->getFlags() & lsfDefaultRipple) == 0) + { + // The other side's default is no rippling + uFlags |= (bSetHigh ? lsfLowNoRipple : lsfHighNoRipple); + } + + sleRippleState->setFieldU32(sfFlags, uFlags); + adjustOwnerCount(view, sleAccount, 1, j); + + // ONLY: Create ripple balance. + sleRippleState->setFieldAmount(sfBalance, bSetHigh ? -saBalance : saBalance); + + view.creditHook(uSrcAccountID, uDstAccountID, saBalance, saBalance.zeroed()); + + return tesSUCCESS; +} + +TER +trustDelete( + ApplyView& view, + std::shared_ptr const& sleRippleState, + AccountID const& uLowAccountID, + AccountID const& uHighAccountID, + beast::Journal j) +{ + // Detect legacy dirs. + std::uint64_t uLowNode = sleRippleState->getFieldU64(sfLowNode); + std::uint64_t uHighNode = sleRippleState->getFieldU64(sfHighNode); + + JLOG(j.trace()) << "trustDelete: Deleting ripple line: low"; + + if (!view.dirRemove(keylet::ownerDir(uLowAccountID), uLowNode, sleRippleState->key(), false)) + { + return tefBAD_LEDGER; // LCOV_EXCL_LINE + } + + JLOG(j.trace()) << "trustDelete: Deleting ripple line: high"; + + if (!view.dirRemove(keylet::ownerDir(uHighAccountID), uHighNode, sleRippleState->key(), false)) + { + return tefBAD_LEDGER; // LCOV_EXCL_LINE + } + + JLOG(j.trace()) << "trustDelete: Deleting ripple line: state"; + view.erase(sleRippleState); + + return tesSUCCESS; +} + +//------------------------------------------------------------------------------ +// +// IOU issuance/redemption +// +//------------------------------------------------------------------------------ + +static bool +updateTrustLine( + ApplyView& view, + SLE::pointer state, + bool bSenderHigh, + AccountID const& sender, + STAmount const& before, + STAmount const& after, + beast::Journal j) +{ + if (!state) + return false; + std::uint32_t const flags(state->getFieldU32(sfFlags)); + + auto sle = view.peek(keylet::account(sender)); + if (!sle) + return false; + + // YYY Could skip this if rippling in reverse. + if (before > beast::zero + // Sender balance was positive. + && after <= beast::zero + // Sender is zero or negative. + && ((flags & (!bSenderHigh ? lsfLowReserve : lsfHighReserve)) != 0u) + // Sender reserve is set. + && static_cast(flags & (!bSenderHigh ? lsfLowNoRipple : lsfHighNoRipple)) != + static_cast(sle->getFlags() & lsfDefaultRipple) && + ((flags & (!bSenderHigh ? lsfLowFreeze : lsfHighFreeze)) == 0u) && + !state->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit) + // Sender trust limit is 0. + && (state->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn) == 0u) + // Sender quality in is 0. + && (state->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut) == 0u)) + // Sender quality out is 0. + { + // VFALCO Where is the line being deleted? + // Clear the reserve of the sender, possibly delete the line! + adjustOwnerCount(view, sle, -1, j); + + // Clear reserve flag. + state->setFieldU32(sfFlags, flags & (!bSenderHigh ? ~lsfLowReserve : ~lsfHighReserve)); + + // Balance is zero, receiver reserve is clear. + if (!after // Balance is zero. + && ((flags & (bSenderHigh ? lsfLowReserve : lsfHighReserve)) == 0u)) + return true; + } + return false; +} + +TER +issueIOU( + ApplyView& view, + AccountID const& account, + STAmount const& amount, + Issue const& issue, + beast::Journal j) +{ + XRPL_ASSERT( + !isXRP(account) && !isXRP(issue.account), + "xrpl::issueIOU : neither account nor issuer is XRP"); + + // Consistency check + XRPL_ASSERT(issue == amount.issue(), "xrpl::issueIOU : matching issue"); + + // Can't send to self! + XRPL_ASSERT(issue.account != account, "xrpl::issueIOU : not issuer account"); + + JLOG(j.trace()) << "issueIOU: " << to_string(account) << ": " << amount.getFullText(); + + bool bSenderHigh = issue.account > account; + + auto const index = keylet::line(issue.account, account, issue.currency); + + if (auto state = view.peek(index)) + { + STAmount final_balance = state->getFieldAmount(sfBalance); + + if (bSenderHigh) + final_balance.negate(); // Put balance in sender terms. + + STAmount const start_balance = final_balance; + + final_balance -= amount; + + auto const must_delete = updateTrustLine( + view, state, bSenderHigh, issue.account, start_balance, final_balance, j); + + view.creditHook(issue.account, account, amount, start_balance); + + if (bSenderHigh) + final_balance.negate(); + + // Adjust the balance on the trust line if necessary. We do this even + // if we are going to delete the line to reflect the correct balance + // at the time of deletion. + state->setFieldAmount(sfBalance, final_balance); + if (must_delete) + { + return trustDelete( + view, + state, + bSenderHigh ? account : issue.account, + bSenderHigh ? issue.account : account, + j); + } + + view.update(state); + + return tesSUCCESS; + } + + // NIKB TODO: The limit uses the receiver's account as the issuer and + // this is unnecessarily inefficient as copying which could be avoided + // is now required. Consider available options. + STAmount const limit(Issue{issue.currency, account}); + STAmount final_balance = amount; + + final_balance.setIssuer(noAccount()); + + auto const receiverAccount = view.peek(keylet::account(account)); + if (!receiverAccount) + return tefINTERNAL; // LCOV_EXCL_LINE + + bool noRipple = (receiverAccount->getFlags() & lsfDefaultRipple) == 0; + + return trustCreate( + view, + bSenderHigh, + issue.account, + account, + index.key, + receiverAccount, + false, + noRipple, + false, + false, + final_balance, + limit, + 0, + 0, + j); +} + +TER +redeemIOU( + ApplyView& view, + AccountID const& account, + STAmount const& amount, + Issue const& issue, + beast::Journal j) +{ + XRPL_ASSERT( + !isXRP(account) && !isXRP(issue.account), + "xrpl::redeemIOU : neither account nor issuer is XRP"); + + // Consistency check + XRPL_ASSERT(issue == amount.issue(), "xrpl::redeemIOU : matching issue"); + + // Can't send to self! + XRPL_ASSERT(issue.account != account, "xrpl::redeemIOU : not issuer account"); + + JLOG(j.trace()) << "redeemIOU: " << to_string(account) << ": " << amount.getFullText(); + + bool bSenderHigh = account > issue.account; + + if (auto state = view.peek(keylet::line(account, issue.account, issue.currency))) + { + STAmount final_balance = state->getFieldAmount(sfBalance); + + if (bSenderHigh) + final_balance.negate(); // Put balance in sender terms. + + STAmount const start_balance = final_balance; + + final_balance -= amount; + + auto const must_delete = + updateTrustLine(view, state, bSenderHigh, account, start_balance, final_balance, j); + + view.creditHook(account, issue.account, amount, start_balance); + + if (bSenderHigh) + final_balance.negate(); + + // Adjust the balance on the trust line if necessary. We do this even + // if we are going to delete the line to reflect the correct balance + // at the time of deletion. + state->setFieldAmount(sfBalance, final_balance); + + if (must_delete) + { + return trustDelete( + view, + state, + bSenderHigh ? issue.account : account, + bSenderHigh ? account : issue.account, + j); + } + + view.update(state); + return tesSUCCESS; + } + + // In order to hold an IOU, a trust line *MUST* exist to track the + // balance. If it doesn't, then something is very wrong. Don't try + // to continue. + // LCOV_EXCL_START + JLOG(j.fatal()) << "redeemIOU: " << to_string(account) << " attempts to " + << "redeem " << amount.getFullText() << " but no trust line exists!"; + + return tefINTERNAL; + // LCOV_EXCL_STOP +} + +//------------------------------------------------------------------------------ +// +// Authorization and transfer checks (IOU-specific) +// +//------------------------------------------------------------------------------ + +TER +requireAuth(ReadView const& view, Issue const& issue, AccountID const& account, AuthType authType) +{ + if (isXRP(issue) || issue.account == account) + return tesSUCCESS; + + auto const trustLine = view.read(keylet::line(account, issue.account, issue.currency)); + // If account has no line, and this is a strong check, fail + if (!trustLine && authType == AuthType::StrongAuth) + return tecNO_LINE; + + // 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) != 0u)) + { + if (trustLine) + { + return (((*trustLine)[sfFlags] & + ((account > issue.account) ? lsfLowAuth : lsfHighAuth)) != 0u) + ? tesSUCCESS + : TER{tecNO_AUTH}; + } + return TER{tecNO_LINE}; + } + + return tesSUCCESS; +} + +TER +canTransfer(ReadView const& view, Issue const& issue, AccountID const& from, AccountID const& to) +{ + if (issue.native()) + return tesSUCCESS; + + auto const& issuerId = issue.getIssuer(); + if (issuerId == from || issuerId == to) + return tesSUCCESS; + auto const sleIssuer = view.read(keylet::account(issuerId)); + if (sleIssuer == nullptr) + return tefINTERNAL; // LCOV_EXCL_LINE + + auto const isRippleDisabled = [&](AccountID account) -> bool { + // Line might not exist, but some transfers can create it. If this + // is the case, just check the default ripple on the issuer account. + auto const line = view.read(keylet::line(account, issue)); + if (line) + { + bool const issuerHigh = issuerId > account; + return line->isFlag(issuerHigh ? lsfHighNoRipple : lsfLowNoRipple); + } + return !sleIssuer->isFlag(lsfDefaultRipple); + }; + + // Fail if rippling disabled on both trust lines + if (isRippleDisabled(from) && isRippleDisabled(to)) + return terNO_RIPPLE; + + return tesSUCCESS; +} + +//------------------------------------------------------------------------------ +// +// Empty holding operations (IOU-specific) +// +//------------------------------------------------------------------------------ + +TER +addEmptyHolding( + ApplyView& view, + AccountID const& accountID, + XRPAmount priorBalance, + Issue const& issue, + beast::Journal journal) +{ + // Every account can hold XRP. An issuer can issue directly. + if (issue.native() || accountID == issue.getIssuer()) + return tesSUCCESS; + + auto const& issuerId = issue.getIssuer(); + auto const& currency = issue.currency; + if (isGlobalFrozen(view, issuerId)) + return tecFROZEN; // LCOV_EXCL_LINE + + auto const& srcId = issuerId; + auto const& dstId = accountID; + auto const high = srcId > dstId; + auto const index = keylet::line(srcId, dstId, currency); + auto const sleSrc = view.peek(keylet::account(srcId)); + auto const sleDst = view.peek(keylet::account(dstId)); + if (!sleDst || !sleSrc) + return tefINTERNAL; // LCOV_EXCL_LINE + if (!sleSrc->isFlag(lsfDefaultRipple)) + return tecINTERNAL; // LCOV_EXCL_LINE + // If the line already exists, don't create it again. + if (view.read(index)) + return tecDUPLICATE; + + // Can the account cover the trust line reserve ? + std::uint32_t const ownerCount = sleDst->at(sfOwnerCount); + if (priorBalance < view.fees().accountReserve(ownerCount + 1)) + return tecNO_LINE_INSUF_RESERVE; + + return trustCreate( + view, + high, + srcId, + dstId, + index.key, + sleDst, + /*bAuth=*/false, + /*bNoRipple=*/true, + /*bFreeze=*/false, + /*deepFreeze*/ false, + /*saBalance=*/STAmount{Issue{currency, noAccount()}}, + /*saLimit=*/STAmount{Issue{currency, dstId}}, + /*uQualityIn=*/0, + /*uQualityOut=*/0, + journal); +} + +TER +removeEmptyHolding( + ApplyView& view, + AccountID const& accountID, + Issue const& issue, + beast::Journal journal) +{ + if (issue.native()) + { + auto const sle = view.read(keylet::account(accountID)); + if (!sle) + return tecINTERNAL; // LCOV_EXCL_LINE + + auto const balance = sle->getFieldAmount(sfBalance); + if (balance.xrp() != 0) + return tecHAS_OBLIGATIONS; + + return tesSUCCESS; + } + + // `asset` is an IOU. + // If the account is the issuer, then no line should exist. Check anyway. + // If a line does exist, it will get deleted. If not, return success. + bool const accountIsIssuer = accountID == issue.account; + auto const line = view.peek(keylet::line(accountID, issue)); + if (!line) + return accountIsIssuer ? (TER)tesSUCCESS : (TER)tecOBJECT_NOT_FOUND; + if (!accountIsIssuer && line->at(sfBalance)->iou() != beast::zero) + return tecHAS_OBLIGATIONS; + + // Adjust the owner count(s) + if (line->isFlag(lsfLowReserve)) + { + // Clear reserve for low account. + auto sleLowAccount = view.peek(keylet::account(line->at(sfLowLimit)->getIssuer())); + if (!sleLowAccount) + return tecINTERNAL; // LCOV_EXCL_LINE + + adjustOwnerCount(view, sleLowAccount, -1, journal); + // It's not really necessary to clear the reserve flag, since the line + // is about to be deleted, but this will make the metadata reflect an + // accurate state at the time of deletion. + line->clearFlag(lsfLowReserve); + } + + if (line->isFlag(lsfHighReserve)) + { + // Clear reserve for high account. + auto sleHighAccount = view.peek(keylet::account(line->at(sfHighLimit)->getIssuer())); + if (!sleHighAccount) + return tecINTERNAL; // LCOV_EXCL_LINE + + adjustOwnerCount(view, sleHighAccount, -1, journal); + // It's not really necessary to clear the reserve flag, since the line + // is about to be deleted, but this will make the metadata reflect an + // accurate state at the time of deletion. + line->clearFlag(lsfHighReserve); + } + + return trustDelete( + view, line, line->at(sfLowLimit)->getIssuer(), line->at(sfHighLimit)->getIssuer(), journal); +} + +TER +deleteAMMTrustLine( + ApplyView& view, + std::shared_ptr sleState, + std::optional const& ammAccountID, + beast::Journal j) +{ + if (!sleState || sleState->getType() != ltRIPPLE_STATE) + return tecINTERNAL; // LCOV_EXCL_LINE + + auto const& [low, high] = std::minmax( + sleState->getFieldAmount(sfLowLimit).getIssuer(), + sleState->getFieldAmount(sfHighLimit).getIssuer()); + auto sleLow = view.peek(keylet::account(low)); + auto sleHigh = view.peek(keylet::account(high)); + if (!sleLow || !sleHigh) + return tecINTERNAL; // LCOV_EXCL_LINE + + bool const ammLow = sleLow->isFieldPresent(sfAMMID); + bool const ammHigh = sleHigh->isFieldPresent(sfAMMID); + + // can't both be AMM + if (ammLow && ammHigh) + return tecINTERNAL; // LCOV_EXCL_LINE + + // at least one must be + if (!ammLow && !ammHigh) + return terNO_AMM; + + // one must be the target amm + if (ammAccountID && (low != *ammAccountID && high != *ammAccountID)) + return terNO_AMM; + + if (auto const ter = trustDelete(view, sleState, low, high, j); !isTesSuccess(ter)) + { + JLOG(j.error()) << "deleteAMMTrustLine: failed to delete the trustline."; + return ter; + } + + auto const uFlags = !ammLow ? lsfLowReserve : lsfHighReserve; + if ((sleState->getFlags() & uFlags) == 0u) + return tecINTERNAL; // LCOV_EXCL_LINE + + adjustOwnerCount(view, !ammLow ? sleLow : sleHigh, -1, j); + + return tesSUCCESS; +} + +} // namespace xrpl diff --git a/src/libxrpl/ledger/helpers/TokenHelpers.cpp b/src/libxrpl/ledger/helpers/TokenHelpers.cpp new file mode 100644 index 0000000000..27ee257e64 --- /dev/null +++ b/src/libxrpl/ledger/helpers/TokenHelpers.cpp @@ -0,0 +1,1393 @@ +#include +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace xrpl { + +// Forward declaration for function that remains in View.h/cpp +bool +isLPTokenFrozen( + ReadView const& view, + AccountID const& account, + Issue const& asset, + Issue const& asset2); + +//------------------------------------------------------------------------------ +// +// Freeze checking (Asset-based) +// +//------------------------------------------------------------------------------ + +bool +isGlobalFrozen(ReadView const& view, Asset const& asset) +{ + return std::visit( + [&](TIss const& issue) { + if constexpr (std::is_same_v) + { + return isGlobalFrozen(view, issue.getIssuer()); + } + else + { + return isGlobalFrozen(view, issue); + } + }, + asset.value()); +} + +bool +isIndividualFrozen(ReadView const& view, AccountID const& account, Asset const& asset) +{ + return std::visit( + [&](auto const& issue) { return isIndividualFrozen(view, account, issue); }, asset.value()); +} + +bool +isFrozen(ReadView const& view, AccountID const& account, Asset const& asset, int depth) +{ + return std::visit( + [&](auto const& issue) { return isFrozen(view, account, issue, depth); }, asset.value()); +} + +TER +checkFrozen(ReadView const& view, AccountID const& account, Issue const& issue) +{ + return isFrozen(view, account, issue) ? (TER)tecFROZEN : (TER)tesSUCCESS; +} + +TER +checkFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue) +{ + return isFrozen(view, account, mptIssue) ? (TER)tecLOCKED : (TER)tesSUCCESS; +} + +TER +checkFrozen(ReadView const& view, AccountID const& account, Asset const& asset) +{ + return std::visit( + [&](auto const& issue) { return checkFrozen(view, account, issue); }, asset.value()); +} + +bool +isAnyFrozen( + ReadView const& view, + std::initializer_list const& accounts, + Issue const& issue) +{ + for (auto const& account : accounts) + { + if (isFrozen(view, account, issue.currency, issue.account)) + return true; + } + return false; +} + +bool +isAnyFrozen( + ReadView const& view, + std::initializer_list const& accounts, + Asset const& asset, + int depth) +{ + return std::visit( + [&](TIss const& issue) { + if constexpr (std::is_same_v) + { + return isAnyFrozen(view, accounts, issue); + } + else + { + return isAnyFrozen(view, accounts, issue, depth); + } + }, + asset.value()); +} + +bool +isDeepFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue, int depth) +{ + // Unlike IOUs, frozen / locked MPTs are not allowed to send or receive + // funds, so checking "deep frozen" is the same as checking "frozen". + return isFrozen(view, account, mptIssue, depth); +} + +bool +isDeepFrozen(ReadView const& view, AccountID const& account, Asset const& asset, int depth) +{ + return std::visit( + [&](auto const& issue) { return isDeepFrozen(view, account, issue, depth); }, + asset.value()); +} + +TER +checkDeepFrozen(ReadView const& view, AccountID const& account, MPTIssue const& mptIssue) +{ + return isDeepFrozen(view, account, mptIssue) ? (TER)tecLOCKED : (TER)tesSUCCESS; +} + +TER +checkDeepFrozen(ReadView const& view, AccountID const& account, Asset const& asset) +{ + return std::visit( + [&](auto const& issue) { return checkDeepFrozen(view, account, issue); }, asset.value()); +} + +//------------------------------------------------------------------------------ +// +// Account balance functions +// +//------------------------------------------------------------------------------ + +static SLE::const_pointer +getLineIfUsable( + ReadView const& view, + AccountID const& account, + Currency const& currency, + AccountID const& issuer, + FreezeHandling zeroIfFrozen, + beast::Journal j) +{ + auto sle = view.read(keylet::line(account, issuer, currency)); + + if (!sle) + { + return nullptr; + } + + if (zeroIfFrozen == fhZERO_IF_FROZEN) + { + if (isFrozen(view, account, currency, issuer) || + isDeepFrozen(view, account, currency, issuer)) + { + return nullptr; + } + + // when fixFrozenLPTokenTransfer is enabled, if currency is lptoken, + // we need to check if the associated assets have been frozen + if (view.rules().enabled(fixFrozenLPTokenTransfer)) + { + auto const sleIssuer = view.read(keylet::account(issuer)); + if (!sleIssuer) + { + return nullptr; // LCOV_EXCL_LINE + } + if (sleIssuer->isFieldPresent(sfAMMID)) + { + auto const sleAmm = view.read(keylet::amm((*sleIssuer)[sfAMMID])); + + if (!sleAmm || + isLPTokenFrozen( + view, + account, + (*sleAmm)[sfAsset].get(), + (*sleAmm)[sfAsset2].get())) + { + return nullptr; + } + } + } + } + + return sle; +} + +static STAmount +getTrustLineBalance( + ReadView const& view, + SLE::const_ref sle, + AccountID const& account, + Currency const& currency, + AccountID const& issuer, + bool includeOppositeLimit, + beast::Journal j) +{ + STAmount amount; + if (sle) + { + amount = sle->getFieldAmount(sfBalance); + bool const accountHigh = account > issuer; + auto const& oppositeField = accountHigh ? sfLowLimit : sfHighLimit; + if (accountHigh) + { + // Put balance in account terms. + amount.negate(); + } + if (includeOppositeLimit) + { + amount += sle->getFieldAmount(oppositeField); + } + amount.setIssuer(issuer); + } + else + { + amount.clear(Issue{currency, issuer}); + } + + JLOG(j.trace()) << "getTrustLineBalance:" << " account=" << to_string(account) + << " amount=" << amount.getFullText(); + + return view.balanceHook(account, issuer, amount); +} + +STAmount +accountHolds( + ReadView const& view, + AccountID const& account, + Currency const& currency, + AccountID const& issuer, + FreezeHandling zeroIfFrozen, + beast::Journal j, + SpendableHandling includeFullBalance) +{ + STAmount amount; + if (isXRP(currency)) + { + return {xrpLiquid(view, account, 0, j)}; + } + + bool const returnSpendable = (includeFullBalance == shFULL_BALANCE); + if (returnSpendable && account == issuer) + { + // If the account is the issuer, then their limit is effectively + // infinite + return STAmount{Issue{currency, issuer}, STAmount::cMaxValue, STAmount::cMaxOffset}; + } + + // IOU: Return balance on trust line modulo freeze + SLE::const_pointer const sle = + getLineIfUsable(view, account, currency, issuer, zeroIfFrozen, j); + + return getTrustLineBalance(view, sle, account, currency, issuer, returnSpendable, j); +} + +STAmount +accountHolds( + ReadView const& view, + AccountID const& account, + Issue const& issue, + FreezeHandling zeroIfFrozen, + beast::Journal j, + SpendableHandling includeFullBalance) +{ + return accountHolds( + view, account, issue.currency, issue.account, zeroIfFrozen, j, includeFullBalance); +} + +STAmount +accountHolds( + ReadView const& view, + AccountID const& account, + MPTIssue const& mptIssue, + FreezeHandling zeroIfFrozen, + AuthHandling zeroIfUnauthorized, + beast::Journal j, + SpendableHandling includeFullBalance) +{ + bool const returnSpendable = (includeFullBalance == shFULL_BALANCE); + + if (returnSpendable && account == mptIssue.getIssuer()) + { + // if the account is the issuer, and the issuance exists, their limit is + // the issuance limit minus the outstanding value + auto const issuance = view.read(keylet::mptIssuance(mptIssue.getMptID())); + + if (!issuance) + { + return STAmount{mptIssue}; + } + return STAmount{ + mptIssue, + issuance->at(~sfMaximumAmount).value_or(maxMPTokenAmount) - + issuance->at(sfOutstandingAmount)}; + } + + STAmount amount; + + auto const sleMpt = view.read(keylet::mptoken(mptIssue.getMptID(), account)); + + if (!sleMpt) + { + amount.clear(mptIssue); + } + else if (zeroIfFrozen == fhZERO_IF_FROZEN && isFrozen(view, account, mptIssue)) + { + amount.clear(mptIssue); + } + else + { + amount = STAmount{mptIssue, sleMpt->getFieldU64(sfMPTAmount)}; + + // Only if auth check is needed, as it needs to do an additional read + // operation. Note featureSingleAssetVault will affect error codes. + if (zeroIfUnauthorized == ahZERO_IF_UNAUTHORIZED && + view.rules().enabled(featureSingleAssetVault)) + { + if (auto const err = requireAuth(view, mptIssue, account, AuthType::StrongAuth); + !isTesSuccess(err)) + amount.clear(mptIssue); + } + else if (zeroIfUnauthorized == ahZERO_IF_UNAUTHORIZED) + { + auto const sleIssuance = view.read(keylet::mptIssuance(mptIssue.getMptID())); + + // if auth is enabled on the issuance and mpt is not authorized, + // clear amount + if (sleIssuance && sleIssuance->isFlag(lsfMPTRequireAuth) && + !sleMpt->isFlag(lsfMPTAuthorized)) + amount.clear(mptIssue); + } + } + + return amount; +} + +[[nodiscard]] STAmount +accountHolds( + ReadView const& view, + AccountID const& account, + Asset const& asset, + FreezeHandling zeroIfFrozen, + AuthHandling zeroIfUnauthorized, + beast::Journal j, + SpendableHandling includeFullBalance) +{ + return std::visit( + [&](TIss const& value) { + if constexpr (std::is_same_v) + { + return accountHolds(view, account, value, zeroIfFrozen, j, includeFullBalance); + } + else if constexpr (std::is_same_v) + { + return accountHolds( + view, account, value, zeroIfFrozen, zeroIfUnauthorized, j, includeFullBalance); + } + }, + asset.value()); +} + +STAmount +accountFunds( + ReadView const& view, + AccountID const& id, + STAmount const& saDefault, + FreezeHandling freezeHandling, + beast::Journal j) +{ + if (!saDefault.native() && saDefault.getIssuer() == id) + return saDefault; + + return accountHolds( + view, id, saDefault.getCurrency(), saDefault.getIssuer(), freezeHandling, j); +} + +Rate +transferRate(ReadView const& view, STAmount const& amount) +{ + return std::visit( + [&](TIss const& issue) { + if constexpr (std::is_same_v) + { + return transferRate(view, issue.getIssuer()); + } + else + { + return transferRate(view, issue.getMptID()); + } + }, + amount.asset().value()); +} + +//------------------------------------------------------------------------------ +// +// Holding operations +// +//------------------------------------------------------------------------------ + +[[nodiscard]] TER +canAddHolding(ReadView const& view, Issue const& issue) +{ + if (issue.native()) + { + return tesSUCCESS; // No special checks for XRP + } + + auto const issuer = view.read(keylet::account(issue.getIssuer())); + if (!issuer) + { + return terNO_ACCOUNT; + } + if (!issuer->isFlag(lsfDefaultRipple)) + { + return terNO_RIPPLE; + } + + return tesSUCCESS; +} + +[[nodiscard]] TER +canAddHolding(ReadView const& view, Asset const& asset) +{ + return std::visit( + [&](TIss const& issue) -> TER { return canAddHolding(view, issue); }, + asset.value()); +} + +TER +addEmptyHolding( + ApplyView& view, + AccountID const& accountID, + XRPAmount priorBalance, + Asset const& asset, + beast::Journal journal) +{ + return std::visit( + [&](TIss const& issue) -> TER { + return addEmptyHolding(view, accountID, priorBalance, issue, journal); + }, + asset.value()); +} + +TER +removeEmptyHolding( + ApplyView& view, + AccountID const& accountID, + Asset const& asset, + beast::Journal journal) +{ + return std::visit( + [&](TIss const& issue) -> TER { + return removeEmptyHolding(view, accountID, issue, journal); + }, + asset.value()); +} + +//------------------------------------------------------------------------------ +// +// Authorization and transfer checks +// +//------------------------------------------------------------------------------ + +TER +requireAuth(ReadView const& view, Asset const& asset, AccountID const& account, AuthType authType) +{ + return std::visit( + [&](TIss const& issue_) { + return requireAuth(view, issue_, account, authType); + }, + asset.value()); +} + +TER +canTransfer(ReadView const& view, Asset const& asset, AccountID const& from, AccountID const& to) +{ + return std::visit( + [&](TIss const& issue) -> TER { + return canTransfer(view, issue, from, to); + }, + asset.value()); +} + +//------------------------------------------------------------------------------ +// +// Money Transfers +// +//------------------------------------------------------------------------------ + +// Direct send w/o fees: +// - Redeeming IOUs and/or sending sender's own IOUs. +// - Create trust line if needed. +// --> bCheckIssuer : normally require issuer to be involved. +static TER +rippleCreditIOU( + ApplyView& view, + AccountID const& uSenderID, + AccountID const& uReceiverID, + STAmount const& saAmount, + bool bCheckIssuer, + beast::Journal j) +{ + AccountID const& issuer = saAmount.getIssuer(); + Currency const& currency = saAmount.getCurrency(); + + // Make sure issuer is involved. + XRPL_ASSERT( + !bCheckIssuer || uSenderID == issuer || uReceiverID == issuer, + "xrpl::rippleCreditIOU : matching issuer or don't care"); + (void)issuer; + + // Disallow sending to self. + XRPL_ASSERT(uSenderID != uReceiverID, "xrpl::rippleCreditIOU : sender is not receiver"); + + bool const bSenderHigh = uSenderID > uReceiverID; + auto const index = keylet::line(uSenderID, uReceiverID, currency); + + XRPL_ASSERT( + !isXRP(uSenderID) && uSenderID != noAccount(), "xrpl::rippleCreditIOU : sender is not XRP"); + XRPL_ASSERT( + !isXRP(uReceiverID) && uReceiverID != noAccount(), + "xrpl::rippleCreditIOU : receiver is not XRP"); + + // If the line exists, modify it accordingly. + if (auto const sleRippleState = view.peek(index)) + { + STAmount saBalance = sleRippleState->getFieldAmount(sfBalance); + + if (bSenderHigh) + saBalance.negate(); // Put balance in sender terms. + + view.creditHook(uSenderID, uReceiverID, saAmount, saBalance); + + STAmount const saBefore = saBalance; + + saBalance -= saAmount; + + JLOG(j.trace()) << "rippleCreditIOU: " << to_string(uSenderID) << " -> " + << to_string(uReceiverID) << " : before=" << saBefore.getFullText() + << " amount=" << saAmount.getFullText() + << " after=" << saBalance.getFullText(); + + std::uint32_t const uFlags(sleRippleState->getFieldU32(sfFlags)); + bool bDelete = false; + + // FIXME This NEEDS to be cleaned up and simplified. It's impossible + // for anyone to understand. + if (saBefore > beast::zero + // Sender balance was positive. + && saBalance <= beast::zero + // Sender is zero or negative. + && ((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)) == 0u) && + !sleRippleState->getFieldAmount(!bSenderHigh ? sfLowLimit : sfHighLimit) + // Sender trust limit is 0. + && (sleRippleState->getFieldU32(!bSenderHigh ? sfLowQualityIn : sfHighQualityIn) == 0u) + // Sender quality in is 0. + && + (sleRippleState->getFieldU32(!bSenderHigh ? sfLowQualityOut : sfHighQualityOut) == 0u)) + // Sender quality out is 0. + { + // Clear the reserve of the sender, possibly delete the line! + adjustOwnerCount(view, view.peek(keylet::account(uSenderID)), -1, j); + + // Clear reserve flag. + sleRippleState->setFieldU32( + sfFlags, uFlags & (!bSenderHigh ? ~lsfLowReserve : ~lsfHighReserve)); + + // Balance is zero, receiver reserve is clear. + bDelete = !saBalance // Balance is zero. + && ((uFlags & (bSenderHigh ? lsfLowReserve : lsfHighReserve)) == 0u); + // Receiver reserve is clear. + } + + if (bSenderHigh) + saBalance.negate(); + + // Want to reflect balance to zero even if we are deleting line. + sleRippleState->setFieldAmount(sfBalance, saBalance); + // ONLY: Adjust ripple balance. + + if (bDelete) + { + return trustDelete( + view, + sleRippleState, + bSenderHigh ? uReceiverID : uSenderID, + !bSenderHigh ? uReceiverID : uSenderID, + j); + } + + view.update(sleRippleState); + return tesSUCCESS; + } + + STAmount const saReceiverLimit(Issue{currency, uReceiverID}); + STAmount saBalance{saAmount}; + + saBalance.setIssuer(noAccount()); + + JLOG(j.debug()) << "rippleCreditIOU: " + "create line: " + << to_string(uSenderID) << " -> " << to_string(uReceiverID) << " : " + << saAmount.getFullText(); + + auto const sleAccount = view.peek(keylet::account(uReceiverID)); + if (!sleAccount) + return tefINTERNAL; // LCOV_EXCL_LINE + + bool const noRipple = (sleAccount->getFlags() & lsfDefaultRipple) == 0; + + return trustCreate( + view, + bSenderHigh, + uSenderID, + uReceiverID, + index.key, + sleAccount, + false, + noRipple, + false, + false, + saBalance, + saReceiverLimit, + 0, + 0, + j); +} + +// Send regardless of limits. +// --> saAmount: Amount/currency/issuer to deliver to receiver. +// <-- saActual: Amount actually cost. Sender pays fees. +static TER +rippleSendIOU( + ApplyView& view, + AccountID const& uSenderID, + AccountID const& uReceiverID, + STAmount const& saAmount, + STAmount& saActual, + beast::Journal j, + WaiveTransferFee waiveFee) +{ + auto const& issuer = saAmount.getIssuer(); + + XRPL_ASSERT( + !isXRP(uSenderID) && !isXRP(uReceiverID), + "xrpl::rippleSendIOU : neither sender nor receiver is XRP"); + XRPL_ASSERT(uSenderID != uReceiverID, "xrpl::rippleSendIOU : sender is not receiver"); + + if (uSenderID == issuer || uReceiverID == issuer || issuer == noAccount()) + { + // Direct send: redeeming IOUs and/or sending own IOUs. + auto const ter = rippleCreditIOU(view, uSenderID, uReceiverID, saAmount, false, j); + if (!isTesSuccess(ter)) + return ter; + saActual = saAmount; + return tesSUCCESS; + } + + // Sending 3rd party IOUs: transit. + + // Calculate the amount to transfer accounting + // for any transfer fees if the fee is not waived: + saActual = (waiveFee == WaiveTransferFee::Yes) ? saAmount + : multiply(saAmount, transferRate(view, issuer)); + + JLOG(j.debug()) << "rippleSendIOU> " << to_string(uSenderID) << " - > " + << to_string(uReceiverID) << " : deliver=" << saAmount.getFullText() + << " cost=" << saActual.getFullText(); + + TER terResult = rippleCreditIOU(view, issuer, uReceiverID, saAmount, true, j); + + if (tesSUCCESS == terResult) + terResult = rippleCreditIOU(view, uSenderID, issuer, saActual, true, j); + + return terResult; +} + +// Send regardless of limits. +// --> receivers: Amount/currency/issuer to deliver to receivers. +// <-- saActual: Amount actually cost to sender. Sender pays fees. +static TER +rippleSendMultiIOU( + ApplyView& view, + AccountID const& senderID, + Issue const& issue, + MultiplePaymentDestinations const& receivers, + STAmount& actual, + beast::Journal j, + WaiveTransferFee waiveFee) +{ + auto const& issuer = issue.getIssuer(); + + XRPL_ASSERT(!isXRP(senderID), "xrpl::rippleSendMultiIOU : sender is not XRP"); + + // These may diverge + STAmount takeFromSender{issue}; + actual = takeFromSender; + + // Failures return immediately. + for (auto const& r : receivers) + { + auto const& receiverID = r.first; + STAmount amount{issue, r.second}; + + /* If we aren't sending anything or if the sender is the same as the + * receiver then we don't need to do anything. + */ + if (!amount || (senderID == receiverID)) + continue; + + XRPL_ASSERT(!isXRP(receiverID), "xrpl::rippleSendMultiIOU : receiver is not XRP"); + + if (senderID == issuer || receiverID == issuer || issuer == noAccount()) + { + // Direct send: redeeming IOUs and/or sending own IOUs. + if (auto const ter = rippleCreditIOU(view, senderID, receiverID, amount, false, j)) + return ter; + actual += amount; + // Do not add amount to takeFromSender, because rippleCreditIOU took + // it. + + continue; + } + + // Sending 3rd party IOUs: transit. + + // Calculate the amount to transfer accounting + // for any transfer fees if the fee is not waived: + STAmount actualSend = (waiveFee == WaiveTransferFee::Yes) + ? amount + : multiply(amount, transferRate(view, issuer)); + actual += actualSend; + takeFromSender += actualSend; + + JLOG(j.debug()) << "rippleSendMultiIOU> " << to_string(senderID) << " - > " + << to_string(receiverID) << " : deliver=" << amount.getFullText() + << " cost=" << actual.getFullText(); + + if (TER const terResult = rippleCreditIOU(view, issuer, receiverID, amount, true, j)) + return terResult; + } + + if (senderID != issuer && takeFromSender) + { + if (TER const terResult = rippleCreditIOU(view, senderID, issuer, takeFromSender, true, j)) + return terResult; + } + + return tesSUCCESS; +} + +static TER +accountSendIOU( + ApplyView& view, + AccountID const& uSenderID, + AccountID const& uReceiverID, + STAmount const& saAmount, + beast::Journal j, + WaiveTransferFee waiveFee) +{ + if (view.rules().enabled(fixAMMv1_1)) + { + if (saAmount < beast::zero || saAmount.holds()) + { + return tecINTERNAL; // LCOV_EXCL_LINE + } + } + else + { + // LCOV_EXCL_START + XRPL_ASSERT( + saAmount >= beast::zero && !saAmount.holds(), + "xrpl::accountSendIOU : minimum amount and not MPT"); + // LCOV_EXCL_STOP + } + + /* If we aren't sending anything or if the sender is the same as the + * receiver then we don't need to do anything. + */ + if (!saAmount || (uSenderID == uReceiverID)) + return tesSUCCESS; + + if (!saAmount.native()) + { + STAmount saActual; + + JLOG(j.trace()) << "accountSendIOU: " << to_string(uSenderID) << " -> " + << to_string(uReceiverID) << " : " << saAmount.getFullText(); + + return rippleSendIOU(view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee); + } + + /* XRP send which does not check reserve and can do pure adjustment. + * Note that sender or receiver may be null and this not a mistake; this + * setup is used during pathfinding and it is carefully controlled to + * ensure that transfers are balanced. + */ + TER terResult(tesSUCCESS); + + SLE::pointer sender = + uSenderID != beast::zero ? view.peek(keylet::account(uSenderID)) : SLE::pointer(); + SLE::pointer receiver = + uReceiverID != beast::zero ? view.peek(keylet::account(uReceiverID)) : SLE::pointer(); + + if (auto stream = j.trace()) + { + std::string sender_bal("-"); + std::string receiver_bal("-"); + + if (sender) + sender_bal = sender->getFieldAmount(sfBalance).getFullText(); + + if (receiver) + receiver_bal = receiver->getFieldAmount(sfBalance).getFullText(); + + stream << "accountSendIOU> " << to_string(uSenderID) << " (" << sender_bal << ") -> " + << to_string(uReceiverID) << " (" << receiver_bal + << ") : " << saAmount.getFullText(); + } + + if (sender) + { + if (sender->getFieldAmount(sfBalance) < saAmount) + { + // VFALCO Its laborious to have to mutate the + // TER based on params everywhere + // LCOV_EXCL_START + terResult = view.open() ? TER{telFAILED_PROCESSING} : TER{tecFAILED_PROCESSING}; + // LCOV_EXCL_STOP + } + else + { + auto const sndBal = sender->getFieldAmount(sfBalance); + view.creditHook(uSenderID, xrpAccount(), saAmount, sndBal); + + // Decrement XRP balance. + sender->setFieldAmount(sfBalance, sndBal - saAmount); + view.update(sender); + } + } + + if (tesSUCCESS == terResult && receiver) + { + // Increment XRP balance. + auto const rcvBal = receiver->getFieldAmount(sfBalance); + receiver->setFieldAmount(sfBalance, rcvBal + saAmount); + view.creditHook(xrpAccount(), uReceiverID, saAmount, -rcvBal); + + view.update(receiver); + } + + if (auto stream = j.trace()) + { + std::string sender_bal("-"); + std::string receiver_bal("-"); + + if (sender) + sender_bal = sender->getFieldAmount(sfBalance).getFullText(); + + if (receiver) + receiver_bal = receiver->getFieldAmount(sfBalance).getFullText(); + + stream << "accountSendIOU< " << to_string(uSenderID) << " (" << sender_bal << ") -> " + << to_string(uReceiverID) << " (" << receiver_bal + << ") : " << saAmount.getFullText(); + } + + return terResult; +} + +static TER +accountSendMultiIOU( + ApplyView& view, + AccountID const& senderID, + Issue const& issue, + MultiplePaymentDestinations const& receivers, + beast::Journal j, + WaiveTransferFee waiveFee) +{ + XRPL_ASSERT_PARTS( + receivers.size() > 1, "xrpl::accountSendMultiIOU", "multiple recipients provided"); + + if (!issue.native()) + { + STAmount actual; + JLOG(j.trace()) << "accountSendMultiIOU: " << to_string(senderID) << " sending " + << receivers.size() << " IOUs"; + + return rippleSendMultiIOU(view, senderID, issue, receivers, actual, j, waiveFee); + } + + /* XRP send which does not check reserve and can do pure adjustment. + * Note that sender or receiver may be null and this not a mistake; this + * setup could be used during pathfinding and it is carefully controlled to + * ensure that transfers are balanced. + */ + + SLE::pointer sender = + senderID != beast::zero ? view.peek(keylet::account(senderID)) : SLE::pointer(); + + if (auto stream = j.trace()) + { + std::string sender_bal("-"); + + if (sender) + sender_bal = sender->getFieldAmount(sfBalance).getFullText(); + + stream << "accountSendMultiIOU> " << to_string(senderID) << " (" << sender_bal << ") -> " + << receivers.size() << " receivers."; + } + + // Failures return immediately. + STAmount takeFromSender{issue}; + for (auto const& r : receivers) + { + auto const& receiverID = r.first; + STAmount amount{issue, r.second}; + + if (amount < beast::zero) + { + return tecINTERNAL; // LCOV_EXCL_LINE + } + + /* If we aren't sending anything or if the sender is the same as the + * receiver then we don't need to do anything. + */ + if (!amount || (senderID == receiverID)) + continue; + + SLE::pointer receiver = + receiverID != beast::zero ? view.peek(keylet::account(receiverID)) : SLE::pointer(); + + if (auto stream = j.trace()) + { + std::string receiver_bal("-"); + + if (receiver) + receiver_bal = receiver->getFieldAmount(sfBalance).getFullText(); + + stream << "accountSendMultiIOU> " << to_string(senderID) << " -> " + << to_string(receiverID) << " (" << receiver_bal + << ") : " << amount.getFullText(); + } + + if (receiver) + { + // Increment XRP balance. + auto const rcvBal = receiver->getFieldAmount(sfBalance); + receiver->setFieldAmount(sfBalance, rcvBal + amount); + view.creditHook(xrpAccount(), receiverID, amount, -rcvBal); + + view.update(receiver); + + // Take what is actually sent + takeFromSender += amount; + } + + if (auto stream = j.trace()) + { + std::string receiver_bal("-"); + + if (receiver) + receiver_bal = receiver->getFieldAmount(sfBalance).getFullText(); + + stream << "accountSendMultiIOU< " << to_string(senderID) << " -> " + << to_string(receiverID) << " (" << receiver_bal + << ") : " << amount.getFullText(); + } + } + + if (sender) + { + if (sender->getFieldAmount(sfBalance) < takeFromSender) + { + return TER{tecFAILED_PROCESSING}; + } + auto const sndBal = sender->getFieldAmount(sfBalance); + view.creditHook(senderID, xrpAccount(), takeFromSender, sndBal); + + // Decrement XRP balance. + sender->setFieldAmount(sfBalance, sndBal - takeFromSender); + view.update(sender); + } + + if (auto stream = j.trace()) + { + std::string sender_bal("-"); + + if (sender) + sender_bal = sender->getFieldAmount(sfBalance).getFullText(); + + stream << "accountSendMultiIOU< " << to_string(senderID) << " (" << sender_bal << ") -> " + << receivers.size() << " receivers."; + } + return tesSUCCESS; +} + +static TER +rippleCreditMPT( + ApplyView& view, + AccountID const& uSenderID, + AccountID const& uReceiverID, + STAmount const& saAmount, + beast::Journal j) +{ + // Do not check MPT authorization here - it must have been checked earlier + auto const mptID = keylet::mptIssuance(saAmount.get().getMptID()); + auto const& issuer = saAmount.getIssuer(); + auto sleIssuance = view.peek(mptID); + if (!sleIssuance) + return tecOBJECT_NOT_FOUND; + if (uSenderID == issuer) + { + (*sleIssuance)[sfOutstandingAmount] += saAmount.mpt().value(); + view.update(sleIssuance); + } + else + { + auto const mptokenID = keylet::mptoken(mptID.key, uSenderID); + if (auto sle = view.peek(mptokenID)) + { + auto const amt = sle->getFieldU64(sfMPTAmount); + auto const pay = saAmount.mpt().value(); + if (amt < pay) + return tecINSUFFICIENT_FUNDS; + (*sle)[sfMPTAmount] = amt - pay; + view.update(sle); + } + else + { + return tecNO_AUTH; + } + } + + if (uReceiverID == issuer) + { + auto const outstanding = sleIssuance->getFieldU64(sfOutstandingAmount); + auto const redeem = saAmount.mpt().value(); + if (outstanding >= redeem) + { + sleIssuance->setFieldU64(sfOutstandingAmount, outstanding - redeem); + view.update(sleIssuance); + } + else + { + return tecINTERNAL; // LCOV_EXCL_LINE + } + } + else + { + auto const mptokenID = keylet::mptoken(mptID.key, uReceiverID); + if (auto sle = view.peek(mptokenID)) + { + (*sle)[sfMPTAmount] += saAmount.mpt().value(); + view.update(sle); + } + else + { + return tecNO_AUTH; + } + } + + return tesSUCCESS; +} + +static TER +rippleSendMPT( + ApplyView& view, + AccountID const& uSenderID, + AccountID const& uReceiverID, + STAmount const& saAmount, + STAmount& saActual, + beast::Journal j, + WaiveTransferFee waiveFee) +{ + XRPL_ASSERT(uSenderID != uReceiverID, "xrpl::rippleSendMPT : sender is not receiver"); + + // Safe to get MPT since rippleSendMPT is only called by accountSendMPT + auto const& issuer = saAmount.getIssuer(); + + auto const sle = view.read(keylet::mptIssuance(saAmount.get().getMptID())); + if (!sle) + return tecOBJECT_NOT_FOUND; + + if (uSenderID == issuer || uReceiverID == issuer) + { + // if sender is issuer, check that the new OutstandingAmount will not + // exceed MaximumAmount + if (uSenderID == issuer) + { + auto const sendAmount = saAmount.mpt().value(); + auto const maximumAmount = sle->at(~sfMaximumAmount).value_or(maxMPTokenAmount); + if (sendAmount > maximumAmount || + sle->getFieldU64(sfOutstandingAmount) > maximumAmount - sendAmount) + return tecPATH_DRY; + } + + // Direct send: redeeming MPTs and/or sending own MPTs. + auto const ter = rippleCreditMPT(view, uSenderID, uReceiverID, saAmount, j); + if (!isTesSuccess(ter)) + return ter; + saActual = saAmount; + return tesSUCCESS; + } + + // Sending 3rd party MPTs: transit. + saActual = (waiveFee == WaiveTransferFee::Yes) + ? saAmount + : multiply(saAmount, transferRate(view, saAmount.get().getMptID())); + + JLOG(j.debug()) << "rippleSendMPT> " << to_string(uSenderID) << " - > " + << to_string(uReceiverID) << " : deliver=" << saAmount.getFullText() + << " cost=" << saActual.getFullText(); + + if (auto const terResult = rippleCreditMPT(view, issuer, uReceiverID, saAmount, j); + !isTesSuccess(terResult)) + return terResult; + + return rippleCreditMPT(view, uSenderID, issuer, saActual, j); +} + +static TER +rippleSendMultiMPT( + ApplyView& view, + AccountID const& senderID, + MPTIssue const& mptIssue, + MultiplePaymentDestinations const& receivers, + STAmount& actual, + beast::Journal j, + WaiveTransferFee waiveFee) +{ + // Safe to get MPT since rippleSendMultiMPT is only called by + // accountSendMultiMPT + auto const& issuer = mptIssue.getIssuer(); + + auto const sle = view.read(keylet::mptIssuance(mptIssue.getMptID())); + if (!sle) + return tecOBJECT_NOT_FOUND; + + // These may diverge + STAmount takeFromSender{mptIssue}; + actual = takeFromSender; + + for (auto const& r : receivers) + { + auto const& receiverID = r.first; + STAmount amount{mptIssue, r.second}; + + if (amount < beast::zero) + { + return tecINTERNAL; // LCOV_EXCL_LINE + } + + /* If we aren't sending anything or if the sender is the same as the + * receiver then we don't need to do anything. + */ + if (!amount || (senderID == receiverID)) + continue; + + if (senderID == issuer || receiverID == issuer) + { + // if sender is issuer, check that the new OutstandingAmount will + // not exceed MaximumAmount + if (senderID == issuer) + { + XRPL_ASSERT_PARTS( + takeFromSender == beast::zero, + "xrpl::rippleSendMultiMPT", + "sender == issuer, takeFromSender == zero"); + auto const sendAmount = amount.mpt().value(); + auto const maximumAmount = sle->at(~sfMaximumAmount).value_or(maxMPTokenAmount); + if (sendAmount > maximumAmount || + sle->getFieldU64(sfOutstandingAmount) > maximumAmount - sendAmount) + return tecPATH_DRY; + } + + // Direct send: redeeming MPTs and/or sending own MPTs. + if (auto const ter = rippleCreditMPT(view, senderID, receiverID, amount, j)) + return ter; + actual += amount; + // Do not add amount to takeFromSender, because rippleCreditMPT took + // it + + continue; + } + + // Sending 3rd party MPTs: transit. + STAmount actualSend = (waiveFee == WaiveTransferFee::Yes) + ? amount + : multiply(amount, transferRate(view, amount.get().getMptID())); + actual += actualSend; + takeFromSender += actualSend; + + JLOG(j.debug()) << "rippleSendMultiMPT> " << to_string(senderID) << " - > " + << to_string(receiverID) << " : deliver=" << amount.getFullText() + << " cost=" << actualSend.getFullText(); + + if (auto const terResult = rippleCreditMPT(view, issuer, receiverID, amount, j)) + return terResult; + } + if (senderID != issuer && takeFromSender) + { + if (TER const terResult = rippleCreditMPT(view, senderID, issuer, takeFromSender, j)) + return terResult; + } + + return tesSUCCESS; +} + +static TER +accountSendMPT( + ApplyView& view, + AccountID const& uSenderID, + AccountID const& uReceiverID, + STAmount const& saAmount, + beast::Journal j, + WaiveTransferFee waiveFee) +{ + XRPL_ASSERT( + saAmount >= beast::zero && saAmount.holds(), + "xrpl::accountSendMPT : minimum amount and MPT"); + + /* If we aren't sending anything or if the sender is the same as the + * receiver then we don't need to do anything. + */ + if (!saAmount || (uSenderID == uReceiverID)) + return tesSUCCESS; + + STAmount saActual{saAmount.asset()}; + + return rippleSendMPT(view, uSenderID, uReceiverID, saAmount, saActual, j, waiveFee); +} + +static TER +accountSendMultiMPT( + ApplyView& view, + AccountID const& senderID, + MPTIssue const& mptIssue, + MultiplePaymentDestinations const& receivers, + beast::Journal j, + WaiveTransferFee waiveFee) +{ + STAmount actual; + + return rippleSendMultiMPT(view, senderID, mptIssue, receivers, actual, j, waiveFee); +} + +//------------------------------------------------------------------------------ +// +// Public Dispatcher Functions +// +//------------------------------------------------------------------------------ + +TER +rippleCredit( + ApplyView& view, + AccountID const& uSenderID, + AccountID const& uReceiverID, + STAmount const& saAmount, + bool bCheckIssuer, + beast::Journal j) +{ + return std::visit( + [&](TIss const& issue) { + if constexpr (std::is_same_v) + { + return rippleCreditIOU(view, uSenderID, uReceiverID, saAmount, bCheckIssuer, j); + } + else + { + XRPL_ASSERT(!bCheckIssuer, "xrpl::rippleCredit : not checking issuer"); + return rippleCreditMPT(view, uSenderID, uReceiverID, saAmount, j); + } + }, + saAmount.asset().value()); +} + +TER +accountSend( + ApplyView& view, + AccountID const& uSenderID, + AccountID const& uReceiverID, + STAmount const& saAmount, + beast::Journal j, + WaiveTransferFee waiveFee) +{ + return std::visit( + [&](TIss const& issue) { + if constexpr (std::is_same_v) + { + return accountSendIOU(view, uSenderID, uReceiverID, saAmount, j, waiveFee); + } + else + { + return accountSendMPT(view, uSenderID, uReceiverID, saAmount, j, waiveFee); + } + }, + saAmount.asset().value()); +} + +TER +accountSendMulti( + ApplyView& view, + AccountID const& senderID, + Asset const& asset, + MultiplePaymentDestinations const& receivers, + beast::Journal j, + WaiveTransferFee waiveFee) +{ + XRPL_ASSERT_PARTS( + receivers.size() > 1, "xrpl::accountSendMulti", "multiple recipients provided"); + return std::visit( + [&](TIss const& issue) { + if constexpr (std::is_same_v) + { + return accountSendMultiIOU(view, senderID, issue, receivers, j, waiveFee); + } + else + { + return accountSendMultiMPT(view, senderID, issue, receivers, j, waiveFee); + } + }, + asset.value()); +} + +TER +transferXRP( + ApplyView& view, + AccountID const& from, + AccountID const& to, + STAmount const& amount, + beast::Journal j) +{ + XRPL_ASSERT(from != beast::zero, "xrpl::transferXRP : nonzero from account"); + XRPL_ASSERT(to != beast::zero, "xrpl::transferXRP : nonzero to account"); + XRPL_ASSERT(from != to, "xrpl::transferXRP : sender is not receiver"); + XRPL_ASSERT(amount.native(), "xrpl::transferXRP : amount is XRP"); + + SLE::pointer const sender = view.peek(keylet::account(from)); + SLE::pointer const receiver = view.peek(keylet::account(to)); + if (!sender || !receiver) + return tefINTERNAL; // LCOV_EXCL_LINE + + JLOG(j.trace()) << "transferXRP: " << to_string(from) << " -> " << to_string(to) + << ") : " << amount.getFullText(); + + if (sender->getFieldAmount(sfBalance) < amount) + { + // VFALCO Its unfortunate we have to keep + // mutating these TER everywhere + // FIXME: this logic should be moved to callers maybe? + // LCOV_EXCL_START + return view.open() ? TER{telFAILED_PROCESSING} : TER{tecFAILED_PROCESSING}; + // LCOV_EXCL_STOP + } + + // Decrement XRP balance. + sender->setFieldAmount(sfBalance, sender->getFieldAmount(sfBalance) - amount); + view.update(sender); + + receiver->setFieldAmount(sfBalance, receiver->getFieldAmount(sfBalance) + amount); + view.update(receiver); + + return tesSUCCESS; +} + +} // namespace xrpl diff --git a/src/libxrpl/ledger/helpers/VaultHelpers.cpp b/src/libxrpl/ledger/helpers/VaultHelpers.cpp new file mode 100644 index 0000000000..83a1b9fc4f --- /dev/null +++ b/src/libxrpl/ledger/helpers/VaultHelpers.cpp @@ -0,0 +1,112 @@ +#include +// +#include +#include +#include + +namespace xrpl { + +[[nodiscard]] std::optional +assetsToSharesDeposit( + std::shared_ptr const& vault, + std::shared_ptr const& issuance, + STAmount const& assets) +{ + XRPL_ASSERT(!assets.negative(), "xrpl::assetsToSharesDeposit : non-negative assets"); + XRPL_ASSERT( + assets.asset() == vault->at(sfAsset), + "xrpl::assetsToSharesDeposit : assets and vault match"); + if (assets.negative() || assets.asset() != vault->at(sfAsset)) + return std::nullopt; // LCOV_EXCL_LINE + + Number const assetTotal = vault->at(sfAssetsTotal); + STAmount shares{vault->at(sfShareMPTID)}; + if (assetTotal == 0) + { + return STAmount{ + shares.asset(), + Number(assets.mantissa(), assets.exponent() + vault->at(sfScale)).truncate()}; + } + + Number const shareTotal = issuance->at(sfOutstandingAmount); + shares = ((shareTotal * assets) / assetTotal).truncate(); + return shares; +} + +[[nodiscard]] std::optional +sharesToAssetsDeposit( + std::shared_ptr const& vault, + std::shared_ptr const& issuance, + STAmount const& shares) +{ + XRPL_ASSERT(!shares.negative(), "xrpl::sharesToAssetsDeposit : non-negative shares"); + XRPL_ASSERT( + shares.asset() == vault->at(sfShareMPTID), + "xrpl::sharesToAssetsDeposit : shares and vault match"); + if (shares.negative() || shares.asset() != vault->at(sfShareMPTID)) + return std::nullopt; // LCOV_EXCL_LINE + + Number const assetTotal = vault->at(sfAssetsTotal); + STAmount assets{vault->at(sfAsset)}; + if (assetTotal == 0) + { + return STAmount{ + assets.asset(), shares.mantissa(), shares.exponent() - vault->at(sfScale), false}; + } + + Number const shareTotal = issuance->at(sfOutstandingAmount); + assets = (assetTotal * shares) / shareTotal; + return assets; +} + +[[nodiscard]] std::optional +assetsToSharesWithdraw( + std::shared_ptr const& vault, + std::shared_ptr const& issuance, + STAmount const& assets, + TruncateShares truncate) +{ + XRPL_ASSERT(!assets.negative(), "xrpl::assetsToSharesWithdraw : non-negative assets"); + XRPL_ASSERT( + assets.asset() == vault->at(sfAsset), + "xrpl::assetsToSharesWithdraw : assets and vault match"); + if (assets.negative() || assets.asset() != vault->at(sfAsset)) + return std::nullopt; // LCOV_EXCL_LINE + + Number assetTotal = vault->at(sfAssetsTotal); + assetTotal -= vault->at(sfLossUnrealized); + STAmount shares{vault->at(sfShareMPTID)}; + if (assetTotal == 0) + return shares; + Number const shareTotal = issuance->at(sfOutstandingAmount); + Number result = (shareTotal * assets) / assetTotal; + if (truncate == TruncateShares::yes) + result = result.truncate(); + shares = result; + return shares; +} + +[[nodiscard]] std::optional +sharesToAssetsWithdraw( + std::shared_ptr const& vault, + std::shared_ptr const& issuance, + STAmount const& shares) +{ + XRPL_ASSERT(!shares.negative(), "xrpl::sharesToAssetsWithdraw : non-negative shares"); + XRPL_ASSERT( + shares.asset() == vault->at(sfShareMPTID), + "xrpl::sharesToAssetsWithdraw : shares and vault match"); + if (shares.negative() || shares.asset() != vault->at(sfShareMPTID)) + return std::nullopt; // LCOV_EXCL_LINE + + Number assetTotal = vault->at(sfAssetsTotal); + assetTotal -= vault->at(sfLossUnrealized); + STAmount assets{vault->at(sfAsset)}; + if (assetTotal == 0) + return assets; + Number const shareTotal = issuance->at(sfOutstandingAmount); + assets = (assetTotal * shares) / shareTotal; + return assets; +} + +} // namespace xrpl diff --git a/src/libxrpl/net/HTTPClient.cpp b/src/libxrpl/net/HTTPClient.cpp index 8ddae12a7e..65205be39c 100644 --- a/src/libxrpl/net/HTTPClient.cpp +++ b/src/libxrpl/net/HTTPClient.cpp @@ -59,6 +59,7 @@ public: //-------------------------------------------------------------------------- void + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) makeGet(std::string const& strPath, boost::asio::streambuf& sb, std::string const& strHost) { std::ostream osRequest(&sb); diff --git a/src/libxrpl/nodestore/ManagerImp.cpp b/src/libxrpl/nodestore/ManagerImp.cpp index b749a329ff..da9534f68b 100644 --- a/src/libxrpl/nodestore/ManagerImp.cpp +++ b/src/libxrpl/nodestore/ManagerImp.cpp @@ -55,7 +55,7 @@ ManagerImp::make_Backend( missing_backend(); auto factory{find(type)}; - if (!factory) + if (factory == nullptr) { missing_backend(); } diff --git a/src/libxrpl/nodestore/backend/RocksDBFactory.cpp b/src/libxrpl/nodestore/backend/RocksDBFactory.cpp index 67c329bb4a..ac040f178b 100644 --- a/src/libxrpl/nodestore/backend/RocksDBFactory.cpp +++ b/src/libxrpl/nodestore/backend/RocksDBFactory.cpp @@ -213,7 +213,7 @@ public: rocksdb::DB* db = nullptr; m_options.create_if_missing = createIfMissing; rocksdb::Status status = rocksdb::DB::Open(m_options, m_name, &db); - if (!status.ok() || !db) + if (!status.ok() || (db == nullptr)) { Throw( std::string("Unable to open/create RocksDB: ") + status.ToString()); diff --git a/src/libxrpl/protocol/BuildInfo.cpp b/src/libxrpl/protocol/BuildInfo.cpp index 7d9a2047a9..0fddb9ff19 100644 --- a/src/libxrpl/protocol/BuildInfo.cpp +++ b/src/libxrpl/protocol/BuildInfo.cpp @@ -113,7 +113,7 @@ encodeSoftwareVersion(std::string_view versionStr) { std::uint8_t x = 0; - for (auto id : v.preReleaseIdentifiers) + for (auto const& id : v.preReleaseIdentifiers) { auto parsePreRelease = [](std::string_view identifier, std::string_view prefix, @@ -140,7 +140,7 @@ encodeSoftwareVersion(std::string_view versionStr) if (x == 0) x = parsePreRelease(id, "b", 0x40, 0, 63); - if (x & 0xC0) + if ((x & 0xC0) != 0) { c |= static_cast(x) << 16; break; diff --git a/src/libxrpl/protocol/ErrorCodes.cpp b/src/libxrpl/protocol/ErrorCodes.cpp index 33ec869db6..407e1ab3f3 100644 --- a/src/libxrpl/protocol/ErrorCodes.cpp +++ b/src/libxrpl/protocol/ErrorCodes.cpp @@ -205,9 +205,7 @@ make_error(error_code_i code, std::string const& message) bool contains_error(Json::Value const& json) { - if (json.isObject() && json.isMember(jss::error)) - return true; - return false; + return json.isObject() && json.isMember(jss::error); } int diff --git a/src/libxrpl/protocol/Feature.cpp b/src/libxrpl/protocol/Feature.cpp index f91e164c92..1762d7d22d 100644 --- a/src/libxrpl/protocol/Feature.cpp +++ b/src/libxrpl/protocol/Feature.cpp @@ -209,7 +209,7 @@ FeatureCollections::getRegisteredFeature(std::string const& name) const XRPL_ASSERT( readOnly.load(), "xrpl::FeatureCollections::getRegisteredFeature : startup completed"); Feature const* feature = getByName(name); - if (feature) + if (feature != nullptr) return feature->feature; return std::nullopt; } @@ -229,7 +229,7 @@ FeatureCollections::registerFeature(std::string const& name, Supported support, support == Supported::yes || vote == VoteBehavior::DefaultNo, "Invalid feature parameters. Must be supported to be up-voted."); Feature const* i = getByName(name); - if (!i) + if (i == nullptr) { check(features.size() < detail::numFeatures, "More features defined than allocated."); @@ -283,7 +283,7 @@ FeatureCollections::featureToBitsetIndex(uint256 const& f) const readOnly.load(), "xrpl::FeatureCollections::featureToBitsetIndex : startup completed"); Feature const* feature = getByFeature(f); - if (!feature) + if (feature == nullptr) LogicError("Invalid Feature ID"); return getIndex(*feature); @@ -303,7 +303,7 @@ FeatureCollections::featureToName(uint256 const& f) const { XRPL_ASSERT(readOnly.load(), "xrpl::FeatureCollections::featureToName : startup completed"); Feature const* feature = getByFeature(f); - return feature ? feature->name : to_string(f); + return (feature != nullptr) ? feature->name : to_string(f); } FeatureCollections featureCollections; diff --git a/src/libxrpl/protocol/IOUAmount.cpp b/src/libxrpl/protocol/IOUAmount.cpp index eba78e6051..338f2c2760 100644 --- a/src/libxrpl/protocol/IOUAmount.cpp +++ b/src/libxrpl/protocol/IOUAmount.cpp @@ -186,7 +186,7 @@ mulRatio(IOUAmount const& amt, std::uint32_t num, std::uint32_t den, bool roundU { using namespace boost::multiprecision; - if (!den) + if (den == 0u) Throw("division by zero"); // A vector with the value 10^index for indexes from 0 to 29 diff --git a/src/libxrpl/protocol/InnerObjectFormats.cpp b/src/libxrpl/protocol/InnerObjectFormats.cpp index 8139ef0f55..bccfe210d1 100644 --- a/src/libxrpl/protocol/InnerObjectFormats.cpp +++ b/src/libxrpl/protocol/InnerObjectFormats.cpp @@ -172,7 +172,7 @@ SOTemplate const* InnerObjectFormats::findSOTemplateBySField(SField const& sField) const { auto itemPtr = findByType(sField.getCode()); - if (itemPtr) + if (itemPtr != nullptr) return &(itemPtr->getSOTemplate()); return nullptr; 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/protocol/NFTokenOfferID.cpp b/src/libxrpl/protocol/NFTokenOfferID.cpp index e7ebbcf84b..4af589a4e9 100644 --- a/src/libxrpl/protocol/NFTokenOfferID.cpp +++ b/src/libxrpl/protocol/NFTokenOfferID.cpp @@ -24,7 +24,7 @@ canHaveNFTokenOfferID( return false; TxType const tt = serializedTx->getTxnType(); - if (!(tt == ttNFTOKEN_MINT && serializedTx->isFieldPresent(sfAmount)) && + if ((tt != ttNFTOKEN_MINT || !serializedTx->isFieldPresent(sfAmount)) && tt != ttNFTOKEN_CREATE_OFFER) return false; diff --git a/src/libxrpl/protocol/Permissions.cpp b/src/libxrpl/protocol/Permissions.cpp index 4137c73624..47fc0d28b6 100644 --- a/src/libxrpl/protocol/Permissions.cpp +++ b/src/libxrpl/protocol/Permissions.cpp @@ -176,13 +176,13 @@ Permission::isDelegable(std::uint32_t const& permissionValue, Rules const& rules } uint32_t -Permission::txToPermissionType(TxType const& type) const +Permission::txToPermissionType(TxType const& type) { return static_cast(type) + 1; } TxType -Permission::permissionToTxType(uint32_t const& value) const +Permission::permissionToTxType(uint32_t const& value) { return static_cast(value - 1); } diff --git a/src/libxrpl/protocol/PublicKey.cpp b/src/libxrpl/protocol/PublicKey.cpp index 2c63ddac64..2e08c49a4e 100644 --- a/src/libxrpl/protocol/PublicKey.cpp +++ b/src/libxrpl/protocol/PublicKey.cpp @@ -75,7 +75,7 @@ static std::string sliceToHex(Slice const& slice) { std::string s; - if (slice[0] & 0x80) + if ((slice[0] & 0x80) != 0) { s.reserve(2 * (slice.size() + 2)); s = "0x00"; diff --git a/src/libxrpl/protocol/STAccount.cpp b/src/libxrpl/protocol/STAccount.cpp index ffd0b5d3c8..2dc83cb591 100644 --- a/src/libxrpl/protocol/STAccount.cpp +++ b/src/libxrpl/protocol/STAccount.cpp @@ -84,7 +84,7 @@ bool STAccount::isEquivalent(STBase const& t) const { auto const* const tPtr = dynamic_cast(&t); - return tPtr && (default_ == tPtr->default_) && (value_ == tPtr->value_); + return (tPtr != nullptr) && (default_ == tPtr->default_) && (value_ == tPtr->value_); } bool diff --git a/src/libxrpl/protocol/STAmount.cpp b/src/libxrpl/protocol/STAmount.cpp index 92ce129825..8c0068a275 100644 --- a/src/libxrpl/protocol/STAmount.cpp +++ b/src/libxrpl/protocol/STAmount.cpp @@ -152,7 +152,7 @@ STAmount::STAmount(SerialIter& sit, SField const& name) : STBase(name) value &= ~(1023ull << (64 - 10)); - if (value) + if (value != 0u) { bool isNegative = (offset & 256) == 0; offset = (offset & 255) - 97; // center the range @@ -505,14 +505,11 @@ canAdd(STAmount const& a, STAmount const& b) XRPAmount A = a.xrp(); XRPAmount B = b.xrp(); - if ((B > XRPAmount{0} && + return !( + (B > XRPAmount{0} && A > XRPAmount{std::numeric_limits::max()} - B) || (B < XRPAmount{0} && - A < XRPAmount{std::numeric_limits::min()} - B)) - { - return false; - } - return true; + A < XRPAmount{std::numeric_limits::min()} - B)); } // IOU case (precision check) @@ -530,15 +527,11 @@ canAdd(STAmount const& a, STAmount const& b) { MPTAmount A = a.mpt(); MPTAmount B = b.mpt(); - if ((B > MPTAmount{0} && + return !( + (B > MPTAmount{0} && A > MPTAmount{std::numeric_limits::max()} - B) || (B < MPTAmount{0} && - A < MPTAmount{std::numeric_limits::min()} - B)) - { - return false; - } - - return true; + A < MPTAmount{std::numeric_limits::min()} - B)); } // LCOV_EXCL_START UNREACHABLE("STAmount::canAdd : unexpected STAmount type"); @@ -803,7 +796,7 @@ bool STAmount::isEquivalent(STBase const& t) const { STAmount const* v = dynamic_cast(&t); - return v && (*v == *this); + return (v != nullptr) && (*v == *this); } bool diff --git a/src/libxrpl/protocol/STBlob.cpp b/src/libxrpl/protocol/STBlob.cpp index 1a9dae7771..e7d45a698d 100644 --- a/src/libxrpl/protocol/STBlob.cpp +++ b/src/libxrpl/protocol/STBlob.cpp @@ -53,7 +53,7 @@ bool STBlob::isEquivalent(STBase const& t) const { STBlob const* v = dynamic_cast(&t); - return v && (value_ == v->value_); + return (v != nullptr) && (value_ == v->value_); } bool diff --git a/src/libxrpl/protocol/STCurrency.cpp b/src/libxrpl/protocol/STCurrency.cpp index 1616de59b9..3ca7b60d6b 100644 --- a/src/libxrpl/protocol/STCurrency.cpp +++ b/src/libxrpl/protocol/STCurrency.cpp @@ -56,7 +56,7 @@ bool STCurrency::isEquivalent(STBase const& t) const { STCurrency const* v = dynamic_cast(&t); - return v && (*v == *this); + return (v != nullptr) && (*v == *this); } bool diff --git a/src/libxrpl/protocol/STIssue.cpp b/src/libxrpl/protocol/STIssue.cpp index 1d37554251..bc39ea1b55 100644 --- a/src/libxrpl/protocol/STIssue.cpp +++ b/src/libxrpl/protocol/STIssue.cpp @@ -110,7 +110,7 @@ bool STIssue::isEquivalent(STBase const& t) const { STIssue const* v = dynamic_cast(&t); - return v && (*v == *this); + return (v != nullptr) && (*v == *this); } bool diff --git a/src/libxrpl/protocol/STLedgerEntry.cpp b/src/libxrpl/protocol/STLedgerEntry.cpp index aa97b6b3a2..02e5ddb451 100644 --- a/src/libxrpl/protocol/STLedgerEntry.cpp +++ b/src/libxrpl/protocol/STLedgerEntry.cpp @@ -136,7 +136,7 @@ STLedgerEntry::isThreadedType(Rules const& rules) const // Exclude PrevTxnID/PrevTxnLgrSeq if the fixPreviousTxnID amendment is not // enabled and the ledger object type is in the above set bool const excludePrevTxnID = !rules.enabled(fixPreviousTxnID) && - std::count(newPreviousTxnIDTypes.cbegin(), newPreviousTxnIDTypes.cend(), type_); + (std::count(newPreviousTxnIDTypes.cbegin(), newPreviousTxnIDTypes.cend(), type_) != 0); return !excludePrevTxnID && getFieldIndex(sfPreviousTxnID) != -1; } diff --git a/src/libxrpl/protocol/STObject.cpp b/src/libxrpl/protocol/STObject.cpp index fe9e95cc82..182653d11d 100644 --- a/src/libxrpl/protocol/STObject.cpp +++ b/src/libxrpl/protocol/STObject.cpp @@ -204,7 +204,7 @@ void STObject::applyTemplateFromSField(SField const& sField) { SOTemplate const* elements = InnerObjectFormats::getInstance().findSOTemplateBySField(sField); - if (elements) + if (elements != nullptr) applyTemplate(*elements); // May throw } @@ -276,7 +276,7 @@ STObject::hasMatchingEntry(STBase const& t) const { STBase const* o = peekAtPField(t.getFName()); - if (!o) + if (o == nullptr) return false; return t == *o; @@ -343,7 +343,7 @@ STObject::isEquivalent(STBase const& t) const { STObject const* v = dynamic_cast(&t); - if (!v) + if (v == nullptr) return false; if (mType != nullptr && v->mType == mType) @@ -480,7 +480,7 @@ STObject::setFlag(std::uint32_t f) { STUInt32* t = dynamic_cast(getPField(sfFlags, true)); - if (!t) + if (t == nullptr) return false; t->setValue(t->value() | f); @@ -492,7 +492,7 @@ STObject::clearFlag(std::uint32_t f) { STUInt32* t = dynamic_cast(getPField(sfFlags)); - if (!t) + if (t == nullptr) return false; t->setValue(t->value() & ~f); @@ -510,7 +510,7 @@ STObject::getFlags(void) const { STUInt32 const* t = dynamic_cast(peekAtPField(sfFlags)); - if (!t) + if (t == nullptr) return 0; return t->value(); @@ -574,7 +574,7 @@ STObject::delField(int index) SOEStyle STObject::getStyle(SField const& field) const { - return mType ? mType->style(field) : soeINVALID; + return (mType != nullptr) ? mType->style(field) : soeINVALID; } unsigned char @@ -877,10 +877,7 @@ STObject::operator==(STObject const& obj) const ++fields; } - if (fields != matches) - return false; - - return true; + return fields == matches; } void @@ -917,7 +914,8 @@ STObject::getSortedFields(STObject const& objToSort, WhichFields whichFields) for (detail::STVar const& elem : objToSort.v_) { STBase const& base = elem.get(); - if ((base.getSType() != STI_NOTPRESENT) && base.getFName().shouldInclude(whichFields)) + if ((base.getSType() != STI_NOTPRESENT) && + base.getFName().shouldInclude(static_cast(whichFields))) { sf.push_back(&base); } diff --git a/src/libxrpl/protocol/STParsedJSON.cpp b/src/libxrpl/protocol/STParsedJSON.cpp index 0bf0c827af..702ad28414 100644 --- a/src/libxrpl/protocol/STParsedJSON.cpp +++ b/src/libxrpl/protocol/STParsedJSON.cpp @@ -1075,20 +1075,20 @@ parseArray( // TODO: There doesn't seem to be a nice way to get just the // first/only key in an object without copying all keys into // a vector - std::string const objectName(json[i].getMemberNames()[0]); + std::string const memberName(json[i].getMemberNames()[0]); ; - auto const& nameField(SField::getField(objectName)); + auto const& nameField(SField::getField(memberName)); if (nameField == sfInvalid) { - error = unknown_field(json_name, objectName); + error = unknown_field(json_name, memberName); return std::nullopt; } - Json::Value const objectFields(json[i][objectName]); + Json::Value const objectFields(json[i][memberName]); std::stringstream ss; - ss << json_name << "." << "[" << i << "]." << objectName; + ss << json_name << "." << "[" << i << "]." << memberName; auto ret = parseObject(ss.str(), objectFields, nameField, depth + 1, error); if (!ret) diff --git a/src/libxrpl/protocol/STPathSet.cpp b/src/libxrpl/protocol/STPathSet.cpp index 060f5c4d7c..fde33fb58e 100644 --- a/src/libxrpl/protocol/STPathSet.cpp +++ b/src/libxrpl/protocol/STPathSet.cpp @@ -61,7 +61,7 @@ STPathSet::STPathSet(SerialIter& sit, SField const& name) : STBase(name) if (iType == STPathElement::typeNone) return; } - else if (iType & ~STPathElement::typeAll) + else if ((iType & ~STPathElement::typeAll) != 0) { JLOG(debugLog().error()) << "Bad path element " << iType << " in pathset"; Throw("bad path element"); @@ -76,13 +76,13 @@ STPathSet::STPathSet(SerialIter& sit, SField const& name) : STBase(name) Currency currency; AccountID issuer; - if (hasAccount) + if (hasAccount != 0) account = sit.get160(); - if (hasCurrency) + if (hasCurrency != 0) currency = sit.get160(); - if (hasIssuer) + if (hasIssuer != 0) issuer = sit.get160(); path.emplace_back(account, currency, issuer, hasCurrency); @@ -127,7 +127,7 @@ bool STPathSet::isEquivalent(STBase const& t) const { STPathSet const* v = dynamic_cast(&t); - return v && (value == v->value); + return (v != nullptr) && (value == v->value); } bool @@ -153,20 +153,20 @@ STPath::getJson(JsonOptions) const { Json::Value ret(Json::arrayValue); - for (auto it : mPath) + for (auto const& it : mPath) { Json::Value elem(Json::objectValue); auto const iType = it.getNodeType(); elem[jss::type] = iType; - if (iType & STPathElement::typeAccount) + if ((iType & STPathElement::typeAccount) != 0u) elem[jss::account] = to_string(it.getAccountID()); - if (iType & STPathElement::typeCurrency) + if ((iType & STPathElement::typeCurrency) != 0u) elem[jss::currency] = to_string(it.getCurrency()); - if (iType & STPathElement::typeIssuer) + if ((iType & STPathElement::typeIssuer) != 0u) elem[jss::issuer] = to_string(it.getIssuerID()); ret.append(elem); @@ -179,7 +179,7 @@ Json::Value STPathSet::getJson(JsonOptions options) const { Json::Value ret(Json::arrayValue); - for (auto it : value) + for (auto const& it : value) ret.append(it.getJson(options)); return ret; @@ -209,13 +209,13 @@ STPathSet::add(Serializer& s) const s.add8(iType); - if (iType & STPathElement::typeAccount) + if ((iType & STPathElement::typeAccount) != 0) s.addBitString(speElement.getAccountID()); - if (iType & STPathElement::typeCurrency) + if ((iType & STPathElement::typeCurrency) != 0) s.addBitString(speElement.getCurrency()); - if (iType & STPathElement::typeIssuer) + if ((iType & STPathElement::typeIssuer) != 0) s.addBitString(speElement.getIssuerID()); } diff --git a/src/libxrpl/protocol/STTx.cpp b/src/libxrpl/protocol/STTx.cpp index 00a2acd788..7da1919f35 100644 --- a/src/libxrpl/protocol/STTx.cpp +++ b/src/libxrpl/protocol/STTx.cpp @@ -574,7 +574,7 @@ STTx::getBatchTransactionIDs() const { XRPL_ASSERT(getTxnType() == ttBATCH, "STTx::getBatchTransactionIDs : not a batch transaction"); XRPL_ASSERT( - getFieldArray(sfRawTransactions).size() != 0, + !getFieldArray(sfRawTransactions).empty(), "STTx::getBatchTransactionIDs : empty raw transactions"); // The list of inner ids is built once, then reused on subsequent calls. @@ -618,7 +618,7 @@ isMemoOkay(STObject const& st, std::string& reason) { auto memoObj = dynamic_cast(&memo); - if (!memoObj || (memoObj->getFName() != sfMemo)) + if ((memoObj == nullptr) || (memoObj->getFName() != sfMemo)) { reason = "A memo array may contain only Memo objects."; return false; @@ -669,7 +669,7 @@ isMemoOkay(STObject const& st, std::string& reason) for (unsigned char c : *optData) { - if (!allowedSymbols[c]) + if (allowedSymbols[c] == 0) { reason = "The MemoType and MemoFormat fields may only " @@ -691,7 +691,7 @@ isAccountFieldOkay(STObject const& st) for (int i = 0; i < st.getCount(); ++i) { auto t = dynamic_cast(st.peekAtPIndex(i)); - if (t && t->isDefault()) + if ((t != nullptr) && t->isDefault()) return false; } diff --git a/src/libxrpl/protocol/STValidation.cpp b/src/libxrpl/protocol/STValidation.cpp index f6f89d43e9..ba6e679081 100644 --- a/src/libxrpl/protocol/STValidation.cpp +++ b/src/libxrpl/protocol/STValidation.cpp @@ -107,7 +107,7 @@ STValidation::isValid() const noexcept getSignerPublic(), getSigningHash(), makeSlice(getFieldVL(sfSignature)), - getFlags() & vfFullyCanonicalSig); + (getFlags() & vfFullyCanonicalSig) != 0u); } return valid_.value(); diff --git a/src/libxrpl/protocol/STVar.cpp b/src/libxrpl/protocol/STVar.cpp index 255514d70c..8b76d8a322 100644 --- a/src/libxrpl/protocol/STVar.cpp +++ b/src/libxrpl/protocol/STVar.cpp @@ -60,7 +60,7 @@ STVar::operator=(STVar const& rhs) if (&rhs != this) { destroy(); - if (rhs.p_) + if (rhs.p_ != nullptr) { p_ = rhs.p_->copy(max_size, &d_); } diff --git a/src/libxrpl/protocol/STVector256.cpp b/src/libxrpl/protocol/STVector256.cpp index 6357e2f2cb..2a70dd1e05 100644 --- a/src/libxrpl/protocol/STVector256.cpp +++ b/src/libxrpl/protocol/STVector256.cpp @@ -68,7 +68,7 @@ bool STVector256::isEquivalent(STBase const& t) const { STVector256 const* v = dynamic_cast(&t); - return v && (mValue == v->mValue); + return (v != nullptr) && (mValue == v->mValue); } Json::Value diff --git a/src/libxrpl/protocol/STXChainBridge.cpp b/src/libxrpl/protocol/STXChainBridge.cpp index 85d36f9b46..428e4655ff 100644 --- a/src/libxrpl/protocol/STXChainBridge.cpp +++ b/src/libxrpl/protocol/STXChainBridge.cpp @@ -167,7 +167,7 @@ bool STXChainBridge::isEquivalent(STBase const& t) const { STXChainBridge const* v = dynamic_cast(&t); - return v && (*v == *this); + return (v != nullptr) && (*v == *this); } bool diff --git a/src/libxrpl/protocol/Serializer.cpp b/src/libxrpl/protocol/Serializer.cpp index 08d221f75b..0e8beae0d9 100644 --- a/src/libxrpl/protocol/Serializer.cpp +++ b/src/libxrpl/protocol/Serializer.cpp @@ -199,7 +199,7 @@ Serializer::addVL(void const* ptr, int len) { int ret = addEncoded(len); - if (len) + if (len != 0) addRaw(ptr, len); return ret; @@ -298,7 +298,7 @@ Serializer::decodeVLLength(int b1, int b2) if (b1 > 240) Throw("b1>240"); - return 193 + (b1 - 193) * 256 + b2; + return 193 + ((b1 - 193) * 256) + b2; } int @@ -310,7 +310,7 @@ Serializer::decodeVLLength(int b1, int b2, int b3) if (b1 > 254) Throw("b1>254"); - return 12481 + (b1 - 241) * 65536 + b2 * 256 + b3; + return 12481 + ((b1 - 241) * 65536) + (b2 * 256) + b3; } //------------------------------------------------------------------------------ diff --git a/src/libxrpl/protocol/TxMeta.cpp b/src/libxrpl/protocol/TxMeta.cpp index f4932b2af4..19a2755a29 100644 --- a/src/libxrpl/protocol/TxMeta.cpp +++ b/src/libxrpl/protocol/TxMeta.cpp @@ -28,7 +28,7 @@ TxMeta::TxMeta(uint256 const& txid, std::uint32_t ledger, STObject const& obj) auto affectedNodes = dynamic_cast(obj.peekAtPField(sfAffectedNodes)); XRPL_ASSERT(affectedNodes, "xrpl::TxMeta::TxMeta(STObject) : type cast succeeded"); - if (affectedNodes) + if (affectedNodes != nullptr) nodes_ = *affectedNodes; setAdditionalFields(obj); @@ -96,7 +96,7 @@ TxMeta::getAffectedAccounts() const { auto const* inner = dynamic_cast(&node.peekAtIndex(index)); XRPL_ASSERT(inner, "xrpl::getAffectedAccounts : STObject type cast succeeded"); - if (inner) + if (inner != nullptr) { for (auto const& field : *inner) { diff --git a/src/libxrpl/protocol/UintTypes.cpp b/src/libxrpl/protocol/UintTypes.cpp index df9eadb511..5ace6c29d6 100644 --- a/src/libxrpl/protocol/UintTypes.cpp +++ b/src/libxrpl/protocol/UintTypes.cpp @@ -63,7 +63,7 @@ to_string(Currency const& currency) bool to_currency(Currency& currency, std::string const& code) { - if (code.empty() || !code.compare(systemCurrencyCode())) + if (code.empty() || (code.compare(systemCurrencyCode()) == 0)) { currency = beast::zero; return true; diff --git a/src/libxrpl/protocol/tokens.cpp b/src/libxrpl/protocol/tokens.cpp index b46591725f..bca8919c4e 100644 --- a/src/libxrpl/protocol/tokens.cpp +++ b/src/libxrpl/protocol/tokens.cpp @@ -263,7 +263,7 @@ decodeBase58(std::string const& s) // Allocate enough space in big-endian base256 representation. // log(58) / log(256), rounded up. - std::vector b256(remain * 733 / 1000 + 1); + std::vector b256((remain * 733 / 1000) + 1); while (remain > 0) { auto carry = alphabetReverse[*psz]; @@ -308,7 +308,7 @@ encodeBase58Token(TokenType type, void const* token, std::size_t size) // Lay the data out as // buf[0] = safe_cast>(type); - if (size) + if (size != 0u) std::memcpy(buf.data() + 1, token, size); checksum(buf.data() + 1 + size, buf.data(), 1 + size); @@ -383,7 +383,7 @@ b256_to_b58_be(std::span input, std::span out) { break; } - auto const src_i_end = input.size() - i * 8; + auto const src_i_end = input.size() - (i * 8); if (src_i_end >= 8) { std::memcpy(&base_2_64_coeff_buf[num_coeff], &input[src_i_end - 8], 8); @@ -450,7 +450,7 @@ b256_to_b58_be(std::span input, std::span out) { to_skip = count_leading_zeros(b58_be_s); skip_zeros = false; - if (out.size() < (i + 1) * 10 - to_skip) + if (out.size() < ((i + 1) * 10) - to_skip) { return Unexpected(TokenCodecErrc::outputTooSmall); } @@ -502,7 +502,7 @@ b58_to_b256_be(std::string_view input, std::span out) // log(2^(38*8),58^10)) ~= 5.18. So 6 coeff are enough std::array b_58_10_coeff{}; auto [num_full_coeffs, partial_coeff_len] = xrpl::b58_fast::detail::div_rem(input.size(), 10); - auto const num_partial_coeffs = partial_coeff_len ? 1 : 0; + auto const num_partial_coeffs = (partial_coeff_len != 0u) ? 1 : 0; auto const num_b_58_10_coeffs = num_full_coeffs + num_partial_coeffs; XRPL_ASSERT( num_b_58_10_coeffs <= b_58_10_coeff.size(), @@ -521,7 +521,7 @@ b58_to_b256_be(std::string_view input, std::span out) { for (int j = 0; j < num_full_coeffs; ++j) { - unsigned char c = input[partial_coeff_len + j * 10 + i]; + unsigned char c = input[partial_coeff_len + (j * 10) + i]; auto cur_val = ::xrpl::alphabetReverse[c]; if (cur_val < 0) { @@ -586,7 +586,7 @@ b58_to_b256_be(std::string_view input, std::span out) cur_out_i += 1; } } - if ((cur_out_i + 8 * (cur_result_size - 1)) > out.size()) + if ((cur_out_i + (8 * (cur_result_size - 1))) > out.size()) { return Unexpected(TokenCodecErrc::outputTooSmall); } diff --git a/src/libxrpl/rdb/DatabaseCon.cpp b/src/libxrpl/rdb/DatabaseCon.cpp index 344df85b4a..d064192a14 100644 --- a/src/libxrpl/rdb/DatabaseCon.cpp +++ b/src/libxrpl/rdb/DatabaseCon.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -29,7 +29,7 @@ public: auto it = checkpointers_.find(id); if (it != checkpointers_.end()) return it->second; - return {}; + return nullptr; } void @@ -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; } @@ -72,7 +75,7 @@ DatabaseCon::~DatabaseCon() // checkpoint is currently in progress. Wait for it to end, otherwise // creating a new DatabaseCon to the same database may fail due to the // database being locked by our (now old) Checkpointer. - while (wk.use_count()) + while (wk.use_count() != 0) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); } @@ -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) + 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 baadeef00a..ac96985407 100644 --- a/src/libxrpl/rdb/SociDB.cpp +++ b/src/libxrpl/rdb/SociDB.cpp @@ -98,7 +98,7 @@ getConnection(soci::session& s) if (auto b = dynamic_cast(be)) result = b->conn_; - if (!result) + if (result == nullptr) Throw("Didn't get a database connection."); return result; @@ -107,7 +107,7 @@ getConnection(soci::session& s) std::uint32_t getKBUsedAll(soci::session& s) { - if (!getConnection(s)) + if (getConnection(s) == nullptr) Throw("No connection found."); return static_cast(sqlite_api::sqlite3_memory_used() / kilobytes(1)); } @@ -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) { @@ -249,7 +252,7 @@ public: { auto [conn, keepAlive] = getConnection(); (void)keepAlive; - if (!conn) + if (conn == nullptr) return; int log = 0, ckpt = 0; @@ -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/libxrpl/resource/Consumer.cpp b/src/libxrpl/resource/Consumer.cpp index e9435bd340..c1cb9d4367 100644 --- a/src/libxrpl/resource/Consumer.cpp +++ b/src/libxrpl/resource/Consumer.cpp @@ -23,7 +23,7 @@ Consumer::Consumer() : m_logic(nullptr), m_entry(nullptr) Consumer::Consumer(Consumer const& other) : m_logic(other.m_logic), m_entry(nullptr) { - if (m_logic && other.m_entry) + if ((m_logic != nullptr) && (other.m_entry != nullptr)) { m_entry = other.m_entry; m_logic->acquire(*m_entry); @@ -32,7 +32,7 @@ Consumer::Consumer(Consumer const& other) : m_logic(other.m_logic), m_entry(null Consumer::~Consumer() { - if (m_logic && m_entry) + if ((m_logic != nullptr) && (m_entry != nullptr)) m_logic->release(*m_entry); } @@ -43,14 +43,14 @@ Consumer::operator=(Consumer const& other) return *this; // remove old ref - if (m_logic && m_entry) + if ((m_logic != nullptr) && (m_entry != nullptr)) m_logic->release(*m_entry); m_logic = other.m_logic; m_entry = other.m_entry; // add new ref - if (m_logic && m_entry) + if ((m_logic != nullptr) && (m_entry != nullptr)) m_logic->acquire(*m_entry); return *this; @@ -68,7 +68,7 @@ Consumer::to_string() const bool Consumer::isUnlimited() const { - if (m_entry) + if (m_entry != nullptr) return m_entry->isUnlimited(); return false; @@ -78,7 +78,7 @@ Disposition Consumer::disposition() const { Disposition d = ok; - if (m_logic && m_entry) + if ((m_logic != nullptr) && (m_entry != nullptr)) d = m_logic->charge(*m_entry, Charge(0)); return d; @@ -89,7 +89,7 @@ Consumer::charge(Charge const& what, std::string const& context) { Disposition d = ok; - if (m_logic && m_entry && !m_entry->isUnlimited()) + if ((m_logic != nullptr) && (m_entry != nullptr) && !m_entry->isUnlimited()) d = m_logic->charge(*m_entry, what, context); return d; 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/server/State.cpp b/src/libxrpl/server/State.cpp index 371f2b4d0a..a7c0c0fca2 100644 --- a/src/libxrpl/server/State.cpp +++ b/src/libxrpl/server/State.cpp @@ -31,7 +31,7 @@ initStateDB(soci::session& session, BasicConfig const& config, std::string const count = *countO; } - if (!count) + if (count == 0) { session << "INSERT INTO DbState VALUES (1, '', '', 0);"; } @@ -45,7 +45,7 @@ initStateDB(soci::session& session, BasicConfig const& config, std::string const count = *countO; } - if (!count) + if (count == 0) { session << "INSERT INTO CanDelete VALUES (1, 0);"; } diff --git a/src/libxrpl/shamap/SHAMap.cpp b/src/libxrpl/shamap/SHAMap.cpp index a6aacfabc9..8a853e4d1b 100644 --- a/src/libxrpl/shamap/SHAMap.cpp +++ b/src/libxrpl/shamap/SHAMap.cpp @@ -130,7 +130,7 @@ SHAMapLeafNode* SHAMap::findKey(uint256 const& id) const { SHAMapLeafNode* leaf = walkTowardsKey(id); - if (leaf && leaf->peekItem()->key() != id) + if ((leaf != nullptr) && leaf->peekItem()->key() != id) leaf = nullptr; return leaf; } @@ -221,7 +221,7 @@ SHAMap::fetchNodeNT(SHAMapHash const& hash, SHAMapSyncFilter* filter) const } } - if (filter) + if (filter != nullptr) node = checkFilter(hash, filter); return node; @@ -255,7 +255,7 @@ SHAMap::descendThrow(SHAMapInnerNode* parent, int branch) const { SHAMapTreeNode* ret = descend(parent, branch); - if (!ret && !parent->isEmptyBranch(branch)) + if ((ret == nullptr) && !parent->isEmptyBranch(branch)) Throw(type_, parent->getChildHash(branch)); return ret; @@ -276,7 +276,7 @@ SHAMapTreeNode* SHAMap::descend(SHAMapInnerNode* parent, int branch) const { SHAMapTreeNode* ret = parent->getChildPointer(branch); - if (ret || !backed_) + if ((ret != nullptr) || !backed_) return ret; intr_ptr::SharedPtr node = fetchNodeNT(parent->getChildHash(branch)); @@ -328,7 +328,7 @@ SHAMap::descend( SHAMapTreeNode* child = parent->getChildPointer(branch); - if (!child) + if (child == nullptr) { auto const& childHash = parent->getChildHash(branch); intr_ptr::SharedPtr childNode = fetchNodeNT(childHash, filter); @@ -354,7 +354,7 @@ SHAMap::descendAsync( pending = false; SHAMapTreeNode* ret = parent->getChildPointer(branch); - if (ret) + if (ret != nullptr) return ret; auto const& hash = parent->getChildHash(branch); @@ -362,7 +362,7 @@ SHAMap::descendAsync( auto ptr = cacheLookup(hash); if (!ptr) { - if (filter) + if (filter != nullptr) ptr = checkFilter(hash, filter); if (!ptr && backed_) @@ -483,14 +483,14 @@ SHAMap::onlyBelow(SHAMapTreeNode* node) const { if (!inner->isEmptyBranch(i)) { - if (nextNode) + if (nextNode != nullptr) return no_item; nextNode = descendThrow(inner, i); } } - if (!nextNode) + if (nextNode == nullptr) { // LCOV_EXCL_START UNREACHABLE("xrpl::SHAMap::onlyBelow : no next node"); @@ -514,7 +514,7 @@ SHAMap::peekFirstItem(SharedPtrNodeStack& stack) const { XRPL_ASSERT(stack.empty(), "xrpl::SHAMap::peekFirstItem : empty stack input"); SHAMapLeafNode* node = firstBelow(root_, stack); - if (!node) + if (node == nullptr) { while (!stack.empty()) stack.pop(); @@ -540,7 +540,7 @@ SHAMap::peekNextItem(uint256 const& id, SharedPtrNodeStack& stack) const { node = descendThrow(*inner, i); auto leaf = firstBelow(node, stack, i); - if (!leaf) + if (leaf == nullptr) Throw(type_, id); XRPL_ASSERT(leaf->isLeaf(), "xrpl::SHAMap::peekNextItem : leaf is valid"); return leaf; @@ -557,7 +557,7 @@ SHAMap::peekItem(uint256 const& id) const { SHAMapLeafNode* leaf = findKey(id); - if (!leaf) + if (leaf == nullptr) return no_item; return leaf->peekItem(); @@ -568,7 +568,7 @@ SHAMap::peekItem(uint256 const& id, SHAMapHash& hash) const { SHAMapLeafNode* leaf = findKey(id); - if (!leaf) + if (leaf == nullptr) return no_item; hash = leaf->getHash(); @@ -598,7 +598,7 @@ SHAMap::upper_bound(uint256 const& id) const { node = descendThrow(*inner, branch); auto leaf = firstBelow(node, stack, branch); - if (!leaf) + if (leaf == nullptr) Throw(type_, id); return const_iterator(this, leaf->peekItem().get(), std::move(stack)); } @@ -631,7 +631,7 @@ SHAMap::lower_bound(uint256 const& id) const { node = descendThrow(*inner, branch); auto leaf = lastBelow(node, stack, branch); - if (!leaf) + if (leaf == nullptr) Throw(type_, id); return const_iterator(this, leaf->peekItem().get(), std::move(stack)); } @@ -995,7 +995,7 @@ SHAMap::walkSubTree(bool doWrite, NodeObjectType t) int pos = 0; // We can't flush an inner node until we flush its children - while (1) + while (true) { while (pos < branchFactor) { @@ -1021,10 +1021,7 @@ SHAMap::walkSubTree(bool doWrite, NodeObjectType t) // save our place and work on this node stack.emplace(std::move(node), branch); - // The semantics of this changes when we move to c++-20 - // Right now no move will occur; With c++-20 child will - // be moved from. - node = intr_ptr::static_pointer_cast(std::move(child)); + node = intr_ptr::static_pointer_cast(child); pos = 0; } else @@ -1109,7 +1106,7 @@ SHAMap::dump(bool hash) const if (!inner->isEmptyBranch(i)) { auto child = inner->getChildPointer(i); - if (child) + if (child != nullptr) { XRPL_ASSERT( child->getHash() == inner->getChildHash(i), diff --git a/src/libxrpl/shamap/SHAMapDelta.cpp b/src/libxrpl/shamap/SHAMapDelta.cpp index 98a31fea55..0b5a09d4a7 100644 --- a/src/libxrpl/shamap/SHAMapDelta.cpp +++ b/src/libxrpl/shamap/SHAMapDelta.cpp @@ -136,7 +136,7 @@ SHAMap::compare(SHAMap const& otherMap, Delta& differences, int maxCount) const auto [ourNode, otherNode] = nodeStack.top(); nodeStack.pop(); - if (!ourNode || !otherNode) + if ((ourNode == nullptr) || (otherNode == nullptr)) { // LCOV_EXCL_START UNREACHABLE("xrpl::SHAMap::compare : missing a node"); diff --git a/src/libxrpl/shamap/SHAMapNodeID.cpp b/src/libxrpl/shamap/SHAMapNodeID.cpp index 6536e628ef..97a8b26a3b 100644 --- a/src/libxrpl/shamap/SHAMapNodeID.cpp +++ b/src/libxrpl/shamap/SHAMapNodeID.cpp @@ -76,7 +76,7 @@ SHAMapNodeID::getChildNodeID(unsigned int m) const Throw("Incorrect mask for " + to_string(*this)); SHAMapNodeID node{depth_ + 1, id_}; - node.id_.begin()[depth_ / 2] |= (depth_ & 1) ? m : (m << 4); + node.id_.begin()[depth_ / 2] |= ((depth_ & 1) != 0u) ? m : (m << 4); return node; } @@ -106,7 +106,7 @@ selectBranch(SHAMapNodeID const& id, uint256 const& hash) auto const depth = id.getDepth(); auto branch = static_cast(*(hash.begin() + (depth / 2))); - if (depth & 1) + if ((depth & 1) != 0u) { branch &= 0xf; } diff --git a/src/libxrpl/shamap/SHAMapSync.cpp b/src/libxrpl/shamap/SHAMapSync.cpp index c6e4c3dcb0..14ccdca2eb 100644 --- a/src/libxrpl/shamap/SHAMapSync.cpp +++ b/src/libxrpl/shamap/SHAMapSync.cpp @@ -93,13 +93,13 @@ SHAMap::visitDifferences( if (root_->getHash().isZero()) return; - if (have && (root_->getHash() == have->root_->getHash())) + if ((have != nullptr) && (root_->getHash() == have->root_->getHash())) return; if (root_->isLeaf()) { auto leaf = intr_ptr::static_pointer_cast(root_); - if (!have || !have->hasLeafNode(leaf->peekItem()->key(), leaf->getHash())) + if ((have == nullptr) || !have->hasLeafNode(leaf->peekItem()->key(), leaf->getHash())) function(*root_); return; } @@ -129,11 +129,11 @@ SHAMap::visitDifferences( if (next->isInner()) { - if (!have || !have->hasInnerNode(childID, childHash)) + if ((have == nullptr) || !have->hasInnerNode(childID, childHash)) stack.push({safe_downcast(next), childID}); } else if ( - !have || + (have == nullptr) || !have->hasLeafNode( safe_downcast(next)->peekItem()->key(), childHash)) { @@ -192,7 +192,7 @@ SHAMap::gmn_ProcessNodes(MissingNodes& mn, MissingNodes::StackEntry& se) fullBelow = false; ++mn.deferred_; } - else if (!d) + else if (d == nullptr) { // node is not in database @@ -347,7 +347,7 @@ SHAMap::getMissingNodes(int max, SHAMapSyncFilter* filter) // We have either emptied the stack or // posted as many deferred reads as we can - if (mn.deferred_) + if (mn.deferred_ != 0) gmn_ProcessDeferredReads(mn); if (mn.max_ <= 0) @@ -402,7 +402,7 @@ SHAMap::getNodeFat( auto node = root_.get(); SHAMapNodeID nodeID; - while (node && node->isInner() && (nodeID.getDepth() < wanted.getDepth())) + while ((node != nullptr) && node->isInner() && (nodeID.getDepth() < wanted.getDepth())) { int branch = selectBranch(nodeID, wanted.getNodeID()); auto inner = safe_downcast(node); @@ -509,7 +509,7 @@ SHAMap::addRootNode(SHAMapHash const& hash, Slice const& rootNode, SHAMapSyncFil if (root_->isLeaf()) clearSynching(); - if (filter) + if (filter != nullptr) { Serializer s; root_->serializeWithPrefix(s); @@ -615,7 +615,7 @@ SHAMap::addKnownNode(SHAMapNodeID const& node, Slice const& rawNode, SHAMapSyncF newNode = prevNode->canonicalizeChild(branch, std::move(newNode)); - if (filter) + if (filter != nullptr) { Serializer s; newNode->serializeWithPrefix(s); @@ -643,7 +643,7 @@ SHAMap::deepCompare(SHAMap& other) const auto const [node, otherNode] = stack.top(); stack.pop(); - if (!node || !otherNode) + if ((node == nullptr) || (otherNode == nullptr)) { JLOG(journal_.info()) << "unable to fetch node"; return false; @@ -685,7 +685,7 @@ SHAMap::deepCompare(SHAMap& other) const auto next = descend(node_inner, i); auto otherNext = other.descend(other_inner, i); - if (!next || !otherNext) + if ((next == nullptr) || (otherNext == nullptr)) { JLOG(journal_.warn()) << "unable to fetch inner node"; return false; diff --git a/src/libxrpl/tx/ApplyContext.cpp b/src/libxrpl/tx/ApplyContext.cpp index d4372a9ba1..a73b163ac5 100644 --- a/src/libxrpl/tx/ApplyContext.cpp +++ b/src/libxrpl/tx/ApplyContext.cpp @@ -40,7 +40,7 @@ ApplyContext::discard() std::optional ApplyContext::apply(TER ter) { - return view_->apply(base_, tx, ter, parentBatchId_, flags_ & tapDRY_RUN, journal); + return view_->apply(base_, tx, ter, parentBatchId_, (flags_ & tapDRY_RUN) != 0u, journal); } std::size_t 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 d98c43e639..e029c71f4f 100644 --- a/src/libxrpl/tx/Transactor.cpp +++ b/src/libxrpl/tx/Transactor.cpp @@ -1,9 +1,11 @@ -#include #include #include #include -#include #include +#include +#include +#include +#include #include #include #include @@ -32,7 +34,7 @@ preflight0(PreflightContext const& ctx, std::uint32_t flagMask) if (!isPseudoTx(ctx.tx) || ctx.tx.isFieldPresent(sfNetworkID)) { - uint32_t nodeNID = ctx.registry.getNetworkIDService().getNetworkID(); + uint32_t nodeNID = ctx.registry.get().getNetworkIDService().getNetworkID(); std::optional txNID = ctx.tx[~sfNetworkID]; if (nodeNID <= 1024) @@ -62,7 +64,7 @@ preflight0(PreflightContext const& ctx, std::uint32_t flagMask) return temINVALID; } - if (ctx.tx.getFlags() & flagMask) + if ((ctx.tx.getFlags() & flagMask) != 0u) { JLOG(ctx.j.debug()) << ctx.tx.peekAtField(sfTransactionType).getFullText() << ": invalid flags."; @@ -93,7 +95,7 @@ preflightCheckSigningKey(STObject const& sigObject, beast::Journal j) std::optional preflightCheckSimulateKeys(ApplyFlags flags, STObject const& sigObject, beast::Journal j) { - if (flags & tapDRY_RUN) // simulation + if ((flags & tapDRY_RUN) != 0u) // simulation { std::optional const signature = sigObject[~sfTxnSignature]; if (signature && !signature->empty()) @@ -209,7 +211,7 @@ Transactor::preflight2(PreflightContext const& ctx) // Do not add any checks after this point that are relevant for // batch inner transactions. They will be skipped. - auto const sigValid = checkValidity(ctx.registry.getHashRouter(), ctx.tx, ctx.rules); + auto const sigValid = checkValidity(ctx.registry.get().getHashRouter(), ctx.tx, ctx.rules); if (sigValid.first == Validity::SigBad) { // LCOV_EXCL_START JLOG(ctx.j.debug()) << "preflight2: bad signature. " << sigValid.second; @@ -299,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, @@ -315,7 +317,7 @@ Transactor::minimumFee( Fees const& fees, ApplyFlags flags) { - return scaleFeeLoad(baseFee, registry.getFeeTrack(), fees, flags & tapUNLIMITED); + return scaleFeeLoad(baseFee, registry.getFeeTrack(), fees, (flags & tapUNLIMITED) != 0u); } TER @@ -326,7 +328,7 @@ Transactor::checkFee(PreclaimContext const& ctx, XRPAmount baseFee) auto const feePaid = ctx.tx[sfFee].xrp(); - if (ctx.flags & tapBATCH) + if ((ctx.flags & tapBATCH) != 0u) { if (feePaid == beast::zero) return tesSUCCESS; @@ -650,7 +652,7 @@ Transactor::checkSign( return tesSUCCESS; } - if ((flags & tapDRY_RUN) && pkSigner.empty() && !sigObject.isFieldPresent(sfSigners)) + if (((flags & tapDRY_RUN) != 0u) && pkSigner.empty() && !sigObject.isFieldPresent(sfSigners)) { // simulate: skip signature validation when neither SigningPubKey nor // Signers are provided @@ -674,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; @@ -883,7 +884,7 @@ Transactor::checkMultiSign( // Master Key. Account may not have asfDisableMaster set. std::uint32_t const signerAccountFlags = sleTxSignerRoot->getFieldU32(sfFlags); - if (signerAccountFlags & lsfDisableMaster) + if ((signerAccountFlags & lsfDisableMaster) != 0u) { JLOG(j.trace()) << "applyTransaction: Signer:Account lsfDisableMaster."; return tefMASTER_DISABLED; @@ -1146,7 +1147,8 @@ Transactor::operator()() } #endif - if (auto const& trap = ctx_.registry.trapTxID(); trap && *trap == ctx_.tx.getTransactionID()) + if (auto const& trap = ctx_.registry.get().getTrapTxID(); + trap && *trap == ctx_.tx.getTransactionID()) { trapTransaction(*trap); } @@ -1168,7 +1170,7 @@ Transactor::operator()() if (ctx_.size() > oversizeMetaDataCap) result = tecOVERSIZE; - if (isTecClaim(result) && (view().flags() & tapFAIL_HARD)) + if (isTecClaim(result) && ((view().flags() & tapFAIL_HARD) != 0u)) { // If the tapFAIL_HARD flag is set, a tec result // must not do anything @@ -1248,16 +1250,27 @@ 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.get().getJournal("View")); + } if (result == tecEXPIRED) - removeExpiredNFTokenOffers(view(), expiredNFTokenOffers, ctx_.registry.journal("View")); + { + removeExpiredNFTokenOffers( + view(), expiredNFTokenOffers, ctx_.registry.get().getJournal("View")); + } if (result == tecINCOMPLETE) - removeDeletedTrustLines(view(), removedTrustLines, ctx_.registry.journal("View")); + { + removeDeletedTrustLines( + view(), removedTrustLines, ctx_.registry.get().getJournal("View")); + } if (result == tecEXPIRED) - removeExpiredCredentials(view(), expiredCredentials, ctx_.registry.journal("View")); + { + removeExpiredCredentials( + view(), expiredCredentials, ctx_.registry.get().getJournal("View")); + } applied = isTecClaim(result); } @@ -1313,7 +1326,7 @@ Transactor::operator()() metadata = ctx_.apply(result); } - if (ctx_.flags() & tapDRY_RUN) + if ((ctx_.flags() & tapDRY_RUN) != 0u) { applied = false; } diff --git a/src/libxrpl/tx/apply.cpp b/src/libxrpl/tx/apply.cpp index 8fd898366e..caf716eda6 100644 --- a/src/libxrpl/tx/apply.cpp +++ b/src/libxrpl/tx/apply.cpp @@ -149,7 +149,7 @@ applyBatchTransactions( beast::Journal j) { XRPL_ASSERT( - batchTxn.getTxnType() == ttBATCH && batchTxn.getFieldArray(sfRawTransactions).size() != 0, + batchTxn.getTxnType() == ttBATCH && !batchTxn.getFieldArray(sfRawTransactions).empty(), "Batch transaction missing sfRawTransactions"); auto const parentBatchId = batchTxn.getTransactionID(); @@ -188,13 +188,13 @@ applyBatchTransactions( if (!isTesSuccess(result.ter)) { - if (mode & tfAllOrNothing) + if ((mode & tfAllOrNothing) != 0u) return false; - if (mode & tfUntilFailure) + if ((mode & tfUntilFailure) != 0u) break; } - else if (mode & tfOnlyOne) + else if ((mode & tfOnlyOne) != 0u) { break; } diff --git a/src/libxrpl/tx/invariants/AMMInvariant.cpp b/src/libxrpl/tx/invariants/AMMInvariant.cpp index b64be6192b..96df97016f 100644 --- a/src/libxrpl/tx/invariants/AMMInvariant.cpp +++ b/src/libxrpl/tx/invariants/AMMInvariant.cpp @@ -28,7 +28,7 @@ ValidAMM::visitEntry( } // AMM pool changed else if ( - (type == ltRIPPLE_STATE && after->getFlags() & lsfAMMNode) || + (type == ltRIPPLE_STATE && ((after->getFlags() & lsfAMMNode) != 0u)) || (type == ltACCOUNT_ROOT && after->isFieldPresent(sfAMMID))) { ammPoolChanged_ = true; diff --git a/src/libxrpl/tx/invariants/FreezeInvariant.cpp b/src/libxrpl/tx/invariants/FreezeInvariant.cpp index f38d260782..c8723b9bbf 100644 --- a/src/libxrpl/tx/invariants/FreezeInvariant.cpp +++ b/src/libxrpl/tx/invariants/FreezeInvariant.cpp @@ -271,12 +271,7 @@ TransfersNotFrozen::validateFrozenState( "xrpl::TransfersNotFrozen::validateFrozenState : enforce " "invariant."); - if (enforce) - { - return false; - } - - return true; + return !enforce; } } // namespace xrpl diff --git a/src/libxrpl/tx/invariants/InvariantCheck.cpp b/src/libxrpl/tx/invariants/InvariantCheck.cpp index 00580b2548..bf0f65f000 100644 --- a/src/libxrpl/tx/invariants/InvariantCheck.cpp +++ b/src/libxrpl/tx/invariants/InvariantCheck.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #include #include @@ -629,11 +631,11 @@ NoDeepFreezeTrustLinesWithoutFreeze::visitEntry( if (after && after->getType() == ltRIPPLE_STATE) { std::uint32_t const uFlags = after->getFieldU32(sfFlags); - bool const lowFreeze = uFlags & lsfLowFreeze; - bool const lowDeepFreeze = uFlags & lsfLowDeepFreeze; + bool const lowFreeze = (uFlags & lsfLowFreeze) != 0u; + bool const lowDeepFreeze = (uFlags & lsfLowDeepFreeze) != 0u; - bool const highFreeze = uFlags & lsfHighFreeze; - bool const highDeepFreeze = uFlags & lsfHighDeepFreeze; + bool const highFreeze = (uFlags & lsfHighFreeze) != 0u; + bool const highDeepFreeze = (uFlags & lsfHighDeepFreeze) != 0u; deepFreezeWithoutFreeze_ = (lowDeepFreeze && !lowFreeze) || (highDeepFreeze && !highFreeze); } 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 01c4da46ac..6ce1261612 100644 --- a/src/libxrpl/tx/invariants/LoanInvariant.cpp +++ b/src/libxrpl/tx/invariants/LoanInvariant.cpp @@ -2,196 +2,11 @@ // #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) const -{ - auto const next = dir->at(~sfIndexNext); - auto const prev = dir->at(~sfIndexPrevious); - if ((prev && *prev) || (next && *next)) - { - 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, @@ -235,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/libxrpl/tx/invariants/PermissionedDomainInvariant.cpp b/src/libxrpl/tx/invariants/PermissionedDomainInvariant.cpp index d4cbe81f9b..7365fc7b1a 100644 --- a/src/libxrpl/tx/invariants/PermissionedDomainInvariant.cpp +++ b/src/libxrpl/tx/invariants/PermissionedDomainInvariant.cpp @@ -1,7 +1,7 @@ #include // #include -#include +#include #include #include #include @@ -38,7 +38,7 @@ ValidPermissionedDomain::visitEntry( break; } } - sleStatus.emplace_back(std::move(ss)); + sleStatus.emplace_back(ss); }; if (after) diff --git a/src/libxrpl/tx/invariants/VaultInvariant.cpp b/src/libxrpl/tx/invariants/VaultInvariant.cpp index e955e00b50..c6b3295569 100644 --- a/src/libxrpl/tx/invariants/VaultInvariant.cpp +++ b/src/libxrpl/tx/invariants/VaultInvariant.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -204,7 +205,7 @@ ValidVault::finalize( for (auto const& e : beforeMPTs_) { if (e.share.getMptID() == beforeVault.shareMPTID) - return std::move(e); + return e; } return std::nullopt; }(); @@ -373,7 +374,7 @@ ValidVault::finalize( for (auto const& e : beforeMPTs_) { if (e.share.getMptID() == beforeVault.shareMPTID) - return std::move(e); + return e; } return std::nullopt; }(); 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 98% rename from src/xrpld/app/paths/detail/BookStep.cpp rename to src/libxrpl/tx/paths/BookStep.cpp index ae0c371e3e..3e492d8a19 100644 --- a/src/xrpld/app/paths/detail/BookStep.cpp +++ b/src/libxrpl/tx/paths/BookStep.cpp @@ -1,15 +1,15 @@ -#include -#include - #include #include #include #include +#include #include #include #include #include #include +#include +#include #include #include #include @@ -451,7 +451,7 @@ public: std::uint32_t getOfrInRate(Step const* prevStep, AccountID const& owner, std::uint32_t trIn) const { - auto const srcAcct = prevStep ? prevStep->directStepSrcAcct() : std::nullopt; + auto const srcAcct = (prevStep != nullptr) ? prevStep->directStepSrcAcct() : std::nullopt; return owner == srcAcct // If offer crossing && prevStep is DirectI ? QUALITY_ONE // && src is offer owner @@ -466,9 +466,9 @@ public: AccountID const& strandDst, std::uint32_t trOut) const { - return // If offer crossing - prevStep && prevStep->bookStepBook() && // && prevStep is BookStep - owner == strandDst // && dest is offer owner + return // If offer crossing + (prevStep != nullptr) && prevStep->bookStepBook() && // && prevStep is BookStep + owner == strandDst // && dest is offer owner ? QUALITY_ONE : trOut; // then rate = QUALITY_ONE } @@ -1259,13 +1259,14 @@ BookStep::check(StrandContext const& ctx) const // Do not allow two books to output the same issue. This may cause offers on // one step to unfund offers in another step. - if (!ctx.seenBookOuts.insert(book_.out).second || ctx.seenDirectIssues[0].count(book_.out)) + if (!ctx.seenBookOuts.insert(book_.out).second || + (ctx.seenDirectIssues[0].count(book_.out) != 0u)) { JLOG(j_.debug()) << "BookStep: loop detected: " << *this; return temBAD_PATH_LOOP; } - if (ctx.seenDirectIssues[1].count(book_.out)) + if (ctx.seenDirectIssues[1].count(book_.out) != 0u) { JLOG(j_.debug()) << "BookStep: loop detected: " << *this; return temBAD_PATH_LOOP; @@ -1281,7 +1282,7 @@ BookStep::check(StrandContext const& ctx) const return tecNO_ISSUER; } - if (ctx.prevStep) + if (ctx.prevStep != nullptr) { if (auto const prev = ctx.prevStep->directStepSrcAcct()) { @@ -1291,7 +1292,7 @@ BookStep::check(StrandContext const& ctx) const auto sle = view.read(keylet::line(*prev, cur, book_.in.currency)); if (!sle) return terNO_LINE; - if ((*sle)[sfFlags] & ((cur > *prev) ? lsfHighNoRipple : lsfLowNoRipple)) + if (((*sle)[sfFlags] & ((cur > *prev) ? lsfHighNoRipple : lsfLowNoRipple)) != 0u) return terNO_RIPPLE; } } diff --git a/src/libxrpl/tx/paths/BookTip.cpp b/src/libxrpl/tx/paths/BookTip.cpp index f00da6d7c7..5611a081c3 100644 --- a/src/libxrpl/tx/paths/BookTip.cpp +++ b/src/libxrpl/tx/paths/BookTip.cpp @@ -1,3 +1,5 @@ +#include +#include #include namespace xrpl { diff --git a/src/xrpld/app/paths/detail/DirectStep.cpp b/src/libxrpl/tx/paths/DirectStep.cpp similarity index 96% rename from src/xrpld/app/paths/detail/DirectStep.cpp rename to src/libxrpl/tx/paths/DirectStep.cpp index a07e5824d6..9cae103d8f 100644 --- a/src/xrpld/app/paths/detail/DirectStep.cpp +++ b/src/libxrpl/tx/paths/DirectStep.cpp @@ -1,11 +1,11 @@ -#include - #include -#include #include +#include +#include #include #include #include +#include #include #include @@ -223,15 +223,15 @@ public: using DirectStepI::check; - bool - verifyPrevStepDebtDirection(DebtDirection) const + static bool + verifyPrevStepDebtDirection(DebtDirection) { // A payment doesn't care whether or not prevStepRedeems. return true; } - bool - verifyDstQualityIn(std::uint32_t dstQIn) const + static bool + verifyDstQualityIn(std::uint32_t dstQIn) { // Payments have no particular expectations for what dstQIn will be. return true; @@ -274,8 +274,8 @@ public: using DirectStepI::check; - bool - verifyPrevStepDebtDirection(DebtDirection prevStepDir) const + static bool + verifyPrevStepDebtDirection(DebtDirection prevStepDir) { // During offer crossing we rely on the fact that prevStepRedeems // will *always* issue. That's because: @@ -287,16 +287,16 @@ public: return issues(prevStepDir); } - bool - verifyDstQualityIn(std::uint32_t dstQIn) const + static bool + verifyDstQualityIn(std::uint32_t dstQIn) { // Due to a couple of factors dstQIn is always QUALITY_ONE for // offer crossing. If that changes we need to know. return dstQIn == QUALITY_ONE; } - std::uint32_t - quality(ReadView const& sb, QualityDirection qDir) const; + static std::uint32_t + quality(ReadView const& sb, QualityDirection qDir); // Compute the maximum value that can flow from src->dst at // the best available quality. @@ -307,8 +307,8 @@ public: // Verify the consistency of the step. These checks are specific to // offer crossing and assume that general checks were already performed. - TER - check(StrandContext const& ctx, std::shared_ptr const& sleSrc) const; + static TER + check(StrandContext const& ctx, std::shared_ptr const& sleSrc); std::string logString() const override @@ -355,13 +355,13 @@ DirectIPaymentStep::quality(ReadView const& sb, QualityDirection qDir) const return QUALITY_ONE; auto const q = (*sle)[field]; - if (!q) + if (q == 0u) return QUALITY_ONE; return q; } std::uint32_t -DirectIOfferCrossingStep::quality(ReadView const&, QualityDirection qDir) const +DirectIOfferCrossingStep::quality(ReadView const&, QualityDirection qDir) { // If offer crossing then ignore trust line Quality fields. This // preserves a long-standing tradition. @@ -410,21 +410,21 @@ DirectIPaymentStep::check(StrandContext const& ctx, std::shared_ptr c auto const authField = (src_ > dst_) ? lsfHighAuth : lsfLowAuth; - if (((*sleSrc)[sfFlags] & lsfRequireAuth) && !((*sleLine)[sfFlags] & authField) && - (*sleLine)[sfBalance] == beast::zero) + if ((((*sleSrc)[sfFlags] & lsfRequireAuth) != 0u) && + (((*sleLine)[sfFlags] & authField) == 0u) && (*sleLine)[sfBalance] == beast::zero) { JLOG(j_.debug()) << "DirectStepI: can't receive IOUs from issuer without auth." << " src: " << src_; return terNO_AUTH; } - if (ctx.prevStep) + if (ctx.prevStep != nullptr) { if (ctx.prevStep->bookStepBook()) { auto const noRippleSrcToDst = ((*sleLine)[sfFlags] & ((src_ > dst_) ? lsfHighNoRipple : lsfLowNoRipple)); - if (noRippleSrcToDst) + if (noRippleSrcToDst != 0u) return terNO_RIPPLE; } } @@ -446,7 +446,7 @@ DirectIPaymentStep::check(StrandContext const& ctx, std::shared_ptr c } TER -DirectIOfferCrossingStep::check(StrandContext const&, std::shared_ptr const&) const +DirectIOfferCrossingStep::check(StrandContext const&, std::shared_ptr const&) { // The standard checks are all we can do because any remaining checks // require the existence of a trust line. Offer crossing does not @@ -713,7 +713,7 @@ template std::pair DirectStepI::qualitiesSrcRedeems(ReadView const& sb) const { - if (!prevStep_) + if (prevStep_ == nullptr) return {QUALITY_ONE, QUALITY_ONE}; auto const prevStepQIn = prevStep_->lineQualityIn(sb); @@ -828,7 +828,7 @@ DirectStepI::check(StrandContext const& ctx) const // If previous step was a direct step then we need to check // no ripple flags. - if (ctx.prevStep) + if (ctx.prevStep != nullptr) { if (auto prevSrc = ctx.prevStep->directStepSrcAcct()) { @@ -841,9 +841,9 @@ DirectStepI::check(StrandContext const& ctx) const Issue const srcIssue{currency_, src_}; Issue const dstIssue{currency_, dst_}; - if (ctx.seenBookOuts.count(srcIssue)) + if (ctx.seenBookOuts.count(srcIssue) != 0u) { - if (!ctx.prevStep) + if (ctx.prevStep == nullptr) { // LCOV_EXCL_START UNREACHABLE( @@ -904,7 +904,7 @@ make_DirectStepI( { TER ter = tefINTERNAL; std::unique_ptr r; - if (ctx.offerCrossing) + if (ctx.offerCrossing != 0u) { auto offerCrossingStep = std::make_unique(ctx, src, dst, c); ter = offerCrossingStep->check(ctx); diff --git a/src/libxrpl/tx/paths/Flow.cpp b/src/libxrpl/tx/paths/Flow.cpp index fc33585179..5a706ea812 100644 --- a/src/libxrpl/tx/paths/Flow.cpp +++ b/src/libxrpl/tx/paths/Flow.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include diff --git a/src/libxrpl/tx/paths/OfferStream.cpp b/src/libxrpl/tx/paths/OfferStream.cpp index b406c27298..b7dc431b23 100644 --- a/src/libxrpl/tx/paths/OfferStream.cpp +++ b/src/libxrpl/tx/paths/OfferStream.cpp @@ -1,5 +1,7 @@ #include #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 95% rename from src/xrpld/app/paths/detail/PaySteps.cpp rename to src/libxrpl/tx/paths/PaySteps.cpp index 9087647aeb..33b63f7714 100644 --- a/src/xrpld/app/paths/detail/PaySteps.cpp +++ b/src/libxrpl/tx/paths/PaySteps.cpp @@ -55,8 +55,8 @@ toStep( { auto& j = ctx.j; - if (ctx.isFirst && e1->isAccount() && (e1->getNodeType() & STPathElement::typeCurrency) && - isXRP(e1->getCurrency())) + if (ctx.isFirst && e1->isAccount() && + ((e1->getNodeType() & STPathElement::typeCurrency) != 0u) && isXRP(e1->getCurrency())) { return make_XRPEndpointStep(ctx, e1->getAccountID()); } @@ -83,10 +83,12 @@ toStep( (e2->getNodeType() & STPathElement::typeCurrency) || (e2->getNodeType() & STPathElement::typeIssuer), "xrpl::toStep : currency or issuer"); - auto const outCurrency = - e2->getNodeType() & STPathElement::typeCurrency ? e2->getCurrency() : curIssue.currency; - auto const outIssuer = - e2->getNodeType() & STPathElement::typeIssuer ? e2->getIssuerID() : curIssue.account; + auto const outCurrency = ((e2->getNodeType() & STPathElement::typeCurrency) != 0u) + ? e2->getCurrency() + : curIssue.currency; + auto const outIssuer = ((e2->getNodeType() & STPathElement::typeIssuer) != 0u) + ? e2->getIssuerID() + : curIssue.account; if (isXRP(curIssue.currency) && isXRP(outCurrency)) { @@ -132,12 +134,12 @@ toStrand( { auto const t = pe.getNodeType(); - if ((t & ~STPathElement::typeAll) || !t) + if (((t & ~STPathElement::typeAll) != 0u) || (t == 0u)) return {temBAD_PATH, Strand{}}; - bool const hasAccount = t & STPathElement::typeAccount; - bool const hasIssuer = t & STPathElement::typeIssuer; - bool const hasCurrency = t & STPathElement::typeCurrency; + bool const hasAccount = (t & STPathElement::typeAccount) != 0u; + bool const hasIssuer = (t & STPathElement::typeIssuer) != 0u; + bool const hasCurrency = (t & STPathElement::typeCurrency) != 0u; if (hasAccount && (hasIssuer || hasCurrency)) return {temBAD_PATH, Strand{}}; @@ -192,7 +194,7 @@ toStrand( STPathElement const& lastCurrency = *std::find_if(normPath.rbegin(), normPath.rend(), hasCurrency); if ((lastCurrency.getCurrency() != deliver.currency) || - (offerCrossing && lastCurrency.getIssuerID() != deliver.account)) + ((offerCrossing != 0u) && lastCurrency.getIssuerID() != deliver.account)) { normPath.emplace_back(std::nullopt, deliver.currency, deliver.account); } diff --git a/src/libxrpl/tx/paths/RippleCalc.cpp b/src/libxrpl/tx/paths/RippleCalc.cpp index e87ecab90f..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,17 +34,17 @@ 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 ? true : pInputs->defaultPathsAllowed; + bool const defaultPaths = (pInputs == nullptr) ? true : pInputs->defaultPathsAllowed; - bool const partialPayment = !pInputs ? false : pInputs->partialPaymentAllowed; + bool const partialPayment = (pInputs == nullptr) ? false : pInputs->partialPaymentAllowed; auto const limitQuality = [&]() -> std::optional { if (pInputs && pInputs->limitQuality && saMaxAmountReq > beast::zero) diff --git a/src/xrpld/app/paths/detail/XRPEndpointStep.cpp b/src/libxrpl/tx/paths/XRPEndpointStep.cpp similarity index 98% rename from src/xrpld/app/paths/detail/XRPEndpointStep.cpp rename to src/libxrpl/tx/paths/XRPEndpointStep.cpp index 6eaa0d04c4..7452f57ecd 100644 --- a/src/xrpld/app/paths/detail/XRPEndpointStep.cpp +++ b/src/libxrpl/tx/paths/XRPEndpointStep.cpp @@ -1,13 +1,13 @@ -#include - #include -#include #include +#include +#include #include #include #include #include #include +#include #include #include @@ -368,7 +368,7 @@ make_XRPEndpointStep(StrandContext const& ctx, AccountID const& acc) { TER ter = tefINTERNAL; std::unique_ptr r; - if (ctx.offerCrossing) + if (ctx.offerCrossing != 0u) { auto offerCrossingStep = std::make_unique(ctx, acc); ter = offerCrossingStep->check(ctx); diff --git a/src/libxrpl/tx/transactors/account/AccountDelete.cpp b/src/libxrpl/tx/transactors/account/AccountDelete.cpp index 95e75a31c3..8f74a204ad 100644 --- a/src/libxrpl/tx/transactors/account/AccountDelete.cpp +++ b/src/libxrpl/tx/transactors/account/AccountDelete.cpp @@ -1,7 +1,9 @@ #include #include -#include #include +#include +#include +#include #include #include #include @@ -20,10 +22,7 @@ namespace xrpl { bool AccountDelete::checkExtraFeatures(PreflightContext const& ctx) { - if (ctx.tx.isFieldPresent(sfCredentialIDs) && !ctx.rules.enabled(featureCredentials)) - return false; - - return true; + return !ctx.tx.isFieldPresent(sfCredentialIDs) || ctx.rules.enabled(featureCredentials); } NotTEC @@ -214,7 +213,7 @@ AccountDelete::preclaim(PreclaimContext const& ctx) if (!sleDst) return tecNO_DST; - if ((*sleDst)[sfFlags] & lsfRequireDestTag && !ctx.tx[~sfDestinationTag]) + if ((((*sleDst)[sfFlags] & lsfRequireDestTag) != 0u) && !ctx.tx[~sfDestinationTag]) return tecDST_TAG_NEEDED; // If credentials are provided - check them anyway @@ -226,7 +225,7 @@ AccountDelete::preclaim(PreclaimContext const& ctx) if (!ctx.tx.isFieldPresent(sfCredentialIDs)) { // Check whether the destination account requires deposit authorization. - if (sleDst->getFlags() & lsfDepositAuth) + if ((sleDst->getFlags() & lsfDepositAuth) != 0u) { if (!ctx.view.exists(keylet::depositPreauth(dst, account))) return tecNO_PERMISSION; @@ -311,7 +310,7 @@ AccountDelete::preclaim(PreclaimContext const& ctx) LedgerEntryType const nodeType{safe_cast((*sleItem)[sfLedgerEntryType])}; - if (!nonObligationDeleter(nodeType)) + if (nonObligationDeleter(nodeType) == nullptr) return tecHAS_OBLIGATIONS; // We found a deletable directory entry. Count it. If we find too diff --git a/src/libxrpl/tx/transactors/account/AccountSet.cpp b/src/libxrpl/tx/transactors/account/AccountSet.cpp index 3dcb5eb6ef..98f0360410 100644 --- a/src/libxrpl/tx/transactors/account/AccountSet.cpp +++ b/src/libxrpl/tx/transactors/account/AccountSet.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -62,8 +63,8 @@ AccountSet::preflight(PreflightContext const& ctx) // // RequireAuth // - bool bSetRequireAuth = (uTxFlags & tfRequireAuth) || (uSetFlag == asfRequireAuth); - bool bClearRequireAuth = (uTxFlags & tfOptionalAuth) || (uClearFlag == asfRequireAuth); + bool bSetRequireAuth = ((uTxFlags & tfRequireAuth) != 0u) || (uSetFlag == asfRequireAuth); + bool bClearRequireAuth = ((uTxFlags & tfOptionalAuth) != 0u) || (uClearFlag == asfRequireAuth); if (bSetRequireAuth && bClearRequireAuth) { @@ -74,8 +75,9 @@ AccountSet::preflight(PreflightContext const& ctx) // // RequireDestTag // - bool bSetRequireDest = (uTxFlags & tfRequireDestTag) || (uSetFlag == asfRequireDest); - bool bClearRequireDest = (uTxFlags & tfOptionalDestTag) || (uClearFlag == asfRequireDest); + bool bSetRequireDest = ((uTxFlags & tfRequireDestTag) != 0u) || (uSetFlag == asfRequireDest); + bool bClearRequireDest = + ((uTxFlags & tfOptionalDestTag) != 0u) || (uClearFlag == asfRequireDest); if (bSetRequireDest && bClearRequireDest) { @@ -86,8 +88,8 @@ AccountSet::preflight(PreflightContext const& ctx) // // DisallowXRP // - bool bSetDisallowXRP = (uTxFlags & tfDisallowXRP) || (uSetFlag == asfDisallowXRP); - bool bClearDisallowXRP = (uTxFlags & tfAllowXRP) || (uClearFlag == asfDisallowXRP); + bool bSetDisallowXRP = ((uTxFlags & tfDisallowXRP) != 0u) || (uSetFlag == asfDisallowXRP); + bool bClearDisallowXRP = ((uTxFlags & tfAllowXRP) != 0u) || (uClearFlag == asfDisallowXRP); if (bSetDisallowXRP && bClearDisallowXRP) { @@ -100,7 +102,7 @@ AccountSet::preflight(PreflightContext const& ctx) { std::uint32_t uRate = tx.getFieldU32(sfTransferRate); - if (uRate && (uRate < QUALITY_ONE)) + if ((uRate != 0u) && (uRate < QUALITY_ONE)) { JLOG(j.trace()) << "Malformed transaction: Transfer rate too small."; return temBAD_TRANSFER_RATE; @@ -117,7 +119,8 @@ AccountSet::preflight(PreflightContext const& ctx) if (tx.isFieldPresent(sfTickSize)) { auto uTickSize = tx[sfTickSize]; - if (uTickSize && ((uTickSize < Quality::minTickSize) || (uTickSize > Quality::maxTickSize))) + if ((uTickSize != 0u) && + ((uTickSize < Quality::minTickSize) || (uTickSize > Quality::maxTickSize))) { JLOG(j.trace()) << "Malformed transaction: Bad tick size."; return temBAD_TICK_SIZE; @@ -174,7 +177,7 @@ AccountSet::checkPermission(ReadView const& view, STTx const& tx) // AccountSet transaction. If any delegated account is trying to // update the flag on behalf of another account, it is not // authorized. - if (uSetFlag != 0 || uClearFlag != 0 || uTxFlags & tfUniversalMask) + if (uSetFlag != 0 || uClearFlag != 0 || ((uTxFlags & tfUniversalMask) != 0u)) return terNO_DELEGATE_PERMISSION; if (tx.isFieldPresent(sfEmailHash) && !granularPermissions.contains(AccountEmailHashSet)) @@ -214,17 +217,17 @@ AccountSet::preclaim(PreclaimContext const& ctx) std::uint32_t const uSetFlag = ctx.tx.getFieldU32(sfSetFlag); // legacy AccountSet flags - bool bSetRequireAuth = (uTxFlags & tfRequireAuth) || (uSetFlag == asfRequireAuth); + bool bSetRequireAuth = ((uTxFlags & tfRequireAuth) != 0u) || (uSetFlag == asfRequireAuth); // // RequireAuth // - if (bSetRequireAuth && !(uFlagsIn & lsfRequireAuth)) + if (bSetRequireAuth && ((uFlagsIn & lsfRequireAuth) == 0u)) { if (!dirIsEmpty(ctx.view, keylet::ownerDir(id))) { JLOG(ctx.j.trace()) << "Retry: Owner directory not empty."; - return (ctx.flags & tapRETRY) ? TER{terOWNERS} : TER{tecOWNERS}; + return ((ctx.flags & tapRETRY) != 0u) ? TER{terOWNERS} : TER{tecOWNERS}; } } @@ -235,7 +238,7 @@ AccountSet::preclaim(PreclaimContext const& ctx) { if (uSetFlag == asfAllowTrustLineClawback) { - if (uFlagsIn & lsfNoFreeze) + if ((uFlagsIn & lsfNoFreeze) != 0u) { JLOG(ctx.j.trace()) << "Can't set Clawback if NoFreeze is set"; return tecNO_PERMISSION; @@ -250,7 +253,7 @@ AccountSet::preclaim(PreclaimContext const& ctx) else if (uSetFlag == asfNoFreeze) { // Cannot set NoFreeze if clawback is enabled - if (uFlagsIn & lsfAllowTrustLineClawback) + if ((uFlagsIn & lsfAllowTrustLineClawback) != 0u) { JLOG(ctx.j.trace()) << "Can't set NoFreeze if clawback is enabled"; return tecNO_PERMISSION; @@ -277,12 +280,15 @@ AccountSet::doApply() // legacy AccountSet flags std::uint32_t const uTxFlags{tx.getFlags()}; - bool const bSetRequireDest{(uTxFlags & tfRequireDestTag) || (uSetFlag == asfRequireDest)}; - bool const bClearRequireDest{(uTxFlags & tfOptionalDestTag) || (uClearFlag == asfRequireDest)}; - bool const bSetRequireAuth{(uTxFlags & tfRequireAuth) || (uSetFlag == asfRequireAuth)}; - bool const bClearRequireAuth{(uTxFlags & tfOptionalAuth) || (uClearFlag == asfRequireAuth)}; - bool const bSetDisallowXRP{(uTxFlags & tfDisallowXRP) || (uSetFlag == asfDisallowXRP)}; - bool const bClearDisallowXRP{(uTxFlags & tfAllowXRP) || (uClearFlag == asfDisallowXRP)}; + bool const bSetRequireDest{ + ((uTxFlags & tfRequireDestTag) != 0u) || (uSetFlag == asfRequireDest)}; + bool const bClearRequireDest{ + ((uTxFlags & tfOptionalDestTag) != 0u) || (uClearFlag == asfRequireDest)}; + bool const bSetRequireAuth{((uTxFlags & tfRequireAuth) != 0u) || (uSetFlag == asfRequireAuth)}; + bool const bClearRequireAuth{ + ((uTxFlags & tfOptionalAuth) != 0u) || (uClearFlag == asfRequireAuth)}; + bool const bSetDisallowXRP{((uTxFlags & tfDisallowXRP) != 0u) || (uSetFlag == asfDisallowXRP)}; + bool const bClearDisallowXRP{((uTxFlags & tfAllowXRP) != 0u) || (uClearFlag == asfDisallowXRP)}; bool const sigWithMaster{[&tx, &acct = account_]() { auto const spk = tx.getSigningPubKey(); @@ -300,13 +306,13 @@ AccountSet::doApply() // // RequireAuth // - if (bSetRequireAuth && !(uFlagsIn & lsfRequireAuth)) + if (bSetRequireAuth && ((uFlagsIn & lsfRequireAuth) == 0u)) { JLOG(j_.trace()) << "Set RequireAuth."; uFlagsOut |= lsfRequireAuth; } - if (bClearRequireAuth && (uFlagsIn & lsfRequireAuth)) + if (bClearRequireAuth && ((uFlagsIn & lsfRequireAuth) != 0u)) { JLOG(j_.trace()) << "Clear RequireAuth."; uFlagsOut &= ~lsfRequireAuth; @@ -315,13 +321,13 @@ AccountSet::doApply() // // RequireDestTag // - if (bSetRequireDest && !(uFlagsIn & lsfRequireDestTag)) + if (bSetRequireDest && ((uFlagsIn & lsfRequireDestTag) == 0u)) { JLOG(j_.trace()) << "Set lsfRequireDestTag."; uFlagsOut |= lsfRequireDestTag; } - if (bClearRequireDest && (uFlagsIn & lsfRequireDestTag)) + if (bClearRequireDest && ((uFlagsIn & lsfRequireDestTag) != 0u)) { JLOG(j_.trace()) << "Clear lsfRequireDestTag."; uFlagsOut &= ~lsfRequireDestTag; @@ -330,13 +336,13 @@ AccountSet::doApply() // // DisallowXRP // - if (bSetDisallowXRP && !(uFlagsIn & lsfDisallowXRP)) + if (bSetDisallowXRP && ((uFlagsIn & lsfDisallowXRP) == 0u)) { JLOG(j_.trace()) << "Set lsfDisallowXRP."; uFlagsOut |= lsfDisallowXRP; } - if (bClearDisallowXRP && (uFlagsIn & lsfDisallowXRP)) + if (bClearDisallowXRP && ((uFlagsIn & lsfDisallowXRP) != 0u)) { JLOG(j_.trace()) << "Clear lsfDisallowXRP."; uFlagsOut &= ~lsfDisallowXRP; @@ -345,7 +351,7 @@ AccountSet::doApply() // // DisableMaster // - if ((uSetFlag == asfDisableMaster) && !(uFlagsIn & lsfDisableMaster)) + if ((uSetFlag == asfDisableMaster) && ((uFlagsIn & lsfDisableMaster) == 0u)) { if (!sigWithMaster) { @@ -363,7 +369,7 @@ AccountSet::doApply() uFlagsOut |= lsfDisableMaster; } - if ((uClearFlag == asfDisableMaster) && (uFlagsIn & lsfDisableMaster)) + if ((uClearFlag == asfDisableMaster) && ((uFlagsIn & lsfDisableMaster) != 0u)) { JLOG(j_.trace()) << "Clear lsfDisableMaster."; uFlagsOut &= ~lsfDisableMaster; @@ -388,7 +394,7 @@ AccountSet::doApply() // if (uSetFlag == asfNoFreeze) { - if (!sigWithMaster && !(uFlagsIn & lsfDisableMaster)) + if (!sigWithMaster && ((uFlagsIn & lsfDisableMaster) == 0u)) { JLOG(j_.trace()) << "Must use master key to set NoFreeze."; return tecNEED_MASTER_KEY; diff --git a/src/libxrpl/tx/transactors/account/SetRegularKey.cpp b/src/libxrpl/tx/transactors/account/SetRegularKey.cpp index 4629568c80..42a6e89fae 100644 --- a/src/libxrpl/tx/transactors/account/SetRegularKey.cpp +++ b/src/libxrpl/tx/transactors/account/SetRegularKey.cpp @@ -17,7 +17,7 @@ SetRegularKey::calculateBaseFee(ReadView const& view, STTx const& tx) { auto const sle = view.read(keylet::account(id)); - if (sle && (!(sle->getFlags() & lsfPasswordSpent))) + if (sle && ((sle->getFlags() & lsfPasswordSpent) == 0u)) { // flag is armed and they signed with the right account return XRPAmount{0}; diff --git a/src/libxrpl/tx/transactors/account/SignerListSet.cpp b/src/libxrpl/tx/transactors/account/SignerListSet.cpp index 368f3357bf..cf0d65c06f 100644 --- a/src/libxrpl/tx/transactors/account/SignerListSet.cpp +++ b/src/libxrpl/tx/transactors/account/SignerListSet.cpp @@ -1,6 +1,6 @@ -#include #include -#include +#include +#include #include #include #include @@ -29,7 +29,7 @@ SignerListSet::determineOperation(STTx const& tx, ApplyFlags flags, beast::Journ Operation op = unknown; bool const hasSignerEntries(tx.isFieldPresent(sfSignerEntries)); - if (quorum && hasSignerEntries) + if ((quorum != 0u) && hasSignerEntries) { auto signers = SignerEntries::deserialize(tx, j, "transaction"); @@ -196,7 +196,7 @@ removeSignersFromLedger( } adjustOwnerCount( - view, view.peek(accountKeylet), removeFromOwnerCount, registry.journal("View")); + view, view.peek(accountKeylet), removeFromOwnerCount, registry.getJournal("View")); view.erase(signers); @@ -314,7 +314,7 @@ SignerListSet::replaceSignerList() view().insert(signerList); writeSignersToSLE(signerList, flags); - auto viewJ = ctx_.registry.journal("View"); + auto viewJ = ctx_.registry.get().getJournal("View"); // Add the signer list to the account's directory. auto const page = ctx_.view().dirInsert(ownerDirKeylet, signerListKeylet, describeOwnerDir(account_)); @@ -362,7 +362,7 @@ SignerListSet::writeSignersToSLE(SLE::pointer const& ledgerEntry, std::uint32_t } ledgerEntry->setFieldU32(sfSignerQuorum, quorum_); ledgerEntry->setFieldU32(sfSignerListID, DEFAULT_SIGNER_LIST_ID); - if (flags) // Only set flags if they are non-default (default is zero). + if (flags != 0u) // Only set flags if they are non-default (default is zero). ledgerEntry->setFieldU32(sfFlags, flags); // Create the SignerListArray one SignerEntry at a time. diff --git a/src/libxrpl/tx/transactors/bridge/XChainBridge.cpp b/src/libxrpl/tx/transactors/bridge/XChainBridge.cpp index 5c33184d80..b94da8ef6d 100644 --- a/src/libxrpl/tx/transactors/bridge/XChainBridge.cpp +++ b/src/libxrpl/tx/transactors/bridge/XChainBridge.cpp @@ -5,7 +5,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -108,7 +109,7 @@ checkAttestationPublicKey( if (accountFromPK == attestationSignerAccount) { // master key - if (sleAttestationSigningAccount->getFieldU32(sfFlags) & lsfDisableMaster) + if ((sleAttestationSigningAccount->getFieldU32(sfFlags) & lsfDisableMaster) != 0u) { JLOG(j.trace()) << "Attempt to add an attestation with " "disabled master key."; @@ -385,7 +386,7 @@ transferHelper( { // Check dst tag and deposit auth - if ((sleDst->getFlags() & lsfRequireDestTag) && !dstTag) + if (((sleDst->getFlags() & lsfRequireDestTag) != 0u) && !dstTag) return tecDST_TAG_NEEDED; // If the destination is the claim owner, and this is a claim @@ -394,7 +395,7 @@ transferHelper( bool const canBypassDepositAuth = dst == claimOwner && depositAuthPolicy == DepositAuthPolicy::dstCanBypass; - if (!canBypassDepositAuth && (sleDst->getFlags() & lsfDepositAuth) && + if (!canBypassDepositAuth && ((sleDst->getFlags() & lsfDepositAuth) != 0u) && !psb.exists(keylet::depositPreauth(dst, src))) { return tecNO_PERMISSION; @@ -417,7 +418,7 @@ transferHelper( auto const reserve = psb.fees().accountReserve(ownerCount); auto const availableBalance = [&]() -> STAmount { - STAmount const curBal = (*sleSrc)[sfBalance]; + STAmount curBal = (*sleSrc)[sfBalance]; // Checking that account == src and postFeeBalance == curBal is // not strictly necessary, but helps protect against future // changes @@ -1402,7 +1403,7 @@ XChainCreateBridge::preclaim(PreclaimContext const& ctx) // Allowing clawing back funds would break the bridge's invariant that // wrapped funds are always backed by locked funds - if (sleIssuer->getFlags() & lsfAllowTrustLineClawback) + if ((sleIssuer->getFlags() & lsfAllowTrustLineClawback) != 0u) return tecNO_PERMISSION; } @@ -1481,7 +1482,7 @@ BridgeModify::preflight(PreflightContext const& ctx) auto const reward = ctx.tx[~sfSignatureReward]; auto const minAccountCreate = ctx.tx[~sfMinAccountCreateAmount]; auto const bridgeSpec = ctx.tx[sfXChainBridge]; - bool const clearAccountCreate = ctx.tx.getFlags() & tfClearAccountCreateAmount; + bool const clearAccountCreate = (ctx.tx.getFlags() & tfClearAccountCreateAmount) != 0u; if (!reward && !minAccountCreate && !clearAccountCreate) { @@ -1539,7 +1540,7 @@ BridgeModify::doApply() auto const bridgeSpec = ctx_.tx[sfXChainBridge]; auto const reward = ctx_.tx[~sfSignatureReward]; auto const minAccountCreate = ctx_.tx[~sfMinAccountCreateAmount]; - bool const clearAccountCreate = ctx_.tx.getFlags() & tfClearAccountCreateAmount; + bool const clearAccountCreate = (ctx_.tx.getFlags() & tfClearAccountCreateAmount) != 0u; auto const sleAcct = ctx_.view().peek(keylet::account(account)); if (!sleAcct) diff --git a/src/libxrpl/tx/transactors/check/CheckCancel.cpp b/src/libxrpl/tx/transactors/check/CheckCancel.cpp index aed56ec7f4..0b9a9a90af 100644 --- a/src/libxrpl/tx/transactors/check/CheckCancel.cpp +++ b/src/libxrpl/tx/transactors/check/CheckCancel.cpp @@ -1,6 +1,6 @@ -#include #include #include +#include #include #include #include @@ -57,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.get().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 aca20e0785..d4861e524a 100644 --- a/src/libxrpl/tx/transactors/check/CheckCash.cpp +++ b/src/libxrpl/tx/transactors/check/CheckCash.cpp @@ -1,6 +1,7 @@ -#include #include #include +#include +#include #include #include #include @@ -80,7 +81,8 @@ CheckCash::preclaim(PreclaimContext const& ctx) return tecNO_ENTRY; } - if ((sleDst->getFlags() & lsfRequireDestTag) && !sleCheck->isFieldPresent(sfDestinationTag)) + if (((sleDst->getFlags() & lsfRequireDestTag) != 0u) && + !sleCheck->isFieldPresent(sfDestinationTag)) { // The tag is basically account-specific information we don't // understand, but we can require someone to fill it in. @@ -153,7 +155,7 @@ CheckCash::preclaim(PreclaimContext const& ctx) return tecNO_ISSUER; } - if (sleIssuer->at(sfFlags) & lsfRequireAuth) + if ((sleIssuer->at(sfFlags) & lsfRequireAuth) != 0u) { auto const sleTrustLine = ctx.view.read(keylet::line(dstId, issuerId, currency)); @@ -170,7 +172,7 @@ CheckCash::preclaim(PreclaimContext const& ctx) bool const canonical_gt(dstId > issuerId); bool const is_authorized( - sleTrustLine->at(sfFlags) & (canonical_gt ? lsfLowAuth : lsfHighAuth)); + (sleTrustLine->at(sfFlags) & (canonical_gt ? lsfLowAuth : lsfHighAuth)) != 0u); if (!is_authorized) { @@ -230,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.get().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 c56ba5c28e..4f962a7fa6 100644 --- a/src/libxrpl/tx/transactors/check/CheckCreate.cpp +++ b/src/libxrpl/tx/transactors/check/CheckCreate.cpp @@ -1,5 +1,7 @@ -#include #include +#include +#include +#include #include #include #include @@ -60,7 +62,7 @@ CheckCreate::preclaim(PreclaimContext const& ctx) auto const flags = sleDst->getFlags(); // Check if the destination has disallowed incoming checks - if (flags & lsfDisallowIncomingCheck) + if ((flags & lsfDisallowIncomingCheck) != 0u) return tecNO_PERMISSION; // Pseudo-accounts cannot cash checks. Note, this is not amendment-gated @@ -70,7 +72,7 @@ CheckCreate::preclaim(PreclaimContext const& ctx) if (isPseudoAccount(sleDst)) return tecNO_PERMISSION; - if ((flags & lsfRequireDestTag) && !ctx.tx.isFieldPresent(sfDestinationTag)) + if (((flags & lsfRequireDestTag) != 0u) && !ctx.tx.isFieldPresent(sfDestinationTag)) { // The tag is basically account-specific information we don't // understand, but we can require someone to fill it in. @@ -166,7 +168,7 @@ CheckCreate::doApply() view().insert(sleCheck); - auto viewJ = ctx_.registry.journal("View"); + auto viewJ = ctx_.registry.get().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/credentials/CredentialAccept.cpp b/src/libxrpl/tx/transactors/credentials/CredentialAccept.cpp index df5c581975..9b7eb89661 100644 --- a/src/libxrpl/tx/transactors/credentials/CredentialAccept.cpp +++ b/src/libxrpl/tx/transactors/credentials/CredentialAccept.cpp @@ -1,7 +1,7 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -60,7 +60,7 @@ CredentialAccept::preclaim(PreclaimContext const& ctx) return tecNO_ENTRY; } - if (sleCred->getFieldU32(sfFlags) & lsfAccepted) + if ((sleCred->getFieldU32(sfFlags) & lsfAccepted) != 0u) { JLOG(ctx.j.warn()) << "Credential already accepted: " << to_string(subject) << ", " << to_string(issuer) << ", " << credType; diff --git a/src/libxrpl/tx/transactors/credentials/CredentialCreate.cpp b/src/libxrpl/tx/transactors/credentials/CredentialCreate.cpp index 073da020d1..9c0ea0d43d 100644 --- a/src/libxrpl/tx/transactors/credentials/CredentialCreate.cpp +++ b/src/libxrpl/tx/transactors/credentials/CredentialCreate.cpp @@ -1,7 +1,8 @@ #include #include -#include -#include +#include +#include +#include #include #include #include @@ -146,14 +147,15 @@ CredentialCreate::doApply() } else { + // Added to both dirs, owned only by issuer. CredentialAccept will transfer ownership to + // subject. CredentialDelete will remove from both dirs and decrement 1 ownerCount. auto const page = view().dirInsert(keylet::ownerDir(subject), credentialKey, describeOwnerDir(subject)); - JLOG(j_.trace()) << "Adding Credential to owner directory " << to_string(credentialKey.key) - << ": " << (page ? "success" : "failure"); + JLOG(j_.trace()) << "Adding Credential to subject directory " + << to_string(credentialKey.key) << ": " << (page ? "success" : "failure"); if (!page) return tecDIR_FULL; sleCred->setFieldU64(sfSubjectNode, *page); - view().update(view().peek(keylet::account(subject))); } view().insert(sleCred); diff --git a/src/libxrpl/tx/transactors/credentials/CredentialDelete.cpp b/src/libxrpl/tx/transactors/credentials/CredentialDelete.cpp index 16c07f2cb7..e0fa6147aa 100644 --- a/src/libxrpl/tx/transactors/credentials/CredentialDelete.cpp +++ b/src/libxrpl/tx/transactors/credentials/CredentialDelete.cpp @@ -1,7 +1,7 @@ #include #include -#include #include +#include #include #include #include diff --git a/src/libxrpl/tx/transactors/delegate/DelegateSet.cpp b/src/libxrpl/tx/transactors/delegate/DelegateSet.cpp index ac0b07b6fc..ddd5a4c910 100644 --- a/src/libxrpl/tx/transactors/delegate/DelegateSet.cpp +++ b/src/libxrpl/tx/transactors/delegate/DelegateSet.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include #include diff --git a/src/libxrpl/tx/transactors/dex/AMMClawback.cpp b/src/libxrpl/tx/transactors/dex/AMMClawback.cpp index c6fb67d926..fa3302cce5 100644 --- a/src/libxrpl/tx/transactors/dex/AMMClawback.cpp +++ b/src/libxrpl/tx/transactors/dex/AMMClawback.cpp @@ -40,7 +40,7 @@ AMMClawback::preflight(PreflightContext const& ctx) auto const flags = ctx.tx.getFlags(); - if (flags & tfClawTwoAssets && asset.account != asset2.account) + if (((flags & tfClawTwoAssets) != 0u) && asset.account != asset2.account) { JLOG(ctx.j.trace()) << "AMMClawback: tfClawTwoAssets can only be enabled when two " "assets in the AMM pool are both issued by the issuer"; @@ -90,7 +90,8 @@ AMMClawback::preclaim(PreclaimContext const& ctx) // If AllowTrustLineClawback is not set or NoFreeze is set, return no // permission - if (!(issuerFlagsIn & lsfAllowTrustLineClawback) || (issuerFlagsIn & lsfNoFreeze)) + if (((issuerFlagsIn & lsfAllowTrustLineClawback) == 0u) || + ((issuerFlagsIn & lsfNoFreeze) != 0u)) return tecNO_PERMISSION; return tesSUCCESS; @@ -215,7 +216,7 @@ AMMClawback::applyGuts(Sandbox& sb) return tecINTERNAL; // LCOV_EXCL_LINE auto const flags = ctx_.tx.getFlags(); - if (flags & tfClawTwoAssets) + if ((flags & tfClawTwoAssets) != 0u) return rippleCredit(sb, holder, issuer, *amount2Withdraw, true, j_); return tesSUCCESS; diff --git a/src/libxrpl/tx/transactors/dex/AMMCreate.cpp b/src/libxrpl/tx/transactors/dex/AMMCreate.cpp index 58831cedd2..1f0c01ea63 100644 --- a/src/libxrpl/tx/transactors/dex/AMMCreate.cpp +++ b/src/libxrpl/tx/transactors/dex/AMMCreate.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -280,7 +281,7 @@ applyCreate(ApplyContext& ctx_, Sandbox& sb, AccountID const& account_, beast::J Book const book{issueIn, issueOut, std::nullopt}; auto const dir = keylet::quality(keylet::book(book), uRate); if (auto const bookExisted = static_cast(sb.read(dir)); !bookExisted) - ctx_.registry.getOrderBookDB().addOrderBook(book); + ctx_.registry.get().getOrderBookDB().addOrderBook(book); }; addOrderBook(amount.issue(), amount2.issue(), getRate(amount2, amount)); addOrderBook(amount2.issue(), amount.issue(), getRate(amount, amount2)); diff --git a/src/libxrpl/tx/transactors/dex/AMMDeposit.cpp b/src/libxrpl/tx/transactors/dex/AMMDeposit.cpp index 42093757f0..9f3c84c898 100644 --- a/src/libxrpl/tx/transactors/dex/AMMDeposit.cpp +++ b/src/libxrpl/tx/transactors/dex/AMMDeposit.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -43,35 +44,35 @@ AMMDeposit::preflight(PreflightContext const& ctx) JLOG(ctx.j.debug()) << "AMM Deposit: invalid flags."; return temMALFORMED; } - if (flags & tfLPToken) + if ((flags & tfLPToken) != 0u) { // if included then both amount and amount2 are deposit min if (!lpTokens || ePrice || (amount && !amount2) || (!amount && amount2) || tradingFee) return temMALFORMED; } - else if (flags & tfSingleAsset) + else if ((flags & tfSingleAsset) != 0u) { // if included then lpTokens is deposit min if (!amount || amount2 || ePrice || tradingFee) return temMALFORMED; } - else if (flags & tfTwoAsset) + else if ((flags & tfTwoAsset) != 0u) { // if included then lpTokens is deposit min if (!amount || !amount2 || ePrice || tradingFee) return temMALFORMED; } - else if (flags & tfOneAssetLPToken) + else if ((flags & tfOneAssetLPToken) != 0u) { if (!amount || !lpTokens || amount2 || ePrice || tradingFee) return temMALFORMED; } - else if (flags & tfLimitLPToken) + else if ((flags & tfLimitLPToken) != 0u) { if (!amount || !ePrice || lpTokens || amount2 || tradingFee) return temMALFORMED; } - else if (flags & tfTwoAssetIfEmpty) + else if ((flags & tfTwoAssetIfEmpty) != 0u) { if (!amount || !amount2 || ePrice || lpTokens) return temMALFORMED; @@ -155,7 +156,7 @@ AMMDeposit::preclaim(PreclaimContext const& ctx) if (!expected) return expected.error(); // LCOV_EXCL_LINE auto const [amountBalance, amount2Balance, lptAMMBalance] = *expected; - if (ctx.tx.getFlags() & tfTwoAssetIfEmpty) + if ((ctx.tx.getFlags() & tfTwoAssetIfEmpty) != 0u) { if (lptAMMBalance != beast::zero) return tecAMM_NOT_EMPTY; @@ -282,7 +283,7 @@ AMMDeposit::preclaim(PreclaimContext const& ctx) }; // amount and amount2 are deposit min in case of tfLPToken - if (!(ctx.tx.getFlags() & tfLPToken)) + if ((ctx.tx.getFlags() & tfLPToken) == 0u) { if (auto const ter = checkAmount(amount, true)) return ter; diff --git a/src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp b/src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp index 3667057ff5..c48df7836b 100644 --- a/src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp +++ b/src/libxrpl/tx/transactors/dex/AMMWithdraw.cpp @@ -42,37 +42,37 @@ AMMWithdraw::preflight(PreflightContext const& ctx) JLOG(ctx.j.debug()) << "AMM Withdraw: invalid flags."; return temMALFORMED; } - if (flags & tfLPToken) + if ((flags & tfLPToken) != 0u) { if (!lpTokens || amount || amount2 || ePrice) return temMALFORMED; } - else if (flags & tfWithdrawAll) + else if ((flags & tfWithdrawAll) != 0u) { if (lpTokens || amount || amount2 || ePrice) return temMALFORMED; } - else if (flags & tfOneAssetWithdrawAll) + else if ((flags & tfOneAssetWithdrawAll) != 0u) { if (!amount || lpTokens || amount2 || ePrice) return temMALFORMED; } - else if (flags & tfSingleAsset) + else if ((flags & tfSingleAsset) != 0u) { if (!amount || lpTokens || amount2 || ePrice) return temMALFORMED; } - else if (flags & tfTwoAsset) + else if ((flags & tfTwoAsset) != 0u) { if (!amount || !amount2 || lpTokens || ePrice) return temMALFORMED; } - else if (flags & tfOneAssetLPToken) + else if ((flags & tfOneAssetLPToken) != 0u) { if (!amount || !lpTokens || amount2 || ePrice) return temMALFORMED; } - else if (flags & tfLimitLPToken) + else if ((flags & tfLimitLPToken) != 0u) { if (!amount || !ePrice || lpTokens || amount2) return temMALFORMED; @@ -104,7 +104,7 @@ AMMWithdraw::preflight(PreflightContext const& ctx) if (auto const res = invalidAMMAmount( *amount, std::make_optional(std::make_pair(asset, asset2)), - (flags & (tfOneAssetWithdrawAll | tfOneAssetLPToken)) || ePrice)) + ((flags & (tfOneAssetWithdrawAll | tfOneAssetLPToken)) != 0u) || ePrice)) { JLOG(ctx.j.debug()) << "AMM Withdraw: invalid Asset1Out"; return res; @@ -139,7 +139,7 @@ tokensWithdraw( std::optional const& tokensIn, std::uint32_t flags) { - if (flags & (tfWithdrawAll | tfOneAssetWithdrawAll)) + if ((flags & (tfWithdrawAll | tfOneAssetWithdrawAll)) != 0u) return lpTokens; return tokensIn; } @@ -248,7 +248,7 @@ AMMWithdraw::preclaim(PreclaimContext const& ctx) return temBAD_AMM_TOKENS; } - if (ctx.tx.getFlags() & (tfLPToken | tfWithdrawAll)) + if ((ctx.tx.getFlags() & (tfLPToken | tfWithdrawAll)) != 0u) { if (auto const ter = checkAmount(amountBalance, amountBalance)) return ter; @@ -1018,7 +1018,7 @@ AMMWithdraw::singleWithdrawEPrice( WithdrawAll AMMWithdraw::isWithdrawAll(STTx const& tx) { - if (tx[sfFlags] & (tfWithdrawAll | tfOneAssetWithdrawAll)) + if ((tx[sfFlags] & (tfWithdrawAll | tfOneAssetWithdrawAll)) != 0u) return WithdrawAll::Yes; return WithdrawAll::No; } diff --git a/src/libxrpl/tx/transactors/dex/OfferCancel.cpp b/src/libxrpl/tx/transactors/dex/OfferCancel.cpp index 87d1084685..3c5149dd7d 100644 --- a/src/libxrpl/tx/transactors/dex/OfferCancel.cpp +++ b/src/libxrpl/tx/transactors/dex/OfferCancel.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include #include @@ -8,7 +8,7 @@ namespace xrpl { NotTEC OfferCancel::preflight(PreflightContext const& ctx) { - if (!ctx.tx[sfOfferSequence]) + if (ctx.tx[sfOfferSequence] == 0u) { JLOG(ctx.j.trace()) << "OfferCancel::preflight: missing sequence"; return temBAD_SEQUENCE; @@ -53,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.get().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 6bb1f27e1a..af100bc141 100644 --- a/src/libxrpl/tx/transactors/dex/OfferCreate.cpp +++ b/src/libxrpl/tx/transactors/dex/OfferCreate.cpp @@ -2,6 +2,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -26,10 +30,7 @@ OfferCreate::makeTxConsequences(PreflightContext const& ctx) bool OfferCreate::checkExtraFeatures(PreflightContext const& ctx) { - if (ctx.tx.isFieldPresent(sfDomainID) && !ctx.rules.enabled(featurePermissionedDEX)) - return false; - - return true; + return !ctx.tx.isFieldPresent(sfDomainID) || ctx.rules.enabled(featurePermissionedDEX); } std::uint32_t @@ -55,8 +56,8 @@ OfferCreate::preflight(PreflightContext const& ctx) if (tx.isFlag(tfHybrid) && !tx.isFieldPresent(sfDomainID)) return temINVALID_FLAG; - bool const bImmediateOrCancel(uTxFlags & tfImmediateOrCancel); - bool const bFillOrKill(uTxFlags & tfFillOrKill); + bool const bImmediateOrCancel((uTxFlags & tfImmediateOrCancel) != 0u); + bool const bFillOrKill((uTxFlags & tfFillOrKill) != 0u); if (bImmediateOrCancel && bFillOrKill) { @@ -143,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.get().getJournal("View"); if (isGlobalFrozen(ctx.view, uPaysIssuerID) || isGlobalFrozen(ctx.view, uGetsIssuerID)) { @@ -211,7 +212,7 @@ OfferCreate::checkAcceptAsset( JLOG(j.debug()) << "delay: can't receive IOUs from non-existent issuer: " << to_string(issue.account); - return (flags & tapRETRY) ? TER{terNO_ACCOUNT} : TER{tecNO_ISSUER}; + return ((flags & tapRETRY) != 0u) ? TER{terNO_ACCOUNT} : TER{tecNO_ISSUER}; } // An account cannot create a trustline to itself, so no line can exist @@ -220,13 +221,13 @@ OfferCreate::checkAcceptAsset( if (issue.account == id) return tesSUCCESS; - if ((*issuerAccount)[sfFlags] & lsfRequireAuth) + if (((*issuerAccount)[sfFlags] & lsfRequireAuth) != 0u) { auto const trustLine = view.read(keylet::line(id, issue.account, issue.currency)); if (!trustLine) { - return (flags & tapRETRY) ? TER{terNO_LINE} : TER{tecNO_LINE}; + return ((flags & tapRETRY) != 0u) ? TER{terNO_LINE} : TER{tecNO_LINE}; } // Entries have a canonical representation, determined by a @@ -234,13 +235,14 @@ OfferCreate::checkAcceptAsset( // ordering. Determine which entry we need to access. bool const canonical_gt(id > issue.account); - bool const is_authorized((*trustLine)[sfFlags] & (canonical_gt ? lsfLowAuth : lsfHighAuth)); + bool const is_authorized( + ((*trustLine)[sfFlags] & (canonical_gt ? lsfLowAuth : lsfHighAuth)) != 0u); if (!is_authorized) { JLOG(j.debug()) << "delay: can't receive IOUs from issuer without auth."; - return (flags & tapRETRY) ? TER{terNO_AUTH} : TER{tecNO_AUTH}; + return ((flags & tapRETRY) != 0u) ? TER{terNO_AUTH} : TER{tecNO_AUTH}; } } @@ -253,7 +255,7 @@ OfferCreate::checkAcceptAsset( // There's no difference which side enacted deep freeze, accepting // tokens shouldn't be possible. - bool const deepFrozen = (*trustLine)[sfFlags] & (lsfLowDeepFreeze | lsfHighDeepFreeze); + bool const deepFrozen = ((*trustLine)[sfFlags] & (lsfLowDeepFreeze | lsfHighDeepFreeze)) != 0u; if (deepFrozen) { @@ -309,7 +311,7 @@ OfferCreate::flowCross( // If we're creating a passive offer adjust the threshold so we only // cross offers that have a better quality than this one. std::uint32_t const txFlags = ctx_.tx.getFlags(); - if (txFlags & tfPassive) + if ((txFlags & tfPassive) != 0u) ++threshold; // Don't send more than our balance. @@ -330,7 +332,7 @@ OfferCreate::flowCross( // Special handling for the tfSell flag. STAmount deliver = takerAmount.out; OfferCrossing offerCrossing = OfferCrossing::yes; - if (txFlags & tfSell) + if ((txFlags & tfSell) != 0u) { offerCrossing = OfferCrossing::sell; // We are selling, so we will accept *more* than the offer @@ -358,9 +360,9 @@ OfferCreate::flowCross( account_, account_, paths, - true, // default path - !(txFlags & tfFillOrKill), // partial payment - true, // owner pays transfer fee + true, // default path + (txFlags & tfFillOrKill) == 0u, // partial payment + true, // owner pays transfer fee offerCrossing, threshold, sendMax, @@ -394,7 +396,7 @@ OfferCreate::flowCross( { STAmount const rate{Quality{takerAmount.out, takerAmount.in}.rate()}; - if (txFlags & tfSell) + if ((txFlags & tfSell) != 0u) { // If selling then scale the new out amount based on how // much we sold during crossing. This preserves the offer @@ -500,7 +502,7 @@ OfferCreate::applyHybrid( bookArr.push_back(std::move(bookInfo)); if (!bookExists) - ctx_.registry.getOrderBookDB().addOrderBook(book); + ctx_.registry.get().getOrderBookDB().addOrderBook(book); sleOffer->setFieldArray(sfAdditionalBooks, bookArr); return tesSUCCESS; @@ -513,11 +515,11 @@ OfferCreate::applyGuts(Sandbox& sb, Sandbox& sbCancel) std::uint32_t const uTxFlags = ctx_.tx.getFlags(); - bool const bPassive(uTxFlags & tfPassive); - bool const bImmediateOrCancel(uTxFlags & tfImmediateOrCancel); - bool const bFillOrKill(uTxFlags & tfFillOrKill); - bool const bSell(uTxFlags & tfSell); - bool const bHybrid(uTxFlags & tfHybrid); + bool const bPassive((uTxFlags & tfPassive) != 0u); + bool const bImmediateOrCancel((uTxFlags & tfImmediateOrCancel) != 0u); + bool const bFillOrKill((uTxFlags & tfFillOrKill) != 0u); + bool const bSell((uTxFlags & tfSell) != 0u); + bool const bHybrid((uTxFlags & tfHybrid) != 0u); auto saTakerPays = ctx_.tx[sfTakerPays]; auto saTakerGets = ctx_.tx[sfTakerGets]; @@ -534,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.get().getJournal("View"); TER result = tesSUCCESS; @@ -844,7 +846,7 @@ OfferCreate::applyGuts(Sandbox& sb, Sandbox& sbCancel) sb.insert(sleOffer); if (!bookExisted) - ctx_.registry.getOrderBookDB().addOrderBook(book); + ctx_.registry.get().getOrderBookDB().addOrderBook(book); JLOG(j_.debug()) << "final result: success"; diff --git a/src/libxrpl/tx/transactors/dex/PermissionedDEXHelpers.cpp b/src/libxrpl/tx/transactors/dex/PermissionedDEXHelpers.cpp index 37db2d632f..d857795e39 100644 --- a/src/libxrpl/tx/transactors/dex/PermissionedDEXHelpers.cpp +++ b/src/libxrpl/tx/transactors/dex/PermissionedDEXHelpers.cpp @@ -1,4 +1,4 @@ -#include +#include #include namespace xrpl { diff --git a/src/libxrpl/tx/transactors/did/DIDDelete.cpp b/src/libxrpl/tx/transactors/did/DIDDelete.cpp index 92d176272e..e90cb502d1 100644 --- a/src/libxrpl/tx/transactors/did/DIDDelete.cpp +++ b/src/libxrpl/tx/transactors/did/DIDDelete.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include diff --git a/src/libxrpl/tx/transactors/did/DIDSet.cpp b/src/libxrpl/tx/transactors/did/DIDSet.cpp index a7e3861822..9d307f0662 100644 --- a/src/libxrpl/tx/transactors/did/DIDSet.cpp +++ b/src/libxrpl/tx/transactors/did/DIDSet.cpp @@ -1,6 +1,7 @@ #include #include -#include +#include +#include #include #include #include diff --git a/src/libxrpl/tx/transactors/escrow/EscrowCancel.cpp b/src/libxrpl/tx/transactors/escrow/EscrowCancel.cpp index 9681241891..11a4cfdbaa 100644 --- a/src/libxrpl/tx/transactors/escrow/EscrowCancel.cpp +++ b/src/libxrpl/tx/transactors/escrow/EscrowCancel.cpp @@ -1,8 +1,12 @@ #include #include #include +#include +#include +#include #include #include +#include #include #include diff --git a/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp b/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp index 236a5f0ef8..a27f25071f 100644 --- a/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp +++ b/src/libxrpl/tx/transactors/escrow/EscrowCreate.cpp @@ -3,9 +3,14 @@ #include #include #include +#include +#include +#include +#include #include #include #include +#include #include #include #include @@ -348,8 +353,7 @@ escrowLockApplyHelper( if (issuer == sender) return tecINTERNAL; // LCOV_EXCL_LINE - auto const ter = rippleCredit( - view, sender, issuer, amount, amount.holds() ? false : true, journal); + auto const ter = rippleCredit(view, sender, issuer, amount, !amount.holds(), journal); if (!isTesSuccess(ter)) return ter; // LCOV_EXCL_LINE return tesSUCCESS; @@ -410,7 +414,7 @@ EscrowCreate::doApply() auto const sled = ctx_.view().read(keylet::account(ctx_.tx[sfDestination])); if (!sled) return tecNO_DST; // LCOV_EXCL_LINE - if (((*sled)[sfFlags] & lsfRequireDestTag) && !ctx_.tx[~sfDestinationTag]) + if ((((*sled)[sfFlags] & lsfRequireDestTag) != 0u) && !ctx_.tx[~sfDestinationTag]) return tecDST_TAG_NEEDED; } diff --git a/src/libxrpl/tx/transactors/escrow/EscrowFinish.cpp b/src/libxrpl/tx/transactors/escrow/EscrowFinish.cpp index 0fbaa33eb5..d6b37f530e 100644 --- a/src/libxrpl/tx/transactors/escrow/EscrowFinish.cpp +++ b/src/libxrpl/tx/transactors/escrow/EscrowFinish.cpp @@ -4,10 +4,13 @@ #include #include #include -#include #include +#include +#include +#include #include #include +#include #include #include #include @@ -70,7 +73,7 @@ EscrowFinish::preflightSigValidated(PreflightContext const& ctx) if (cb && fb) { - auto& router = ctx.registry.getHashRouter(); + auto& router = ctx.registry.get().getHashRouter(); auto const id = ctx.tx.getTransactionID(); auto const flags = router.getFlags(id); @@ -234,7 +237,7 @@ EscrowFinish::doApply() // Check cryptocondition fulfillment { auto const id = ctx_.tx.getTransactionID(); - auto flags = ctx_.registry.getHashRouter().getFlags(id); + auto flags = ctx_.registry.get().getHashRouter().getFlags(id); auto const cb = ctx_.tx[~sfCondition]; @@ -258,7 +261,7 @@ EscrowFinish::doApply() flags = SF_CF_INVALID; } - ctx_.registry.getHashRouter().setFlags(id, flags); + ctx_.registry.get().getHashRouter().setFlags(id, flags); // LCOV_EXCL_STOP } diff --git a/src/libxrpl/tx/transactors/escrow/EscrowHelpers.h b/src/libxrpl/tx/transactors/escrow/EscrowHelpers.h index 2aa6ae6db5..5fdc43c359 100644 --- a/src/libxrpl/tx/transactors/escrow/EscrowHelpers.h +++ b/src/libxrpl/tx/transactors/escrow/EscrowHelpers.h @@ -3,9 +3,13 @@ #include #include #include +#include +#include +#include #include #include #include +#include #include namespace xrpl { diff --git a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverClawback.cpp b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverClawback.cpp index 82f41b3cb1..fd2a145516 100644 --- a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverClawback.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverClawback.cpp @@ -1,5 +1,6 @@ #include // +#include #include #include diff --git a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverDeposit.cpp b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverDeposit.cpp index 8734dfb8e4..7de5ab235f 100644 --- a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverDeposit.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverDeposit.cpp @@ -1,5 +1,6 @@ #include // +#include #include #include diff --git a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.cpp b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.cpp index 8cdee5c3a2..ed42547a2b 100644 --- a/src/libxrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanBrokerCoverWithdraw.cpp @@ -1,6 +1,8 @@ #include // -#include +#include +#include +#include #include #include #include diff --git a/src/libxrpl/tx/transactors/lending/LoanBrokerDelete.cpp b/src/libxrpl/tx/transactors/lending/LoanBrokerDelete.cpp index d4eba5939f..b6cf7efb58 100644 --- a/src/libxrpl/tx/transactors/lending/LoanBrokerDelete.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanBrokerDelete.cpp @@ -1,5 +1,7 @@ #include // +#include +#include #include #include diff --git a/src/libxrpl/tx/transactors/lending/LoanBrokerSet.cpp b/src/libxrpl/tx/transactors/lending/LoanBrokerSet.cpp index 14c86eff2e..5a0a6f8d46 100644 --- a/src/libxrpl/tx/transactors/lending/LoanBrokerSet.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanBrokerSet.cpp @@ -1,5 +1,7 @@ #include // +#include +#include #include #include diff --git a/src/libxrpl/tx/transactors/lending/LoanDelete.cpp b/src/libxrpl/tx/transactors/lending/LoanDelete.cpp index c72c85c16c..3c9dae8790 100644 --- a/src/libxrpl/tx/transactors/lending/LoanDelete.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanDelete.cpp @@ -1,5 +1,6 @@ #include // +#include #include #include diff --git a/src/libxrpl/tx/transactors/lending/LoanManage.cpp b/src/libxrpl/tx/transactors/lending/LoanManage.cpp index 5f86417169..8c79171d0e 100644 --- a/src/libxrpl/tx/transactors/lending/LoanManage.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanManage.cpp @@ -1,5 +1,6 @@ #include // +#include #include #include #include @@ -25,7 +26,7 @@ LoanManage::preflight(PreflightContext const& ctx) return temINVALID; // Flags are mutually exclusive - if (auto const flagField = ctx.tx[~sfFlags]; flagField && *flagField) + if (auto const flagField = ctx.tx[~sfFlags]; flagField && (*flagField != 0u)) { auto const flags = *flagField & tfUniversalMask; if ((flags & (flags - 1)) != 0) diff --git a/src/libxrpl/tx/transactors/lending/LoanPay.cpp b/src/libxrpl/tx/transactors/lending/LoanPay.cpp index 2443405d31..c7e680addd 100644 --- a/src/libxrpl/tx/transactors/lending/LoanPay.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanPay.cpp @@ -1,6 +1,7 @@ #include // #include +#include #include #include #include diff --git a/src/libxrpl/tx/transactors/lending/LoanSet.cpp b/src/libxrpl/tx/transactors/lending/LoanSet.cpp index 329b32f123..b424e0763c 100644 --- a/src/libxrpl/tx/transactors/lending/LoanSet.cpp +++ b/src/libxrpl/tx/transactors/lending/LoanSet.cpp @@ -1,5 +1,7 @@ #include // +#include +#include #include #include #include diff --git a/src/libxrpl/tx/transactors/nft/NFTokenAcceptOffer.cpp b/src/libxrpl/tx/transactors/nft/NFTokenAcceptOffer.cpp index ae6e6d423a..05a924cdbc 100644 --- a/src/libxrpl/tx/transactors/nft/NFTokenAcceptOffer.cpp +++ b/src/libxrpl/tx/transactors/nft/NFTokenAcceptOffer.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -343,7 +344,7 @@ NFTokenAcceptOffer::transferNFToken( if (!tokenAndPage) return tecINTERNAL; // LCOV_EXCL_LINE - if (auto const ret = nft::removeToken(view(), seller, nftokenID, std::move(tokenAndPage->page)); + if (auto const ret = nft::removeToken(view(), seller, nftokenID, tokenAndPage->page); !isTesSuccess(ret)) return ret; diff --git a/src/libxrpl/tx/transactors/nft/NFTokenBurn.cpp b/src/libxrpl/tx/transactors/nft/NFTokenBurn.cpp index 6e852b45e1..37c06adae9 100644 --- a/src/libxrpl/tx/transactors/nft/NFTokenBurn.cpp +++ b/src/libxrpl/tx/transactors/nft/NFTokenBurn.cpp @@ -29,7 +29,7 @@ NFTokenBurn::preclaim(PreclaimContext const& ctx) // do so if the token is marked as burnable. if (auto const account = ctx.tx[sfAccount]; owner != account) { - if (!(nft::getFlags(ctx.tx[sfNFTokenID]) & nft::flagBurnable)) + if ((nft::getFlags(ctx.tx[sfNFTokenID]) & nft::flagBurnable) == 0) return tecNO_PERMISSION; if (auto const issuer = nft::getIssuer(ctx.tx[sfNFTokenID]); issuer != account) diff --git a/src/libxrpl/tx/transactors/nft/NFTokenCreateOffer.cpp b/src/libxrpl/tx/transactors/nft/NFTokenCreateOffer.cpp index 4c6c0338d4..48a98490c7 100644 --- a/src/libxrpl/tx/transactors/nft/NFTokenCreateOffer.cpp +++ b/src/libxrpl/tx/transactors/nft/NFTokenCreateOffer.cpp @@ -45,7 +45,7 @@ NFTokenCreateOffer::preclaim(PreclaimContext const& ctx) std::uint32_t const txFlags = ctx.tx.getFlags(); if (!nft::findToken( - ctx.view, ctx.tx[(txFlags & tfSellNFToken) ? sfAccount : sfOwner], nftokenID)) + ctx.view, ctx.tx[((txFlags & tfSellNFToken) != 0u) ? sfAccount : sfOwner], nftokenID)) return tecNO_ENTRY; // Use implementation shared with NFTokenMint diff --git a/src/libxrpl/tx/transactors/nft/NFTokenModify.cpp b/src/libxrpl/tx/transactors/nft/NFTokenModify.cpp index 33863605fb..b4819e250e 100644 --- a/src/libxrpl/tx/transactors/nft/NFTokenModify.cpp +++ b/src/libxrpl/tx/transactors/nft/NFTokenModify.cpp @@ -30,7 +30,7 @@ NFTokenModify::preclaim(PreclaimContext const& ctx) return tecNO_ENTRY; // Check if the NFT is mutable - if (!(nft::getFlags(ctx.tx[sfNFTokenID]) & nft::flagMutable)) + if ((nft::getFlags(ctx.tx[sfNFTokenID]) & nft::flagMutable) == 0) return tecNO_PERMISSION; // Verify permissions for the issuer diff --git a/src/libxrpl/tx/transactors/nft/NFTokenUtils.cpp b/src/libxrpl/tx/transactors/nft/NFTokenUtils.cpp index 40b7171015..6a8b830bf0 100644 --- a/src/libxrpl/tx/transactors/nft/NFTokenUtils.cpp +++ b/src/libxrpl/tx/transactors/nft/NFTokenUtils.cpp @@ -1,6 +1,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -340,7 +344,7 @@ removeToken(ApplyView& view, AccountID const& owner, uint256 const& nftokenID) if (!page) return tecNO_ENTRY; - return removeToken(view, owner, nftokenID, std::move(page)); + return removeToken(view, owner, nftokenID, page); } /** Remove the token from the owner's token directory. */ @@ -597,7 +601,7 @@ removeTokenOffersWithLimit(ApplyView& view, Keylet const& directory, std::size_t if (maxDeletableOffers == deletedOffersCount) break; } - } while (pageIndex.value_or(0) && maxDeletableOffers != deletedOffersCount); + } while ((pageIndex.value_or(0) != 0u) && maxDeletableOffers != deletedOffersCount); return deletedOffersCount; } @@ -643,8 +647,8 @@ deleteTokenOffer(ApplyView& view, std::shared_ptr const& offer) auto const nftokenID = (*offer)[sfNFTokenID]; if (!view.dirRemove( - ((*offer)[sfFlags] & lsfSellNFToken) ? keylet::nft_sells(nftokenID) - : keylet::nft_buys(nftokenID), + (((*offer)[sfFlags] & lsfSellNFToken) != 0u) ? keylet::nft_sells(nftokenID) + : keylet::nft_buys(nftokenID), (*offer)[sfNFTokenOfferNode], offer->key(), false)) @@ -795,7 +799,7 @@ tokenOfferCreatePreflight( if (!isXRP(amount)) { - if (nftFlags & nft::flagOnlyXRP) + if ((nftFlags & nft::flagOnlyXRP) != 0) return temBAD_AMOUNT; if (!amount) @@ -804,7 +808,7 @@ tokenOfferCreatePreflight( // If this is an offer to buy, you must offer something; if it's an // offer to sell, you can ask for nothing. - bool const isSellOffer = txFlags & tfSellNFToken; + bool const isSellOffer = (txFlags & tfSellNFToken) != 0u; if (!isSellOffer && !amount) return temBAD_AMOUNT; @@ -840,7 +844,7 @@ tokenOfferCreatePreclaim( std::optional const& owner, std::uint32_t txFlags) { - if (!(nftFlags & nft::flagCreateTrustLines) && !amount.native() && xferFee) + if (((nftFlags & nft::flagCreateTrustLines) == 0) && !amount.native() && (xferFee != 0u)) { if (!view.exists(keylet::account(nftIssuer))) return tecNO_ISSUER; @@ -862,7 +866,7 @@ tokenOfferCreatePreclaim( return tecFROZEN; } - if (nftIssuer != acctID && !(nftFlags & nft::flagTransferable)) + if (nftIssuer != acctID && ((nftFlags & nft::flagTransferable) == 0)) { auto const root = view.read(keylet::account(nftIssuer)); XRPL_ASSERT(root, "xrpl::nft::tokenOfferCreatePreclaim : non-null account"); @@ -895,7 +899,7 @@ tokenOfferCreatePreclaim( return tecNO_DST; // check if the destination has disallowed incoming offers - if (sleDst->getFlags() & lsfDisallowIncomingNFTokenOffer) + if ((sleDst->getFlags() & lsfDisallowIncomingNFTokenOffer) != 0u) return tecNO_PERMISSION; } @@ -908,7 +912,7 @@ tokenOfferCreatePreclaim( if (!sleOwner) return tecNO_TARGET; - if (sleOwner->getFlags() & lsfDisallowIncomingNFTokenOffer) + if ((sleOwner->getFlags() & lsfDisallowIncomingNFTokenOffer) != 0u) return tecNO_PERMISSION; } @@ -956,7 +960,7 @@ tokenOfferCreateApply( if (!ownerNode) return tecDIR_FULL; // LCOV_EXCL_LINE - bool const isSellOffer = txFlags & tfSellNFToken; + bool const isSellOffer = (txFlags & tfSellNFToken) != 0u; // Token offers are also added to the token's buy or sell offer // directory @@ -1090,7 +1094,8 @@ checkTrustlineDeepFrozen( // There's no difference which side enacted deep freeze, accepting // tokens shouldn't be possible. - bool const deepFrozen = (*trustLine)[sfFlags] & (lsfLowDeepFreeze | lsfHighDeepFreeze); + bool const deepFrozen = + ((*trustLine)[sfFlags] & (lsfLowDeepFreeze | lsfHighDeepFreeze)) != 0u; if (deepFrozen) { diff --git a/src/libxrpl/tx/transactors/oracle/OracleDelete.cpp b/src/libxrpl/tx/transactors/oracle/OracleDelete.cpp index df857c0b31..b7ace79d8e 100644 --- a/src/libxrpl/tx/transactors/oracle/OracleDelete.cpp +++ b/src/libxrpl/tx/transactors/oracle/OracleDelete.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/src/libxrpl/tx/transactors/oracle/OracleSet.cpp b/src/libxrpl/tx/transactors/oracle/OracleSet.cpp index 6b328c6eb6..94cbe32195 100644 --- a/src/libxrpl/tx/transactors/oracle/OracleSet.cpp +++ b/src/libxrpl/tx/transactors/oracle/OracleSet.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include #include @@ -98,7 +100,7 @@ OracleSet::preclaim(PreclaimContext const& ctx) return !v || *v == (*sle)[field]; }; - std::uint32_t adjustReserve = 0; + std::int8_t adjustReserve = 0; if (sle) { // update @@ -234,7 +236,7 @@ OracleSet::doApply() } STArray updatedSeries; for (auto const& iter : pairs) - updatedSeries.push_back(std::move(iter.second)); + updatedSeries.push_back(iter.second); sle->setFieldArray(sfPriceDataSeries, updatedSeries); if (ctx_.tx.isFieldPresent(sfURI)) sle->setFieldVL(sfURI, ctx_.tx[sfURI]); @@ -282,7 +284,7 @@ OracleSet::doApply() pairs.emplace(key, std::move(priceData)); } for (auto const& iter : pairs) - series.push_back(std::move(iter.second)); + series.push_back(iter.second); } sle->setFieldArray(sfPriceDataSeries, series); diff --git a/src/libxrpl/tx/transactors/payment/DepositPreauth.cpp b/src/libxrpl/tx/transactors/payment/DepositPreauth.cpp index 9ef2d966a9..60c0aa586c 100644 --- a/src/libxrpl/tx/transactors/payment/DepositPreauth.cpp +++ b/src/libxrpl/tx/transactors/payment/DepositPreauth.cpp @@ -1,6 +1,8 @@ #include -#include #include +#include +#include +#include #include #include #include @@ -17,10 +19,7 @@ DepositPreauth::checkExtraFeatures(PreflightContext const& ctx) bool const unauthArrPresent = ctx.tx.isFieldPresent(sfUnauthorizeCredentials); bool const authCredPresent = authArrPresent || unauthArrPresent; - if (authCredPresent && !ctx.rules.enabled(featureCredentials)) - return false; - - return true; + return !authCredPresent || ctx.rules.enabled(featureCredentials); } NotTEC @@ -44,7 +43,7 @@ DepositPreauth::preflight(PreflightContext const& ctx) return temMALFORMED; } - if (authPresent) + if (authPresent != 0) { // Make sure that the passed account is valid. AccountID const& target(optAuth ? *optAuth : *optUnauth); diff --git a/src/libxrpl/tx/transactors/payment/Payment.cpp b/src/libxrpl/tx/transactors/payment/Payment.cpp index c9e70f4641..7e97fadfe2 100644 --- a/src/libxrpl/tx/transactors/payment/Payment.cpp +++ b/src/libxrpl/tx/transactors/payment/Payment.cpp @@ -1,8 +1,11 @@ -#include -#include #include +#include +#include +#include +#include #include #include +#include #include #include #include @@ -87,9 +90,9 @@ Payment::preflight(PreflightContext const& ctx) if (mptDirect && ctx.tx.isFieldPresent(sfPaths)) return temMALFORMED; - bool const partialPaymentAllowed = txFlags & tfPartialPayment; - bool const limitQuality = txFlags & tfLimitQuality; - bool const defaultPathsAllowed = !(txFlags & tfNoRippleDirect); + bool const partialPaymentAllowed = (txFlags & tfPartialPayment) != 0u; + bool const limitQuality = (txFlags & tfLimitQuality) != 0u; + bool const defaultPathsAllowed = (txFlags & tfNoRippleDirect) == 0u; bool const hasPaths = tx.isFieldPresent(sfPaths); bool const hasMax = tx.isFieldPresent(sfSendMax); @@ -265,7 +268,7 @@ Payment::preclaim(PreclaimContext const& ctx) { // Ripple if source or destination is non-native or if there are paths. std::uint32_t const txFlags = ctx.tx.getFlags(); - bool const partialPaymentAllowed = txFlags & tfPartialPayment; + bool const partialPaymentAllowed = (txFlags & tfPartialPayment) != 0u; auto const hasPaths = ctx.tx.isFieldPresent(sfPaths); auto const sendMax = ctx.tx[~sfSendMax]; @@ -310,7 +313,9 @@ Payment::preclaim(PreclaimContext const& ctx) return tecNO_DST_INSUF_XRP; } } - else if ((sleDst->getFlags() & lsfRequireDestTag) && !ctx.tx.isFieldPresent(sfDestinationTag)) + else if ( + ((sleDst->getFlags() & lsfRequireDestTag) != 0u) && + !ctx.tx.isFieldPresent(sfDestinationTag)) { // The tag is basically account-specific information we don't // understand, but we can require someone to fill it in. @@ -359,9 +364,9 @@ Payment::doApply() // Ripple if source or destination is non-native or if there are paths. std::uint32_t const txFlags = ctx_.tx.getFlags(); - bool const partialPaymentAllowed = txFlags & tfPartialPayment; - bool const limitQuality = txFlags & tfLimitQuality; - bool const defaultPathsAllowed = !(txFlags & tfNoRippleDirect); + bool const partialPaymentAllowed = (txFlags & tfPartialPayment) != 0u; + bool const limitQuality = (txFlags & tfLimitQuality) != 0u; + bool const defaultPathsAllowed = (txFlags & tfNoRippleDirect) == 0u; auto const hasPaths = ctx_.tx.isFieldPresent(sfPaths); auto const sendMax = ctx_.tx[~sfSendMax]; @@ -429,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* @@ -615,7 +620,7 @@ Payment::doApply() sleDst->setFieldAmount(sfBalance, sleDst->getFieldAmount(sfBalance) + dstAmount); // Re-arm the password change fee if we can and need to. - if ((sleDst->getFlags() & lsfPasswordSpent)) + if ((sleDst->getFlags() & lsfPasswordSpent) != 0u) sleDst->clearFlag(lsfPasswordSpent); return tesSUCCESS; diff --git a/src/libxrpl/tx/transactors/payment_channel/PaymentChannelClaim.cpp b/src/libxrpl/tx/transactors/payment_channel/PaymentChannelClaim.cpp index 02a6635176..d22c907126 100644 --- a/src/libxrpl/tx/transactors/payment_channel/PaymentChannelClaim.cpp +++ b/src/libxrpl/tx/transactors/payment_channel/PaymentChannelClaim.cpp @@ -1,7 +1,6 @@ -#include #include -#include #include +#include #include #include #include @@ -42,7 +41,7 @@ PaymentChannelClaim::preflight(PreflightContext const& ctx) { auto const flags = ctx.tx.getFlags(); - if ((flags & tfClose) && (flags & tfRenew)) + if (((flags & tfClose) != 0u) && ((flags & tfRenew) != 0u)) return temMALFORMED; } @@ -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.get().getJournal("View")); } if (txAccount != src && txAccount != dst) @@ -158,7 +157,7 @@ PaymentChannelClaim::doApply() ctx_.view().update(slep); } - if (ctx_.tx.getFlags() & tfRenew) + if ((ctx_.tx.getFlags() & tfRenew) != 0u) { if (src != txAccount) return tecNO_PERMISSION; @@ -166,11 +165,11 @@ PaymentChannelClaim::doApply() ctx_.view().update(slep); } - if (ctx_.tx.getFlags() & tfClose) + if ((ctx_.tx.getFlags() & tfClose) != 0u) { // 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.get().getJournal("View")); auto const settleExpiration = ctx_.view().header().parentCloseTime.time_since_epoch().count() + diff --git a/src/libxrpl/tx/transactors/payment_channel/PaymentChannelCreate.cpp b/src/libxrpl/tx/transactors/payment_channel/PaymentChannelCreate.cpp index ff7ebbe494..fec4dcd9f4 100644 --- a/src/libxrpl/tx/transactors/payment_channel/PaymentChannelCreate.cpp +++ b/src/libxrpl/tx/transactors/payment_channel/PaymentChannelCreate.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include #include @@ -83,10 +85,10 @@ PaymentChannelCreate::preclaim(PreclaimContext const& ctx) auto const flags = sled->getFlags(); // Check if they have disallowed incoming payment channels - if (flags & lsfDisallowIncomingPayChan) + if ((flags & lsfDisallowIncomingPayChan) != 0u) return tecNO_PERMISSION; - if ((flags & lsfRequireDestTag) && !ctx.tx[~sfDestinationTag]) + if (((flags & lsfRequireDestTag) != 0u) && !ctx.tx[~sfDestinationTag]) return tecDST_TAG_NEEDED; // Pseudo-accounts cannot receive payment channels, other than native diff --git a/src/libxrpl/tx/transactors/payment_channel/PaymentChannelFund.cpp b/src/libxrpl/tx/transactors/payment_channel/PaymentChannelFund.cpp index dde5a97221..fc3330cde5 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.get().getJournal("View")); } if (src != txAccount) diff --git a/src/libxrpl/tx/transactors/payment_channel/PaymentChannelHelpers.cpp b/src/libxrpl/tx/transactors/payment_channel/PaymentChannelHelpers.cpp index 75b68768ed..176b920e6b 100644 --- a/src/libxrpl/tx/transactors/payment_channel/PaymentChannelHelpers.cpp +++ b/src/libxrpl/tx/transactors/payment_channel/PaymentChannelHelpers.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include diff --git a/src/libxrpl/tx/transactors/permissioned_domain/PermissionedDomainDelete.cpp b/src/libxrpl/tx/transactors/permissioned_domain/PermissionedDomainDelete.cpp index e069a3bac0..50d800663c 100644 --- a/src/libxrpl/tx/transactors/permissioned_domain/PermissionedDomainDelete.cpp +++ b/src/libxrpl/tx/transactors/permissioned_domain/PermissionedDomainDelete.cpp @@ -1,4 +1,5 @@ #include +#include #include #include diff --git a/src/libxrpl/tx/transactors/permissioned_domain/PermissionedDomainSet.cpp b/src/libxrpl/tx/transactors/permissioned_domain/PermissionedDomainSet.cpp index 97212f9985..8af2d2c73b 100644 --- a/src/libxrpl/tx/transactors/permissioned_domain/PermissionedDomainSet.cpp +++ b/src/libxrpl/tx/transactors/permissioned_domain/PermissionedDomainSet.cpp @@ -1,7 +1,9 @@ #include // -#include #include +#include +#include +#include #include #include @@ -98,8 +100,6 @@ PermissionedDomainSet::doApply() Keylet const pdKeylet = keylet::permissionedDomain(account_, ctx_.tx.getFieldU32(sfSequence)); auto slePd = std::make_shared(pdKeylet); - if (!slePd) - return tefINTERNAL; // LCOV_EXCL_LINE slePd->setAccountID(sfOwner, account_); slePd->setFieldU32(sfSequence, ctx_.tx.getFieldU32(sfSequence)); diff --git a/src/libxrpl/tx/transactors/system/Batch.cpp b/src/libxrpl/tx/transactors/system/Batch.cpp index 275e10bef9..cac323f637 100644 --- a/src/libxrpl/tx/transactors/system/Batch.cpp +++ b/src/libxrpl/tx/transactors/system/Batch.cpp @@ -270,7 +270,7 @@ Batch::preflight(PreflightContext const& ctx) return temINVALID_INNER_BATCH; } - if (!(stx.getFlags() & tfInnerBatchTxn)) + if ((stx.getFlags() & tfInnerBatchTxn) == 0u) { JLOG(ctx.j.debug()) << "BatchTrace[" << parentBatchId << "]: " << "inner txn must have the tfInnerBatchTxn flag. " @@ -335,7 +335,7 @@ Batch::preflight(PreflightContext const& ctx) } // Duplicate sequence and ticket checks - if (flags & (tfAllOrNothing | tfUntilFailure)) + if ((flags & (tfAllOrNothing | tfUntilFailure)) != 0u) { if (auto const seq = stx.getFieldU32(sfSequence); seq != 0) { diff --git a/src/libxrpl/tx/transactors/system/Change.cpp b/src/libxrpl/tx/transactors/system/Change.cpp index 0087588441..c45dbcb951 100644 --- a/src/libxrpl/tx/transactors/system/Change.cpp +++ b/src/libxrpl/tx/transactors/system/Change.cpp @@ -200,7 +200,7 @@ Change::applyAmendment() entry[sfAmendment] = amendment; entry[sfCloseTime] = view().parentCloseTime().time_since_epoch().count(); - if (!ctx_.registry.getAmendmentTable().isSupported(amendment)) + if (!ctx_.registry.get().getAmendmentTable().isSupported(amendment)) { JLOG(j_.warn()) << "Unsupported amendment " << amendment << " received a majority."; } @@ -211,13 +211,13 @@ Change::applyAmendment() amendments.push_back(amendment); amendmentObject->setFieldV256(sfAmendments, amendments); - ctx_.registry.getAmendmentTable().enable(amendment); + ctx_.registry.get().getAmendmentTable().enable(amendment); - if (!ctx_.registry.getAmendmentTable().isSupported(amendment)) + if (!ctx_.registry.get().getAmendmentTable().isSupported(amendment)) { JLOG(j_.error()) << "Unsupported amendment " << amendment << " activated: server blocked."; - ctx_.registry.getOPs().setAmendmentBlocked(); + ctx_.registry.get().getOPs().setAmendmentBlocked(); } } @@ -292,7 +292,7 @@ Change::applyUNLModify() return tefFAILURE; } - bool const disabling = ctx_.tx.getFieldU8(sfUNLModifyDisabling); + bool const disabling = ctx_.tx.getFieldU8(sfUNLModifyDisabling) != 0u; auto const seq = ctx_.tx.getFieldU32(sfLedgerSequence); if (seq != view().seq()) { diff --git a/src/libxrpl/tx/transactors/system/TicketCreate.cpp b/src/libxrpl/tx/transactors/system/TicketCreate.cpp index ad2cffde52..f3b5b1d537 100644 --- a/src/libxrpl/tx/transactors/system/TicketCreate.cpp +++ b/src/libxrpl/tx/transactors/system/TicketCreate.cpp @@ -1,5 +1,6 @@ -#include #include +#include +#include #include #include #include @@ -69,7 +70,7 @@ TicketCreate::doApply() return tecINSUFFICIENT_RESERVE; } - beast::Journal viewJ{ctx_.registry.journal("View")}; + beast::Journal viewJ{ctx_.registry.get().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/Clawback.cpp b/src/libxrpl/tx/transactors/token/Clawback.cpp index 7777110715..f1f22f51dd 100644 --- a/src/libxrpl/tx/transactors/token/Clawback.cpp +++ b/src/libxrpl/tx/transactors/token/Clawback.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include #include #include @@ -88,7 +90,8 @@ preclaimHelper( // If AllowTrustLineClawback is not set or NoFreeze is set, return no // permission - if (!(issuerFlagsIn & lsfAllowTrustLineClawback) || (issuerFlagsIn & lsfNoFreeze)) + if (((issuerFlagsIn & lsfAllowTrustLineClawback) == 0u) || + ((issuerFlagsIn & lsfNoFreeze) != 0u)) return tecNO_PERMISSION; auto const sleRippleState = @@ -136,7 +139,7 @@ preclaimHelper( if (!sleIssuance) return tecOBJECT_NOT_FOUND; - if (!((*sleIssuance)[sfFlags] & lsfMPTCanClawback)) + if (((*sleIssuance)[sfFlags] & lsfMPTCanClawback) == 0u) return tecNO_PERMISSION; if (sleIssuance->getAccountID(sfIssuer) != issuer) diff --git a/src/libxrpl/tx/transactors/token/MPTokenAuthorize.cpp b/src/libxrpl/tx/transactors/token/MPTokenAuthorize.cpp index 6c6795143d..2897278497 100644 --- a/src/libxrpl/tx/transactors/token/MPTokenAuthorize.cpp +++ b/src/libxrpl/tx/transactors/token/MPTokenAuthorize.cpp @@ -1,4 +1,7 @@ #include +#include +#include +#include #include #include #include @@ -45,7 +48,7 @@ MPTokenAuthorize::preclaim(PreclaimContext const& ctx) // before fetching the MPTIssuance object. // if holder wants to delete/unauthorize a mpt - if (ctx.tx.getFlags() & tfMPTUnauthorize) + if ((ctx.tx.getFlags() & tfMPTUnauthorize) != 0u) { if (!sleMpt) return tecOBJECT_NOT_FOUND; @@ -113,7 +116,7 @@ MPTokenAuthorize::preclaim(PreclaimContext const& ctx) // If tx is submitted by issuer, it only applies for MPT with // lsfMPTRequireAuth set - if (!(mptIssuanceFlags & lsfMPTRequireAuth)) + if ((mptIssuanceFlags & lsfMPTRequireAuth) == 0u) return tecNO_AUTH; // The holder must create the MPT before the issuer can authorize it. diff --git a/src/libxrpl/tx/transactors/token/MPTokenIssuanceCreate.cpp b/src/libxrpl/tx/transactors/token/MPTokenIssuanceCreate.cpp index 34d80e8078..1e6add4f7a 100644 --- a/src/libxrpl/tx/transactors/token/MPTokenIssuanceCreate.cpp +++ b/src/libxrpl/tx/transactors/token/MPTokenIssuanceCreate.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include #include #include @@ -31,8 +33,8 @@ MPTokenIssuanceCreate::preflight(PreflightContext const& ctx) { // If the mutable flags field is included, at least one flag must be // specified. - if (auto const mutableFlags = ctx.tx[~sfMutableFlags]; - mutableFlags && (!*mutableFlags || *mutableFlags & tmfMPTokenIssuanceCreateMutableMask)) + if (auto const mutableFlags = ctx.tx[~sfMutableFlags]; mutableFlags && + ((*mutableFlags == 0u) || ((*mutableFlags & tmfMPTokenIssuanceCreateMutableMask) != 0u))) return temINVALID_FLAG; if (auto const fee = ctx.tx[~sfTransferFee]) diff --git a/src/libxrpl/tx/transactors/token/MPTokenIssuanceDestroy.cpp b/src/libxrpl/tx/transactors/token/MPTokenIssuanceDestroy.cpp index 43ef3dcb8c..0869cafda2 100644 --- a/src/libxrpl/tx/transactors/token/MPTokenIssuanceDestroy.cpp +++ b/src/libxrpl/tx/transactors/token/MPTokenIssuanceDestroy.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/src/libxrpl/tx/transactors/token/MPTokenIssuanceSet.cpp b/src/libxrpl/tx/transactors/token/MPTokenIssuanceSet.cpp index 4d8a56e7d1..dbb7e24f68 100644 --- a/src/libxrpl/tx/transactors/token/MPTokenIssuanceSet.cpp +++ b/src/libxrpl/tx/transactors/token/MPTokenIssuanceSet.cpp @@ -55,7 +55,7 @@ MPTokenIssuanceSet::preflight(PreflightContext const& ctx) auto const txFlags = ctx.tx.getFlags(); // fails if both flags are set - if ((txFlags & tfMPTLock) && (txFlags & tfMPTUnlock)) + if (((txFlags & tfMPTLock) != 0u) && ((txFlags & tfMPTUnlock) != 0u)) return temINVALID_FLAG; auto const accountID = ctx.tx[sfAccount]; @@ -77,7 +77,7 @@ MPTokenIssuanceSet::preflight(PreflightContext const& ctx) return temMALFORMED; // Can not set flags when mutating MPTokenIssuance - if (isMutate && (txFlags & tfUniversalMask)) + if (isMutate && ((txFlags & tfUniversalMask) != 0u)) return temMALFORMED; if (transferFee && *transferFee > maxTransferFee) @@ -88,7 +88,7 @@ MPTokenIssuanceSet::preflight(PreflightContext const& ctx) if (mutableFlags) { - if (!*mutableFlags || (*mutableFlags & tmfMPTokenIssuanceSetMutableMask)) + if ((*mutableFlags == 0u) || ((*mutableFlags & tmfMPTokenIssuanceSetMutableMask) != 0u)) return temINVALID_FLAG; // Can not set and clear the same flag @@ -102,7 +102,7 @@ MPTokenIssuanceSet::preflight(PreflightContext const& ctx) // Trying to set a non-zero TransferFee and clear MPTCanTransfer // in the same transaction is not allowed. - if (transferFee.value_or(0) && (*mutableFlags & tmfMPTClearCanTransfer)) + if ((transferFee.value_or(0) != 0u) && ((*mutableFlags & tmfMPTClearCanTransfer) != 0u)) return temMALFORMED; } } @@ -130,16 +130,16 @@ MPTokenIssuanceSet::checkPermission(ReadView const& view, STTx const& tx) // this is added in case more flags will be added for MPTokenIssuanceSet // in the future. Currently unreachable. - if (txFlags & tfMPTokenIssuanceSetMask) + if ((txFlags & tfMPTokenIssuanceSetMask) != 0u) return terNO_DELEGATE_PERMISSION; // LCOV_EXCL_LINE std::unordered_set granularPermissions; loadGranularPermission(sle, ttMPTOKEN_ISSUANCE_SET, granularPermissions); - if (txFlags & tfMPTLock && !granularPermissions.contains(MPTokenIssuanceLock)) + if (((txFlags & tfMPTLock) != 0u) && !granularPermissions.contains(MPTokenIssuanceLock)) return terNO_DELEGATE_PERMISSION; - if (txFlags & tfMPTUnlock && !granularPermissions.contains(MPTokenIssuanceUnlock)) + if (((txFlags & tfMPTUnlock) != 0u) && !granularPermissions.contains(MPTokenIssuanceUnlock)) return terNO_DELEGATE_PERMISSION; return tesSUCCESS; @@ -258,11 +258,11 @@ MPTokenIssuanceSet::doApply() std::uint32_t const flagsIn = sle->getFieldU32(sfFlags); std::uint32_t flagsOut = flagsIn; - if (txFlags & tfMPTLock) + if ((txFlags & tfMPTLock) != 0u) { flagsOut |= lsfMPTLocked; } - else if (txFlags & tfMPTUnlock) + else if ((txFlags & tfMPTUnlock) != 0u) { flagsOut &= ~lsfMPTLocked; } @@ -271,17 +271,17 @@ MPTokenIssuanceSet::doApply() { for (auto const& f : mptMutabilityFlags) { - if (mutableFlags & f.setFlag) + if ((mutableFlags & f.setFlag) != 0u) { flagsOut |= f.canMutateFlag; } - else if (mutableFlags & f.clearFlag) + else if ((mutableFlags & f.clearFlag) != 0u) { flagsOut &= ~f.canMutateFlag; } } - if (mutableFlags & tmfMPTClearCanTransfer) + if ((mutableFlags & tmfMPTClearCanTransfer) != 0u) { // If the lsfMPTCanTransfer flag is being cleared, then also clear // the TransferFee field. diff --git a/src/libxrpl/tx/transactors/token/TrustSet.cpp b/src/libxrpl/tx/transactors/token/TrustSet.cpp index 77b521c608..44be34604c 100644 --- a/src/libxrpl/tx/transactors/token/TrustSet.cpp +++ b/src/libxrpl/tx/transactors/token/TrustSet.cpp @@ -1,5 +1,6 @@ -#include #include +#include +#include #include #include #include @@ -63,7 +64,7 @@ TrustSet::preflight(PreflightContext const& ctx) { // Even though the deep freeze flags are included in the // `tfTrustSetMask`, they are not valid if the amendment is not enabled. - if (uTxFlags & (tfSetDeepFreeze | tfClearDeepFreeze)) + if ((uTxFlags & (tfSetDeepFreeze | tfClearDeepFreeze)) != 0u) { return temINVALID_FLAG; } @@ -126,7 +127,7 @@ TrustSet::checkPermission(ReadView const& view, STTx const& tx) // Currently we only support TrustlineAuthorize, TrustlineFreeze and // TrustlineUnfreeze granular permission. Setting other flags returns // error. - if (txFlags & tfTrustSetPermissionMask) + if ((txFlags & tfTrustSetPermissionMask) != 0u) return terNO_DELEGATE_PERMISSION; if (tx.isFieldPresent(sfQualityIn) || tx.isFieldPresent(sfQualityOut)) @@ -144,11 +145,11 @@ TrustSet::checkPermission(ReadView const& view, STTx const& tx) std::unordered_set granularPermissions; loadGranularPermission(sle, ttTRUST_SET, granularPermissions); - if (txFlags & tfSetfAuth && !granularPermissions.contains(TrustlineAuthorize)) + if (((txFlags & tfSetfAuth) != 0u) && !granularPermissions.contains(TrustlineAuthorize)) return terNO_DELEGATE_PERMISSION; - if (txFlags & tfSetFreeze && !granularPermissions.contains(TrustlineFreeze)) + if (((txFlags & tfSetFreeze) != 0u) && !granularPermissions.contains(TrustlineFreeze)) return terNO_DELEGATE_PERMISSION; - if (txFlags & tfClearFreeze && !granularPermissions.contains(TrustlineUnfreeze)) + if (((txFlags & tfClearFreeze) != 0u) && !granularPermissions.contains(TrustlineUnfreeze)) return terNO_DELEGATE_PERMISSION; // updating LimitAmount is not allowed only with granular permissions, @@ -177,9 +178,9 @@ TrustSet::preclaim(PreclaimContext const& ctx) std::uint32_t const uTxFlags = ctx.tx.getFlags(); - bool const bSetAuth = (uTxFlags & tfSetfAuth); + bool const bSetAuth = (uTxFlags & tfSetfAuth) != 0u; - if (bSetAuth && !(sle->getFieldU32(sfFlags) & lsfRequireAuth)) + if (bSetAuth && ((sle->getFieldU32(sfFlags) & lsfRequireAuth) == 0u)) { JLOG(ctx.j.trace()) << "Retry: Auth not required."; return tefNO_AUTH_REQUIRED; @@ -201,7 +202,7 @@ TrustSet::preclaim(PreclaimContext const& ctx) // If the destination has opted to disallow incoming trustlines // then honour that flag - if (sleDst->getFlags() & lsfDisallowIncomingTrustline) + if ((sleDst->getFlags() & lsfDisallowIncomingTrustline) != 0u) { // The original implementation of featureDisallowIncoming was // too restrictive. If @@ -266,8 +267,8 @@ TrustSet::preclaim(PreclaimContext const& ctx) if (ctx.view.rules().enabled(featureDeepFreeze)) { bool const bNoFreeze = sle->isFlag(lsfNoFreeze); - bool const bSetFreeze = (uTxFlags & tfSetFreeze); - bool const bSetDeepFreeze = (uTxFlags & tfSetDeepFreeze); + bool const bSetFreeze = (uTxFlags & tfSetFreeze) != 0u; + bool const bSetDeepFreeze = (uTxFlags & tfSetDeepFreeze) != 0u; if (bNoFreeze && (bSetFreeze || bSetDeepFreeze)) { @@ -275,8 +276,8 @@ TrustSet::preclaim(PreclaimContext const& ctx) return tecNO_PERMISSION; } - bool const bClearFreeze = (uTxFlags & tfClearFreeze); - bool const bClearDeepFreeze = (uTxFlags & tfClearDeepFreeze); + bool const bClearFreeze = (uTxFlags & tfClearFreeze) != 0u; + bool const bClearDeepFreeze = (uTxFlags & tfClearDeepFreeze) != 0u; if ((bSetFreeze || bSetDeepFreeze) && (bClearFreeze || bClearDeepFreeze)) { // Freezing and unfreezing in the same transaction should be @@ -298,7 +299,7 @@ TrustSet::preclaim(PreclaimContext const& ctx) // Trying to set deep freeze on not already frozen trust line must // fail. This also checks that clearing normal freeze while deep // frozen must not work - if (deepFrozen && !frozen) + if ((deepFrozen != 0u) && (frozen == 0u)) { return tecNO_PERMISSION; } @@ -357,15 +358,15 @@ TrustSet::doApply() std::uint32_t const uTxFlags = ctx_.tx.getFlags(); - bool const bSetAuth = (uTxFlags & tfSetfAuth); - bool const bSetNoRipple = (uTxFlags & tfSetNoRipple); - bool const bClearNoRipple = (uTxFlags & tfClearNoRipple); - bool const bSetFreeze = (uTxFlags & tfSetFreeze); - bool const bClearFreeze = (uTxFlags & tfClearFreeze); - bool const bSetDeepFreeze = (uTxFlags & tfSetDeepFreeze); - bool const bClearDeepFreeze = (uTxFlags & tfClearDeepFreeze); + bool const bSetAuth = (uTxFlags & tfSetfAuth) != 0u; + bool const bSetNoRipple = (uTxFlags & tfSetNoRipple) != 0u; + bool const bClearNoRipple = (uTxFlags & tfClearNoRipple) != 0u; + bool const bSetFreeze = (uTxFlags & tfSetFreeze) != 0u; + bool const bClearFreeze = (uTxFlags & tfClearFreeze) != 0u; + bool const bSetDeepFreeze = (uTxFlags & tfSetDeepFreeze) != 0u; + bool const bClearDeepFreeze = (uTxFlags & tfClearDeepFreeze) != 0u; - auto viewJ = ctx_.registry.journal("View"); + auto viewJ = ctx_.registry.get().getJournal("View"); SLE::pointer sleDst = view().peek(keylet::account(uDstAccountID)); @@ -422,7 +423,7 @@ TrustSet::doApply() uLowQualityIn = sleRippleState->getFieldU32(sfLowQualityIn); uHighQualityIn = sleRippleState->getFieldU32(sfHighQualityIn); } - else if (uQualityIn) + else if (uQualityIn != 0u) { // Setting. @@ -458,7 +459,7 @@ TrustSet::doApply() uLowQualityOut = sleRippleState->getFieldU32(sfLowQualityOut); uHighQualityOut = sleRippleState->getFieldU32(sfHighQualityOut); } - else if (uQualityOut) + else if (uQualityOut != 0u) { // Setting. @@ -514,23 +515,23 @@ TrustSet::doApply() if (QUALITY_ONE == uHighQualityOut) uHighQualityOut = 0; - bool const bLowDefRipple = sleLowAccount->getFlags() & lsfDefaultRipple; - bool const bHighDefRipple = sleHighAccount->getFlags() & lsfDefaultRipple; + bool const bLowDefRipple = (sleLowAccount->getFlags() & lsfDefaultRipple) != 0u; + bool const bHighDefRipple = (sleHighAccount->getFlags() & lsfDefaultRipple) != 0u; - bool const bLowReserveSet = uLowQualityIn || uLowQualityOut || - ((uFlagsOut & lsfLowNoRipple) == 0) != bLowDefRipple || (uFlagsOut & lsfLowFreeze) || - saLowLimit || saLowBalance > beast::zero; + bool const bLowReserveSet = (uLowQualityIn != 0u) || (uLowQualityOut != 0u) || + ((uFlagsOut & lsfLowNoRipple) == 0) != bLowDefRipple || + ((uFlagsOut & lsfLowFreeze) != 0u) || saLowLimit || saLowBalance > beast::zero; bool const bLowReserveClear = !bLowReserveSet; - bool const bHighReserveSet = uHighQualityIn || uHighQualityOut || - ((uFlagsOut & lsfHighNoRipple) == 0) != bHighDefRipple || (uFlagsOut & lsfHighFreeze) || - saHighLimit || saHighBalance > beast::zero; + bool const bHighReserveSet = (uHighQualityIn != 0u) || (uHighQualityOut != 0u) || + ((uFlagsOut & lsfHighNoRipple) == 0) != bHighDefRipple || + ((uFlagsOut & lsfHighFreeze) != 0u) || saHighLimit || saHighBalance > beast::zero; bool const bHighReserveClear = !bHighReserveSet; bool const bDefault = bLowReserveClear && bHighReserveClear; - bool const bLowReserved = (uFlagsIn & lsfLowReserve); - bool const bHighReserved = (uFlagsIn & lsfHighReserve); + bool const bLowReserved = (uFlagsIn & lsfLowReserve) != 0u; + bool const bHighReserved = (uFlagsIn & lsfHighReserve) != 0u; bool bReserveIncrease = false; @@ -601,11 +602,11 @@ TrustSet::doApply() } // Line does not exist. else if ( - !saLimitAmount && // Setting default limit. - (!bQualityIn || !uQualityIn) && // Not setting quality in or - // setting default quality in. - (!bQualityOut || !uQualityOut) && // Not setting quality out or - // setting default quality out. + !saLimitAmount && // Setting default limit. + (!bQualityIn || (uQualityIn == 0u)) && // Not setting quality in or + // setting default quality in. + (!bQualityOut || (uQualityOut == 0u)) && // Not setting quality out or + // setting default quality out. (!bSetAuth)) { JLOG(j_.trace()) << "Redundant: Setting non-existent ripple line to defaults."; diff --git a/src/libxrpl/tx/transactors/vault/VaultClawback.cpp b/src/libxrpl/tx/transactors/vault/VaultClawback.cpp index 0a661250c0..8251cfc566 100644 --- a/src/libxrpl/tx/transactors/vault/VaultClawback.cpp +++ b/src/libxrpl/tx/transactors/vault/VaultClawback.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include #include diff --git a/src/libxrpl/tx/transactors/vault/VaultCreate.cpp b/src/libxrpl/tx/transactors/vault/VaultCreate.cpp index 0b27324ce5..669a1e0f6d 100644 --- a/src/libxrpl/tx/transactors/vault/VaultCreate.cpp +++ b/src/libxrpl/tx/transactors/vault/VaultCreate.cpp @@ -1,4 +1,7 @@ #include +#include +#include +#include #include #include #include @@ -162,7 +165,7 @@ VaultCreate::doApply() std::uint32_t mptFlags = 0; if ((txFlags & tfVaultShareNonTransferable) == 0) mptFlags |= (lsfMPTCanEscrow | lsfMPTCanTrade | lsfMPTCanTransfer); - if (txFlags & tfVaultPrivate) + if ((txFlags & tfVaultPrivate) != 0u) mptFlags |= lsfMPTRequireAuth; // Note, here we are **not** creating an MPToken for the assets held in @@ -208,7 +211,7 @@ VaultCreate::doApply() { vault->at(sfWithdrawalPolicy) = vaultStrategyFirstComeFirstServe; } - if (scale) + if (scale != 0u) vault->at(sfScale) = scale; view().insert(vault); @@ -219,7 +222,7 @@ VaultCreate::doApply() return err; // If the vault is private, set the authorized flag for the vault owner - if (txFlags & tfVaultPrivate) + if ((txFlags & tfVaultPrivate) != 0u) { if (auto const err = authorizeMPToken( view(), preFeeBalance_, mptIssuanceID, pseudoId, ctx_.journal, {}, account_); diff --git a/src/libxrpl/tx/transactors/vault/VaultDelete.cpp b/src/libxrpl/tx/transactors/vault/VaultDelete.cpp index dc689f89a4..232a11d129 100644 --- a/src/libxrpl/tx/transactors/vault/VaultDelete.cpp +++ b/src/libxrpl/tx/transactors/vault/VaultDelete.cpp @@ -1,4 +1,7 @@ #include +#include +#include +#include #include #include #include @@ -52,7 +55,7 @@ VaultDelete::preclaim(PreclaimContext const& ctx) if (!sleMPT) { // LCOV_EXCL_START - JLOG(ctx.j.error()) << "VaultDeposit: missing issuance of vault shares."; + JLOG(ctx.j.error()) << "VaultDelete: missing issuance of vault shares."; return tecOBJECT_NOT_FOUND; // LCOV_EXCL_STOP } @@ -60,7 +63,7 @@ VaultDelete::preclaim(PreclaimContext const& ctx) if (sleMPT->at(sfIssuer) != vault->getAccountID(sfAccount)) { // LCOV_EXCL_START - JLOG(ctx.j.error()) << "VaultDeposit: invalid owner of vault shares."; + JLOG(ctx.j.error()) << "VaultDelete: invalid owner of vault shares."; return tecNO_PERMISSION; // LCOV_EXCL_STOP } @@ -197,8 +200,6 @@ VaultDelete::doApply() // Destroy the vault. view().erase(vault); - associateAsset(*vault, asset); - return tesSUCCESS; } diff --git a/src/libxrpl/tx/transactors/vault/VaultDeposit.cpp b/src/libxrpl/tx/transactors/vault/VaultDeposit.cpp index 32c76fc071..c4d4ba361f 100644 --- a/src/libxrpl/tx/transactors/vault/VaultDeposit.cpp +++ b/src/libxrpl/tx/transactors/vault/VaultDeposit.cpp @@ -1,5 +1,8 @@ -#include #include +#include +#include +#include +#include #include #include #include diff --git a/src/libxrpl/tx/transactors/vault/VaultSet.cpp b/src/libxrpl/tx/transactors/vault/VaultSet.cpp index 2b55db14a3..056792a1f4 100644 --- a/src/libxrpl/tx/transactors/vault/VaultSet.cpp +++ b/src/libxrpl/tx/transactors/vault/VaultSet.cpp @@ -14,10 +14,7 @@ namespace xrpl { bool VaultSet::checkExtraFeatures(PreflightContext const& ctx) { - if (ctx.tx.isFieldPresent(sfDomainID) && !ctx.rules.enabled(featurePermissionedDomains)) - return false; - - return true; + return !ctx.tx.isFieldPresent(sfDomainID) || ctx.rules.enabled(featurePermissionedDomains); } NotTEC diff --git a/src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp b/src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp index 8c675d4269..932c5b29b9 100644 --- a/src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp +++ b/src/libxrpl/tx/transactors/vault/VaultWithdraw.cpp @@ -1,5 +1,7 @@ -#include #include +#include +#include +#include #include #include #include diff --git a/src/test/app/AMMCalc_test.cpp b/src/test/app/AMMCalc_test.cpp index c1068b08ba..b4043f239b 100644 --- a/src/test/app/AMMCalc_test.cpp +++ b/src/test/app/AMMCalc_test.cpp @@ -40,7 +40,7 @@ class AMMCalc_test : public beast::unit_test::suite boost::regex rx("^([^(]+)[(]([^)]+)[)]([)])?$"); if (boost::regex_search(str, match, rx)) { - if (delimited) + if (delimited != nullptr) *delimited = (match[3] != ""); if (match[1] == "XRP") { @@ -72,7 +72,7 @@ class AMMCalc_test : public beast::unit_test::suite // input is rate * 100, no fraction std::uint32_t rate = 10'000'000 * std::stoi(match[2].str()); // true if delimited - ) - return {{currency, rate, match[3] != "" ? true : false}}; + return {{currency, rate, match[3] != ""}}; } return std::nullopt; } @@ -94,7 +94,7 @@ class AMMCalc_test : public beast::unit_test::suite if (p == end_) return std::nullopt; std::string const s = *p; - bool const amm = s[0] == 'O' ? false : true; + bool const amm = s[0] != 'O'; auto const a1 = getAmt(p++); if (!a1 || p == end_) return std::nullopt; @@ -161,7 +161,7 @@ class AMMCalc_test : public beast::unit_test::suite return {{pairs, *swap, *rate, fee}}; } - std::string + static std::string toString(STAmount const& a) { std::stringstream str; @@ -169,7 +169,7 @@ class AMMCalc_test : public beast::unit_test::suite return str.str(); } - STAmount + static STAmount mulratio(STAmount const& amt, std::uint32_t a, std::uint32_t b, bool round) { if (a == b) @@ -179,7 +179,7 @@ class AMMCalc_test : public beast::unit_test::suite return toSTAmount(mulRatio(amt.iou(), a, b, round), amt.issue()); } - void + static void swapOut(swapargs const& args) { auto const vp = std::get(args); @@ -242,7 +242,7 @@ class AMMCalc_test : public beast::unit_test::suite std::cout << "in: " << toString(resultIn) << " out: " << toString(resultOut) << std::endl; } - void + static void swapIn(swapargs const& args) { auto const vp = std::get(args); 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/AMM_test.cpp b/src/test/app/AMM_test.cpp index f84253588c..704ced2b86 100644 --- a/src/test/app/AMM_test.cpp +++ b/src/test/app/AMM_test.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -1917,7 +1918,7 @@ private: BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount(beast::Zero()))); BEAST_EXPECT(expectHolding(env, carol, USD(30'000))); BEAST_EXPECT( - expectLedgerEntryRoot(env, carol, XRPAmount{30'000'000'000 - 2 * baseFee})); + expectLedgerEntryRoot(env, carol, XRPAmount{30'000'000'000 - (2 * baseFee)})); }); // Equal withdrawal by tokens 1000000, 10% @@ -2731,13 +2732,13 @@ private: // 10th Interval after close, price for 1st interval. env(ammAlice.bid({.account = carol})); - env.close(seconds(10 * AUCTION_SLOT_INTERVAL_DURATION + 1)); + env.close(seconds((10 * AUCTION_SLOT_INTERVAL_DURATION) + 1)); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 10, IOUAmount{121'275, -3})); // 20th Interval (expired) after close, price for 10th interval. env(ammAlice.bid({.account = bob})); env.close( - seconds(AUCTION_SLOT_TIME_INTERVALS * AUCTION_SLOT_INTERVAL_DURATION + 1)); + seconds((AUCTION_SLOT_TIME_INTERVALS * AUCTION_SLOT_INTERVAL_DURATION) + 1)); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, std::nullopt, IOUAmount{127'33875, -5})); // 0 Interval. @@ -4110,7 +4111,7 @@ private: fund(env, gw, {bob}, {EUR(400)}, Fund::IOUOnly); env(trust(alice, EUR(200))); for (int i = 0; i < 30; ++i) - env(offer(alice, EUR(1.0 + 0.01 * i), XRP(1))); + env(offer(alice, EUR(1.0 + (0.01 * i)), XRP(1))); // This is worse quality offer than 30 offers above. // It will not be consumed because of AMM offers limit. env(offer(alice, EUR(140), XRP(100))); @@ -4150,7 +4151,7 @@ private: fund(env, gw, {bob}, {EUR(400)}, Fund::IOUOnly); env(trust(alice, EUR(200))); for (int i = 0; i < 29; ++i) - env(offer(alice, EUR(1.0 + 0.01 * i), XRP(1))); + env(offer(alice, EUR(1.0 + (0.01 * i)), XRP(1))); // This is worse quality offer than 30 offers above. // It will not be consumed because of AMM offers limit. env(offer(alice, EUR(140), XRP(100))); @@ -4267,7 +4268,7 @@ private: env(ammAlice.bid({.account = carol, .bidMin = 100})); BEAST_EXPECT(ammAlice.expectLPTokens(carol, IOUAmount{4'999'900})); BEAST_EXPECT(ammAlice.expectAuctionSlot(0, 0, IOUAmount{100})); - BEAST_EXPECT(accountBalance(env, carol) == std::to_string(22500000000 - 4 * baseFee)); + BEAST_EXPECT(accountBalance(env, carol) == std::to_string(22500000000 - (4 * baseFee))); priceXRP = ammAssetOut( STAmount{XRPAmount{10'000'000'000}}, STAmount{token1, 9'999'900}, @@ -4275,7 +4276,7 @@ private: 0); // Carol withdraws ammAlice.withdrawAll(carol, XRP(0)); - BEAST_EXPECT(accountBalance(env, carol) == std::to_string(29999949999 - 5 * baseFee)); + BEAST_EXPECT(accountBalance(env, carol) == std::to_string(29999949999 - (5 * baseFee))); BEAST_EXPECT(ammAlice.expectBalances( XRPAmount{10'000'000'000} - priceXRP, USD(10'000), IOUAmount{5'000'000})); BEAST_EXPECT(ammAlice.expectLPTokens(alice, IOUAmount{5'000'000})); @@ -5039,7 +5040,7 @@ private: // 30,000 initial - (deposit+withdraw) * 10 BEAST_EXPECT( accountBalance(env, carol) == - std::to_string(30'000'000'000 - 20 * baseFee)); + std::to_string(30'000'000'000 - (20 * baseFee))); BEAST_EXPECT(accountBalance(env, ed) == xrpBalance); BEAST_EXPECT(accountBalance(env, paul) == xrpBalance); BEAST_EXPECT(accountBalance(env, natalie) == xrpBalance); @@ -5063,7 +5064,7 @@ private: BEAST_EXPECT(accountBalance(env, dan) == xrpBalanceText); BEAST_EXPECT( accountBalance(env, carol) == - std::to_string(30'000'000'000 - 20 * baseFee - 10)); + std::to_string(30'000'000'000 - (20 * baseFee) - 10)); BEAST_EXPECT(accountBalance(env, ed) == (xrpBalance + drops(2)).getText()); BEAST_EXPECT(accountBalance(env, paul) == (xrpBalance + drops(3)).getText()); BEAST_EXPECT(accountBalance(env, natalie) == (xrpBalance + drops(5)).getText()); @@ -5154,7 +5155,7 @@ private: all); fund(env, gw, {alice}, XRP(20'000), {USD(10'000)}); AMM amm(env, gw, XRP(10'000), USD(10'000)); - for (auto i = 0; i < maxDeletableAMMTrustLines * 2 + 10; ++i) + for (auto i = 0; i < (maxDeletableAMMTrustLines * 2) + 10; ++i) { Account const a{std::to_string(i)}; env.fund(XRP(1'000), a); diff --git a/src/test/app/AccountSet_test.cpp b/src/test/app/AccountSet_test.cpp index cfd7262a50..748f276433 100644 --- a/src/test/app/AccountSet_test.cpp +++ b/src/test/app/AccountSet_test.cpp @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -402,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) @@ -551,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/AccountTxPaging_test.cpp b/src/test/app/AccountTxPaging_test.cpp index 5efe307812..09b517c37c 100644 --- a/src/test/app/AccountTxPaging_test.cpp +++ b/src/test/app/AccountTxPaging_test.cpp @@ -10,7 +10,7 @@ namespace xrpl { class AccountTxPaging_test : public beast::unit_test::suite { - bool + static bool checkTransaction(Json::Value const& tx, int sequence, int ledger) { return ( @@ -18,7 +18,7 @@ class AccountTxPaging_test : public beast::unit_test::suite tx[jss::tx][jss::ledger_index].asInt() == ledger); } - auto + static auto next( test::jtx::Env& env, test::jtx::Account const& account, diff --git a/src/test/app/AmendmentTable_test.cpp b/src/test/app/AmendmentTable_test.cpp index d8431e5696..39e516304b 100644 --- a/src/test/app/AmendmentTable_test.cpp +++ b/src/test/app/AmendmentTable_test.cpp @@ -439,7 +439,7 @@ public: // Make a list of trusted validators. // Register the validators with AmendmentTable and return the list. - std::vector> + static std::vector> makeValidators(int num, std::unique_ptr const& table) { std::vector> ret; @@ -462,7 +462,7 @@ public: } // Execute a pretend consensus round for a flag ledger - void + static void doRound( Rules const& rules, AmendmentTable& table, diff --git a/src/test/app/Batch_test.cpp b/src/test/app/Batch_test.cpp index ec12fbb21f..a548eb6b49 100644 --- a/src/test/app/Batch_test.cpp +++ b/src/test/app/Batch_test.cpp @@ -35,7 +35,7 @@ class Batch_test : public beast::unit_test::suite std::string txHash; }; - Json::Value + static Json::Value getTxByIndex(Json::Value const& jrr, int const index) { for (auto const& txn : jrr[jss::result][jss::ledger][jss::transactions]) @@ -46,7 +46,7 @@ class Batch_test : public beast::unit_test::suite return {}; } - Json::Value + static Json::Value getLastLedger(jtx::Env& env) { Json::Value params; @@ -93,6 +93,7 @@ class Batch_test : public beast::unit_test::suite auto const ids = batchTxn.stx->getBatchTransactionIDs(); std::vector txIDs; + txIDs.reserve(ids.size()); for (auto const& id : ids) txIDs.push_back(strHex(id)); TxID const batchID = batchTxn.stx->getTransactionID(); @@ -125,7 +126,7 @@ class Batch_test : public beast::unit_test::suite return p; } - auto + static auto openLedgerFee(jtx::Env& env, XRPAmount const& batchFee) { using namespace jtx; @@ -1379,7 +1380,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 +1423,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 +3628,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/Check_test.cpp b/src/test/app/Check_test.cpp index f8bb0ddcf2..671f8aab1a 100644 --- a/src/test/app/Check_test.cpp +++ b/src/test/app/Check_test.cpp @@ -1,5 +1,6 @@ #include +#include #include #include diff --git a/src/test/app/Credentials_test.cpp b/src/test/app/Credentials_test.cpp index 3c3d8b6df8..db09bfc0ca 100644 --- a/src/test/app/Credentials_test.cpp +++ b/src/test/app/Credentials_test.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include @@ -522,6 +522,7 @@ struct Credentials_test : public beast::unit_test::suite directory::adjustOwnerNode); BEAST_EXPECT(res1); + // NOLINTNEXTLINE(readability-suspicious-call-argument) auto const jv = credentials::create(issuer, subject, credType); env(jv, ter(tecDIR_FULL)); // Free one directory entry by using a ticket diff --git a/src/test/app/DepositAuth_test.cpp b/src/test/app/DepositAuth_test.cpp index ad401499bc..7a8404aad8 100644 --- a/src/test/app/DepositAuth_test.cpp +++ b/src/test/app/DepositAuth_test.cpp @@ -304,9 +304,11 @@ struct DepositAuth_test : public beast::unit_test::suite auto const noRipplePrev = i & 0x1; auto const noRippleNext = i & 0x2; auto const withDepositAuth = i & 0x4; - testIssuer(testable_amendments(), noRipplePrev, noRippleNext, withDepositAuth); + testIssuer( + testable_amendments(), noRipplePrev != 0, noRippleNext != 0, withDepositAuth != 0); - testNonIssuer(testable_amendments(), noRipplePrev, noRippleNext, withDepositAuth); + testNonIssuer( + testable_amendments(), noRipplePrev != 0, noRippleNext != 0, withDepositAuth != 0); } } diff --git a/src/test/app/EscrowToken_test.cpp b/src/test/app/EscrowToken_test.cpp index 280356c494..619b584ddb 100644 --- a/src/test/app/EscrowToken_test.cpp +++ b/src/test/app/EscrowToken_test.cpp @@ -35,7 +35,7 @@ struct EscrowToken_test : public beast::unit_test::suite return 0; } - jtx::PrettyAmount + static jtx::PrettyAmount issuerBalance(jtx::Env& env, jtx::Account const& account, Issue const& issue) { Json::Value params; @@ -49,7 +49,7 @@ struct EscrowToken_test : public beast::unit_test::suite return {amount, account.name()}; } - jtx::PrettyAmount + static jtx::PrettyAmount issuerEscrowed(jtx::Env& env, jtx::Account const& account, Issue const& issue) { Json::Value params; @@ -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 f4b8c1874c..3c84f9e007 100644 --- a/src/test/app/FeeVote_test.cpp +++ b/src/test/app/FeeVote_test.cpp @@ -1,10 +1,9 @@ #include -#include #include #include -#include +#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,14 +664,14 @@ 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}); v.setFieldAmount(sfReserveBaseDrops, XRPAmount{setup.account_reserve}); v.setFieldAmount(sfReserveIncrementDrops, XRPAmount{setup.owner_reserve}); }); - if (i % 2) + if ((i % 2) != 0) val->setTrusted(); validations.push_back(val); } diff --git a/src/test/app/FixNFTokenPageLinks_test.cpp b/src/test/app/FixNFTokenPageLinks_test.cpp index 8022c52a5d..25366534cd 100644 --- a/src/test/app/FixNFTokenPageLinks_test.cpp +++ b/src/test/app/FixNFTokenPageLinks_test.cpp @@ -62,7 +62,7 @@ class FixNFTokenPageLinks_test : public beast::unit_test::suite // 0, 3, 2, 5, 4, 7... // in sets of 16 NFTs we can get each page to be fully // populated. - std::uint32_t const intTaxon = (i / 16) + (i & 0b10000 ? 2 : 0); + std::uint32_t const intTaxon = (i / 16) + (((i & 0b10000) != 0u) ? 2 : 0); uint32_t const extTaxon = internalTaxon(owner, intTaxon); nfts.push_back(token::getNextID(env, owner, extTaxon, tfTransferable)); env(token::mint(owner, extTaxon), txflags(tfTransferable)); diff --git a/src/test/app/Flow_test.cpp b/src/test/app/Flow_test.cpp index 692d9d2b50..25bcb4ee64 100644 --- a/src/test/app/Flow_test.cpp +++ b/src/test/app/Flow_test.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -240,7 +241,7 @@ struct Flow_test : public beast::unit_test::suite env.require(balance(bob, USDA(10))); env(pay(bob, carol, USDA(5)), sendmax(USDA(10))); auto const effectiveQ = carolAliceQIn > 100 ? 1.0 : carolAliceQIn / 100.0; - env.require(balance(bob, USDA(10.0 - 5.0 / effectiveQ))); + env.require(balance(bob, USDA(10.0 - (5.0 / effectiveQ)))); } // bob -> alice -> carol; bobAliceQOut varies. @@ -434,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)); @@ -473,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/Freeze_test.cpp b/src/test/app/Freeze_test.cpp index 6f89163c04..1dd0de578b 100644 --- a/src/test/app/Freeze_test.cpp +++ b/src/test/app/Freeze_test.cpp @@ -1907,13 +1907,13 @@ class Freeze_test : public beast::unit_test::suite } // Helper function that returns the index of the next check on account - uint256 + static uint256 getCheckIndex(AccountID const& account, std::uint32_t uSequence) { return keylet::check(account, uSequence).key; } - uint256 + static uint256 createNFTSellOffer( test::jtx::Env& env, test::jtx::Account const& account, diff --git a/src/test/app/HashRouter_test.cpp b/src/test/app/HashRouter_test.cpp index 58bace3ef2..a1601914cf 100644 --- a/src/test/app/HashRouter_test.cpp +++ b/src/test/app/HashRouter_test.cpp @@ -10,7 +10,7 @@ namespace test { class HashRouter_test : public beast::unit_test::suite { - HashRouter::Setup + static HashRouter::Setup getSetup(std::chrono::seconds hold, std::chrono::seconds relay) { HashRouter::Setup setup; diff --git a/src/test/app/Invariants_test.cpp b/src/test/app/Invariants_test.cpp index 008903f725..c1d8003038 100644 --- a/src/test/app/Invariants_test.cpp +++ b/src/test/app/Invariants_test.cpp @@ -4,6 +4,9 @@ #include #include +#include +#include +#include #include #include #include @@ -1204,7 +1207,7 @@ class Invariants_test : public beast::unit_test::suite STArray nfTokens = makeNFTokenIDs(1); auto nftPage = std::make_shared(keylet::nftpage( keylet::nftpage_max(A1), ++(nfTokens[0].getFieldH256(sfNFTokenID)))); - nftPage->setFieldArray(sfNFTokens, std::move(nfTokens)); + nftPage->setFieldArray(sfNFTokens, nfTokens); nftPage->setFieldH256(sfNextPageMin, keylet::nftpage_max(A2).key); ac.view().insert(nftPage); @@ -1217,7 +1220,7 @@ class Invariants_test : public beast::unit_test::suite STArray nfTokens = makeNFTokenIDs(2); auto nftPage = std::make_shared(keylet::nftpage( keylet::nftpage_max(A1), (nfTokens[1].getFieldH256(sfNFTokenID)))); - nftPage->setFieldArray(sfNFTokens, std::move(nfTokens)); + nftPage->setFieldArray(sfNFTokens, nfTokens); ac.view().insert(nftPage); return true; @@ -1238,7 +1241,7 @@ class Invariants_test : public beast::unit_test::suite sle->setAccountID(sfOwner, A1); sle->setFieldU32(sfSequence, seq); - if (numCreds) + if (numCreds != 0u) { // This array is sorted naturally, but if you willing to change this // behavior don't forget to use credentials::makeSorted 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/LedgerLoad_test.cpp b/src/test/app/LedgerLoad_test.cpp index 46c372923e..2fa1193921 100644 --- a/src/test/app/LedgerLoad_test.cpp +++ b/src/test/app/LedgerLoad_test.cpp @@ -109,7 +109,7 @@ class LedgerLoad_test : public beast::unit_test::suite // create a new env with the ledger file specified for startup Env env( *this, - envconfig(ledgerConfig, sd.dbPath, sd.ledgerFile, StartUpType::LOAD_FILE, std::nullopt), + envconfig(ledgerConfig, sd.dbPath, sd.ledgerFile, StartUpType::LoadFile, std::nullopt), nullptr, beast::severities::kDisabled); auto jrb = env.rpc("ledger", "current", "full")[jss::result]; @@ -129,7 +129,7 @@ class LedgerLoad_test : public beast::unit_test::suite except([&] { Env env( *this, - envconfig(ledgerConfig, sd.dbPath, "", StartUpType::LOAD_FILE, std::nullopt), + envconfig(ledgerConfig, sd.dbPath, "", StartUpType::LoadFile, std::nullopt), nullptr, beast::severities::kDisabled); }); @@ -139,7 +139,7 @@ class LedgerLoad_test : public beast::unit_test::suite Env env( *this, envconfig( - ledgerConfig, sd.dbPath, "badfile.json", StartUpType::LOAD_FILE, std::nullopt), + ledgerConfig, sd.dbPath, "badfile.json", StartUpType::LoadFile, std::nullopt), nullptr, beast::severities::kDisabled); }); @@ -164,7 +164,7 @@ class LedgerLoad_test : public beast::unit_test::suite ledgerConfig, sd.dbPath, ledgerFileCorrupt.string(), - StartUpType::LOAD_FILE, + StartUpType::LoadFile, std::nullopt), nullptr, beast::severities::kDisabled); @@ -182,7 +182,7 @@ class LedgerLoad_test : public beast::unit_test::suite boost::erase_all(ledgerHash, "\""); Env env( *this, - envconfig(ledgerConfig, sd.dbPath, ledgerHash, StartUpType::LOAD, std::nullopt), + envconfig(ledgerConfig, sd.dbPath, ledgerHash, StartUpType::Load, std::nullopt), nullptr, beast::severities::kDisabled); auto jrb = env.rpc("ledger", "current", "full")[jss::result]; @@ -203,7 +203,7 @@ class LedgerLoad_test : public beast::unit_test::suite boost::erase_all(ledgerHash, "\""); Env env( *this, - envconfig(ledgerConfig, sd.dbPath, ledgerHash, StartUpType::REPLAY, std::nullopt), + envconfig(ledgerConfig, sd.dbPath, ledgerHash, StartUpType::Replay, std::nullopt), nullptr, beast::severities::kDisabled); auto const jrb = env.rpc("ledger", "current", "full")[jss::result]; @@ -229,7 +229,7 @@ class LedgerLoad_test : public beast::unit_test::suite boost::erase_all(ledgerHash, "\""); Env env( *this, - envconfig(ledgerConfig, sd.dbPath, ledgerHash, StartUpType::REPLAY, sd.trapTxHash), + envconfig(ledgerConfig, sd.dbPath, ledgerHash, StartUpType::Replay, sd.trapTxHash), nullptr, beast::severities::kDisabled); auto const jrb = env.rpc("ledger", "current", "full")[jss::result]; @@ -259,7 +259,7 @@ class LedgerLoad_test : public beast::unit_test::suite // replay when trapTxHash is set to an invalid transaction Env env( *this, - envconfig(ledgerConfig, sd.dbPath, ledgerHash, StartUpType::REPLAY, ~sd.trapTxHash), + envconfig(ledgerConfig, sd.dbPath, ledgerHash, StartUpType::Replay, ~sd.trapTxHash), nullptr, beast::severities::kDisabled); BEAST_EXPECT(false); @@ -283,7 +283,7 @@ class LedgerLoad_test : public beast::unit_test::suite // create a new env with the ledger "latest" specified for startup Env env( *this, - envconfig(ledgerConfig, sd.dbPath, "latest", StartUpType::LOAD, std::nullopt), + envconfig(ledgerConfig, sd.dbPath, "latest", StartUpType::Load, std::nullopt), nullptr, beast::severities::kDisabled); auto jrb = env.rpc("ledger", "current", "full")[jss::result]; @@ -301,7 +301,7 @@ class LedgerLoad_test : public beast::unit_test::suite // create a new env with specific ledger index at startup Env env( *this, - envconfig(ledgerConfig, sd.dbPath, "43", StartUpType::LOAD, std::nullopt), + envconfig(ledgerConfig, sd.dbPath, "43", StartUpType::Load, std::nullopt), nullptr, beast::severities::kDisabled); auto jrb = env.rpc("ledger", "current", "full")[jss::result]; diff --git a/src/test/app/LedgerMaster_test.cpp b/src/test/app/LedgerMaster_test.cpp index b48579043e..3ea16b63eb 100644 --- a/src/test/app/LedgerMaster_test.cpp +++ b/src/test/app/LedgerMaster_test.cpp @@ -8,7 +8,7 @@ namespace test { class LedgerMaster_test : public beast::unit_test::suite { - std::unique_ptr + static std::unique_ptr makeNetworkConfig(uint32_t networkID) { using namespace jtx; diff --git a/src/test/app/LedgerReplay_test.cpp b/src/test/app/LedgerReplay_test.cpp index 54c12b465a..93811d33b0 100644 --- a/src/test/app/LedgerReplay_test.cpp +++ b/src/test/app/LedgerReplay_test.cpp @@ -232,9 +232,7 @@ public: bool supportsFeature(ProtocolFeature f) const override { - if (f == ProtocolFeature::LedgerReplay && ledgerReplayEnabled_) - return true; - return false; + return f == ProtocolFeature::LedgerReplay && ledgerReplayEnabled_; } std::optional publisherListSequence(PublicKey const&) const override @@ -363,7 +361,7 @@ struct TestPeerSet : public PeerSet dropRate = 100; } - if ((rand() % 100 + 1) <= dropRate) + if (((rand() % 100) + 1) <= dropRate) return; switch (type) @@ -466,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); } /** @@ -752,9 +750,7 @@ public: auto t = findTask(hash, totalReplay); if (!t) { - if (taskExpect == TaskStatus::NotExist) - return true; - return false; + return taskExpect == TaskStatus::NotExist; } return asExpected(t, taskExpect, skiplistExpect, deltaExpects); @@ -771,9 +767,7 @@ public: auto t = findTask(hash, totalReplay); if (!t) { - if (taskExpect == TaskStatus::NotExist) - return true; - return false; + return taskExpect == TaskStatus::NotExist; } return asExpected(t, taskExpect, skiplistExpect, deltaExpects); @@ -809,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); @@ -974,6 +968,7 @@ struct LedgerReplayer_test : public beast::unit_test::suite auto makeSkipList = [](int count) -> std::vector { std::vector sList; + sList.reserve(count); for (int i = 0; i < count; ++i) sList.emplace_back(i); return sList; @@ -1066,10 +1061,7 @@ struct LedgerReplayer_test : public beast::unit_test::suite auto http_resp = xrpl::makeResponse( true, http_request, addr, addr, uint256{1}, 1, {1, 0}, serverEnv.app()); auto const clientResult = peerFeatureEnabled(http_resp, FEATURE_LEDGER_REPLAY, client); - if (clientResult != expecting) - return false; - - return true; + return clientResult == expecting; }; BEAST_EXPECT(handshake(false, false, false)); @@ -1301,7 +1293,7 @@ struct LedgerReplayer_test : public beast::unit_test::suite int totalReplay = 5; NetworkOfTwo net( *this, - {totalReplay * 3 + 1}, + {(totalReplay * 3) + 1}, PeerSetBehavior::Good, InboundLedgersBehavior::Good, PeerFeature::LedgerReplayEnabled); @@ -1348,11 +1340,11 @@ struct LedgerReplayer_test : public beast::unit_test::suite TaskStatus::Completed, deltaStatuses)); // deltaStatuses no change BEAST_EXPECT(net.client.waitForLedgers(finalHash_moreEarly, totalReplay)); - BEAST_EXPECT(net.client.countsAsExpected(4, 3, 2 * (totalReplay - 1) + 2)); + BEAST_EXPECT(net.client.countsAsExpected(4, 3, (2 * (totalReplay - 1)) + 2)); // cover net.client.replayer.replay(InboundLedger::Reason::GENERIC, finalHash, totalReplay * 3); - deltaStatuses = std::vector(totalReplay * 3 - 1, TaskStatus::Completed); + deltaStatuses = std::vector((totalReplay * 3) - 1, TaskStatus::Completed); BEAST_EXPECT(net.client.waitAndCheckStatus( finalHash, totalReplay * 3, @@ -1360,7 +1352,7 @@ struct LedgerReplayer_test : public beast::unit_test::suite TaskStatus::Completed, deltaStatuses)); // deltaStatuses changed BEAST_EXPECT(net.client.waitForLedgers(finalHash, totalReplay * 3)); - BEAST_EXPECT(net.client.countsAsExpected(5, 3, totalReplay * 3 - 1)); + BEAST_EXPECT(net.client.countsAsExpected(5, 3, (totalReplay * 3) - 1)); // sweep net.client.replayer.sweep(); @@ -1464,7 +1456,7 @@ struct LedgerReplayerLong_test : public beast::unit_test::suite int rounds = 4; NetworkOfTwo net( *this, - {totalReplay * rounds + 1}, + {(totalReplay * rounds) + 1}, PeerSetBehavior::Good, InboundLedgersBehavior::Good, PeerFeature::LedgerReplayEnabled); diff --git a/src/test/app/Loan_test.cpp b/src/test/app/Loan_test.cpp index 171e2eddb5..4cdc62853c 100644 --- a/src/test/app/Loan_test.cpp +++ b/src/test/app/Loan_test.cpp @@ -388,7 +388,7 @@ protected: if (auto vaultSle = env.le(keylet::vault(brokerSle->at(sfVaultID))); env.test.BEAST_EXPECT(vaultSle)) { - if ((flags & lsfLoanImpaired) && !(flags & lsfLoanDefault)) + if (((flags & lsfLoanImpaired) != 0u) && ((flags & lsfLoanDefault) == 0u)) { env.test.BEAST_EXPECT( vaultSle->at(sfLossUnrealized) == @@ -746,7 +746,7 @@ protected: return std::make_tuple(broker, loanKeylet, pseudoAcct); } - void + static void topUpBorrower( jtx::Env& env, BrokerInfo const& broker, @@ -1439,7 +1439,7 @@ protected: // Either the borrower or the lender can delete the loan. Alternate // between who does it across tests. static unsigned deleteCounter = 0; - auto const deleter = ++deleteCounter % 2 ? lender : borrower; + auto const deleter = ((++deleteCounter % 2) != 0u) ? lender : borrower; env(del(deleter, keylet.key)); env.close(); @@ -1468,7 +1468,7 @@ protected: } } - std::string + static std::string getCurrencyLabel(Asset const& asset) { if (asset.native()) @@ -1539,7 +1539,7 @@ protected: auto const pseudoAcct = [&]() { auto const brokerSle = env.le(keylet::loanbroker(broker.brokerID)); if (!BEAST_EXPECT(brokerSle)) - return lender; + return Account{lender}; auto const brokerPseudo = brokerSle->at(sfAccount); return Account("Broker pseudo-account", brokerPseudo); }(); @@ -1809,9 +1809,9 @@ protected: if (!BEAST_EXPECT(vaultSle)) { // This will be wrong, but the test has failed anyway. - return lender; + return Account{lender}; } - auto const vaultPseudo = Account("Vault pseudo-account", vaultSle->at(sfAccount)); + auto vaultPseudo = Account("Vault pseudo-account", vaultSle->at(sfAccount)); return vaultPseudo; }(); @@ -2149,7 +2149,7 @@ protected: state.totalValue = 0; state.managementFeeOutstanding = 0; state.previousPaymentDate = - state.nextPaymentDate + state.paymentInterval * (numPayments - 1); + state.nextPaymentDate + (state.paymentInterval * (numPayments - 1)); state.nextPaymentDate = 0; verifyLoanStatus(state); @@ -2875,6 +2875,7 @@ protected: // Create vaults and loan brokers std::array const assets{mptAsset, iouAsset}; std::vector brokers; + brokers.reserve(assets.size()); for (auto const& asset : assets) { brokers.emplace_back(createVaultAndBroker(env, asset, lender)); @@ -2983,7 +2984,7 @@ protected: BEAST_EXPECT(sleMPT1 == nullptr); // Burn some XRP - env(noop(borrower), fee(XRP(acctReserve * 2 + incReserve * 2))); + env(noop(borrower), fee(XRP((acctReserve * 2) + (incReserve * 2)))); env.close(); // Cannot create loan, not enough reserve to create MPToken @@ -3007,7 +3008,7 @@ protected: BEAST_EXPECT(sleMPT2 != nullptr); }, {}, - CaseArgs{.initialXRP = acctReserve * 2 + incReserve * 8 + 1}); + CaseArgs{.initialXRP = (acctReserve * 2) + (incReserve * 8) + 1}); testCase( {}, @@ -3029,7 +3030,7 @@ protected: BEAST_EXPECT(sleLine1 == nullptr); // Burn some XRP - env(noop(borrower), fee(XRP(acctReserve * 2 + incReserve * 2))); + env(noop(borrower), fee(XRP((acctReserve * 2) + (incReserve * 2)))); env.close(); // Cannot create loan, not enough reserve to create trust line @@ -3052,7 +3053,7 @@ protected: auto const sleLine2 = env.le(trustline); BEAST_EXPECT(sleLine2 != nullptr); }, - CaseArgs{.initialXRP = acctReserve * 2 + incReserve * 8 + 1}); + CaseArgs{.initialXRP = (acctReserve * 2) + (incReserve * 8) + 1}); testCase( [&, this](Env& env, BrokerInfo const& broker, MPTTester& mptt) { @@ -3102,7 +3103,7 @@ protected: BEAST_EXPECT(sleMPT3 != nullptr); }, {}, - CaseArgs{.initialXRP = acctReserve * 2 + incReserve * 8 + 1}); + CaseArgs{.initialXRP = (acctReserve * 2) + (incReserve * 8) + 1}); testCase( {}, @@ -3152,7 +3153,7 @@ protected: auto const sleLine3 = env.le(trustline); BEAST_EXPECT(sleLine3 != nullptr); }, - CaseArgs{.initialXRP = acctReserve * 2 + incReserve * 8 + 1}); + CaseArgs{.initialXRP = (acctReserve * 2) + (incReserve * 8) + 1}); testCase( [&, this](Env& env, BrokerInfo const& broker, MPTTester& mptt) { @@ -3408,6 +3409,7 @@ protected: // Create vaults and loan brokers std::vector brokers; + brokers.reserve(assets.size()); for (auto const& asset : assets) { brokers.emplace_back(createVaultAndBroker( @@ -4566,7 +4568,7 @@ protected: auto const pseudoAcct = [&]() { auto const brokerSle = env.le(keylet::loanbroker(broker.brokerID)); if (!BEAST_EXPECT(brokerSle)) - return lender; + return Account{lender}; auto const brokerPseudo = brokerSle->at(sfAccount); return Account("Broker pseudo-account", brokerPseudo); }(); diff --git a/src/test/app/Manifest_test.cpp b/src/test/app/Manifest_test.cpp index 609b7bdb89..92a10ef7fa 100644 --- a/src/test/app/Manifest_test.cpp +++ b/src/test/app/Manifest_test.cpp @@ -87,7 +87,7 @@ public: } } - std::string + static std::string makeManifestString( PublicKey const& pk, SecretKey const& sk, @@ -147,9 +147,8 @@ public: Serializer s; st.add(s); - // m is non-const so it can be moved from - std::string m(static_cast(s.data()), s.size()); - if (auto r = deserializeManifest(std::move(m))) + std::string const m(static_cast(s.data()), s.size()); + if (auto r = deserializeManifest(m)) return std::move(*r); Throw("Could not create a revocation manifest"); return *deserializeManifest(std::string{}); // Silence compiler warning. @@ -182,15 +181,14 @@ public: Serializer s; st.add(s); - std::string m(static_cast(s.data()), - s.size()); // non-const so can be moved - if (auto r = deserializeManifest(std::move(m))) + std::string const m(static_cast(s.data()), s.size()); + if (auto r = deserializeManifest(m)) return std::move(*r); Throw("Could not create a manifest"); return *deserializeManifest(std::string{}); // Silence compiler warning. } - Manifest + static Manifest clone(Manifest const& m) { Manifest m2(m.serialized, m.masterKey, m.signingKey, m.sequence, m.domain); @@ -252,6 +250,7 @@ public: // save should store all trusted master keys to db std::vector s1; std::vector keys; + s1.reserve(inManifests.size()); for (auto const& man : inManifests) s1.push_back(toBase58(TokenType::NodePublic, man->masterKey)); unl->load({}, s1, keys); diff --git a/src/test/app/NFTokenAuth_test.cpp b/src/test/app/NFTokenAuth_test.cpp index b973530f41..551882b51a 100644 --- a/src/test/app/NFTokenAuth_test.cpp +++ b/src/test/app/NFTokenAuth_test.cpp @@ -6,7 +6,7 @@ namespace xrpl { class NFTokenAuth_test : public beast::unit_test::suite { - auto + static auto mintAndOfferNFT( test::jtx::Env& env, test::jtx::Account const& account, @@ -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/NFTokenBurn_test.cpp b/src/test/app/NFTokenBurn_test.cpp index 25f5a0f880..b91b245a7f 100644 --- a/src/test/app/NFTokenBurn_test.cpp +++ b/src/test/app/NFTokenBurn_test.cpp @@ -23,7 +23,7 @@ class NFTokenBurn_test : public beast::unit_test::suite // Helper function that returns new nft id for an account and create // specified number of sell offers - uint256 + static uint256 createNftAndOffers( test::jtx::Env& env, test::jtx::Account const& owner, @@ -59,7 +59,7 @@ class NFTokenBurn_test : public beast::unit_test::suite noisy = true, }; - void + static void printNFTPages(test::jtx::Env& env, Volume vol) { Json::Value jvParams; diff --git a/src/test/app/NFTokenDir_test.cpp b/src/test/app/NFTokenDir_test.cpp index 73698f1f89..70514f497f 100644 --- a/src/test/app/NFTokenDir_test.cpp +++ b/src/test/app/NFTokenDir_test.cpp @@ -20,7 +20,7 @@ class NFTokenDir_test : public beast::unit_test::suite noisy = true, }; - void + static void printNFTPages(test::jtx::Env& env, Volume vol) { Json::Value jvParams; diff --git a/src/test/app/NFToken_test.cpp b/src/test/app/NFToken_test.cpp index ba61830758..bd61c959fc 100644 --- a/src/test/app/NFToken_test.cpp +++ b/src/test/app/NFToken_test.cpp @@ -53,7 +53,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite } // Helper function returns the close time of the parent ledger. - std::uint32_t + static std::uint32_t lastClose(test::jtx::Env& env) { return env.current()->header().parentCloseTime.time_since_epoch().count(); @@ -243,7 +243,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { env(token::burn(alice, token::getID(env, alice, 0, seq++))); env.close(); - checkAliceOwnerMintedBurned((33 - seq) ? 1 : 0, 33, seq, __LINE__); + checkAliceOwnerMintedBurned(((33 - seq) != 0u) ? 1 : 0, 33, seq, __LINE__); } // alice burns a non-existent NFT. @@ -352,7 +352,8 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite { env(token::burn(minter, token::getID(env, alice, 0, nftSeq++))); env.close(); - checkMintersOwnerMintedBurned(0, 66, nftSeq, (65 - seq) ? 1 : 0, 0, 0, __LINE__); + checkMintersOwnerMintedBurned( + 0, 66, nftSeq, ((65 - seq) != 0u) ? 1 : 0, 0, 0, __LINE__); } // minter has one more NFT to burn. Should take her owner count to @@ -398,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) @@ -1529,7 +1530,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite env.close(); // becky attempts to sell the nft for AUD. - TER const createOfferTER = xferFee ? TER(tecNO_LINE) : TER(tesSUCCESS); + TER const createOfferTER = (xferFee != 0u) ? TER(tecNO_LINE) : TER(tesSUCCESS); uint256 const beckyOfferIndex = keylet::nftoffer(becky, env.seq(becky)).key; env(token::createOffer(becky, nftNoAutoTrustID, gwAUD(100)), txflags(tfSellNFToken), @@ -4532,7 +4533,7 @@ class NFTokenBaseUtil_test : public beast::unit_test::suite }; // There are no sell offers. - checkOffers("nft_sell_offers", 0, false, __LINE__); + checkOffers("nft_sell_offers", 0, 0, __LINE__); // A lambda that generates sell offers. STAmount sellPrice = XRP(0); diff --git a/src/test/app/NetworkID_test.cpp b/src/test/app/NetworkID_test.cpp index a37f8342e1..17245f7ee5 100644 --- a/src/test/app/NetworkID_test.cpp +++ b/src/test/app/NetworkID_test.cpp @@ -18,7 +18,7 @@ public: testNetworkID(); } - std::unique_ptr + static std::unique_ptr makeNetworkConfig(uint32_t networkID) { using namespace jtx; diff --git a/src/test/app/Offer_test.cpp b/src/test/app/Offer_test.cpp index 62edc844c7..57f938e399 100644 --- a/src/test/app/Offer_test.cpp +++ b/src/test/app/Offer_test.cpp @@ -11,13 +11,13 @@ namespace test { class OfferBaseUtil_test : public beast::unit_test::suite { - XRPAmount + static XRPAmount reserve(jtx::Env& env, std::uint32_t count) { return env.current()->fees().accountReserve(count); } - std::uint32_t + static std::uint32_t lastClose(jtx::Env& env) { return env.current()->header().parentCloseTime.time_since_epoch().count(); @@ -863,7 +863,7 @@ public: auto const aliceOffers = offersOnAccount(env, alice); BEAST_EXPECT(aliceOffers.size() == 1); - for (auto offerPtr : aliceOffers) + for (auto const& offerPtr : aliceOffers) { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfTakerGets] == XRP(2000)); @@ -878,7 +878,7 @@ public: auto const bobOffers = offersOnAccount(env, bob); BEAST_EXPECT(bobOffers.size() == 1); - for (auto offerPtr : bobOffers) + for (auto const& offerPtr : bobOffers) { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfTakerGets] == USD(1000)); @@ -927,7 +927,7 @@ public: auto const bobOffers = offersOnAccount(env, "bob"); BEAST_EXPECT(bobOffers.size() == 1); - for (auto offerPtr : bobOffers) + for (auto const& offerPtr : bobOffers) { auto const& offer = *offerPtr; BEAST_EXPECT(offer[sfTakerGets] == USD(499.5)); @@ -2253,7 +2253,7 @@ public: // The gateway optionally creates an offer that would be crossed. auto const book = t.bookAmount; - if (book) + if (book != 0) env(offer(gw, XRP(book), USD(book))); env.close(); std::uint32_t const gwOfferSeq = env.seq(gw) - 1; @@ -2285,7 +2285,7 @@ public: auto acctOffers = offersOnAccount(env, acct); BEAST_EXPECT(acctOffers.size() == t.offers); - if (!acctOffers.empty() && t.offers) + if (!acctOffers.empty() && (t.offers != 0)) { auto const& acctOffer = *(acctOffers.front()); @@ -2296,7 +2296,7 @@ public: if (t.preTrust == noPreTrust) { - if (t.balanceUsd.value().signum()) + if (t.balanceUsd.value().signum() != 0) { // Verify the correct contents of the trustline verifyDefaultTrustline(env, acct, t.balanceUsd); @@ -2773,7 +2773,7 @@ public: env.require(offers(acct, t.offers)); env.require(owners(acct, t.owners)); - if (t.offers) + if (t.offers != 0) { auto const acctOffers = offersOnAccount(env, acct); if (!acctOffers.empty()) @@ -3875,10 +3875,10 @@ public: // clang-format off TestData const tests[]{ // btcStart --------------------- actor[0] --------------------- -------------------- actor[1] ------------------- - {0, 0, 1, BTC(20), {{"ann", 0, drops(3900000'000000 - 4 * baseFee), BTC(20.0), USD(3000)}, {"abe", 0, drops(4100000'000000 - 3 * baseFee), BTC( 0), USD(750)}}}, // no BTC xfer fee - {0, 1, 0, BTC(20), {{"bev", 0, drops(4100000'000000 - 4 * baseFee), BTC( 7.5), USD(2000)}, {"bob", 0, drops(3900000'000000 - 3 * baseFee), BTC(10), USD( 0)}}}, // no USD xfer fee - {0, 0, 0, BTC(20), {{"cam", 0, drops(4000000'000000 - 5 * baseFee), BTC(20.0), USD(2000)} }}, // no xfer fee - {0, 1, 0, BTC( 5), {{"deb", 1, drops(4040000'000000 - 4 * baseFee), BTC( 0.0), USD(2000)}, {"dan", 1, drops(3960000'000000 - 3 * baseFee), BTC( 4), USD( 0)}}}, // no USD xfer fee + {0, 0, 1, BTC(20), {{"ann", 0, drops(3900000'000000 - (4 * baseFee)), BTC(20.0), USD(3000)}, {"abe", 0, drops(4100000'000000 - (3 * baseFee)), BTC( 0), USD(750)}}}, // no BTC xfer fee + {0, 1, 0, BTC(20), {{"bev", 0, drops(4100000'000000 - (4 * baseFee)), BTC( 7.5), USD(2000)}, {"bob", 0, drops(3900000'000000 - (3 * baseFee)), BTC(10), USD( 0)}}}, // no USD xfer fee + {0, 0, 0, BTC(20), {{"cam", 0, drops(4000000'000000 - (5 * baseFee)), BTC(20.0), USD(2000)} }}, // no xfer fee + {0, 1, 0, BTC( 5), {{"deb", 1, drops(4040000'000000 - (4 * baseFee)), BTC( 0.0), USD(2000)}, {"dan", 1, drops(3960000'000000 - (3 * baseFee)), BTC( 4), USD( 0)}}}, // no USD xfer fee }; // clang-format on @@ -4026,8 +4026,8 @@ public: // clang-format off TestData const tests[]{ // btcStart ------------------- actor[0] -------------------- ------------------- actor[1] -------------------- - {0, 0, 1, BTC(5), {{"gay", 1, drops(3950000'000000 - 4 * baseFee), BTC(5), USD(2500)}, {"gar", 1, drops(4050000'000000 - 3 * baseFee), BTC(0), USD(1375)}}}, // no BTC xfer fee - {0, 0, 0, BTC(5), {{"hye", 2, drops(4000000'000000 - 5 * baseFee), BTC(5), USD(2000)} }} // no xfer fee + {0, 0, 1, BTC(5), {{"gay", 1, drops(3950000'000000 - (4 * baseFee)), BTC(5), USD(2500)}, {"gar", 1, drops(4050000'000000 - (3 * baseFee)), BTC(0), USD(1375)}}}, // no BTC xfer fee + {0, 0, 0, BTC(5), {{"hye", 2, drops(4000000'000000 - (5 * baseFee)), BTC(5), USD(2000)} }} // no xfer fee }; // clang-format on diff --git a/src/test/app/OversizeMeta_test.cpp b/src/test/app/OversizeMeta_test.cpp index 3831e45a78..d6305bedb6 100644 --- a/src/test/app/OversizeMeta_test.cpp +++ b/src/test/app/OversizeMeta_test.cpp @@ -9,7 +9,7 @@ namespace test { class PlumpBook_test : public beast::unit_test::suite { public: - void + static void createOffers(jtx::Env& env, jtx::IOU const& iou, std::size_t n) { using namespace jtx; @@ -64,7 +64,7 @@ BEAST_DEFINE_TESTSUITE(ThinBook, app, xrpl); class OversizeMeta_test : public beast::unit_test::suite { public: - void + static void createOffers(jtx::Env& env, jtx::IOU const& iou, std::size_t n) { using namespace jtx; @@ -130,7 +130,7 @@ public: return lo; } - void + static void createOffers(jtx::Env& env, jtx::IOU const& iou, std::size_t n) { using namespace jtx; diff --git a/src/test/app/Path_test.cpp b/src/test/app/Path_test.cpp index 9315370809..53da92ce1c 100644 --- a/src/test/app/Path_test.cpp +++ b/src/test/app/Path_test.cpp @@ -39,7 +39,7 @@ rpf(jtx::Account const& src, jtx::Account const& dst, std::uint32_t num_src) { auto& sc = (jv[jss::source_currencies] = Json::arrayValue); Json::Value j = Json::objectValue; - while (num_src--) + while ((num_src--) != 0u) { j[jss::currency] = std::to_string(num_src + 100); sc.append(j); diff --git a/src/test/app/PayChan_test.cpp b/src/test/app/PayChan_test.cpp index 5322349797..1150ae4d86 100644 --- a/src/test/app/PayChan_test.cpp +++ b/src/test/app/PayChan_test.cpp @@ -1096,7 +1096,7 @@ struct PayChan_test : public beast::unit_test::suite { auto leftToFind = bobsB58; auto const numFull = bobs.size() / limit; - auto const numNonFull = bobs.size() % limit ? 1 : 0; + auto const numNonFull = ((bobs.size() % limit) != 0u) ? 1 : 0; Json::Value marker = Json::nullValue; @@ -1122,7 +1122,7 @@ struct PayChan_test : public beast::unit_test::suite testIt(expectMarker, limit); } - if (numNonFull) + if (numNonFull != 0) { testIt(false, bobs.size() % limit); } diff --git a/src/test/app/PayStrand_test.cpp b/src/test/app/PayStrand_test.cpp index 70444637bf..256c5ae716 100644 --- a/src/test/app/PayStrand_test.cpp +++ b/src/test/app/PayStrand_test.cpp @@ -176,7 +176,7 @@ class ElementComboIter bool has(SB s) const { - return state_ & (1 << safe_cast(s)); + return (state_ & (1 << safe_cast(s))) != 0; } bool @@ -212,7 +212,7 @@ public: valid() const { return (allowCompound_ || !(has(SB::acc) && hasAny({SB::cur, SB::iss}))) && - (!hasAny({SB::prevAcc, SB::prevCur, SB::prevIss}) || prev_) && + (!hasAny({SB::prevAcc, SB::prevCur, SB::prevIss}) || (prev_ != nullptr)) && (!hasAny({SB::rootAcc, SB::sameAccIss, SB::existingAcc, SB::prevAcc}) || has(SB::acc)) && (!hasAny({SB::rootIss, SB::sameAccIss, SB::existingIss, SB::prevIss}) || @@ -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/PermissionedDEX_test.cpp b/src/test/app/PermissionedDEX_test.cpp index 2817bc0502..7b622a1256 100644 --- a/src/test/app/PermissionedDEX_test.cpp +++ b/src/test/app/PermissionedDEX_test.cpp @@ -34,13 +34,13 @@ using namespace jtx; class PermissionedDEX_test : public beast::unit_test::suite { - [[nodiscard]] bool + [[nodiscard]] static bool offerExists(Env const& env, Account const& account, std::uint32_t offerSeq) { return static_cast(env.le(keylet::offer(account.id(), offerSeq))); } - [[nodiscard]] bool + [[nodiscard]] static bool checkOffer( Env const& env, Account const& account, @@ -120,13 +120,13 @@ class PermissionedDEX_test : public beast::unit_test::suite return true; } - uint256 + static uint256 getBookDirKey(Book const& book, STAmount const& takerPays, STAmount const& takerGets) { return keylet::quality(keylet::book(book), getRate(takerGets, takerPays)).key; } - std::optional + static std::optional getDefaultOfferDirKey(Env const& env, Account const& account, std::uint32_t offerSeq) { if (auto const sle = env.le(keylet::offer(account.id(), offerSeq))) @@ -135,7 +135,7 @@ class PermissionedDEX_test : public beast::unit_test::suite return {}; } - [[nodiscard]] bool + [[nodiscard]] static bool checkDirectorySize(Env const& env, uint256 directory, std::uint32_t dirSize) { std::optional pageIndex{0}; @@ -151,7 +151,7 @@ class PermissionedDEX_test : public beast::unit_test::suite pageIndex = (*page)[~sfIndexNext]; dirCnt += (*page)[sfIndexes].size(); - } while (pageIndex.value_or(0)); + } while (pageIndex.value_or(0) != 0u); return dirCnt == dirSize; } diff --git a/src/test/app/PseudoTx_test.cpp b/src/test/app/PseudoTx_test.cpp index aa16df8e9c..a9180d0e03 100644 --- a/src/test/app/PseudoTx_test.cpp +++ b/src/test/app/PseudoTx_test.cpp @@ -11,7 +11,7 @@ namespace test { struct PseudoTx_test : public beast::unit_test::suite { - std::vector + static std::vector getPseudoTxs(Rules const& rules, std::uint32_t seq) { std::vector res; @@ -43,7 +43,7 @@ struct PseudoTx_test : public beast::unit_test::suite return res; } - std::vector + static std::vector getRealTxs() { std::vector res; @@ -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 a7941ea64f..537563ecc4 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) + 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())); @@ -128,7 +132,7 @@ class RCLValidations_test : public beast::unit_test::suite { RCLValidatedLedger a{RCLValidatedLedger::MakeGenesis{}}; - for (auto ledger : {history.back(), history[maxAncestors - 1]}) + for (auto const& ledger : {history.back(), history[maxAncestors - 1]}) { RCLValidatedLedger b{ledger, env.journal}; BEAST_EXPECT(mismatch(a, b) == 1); @@ -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/ReducedOffer_test.cpp b/src/test/app/ReducedOffer_test.cpp index d0cf1b5324..46193a1544 100644 --- a/src/test/app/ReducedOffer_test.cpp +++ b/src/test/app/ReducedOffer_test.cpp @@ -491,7 +491,7 @@ public: } } - Amounts + static Amounts jsonOfferToAmounts(Json::Value const& json) { STAmount const in = amountFromJson(sfTakerPays, json[sfTakerPays.jsonName]); 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 d7d3e281f4..73cbf1c617 100644 --- a/src/test/app/SHAMapStore_test.cpp +++ b/src/test/app/SHAMapStore_test.cpp @@ -34,7 +34,7 @@ class SHAMapStore_test : public beast::unit_test::suite return cfg; } - bool + static bool goodLedger(jtx::Env& env, Json::Value const& json, std::string ledgerID, bool checkDB = false) { auto good = json.isMember(jss::result) && !RPC::contains_error(json[jss::result]) && @@ -73,7 +73,7 @@ class SHAMapStore_test : public beast::unit_test::suite outTxHash == ledger[jss::transaction_hash].asString(); } - bool + static bool bad(Json::Value const& json, error_code_i error = rpcLGR_NOT_FOUND) { return json.isMember(jss::result) && RPC::contains_error(json[jss::result]) && @@ -346,9 +346,9 @@ public: BEAST_EXPECT(lastRotated == store.getLastRotated()); // This does not kick off a cleanup - canDelete = env.rpc("can_delete", std::to_string(ledgerSeq + deleteInterval / 2)); + canDelete = env.rpc("can_delete", std::to_string(ledgerSeq + (deleteInterval / 2))); BEAST_EXPECT(!RPC::contains_error(canDelete[jss::result])); - BEAST_EXPECT(canDelete[jss::result][jss::can_delete] == ledgerSeq + deleteInterval / 2); + BEAST_EXPECT(canDelete[jss::result][jss::can_delete] == ledgerSeq + (deleteInterval / 2)); store.rendezvous(); @@ -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/Transaction_ordering_test.cpp b/src/test/app/Transaction_ordering_test.cpp index f7d431fc90..c50fbf4e56 100644 --- a/src/test/app/Transaction_ordering_test.cpp +++ b/src/test/app/Transaction_ordering_test.cpp @@ -95,14 +95,16 @@ struct Transaction_ordering_test : public beast::unit_test::suite env.fund(XRP(1000), noripple(alice)); auto const aliceSequence = env.seq(alice); + static constexpr auto kSIZE = 5; std::vector tx; - for (auto i = 0; i < 5; ++i) + tx.reserve(kSIZE); + for (auto i = 0; i < kSIZE; ++i) { tx.emplace_back(env.jt(noop(alice), seq(aliceSequence + i), last_ledger_seq(7))); } - for (auto i = 1; i < 5; ++i) + for (auto i = 1; i < kSIZE; ++i) { env(tx[i], ter(terPRE_SEQ)); BEAST_EXPECT(env.seq(alice) == aliceSequence); @@ -110,11 +112,11 @@ struct Transaction_ordering_test : public beast::unit_test::suite env(tx[0]); env.app().getJobQueue().rendezvous(); - BEAST_EXPECT(env.seq(alice) == aliceSequence + 5); + BEAST_EXPECT(env.seq(alice) == aliceSequence + kSIZE); env.close(); - for (auto i = 0; i < 5; ++i) + for (auto i = 0; i < kSIZE; ++i) { auto const result = env.rpc("tx", to_string(tx[i].stx->getTransactionID())); BEAST_EXPECT(result["result"]["meta"]["TransactionResult"] == "tesSUCCESS"); diff --git a/src/test/app/TrustSet_test.cpp b/src/test/app/TrustSet_test.cpp index 51828fa544..d359ba1f26 100644 --- a/src/test/app/TrustSet_test.cpp +++ b/src/test/app/TrustSet_test.cpp @@ -260,7 +260,7 @@ public: env.close(); } - Json::Value + static Json::Value trust_explicit_amt(jtx::Account const& a, STAmount const& amt) { Json::Value jv; @@ -287,7 +287,7 @@ public: for (std::uint64_t badFlag = 1u; badFlag <= std::numeric_limits::max(); badFlag *= 2) { - if (badFlag & tfTrustSetMask) + if ((badFlag & tfTrustSetMask) != 0u) { env(trust(alice, gw["USD"](100), static_cast(badFlag)), ter(temINVALID_FLAG)); diff --git a/src/test/app/TxQ_test.cpp b/src/test/app/TxQ_test.cpp index 59db7e0d5d..566551fe2a 100644 --- a/src/test/app/TxQ_test.cpp +++ b/src/test/app/TxQ_test.cpp @@ -24,7 +24,7 @@ class TxQPosNegFlows_test : public beast::unit_test::suite static constexpr FeeLevel64 baseFeeLevel{256}; static constexpr FeeLevel64 minEscalationFeeLevel = baseFeeLevel * 500; - void + static void fillQueue(jtx::Env& env, jtx::Account const& account) { auto metrics = env.app().getTxQ().getMetrics(*env.current()); @@ -32,7 +32,7 @@ class TxQPosNegFlows_test : public beast::unit_test::suite env(noop(account)); } - auto + static auto openLedgerCost(jtx::Env& env) { using namespace jtx; @@ -52,7 +52,7 @@ class TxQPosNegFlows_test : public beast::unit_test::suite // Get a fee level of a transaction made by an account // This fee level is used to ensure we can place transaction into TxQ - auto + static auto txFeeLevelByAccount(jtx::Env& env, jtx::Account const& account) { using namespace jtx; @@ -65,7 +65,7 @@ class TxQPosNegFlows_test : public beast::unit_test::suite // Calculating expected median fee level based on known fee levels of median // transaction levels. - auto + static auto calcMedFeeLevel(FeeLevel64 const feeLevel1, FeeLevel64 const feeLevel2) { FeeLevel64 const expectedMedFeeLevel = (feeLevel1 + feeLevel2 + FeeLevel64{1}) / 2; @@ -73,7 +73,7 @@ class TxQPosNegFlows_test : public beast::unit_test::suite return std::max(expectedMedFeeLevel, minEscalationFeeLevel).fee(); } - auto + static auto calcMedFeeLevel(FeeLevel64 const feeLevel) { return calcMedFeeLevel(feeLevel, feeLevel); @@ -551,16 +551,16 @@ public: // The lowest fee ticket is baseFee * 2.1, trying to replace it env(noop(alice), ticket::use(tkt1 + 18), - fee(baseFee * 2.1 * 1.25 - 1), + fee((baseFee * 2.1 * 1.25) - 1), ter(telCAN_NOT_QUEUE_FEE)); - env(noop(alice), ticket::use(tkt1 + 18), fee(baseFee * 2.1 * 1.25 + 1), queued); + env(noop(alice), ticket::use(tkt1 + 18), fee((baseFee * 2.1 * 1.25) + 1), queued); // New lowest fee ticket is baseFee * 2.2 env(noop(alice), ticket::use(tkt250 - 4), - fee(baseFee * 2.2 * 1.25 - 1), + fee((baseFee * 2.2 * 1.25) - 1), ter(telCAN_NOT_QUEUE_FEE)); - env(noop(alice), ticket::use(tkt250 - 4), fee(baseFee * 2.2 * 1.25 + 1), queued); + env(noop(alice), ticket::use(tkt250 - 4), fee((baseFee * 2.2 * 1.25) + 1), queued); env.close(); env.require(owners(alice, 227), tickets(alice, 227)); @@ -858,7 +858,7 @@ public: ++seqCarol; } // clang-format off - checkMetrics(*this, env, 6, 6, 4, 3, baseFeeLevel.fee() * aliceFeeMultiplier + 1); + checkMetrics(*this, env, 6, 6, 4, 3, (baseFeeLevel.fee() * aliceFeeMultiplier) + 1); // clang-format on // Carol submits high enough to beat Bob's average fee which kicks @@ -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; @@ -2632,7 +2632,7 @@ public: // Start by procuring tickets for alice to use to keep her queue full // without affecting the sequence gap that will appear later. - env(ticket::create(alice, 11), seq(aliceSeq + 0), fee(baseFee * 20 + 1), ter(terQUEUED)); + env(ticket::create(alice, 11), seq(aliceSeq + 0), fee((baseFee * 20) + 1), ter(terQUEUED)); env(noop(alice), seq(aliceSeq + 11), last_ledger_seq(11), ter(terQUEUED)); env(noop(alice), seq(aliceSeq + 12), last_ledger_seq(11), ter(terQUEUED)); env(noop(alice), seq(aliceSeq + 13), last_ledger_seq(11), ter(terQUEUED)); @@ -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); @@ -4083,7 +4083,7 @@ public: // Use fees to guarantee order int txFee{static_cast(baseFee * 9)}; auto prepareFee = [&](uint64_t multiplier) { - return fee(txFee - multiplier * baseFee / 10); + return fee(txFee - (multiplier * baseFee / 10)); }; uint64_t multiplier = 0; 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 32e899ad95..3f1c20ee25 100644 --- a/src/test/app/ValidatorList_test.cpp +++ b/src/test/app/ValidatorList_test.cpp @@ -98,7 +98,7 @@ private: masterPublic, secret, signingKeys.first, signingKeys.second, 1))}; } - std::string + static std::string makeList( std::vector const& validators, std::size_t sequence, @@ -122,7 +122,7 @@ private: return base64_encode(data); } - std::string + static std::string signList(std::string const& blob, std::pair const& keys) { auto const data = base64_decode(blob); @@ -373,13 +373,14 @@ private: // load should accept valid validator list publisher keys std::vector cfgPublishers; + cfgPublishers.reserve(keys.size()); for (auto const& key : keys) cfgPublishers.push_back(strHex(key)); BEAST_EXPECT(trustedKeys->load({}, emptyCfgKeys, cfgPublishers)); for (auto const& key : keys) BEAST_EXPECT(trustedKeys->trustedPublisher(key)); - BEAST_EXPECT(trustedKeys->getListThreshold() == keys.size() / 2 + 1); + BEAST_EXPECT(trustedKeys->getListThreshold() == (keys.size() / 2) + 1); } { ManifestCache manifests; @@ -393,6 +394,7 @@ private: std::vector keys( {randomMasterKey(), randomMasterKey(), randomMasterKey(), randomMasterKey()}); std::vector cfgPublishers; + cfgPublishers.reserve(keys.size()); for (auto const& key : keys) cfgPublishers.push_back(strHex(key)); @@ -534,7 +536,7 @@ private: auto trustedKeys = std::make_unique( manifests, manifests, - env.app().timeKeeper(), + env.app().getTimeKeeper(), app.config().legacy("database_path"), env.journal); @@ -561,10 +563,10 @@ private: auto const manifest1 = base64_encode(makeManifestString( publisherPublic, publisherSecret, pubSigningKeys1.first, pubSigningKeys1.second, 1)); - std::vector cfgKeys1({strHex(publisherPublic)}); + std::vector cfgPublisherKeys({strHex(publisherPublic)}); std::vector emptyCfgKeys; - BEAST_EXPECT(trustedKeys->load({}, emptyCfgKeys, cfgKeys1)); + BEAST_EXPECT(trustedKeys->load({}, emptyCfgKeys, cfgPublisherKeys)); std::map> const lists = []() { auto constexpr listSize = 20; @@ -813,7 +815,7 @@ private: {}, effective6 + 1s, env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); expectUntrusted(lists.at(3)); @@ -831,7 +833,7 @@ private: {}, effective8 + 1s, env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); expectUntrusted(lists.at(6)); @@ -896,7 +898,7 @@ private: auto trustedKeys = std::make_unique( manifests, manifests, - env.app().timeKeeper(), + env.app().getTimeKeeper(), app.config().legacy("database_path"), env.journal); @@ -907,10 +909,10 @@ private: auto const manifest = base64_encode(makeManifestString( publisherPublic, publisherSecret, pubSigningKeys1.first, pubSigningKeys1.second, 1)); - std::vector cfgKeys1({strHex(publisherPublic)}); + std::vector cfgPublisherKeys({strHex(publisherPublic)}); std::vector emptyCfgKeys; - BEAST_EXPECT(trustedKeys->load({}, emptyCfgKeys, cfgKeys1)); + BEAST_EXPECT(trustedKeys->load({}, emptyCfgKeys, cfgPublisherKeys)); std::vector const list = []() { auto constexpr listSize = 20; @@ -1062,7 +1064,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 +1090,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 +1114,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 +1175,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 +1210,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 +1242,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 +1289,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 +1301,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 +1312,7 @@ private: auto trustedKeys = std::make_unique( manifestsOuter, manifestsOuter, - env.app().timeKeeper(), + env.app().getTimeKeeper(), app.config().legacy("database_path"), env.journal); @@ -1324,9 +1326,9 @@ private: pubSigningKeys.second, 1)); - std::vector cfgKeys({strHex(publisherKeys.first)}); + std::vector cfgPublisherKeys({strHex(publisherKeys.first)}); - BEAST_EXPECT(trustedKeys->load({}, emptyCfgKeys, cfgKeys)); + BEAST_EXPECT(trustedKeys->load({}, emptyCfgKeys, cfgPublisherKeys)); std::vector list({randomValidator(), randomValidator()}); hash_set activeValidators( @@ -1349,7 +1351,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 +1367,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 +1392,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 +1433,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 +1470,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 +1562,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 +1677,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 +1708,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 +1741,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 +1811,7 @@ private: auto trustedKeys = std::make_unique( manifests, manifests, - env.app().timeKeeper(), + env.app().getTimeKeeper(), app.config().legacy("database_path"), env.journal); @@ -1907,7 +1909,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT( trustedKeys->expires() && @@ -1924,7 +1926,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT( trustedKeys->expires() && @@ -1969,7 +1971,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 +2021,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); BEAST_EXPECT( validators->quorum() == @@ -2063,7 +2065,7 @@ private: activeValidators, env.timeKeeper().now(), env.app().getOPs(), - env.app().overlay(), + env.app().getOverlay(), env.app().getHashRouter()); return validators->quorum() == quorum; } @@ -2094,7 +2096,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 +2123,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 +2138,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 +2631,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 +2652,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 +2690,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 +2710,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 +2755,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 +2775,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 +2824,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 +2845,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 +2891,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 +2911,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 +2958,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 +2978,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 +3023,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 +3044,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 +3082,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 +3103,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 +3141,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 +3161,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 +3197,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 +3217,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 +3262,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 +3283,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 +3329,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 +3349,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 +3396,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 +3416,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 +3455,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 +3476,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 +3516,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 +3537,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 +3578,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 +3598,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 +3639,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 +3660,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 +3702,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 +3740,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 +3786,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 +3807,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 +3855,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 +3875,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 c47c93c426..ee28410d9e 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; @@ -240,7 +240,7 @@ private: sink.messages().str()); } - if (u.cfg.expectedRefreshMin) + if (u.cfg.expectedRefreshMin != 0) { BEAST_EXPECTS( myStatus[jss::refresh_interval_min].asInt() == u.cfg.expectedRefreshMin, @@ -298,6 +298,7 @@ private: auto sites = std::make_unique(env.app(), journal); std::vector uris; + uris.reserve(servers.size()); for (auto const& u : servers) uris.push_back(u.uri); sites->load(uris); diff --git a/src/test/app/Vault_test.cpp b/src/test/app/Vault_test.cpp index e62f7fee50..54cc6646b1 100644 --- a/src/test/app/Vault_test.cpp +++ b/src/test/app/Vault_test.cpp @@ -9,8 +9,9 @@ #include #include #include +#include #include -#include +#include #include #include #include @@ -1328,7 +1329,7 @@ class Vault_test : public beast::unit_test::suite return defXRP; return a + XRP(1000); } - auto const defIOU = STAmount{a.issue(), 30000}; + auto defIOU = STAmount{a.issue(), 30000}; if (a <= defIOU) return defIOU; return a + STAmount{a.issue(), 1000}; @@ -1897,7 +1898,7 @@ class Vault_test : public beast::unit_test::suite env.close(); } }, - {.requireAuth = false, .initialXRP = acctReserve + incReserve * 4 + 1}); + {.requireAuth = false, .initialXRP = acctReserve + (incReserve * 4) + 1}); testCase([this]( Env& env, @@ -2744,7 +2745,7 @@ class Vault_test : public beast::unit_test::suite env(vault.withdraw( {.depositor = owner, .id = keylet.key, - .amount = asset(Number(1000 + 37 * 5, -1))})); + .amount = asset(Number(1000 + (37 * 5), -1))})); { BEAST_EXPECT(env.balance(owner, asset) == startingOwnerBalance.value()); @@ -2807,7 +2808,7 @@ class Vault_test : public beast::unit_test::suite env(tx); env.close(); }, - CaseArgs{.initialXRP = acctReserve + incReserve * 4 + 1}); + CaseArgs{.initialXRP = acctReserve + (incReserve * 4) + 1}); testCase( [&, this]( @@ -2842,7 +2843,7 @@ class Vault_test : public beast::unit_test::suite env(tx); env.close(); }, - CaseArgs{.initialXRP = acctReserve + incReserve * 4 + 1}); + CaseArgs{.initialXRP = acctReserve + (incReserve * 4) + 1}); testCase([&, this]( Env& env, @@ -3365,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/app/XChain_test.cpp b/src/test/app/XChain_test.cpp index b90ff49a84..72f2597883 100644 --- a/src/test/app/XChain_test.cpp +++ b/src/test/app/XChain_test.cpp @@ -3856,7 +3856,7 @@ private: auto& c = counters[bridge]; auto& create_claims = claims.create_claims[c.claim_count]; auto num_attns = create_claims.size(); - if (num_attns) + if (num_attns != 0u) { c.num_create_attn_sent += sendCreateAttestations(i, bridge, create_claims); diff --git a/src/test/basics/Buffer_test.cpp b/src/test/basics/Buffer_test.cpp index f5f626133f..a329e527ba 100644 --- a/src/test/basics/Buffer_test.cpp +++ b/src/test/basics/Buffer_test.cpp @@ -9,8 +9,8 @@ namespace test { struct Buffer_test : beast::unit_test::suite { - bool - sane(Buffer const& b) const + static bool + sane(Buffer const& b) { if (b.empty()) return b.data() == nullptr; diff --git a/src/test/basics/IntrusiveShared_test.cpp b/src/test/basics/IntrusiveShared_test.cpp index 5a460a6044..41ecf9a7a4 100644 --- a/src/test/basics/IntrusiveShared_test.cpp +++ b/src/test/basics/IntrusiveShared_test.cpp @@ -592,6 +592,7 @@ public: } }; std::vector threads; + threads.reserve(numThreads); for (int i = 0; i < numThreads; ++i) { threads.emplace_back(cloneAndDestroy, i); @@ -737,6 +738,7 @@ public: } }; std::vector threads; + threads.reserve(numThreads); for (int i = 0; i < numThreads; ++i) { threads.emplace_back(cloneAndDestroy, i); @@ -845,6 +847,7 @@ public: } }; std::vector threads; + threads.reserve(numThreads); for (int i = 0; i < numThreads; ++i) { threads.emplace_back(lockAndDestroy, i); diff --git a/src/test/basics/Number_test.cpp b/src/test/basics/Number_test.cpp index fb434a0182..4676884660 100644 --- a/src/test/basics/Number_test.cpp +++ b/src/test/basics/Number_test.cpp @@ -279,7 +279,7 @@ public: {Number{Number::maxRep}, Number{6, -1}, Number{Number::maxRep - 1}}, {Number{false, Number::maxRep + 1, 0, Number::normalized{}}, Number{1, 0}, - Number{Number::maxRep / 10 + 1, 1}}, + Number{(Number::maxRep / 10) + 1, 1}}, {Number{false, Number::maxRep + 1, 0, Number::normalized{}}, Number{3, 0}, Number{Number::maxRep}}, @@ -456,7 +456,7 @@ public: // 99'999'999'999'999'999'800'000'000'000'000'000'100 {Number{false, maxMantissa, 0, Number::normalized{}}, Number{false, maxMantissa, 0, Number::normalized{}}, - Number{false, maxMantissa / 10 - 1, 20, Number::normalized{}}}, + Number{false, (maxMantissa / 10) - 1, 20, Number::normalized{}}}, // Maximum int64 range // 85'070'591'730'234'615'847'396'907'784'232'501'249 {Number{Number::maxRep, 0}, @@ -523,7 +523,7 @@ public: // 99'999'999'999'999'999'800'000'000'000'000'000'100 {Number{false, maxMantissa, 0, Number::normalized{}}, Number{false, maxMantissa, 0, Number::normalized{}}, - Number{false, maxMantissa / 10 - 1, 20, Number::normalized{}}}, + Number{false, (maxMantissa / 10) - 1, 20, Number::normalized{}}}, // Maximum int64 range // 85'070'591'730'234'615'847'396'907'784'232'501'249 {Number{Number::maxRep, 0}, @@ -1238,10 +1238,10 @@ public: auto const maxMantissa = Number::maxMantissa(); BEAST_EXPECT(maxMantissa == 9'999'999'999'999'999); test( - Number{false, maxMantissa * 1000 + 999, -3, Number::normalized()}, + Number{false, (maxMantissa * 1000) + 999, -3, Number::normalized()}, "9999999999999999"); test( - Number{true, maxMantissa * 1000 + 999, -3, Number::normalized()}, + Number{true, (maxMantissa * 1000) + 999, -3, Number::normalized()}, "-9999999999999999"); test(Number{std::numeric_limits::max(), -3}, "9223372036854775"); @@ -1537,7 +1537,7 @@ public: // 99'999'999'999'999'999'800'000'000'000'000'000'100 - also 38 // digits BEAST_EXPECT( - (power(max, 2) == Number{false, maxMantissa / 10 - 1, 20, Number::normalized{}})); + (power(max, 2) == Number{false, (maxMantissa / 10) - 1, 20, Number::normalized{}})); } } diff --git a/src/test/basics/PerfLog_test.cpp b/src/test/basics/PerfLog_test.cpp index ce0109c53d..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 { @@ -63,21 +63,21 @@ class PerfLog_test : public beast::unit_test::suite stopSignaled = true; } - path - logDir() const + static path + logDir() { using namespace boost::filesystem; return temp_directory_path() / "perf_log_test_dir"; } - path - logFile() const + static path + logFile() { return logDir() / "perf_log.txt"; } - std::chrono::milliseconds - logInterval() const + static std::chrono::milliseconds + logInterval() { return std::chrono::milliseconds{10}; } @@ -96,8 +96,8 @@ class PerfLog_test : public beast::unit_test::suite // Block until the log file has grown in size, indicating that the // PerfLog has written new values to the file and _should_ have the // latest update. - void - wait() const + static void + wait() { using namespace boost::filesystem; diff --git a/src/test/basics/base58_test.cpp b/src/test/basics/base58_test.cpp index ca62ac02ef..52d06b324d 100644 --- a/src/test/basics/base58_test.cpp +++ b/src/test/basics/base58_test.cpp @@ -162,7 +162,7 @@ class base58_test : public beast::unit_test::suite for (int i = 0; i < iters; ++i) { std::uint64_t const d = dist(eng); - if (!d) + if (d == 0u) continue; auto bigInt = multiprecision_utils::randomBigInt(); auto const boostBigInt = multiprecision_utils::toBoostMP( diff --git a/src/test/beast/aged_associative_container_test.cpp b/src/test/beast/aged_associative_container_test.cpp index 690f03cd49..1578ffceca 100644 --- a/src/test/beast/aged_associative_container_test.cpp +++ b/src/test/beast/aged_associative_container_test.cpp @@ -523,7 +523,7 @@ public: testArrayCreate(); template - typename std::enable_if::type + typename std::enable_if::type testArrayCreate() { } @@ -1362,7 +1362,7 @@ aged_associative_container_test_base::testArrayCreate() { // Copy construct key typename Traits::template Cont<> c(clock); - for (auto e : v) + for (auto const& e : v) c[e.first] = e.second; checkContents(c, v); } 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/conditions/PreimageSha256_test.cpp b/src/test/conditions/PreimageSha256_test.cpp index 973f714ba4..374b6eb925 100644 --- a/src/test/conditions/PreimageSha256_test.cpp +++ b/src/test/conditions/PreimageSha256_test.cpp @@ -149,7 +149,7 @@ class PreimageSha256_test : public beast::unit_test::suite "9CF1D5F810302" "0000"}}; - for (auto x : others) + for (auto const& x : others) { std::error_code ec; diff --git a/src/test/consensus/Consensus_test.cpp b/src/test/consensus/Consensus_test.cpp index a096b82365..3550717a4d 100644 --- a/src/test/consensus/Consensus_test.cpp +++ b/src/test/consensus/Consensus_test.cpp @@ -1295,10 +1295,10 @@ public: for (int i = 0; i < 1; ++i) { - BEAST_EXPECT(!proposingTrue.updateVote(250 + 10 * i, true, p)); - BEAST_EXPECT(!proposingFalse.updateVote(250 + 10 * i, true, p)); - BEAST_EXPECT(!followingTrue.updateVote(250 + 10 * i, false, p)); - BEAST_EXPECT(!followingFalse.updateVote(250 + 10 * i, false, p)); + BEAST_EXPECT(!proposingTrue.updateVote(250 + (10 * i), true, p)); + BEAST_EXPECT(!proposingFalse.updateVote(250 + (10 * i), true, p)); + BEAST_EXPECT(!followingTrue.updateVote(250 + (10 * i), false, p)); + BEAST_EXPECT(!followingFalse.updateVote(250 + (10 * i), false, p)); BEAST_EXPECT(proposingTrue.getOurVote() == true); BEAST_EXPECT(proposingFalse.getOurVote() == false); @@ -1333,10 +1333,10 @@ public: } for (int i = 1; i < 3; ++i) { - BEAST_EXPECT(!proposingTrue.updateVote(250 + 10 * i, true, p)); - BEAST_EXPECT(!proposingFalse.updateVote(250 + 10 * i, true, p)); - BEAST_EXPECT(!followingTrue.updateVote(250 + 10 * i, false, p)); - BEAST_EXPECT(!followingFalse.updateVote(250 + 10 * i, false, p)); + BEAST_EXPECT(!proposingTrue.updateVote(250 + (10 * i), true, p)); + BEAST_EXPECT(!proposingFalse.updateVote(250 + (10 * i), true, p)); + BEAST_EXPECT(!followingTrue.updateVote(250 + (10 * i), false, p)); + BEAST_EXPECT(!followingFalse.updateVote(250 + (10 * i), false, p)); BEAST_EXPECT(proposingTrue.getOurVote() == true); BEAST_EXPECT(proposingFalse.getOurVote() == false); @@ -1369,10 +1369,10 @@ public: } for (int i = 3; i < 5; ++i) { - BEAST_EXPECT(!proposingTrue.updateVote(250 + 10 * i, true, p)); - BEAST_EXPECT(!proposingFalse.updateVote(250 + 10 * i, true, p)); - BEAST_EXPECT(!followingTrue.updateVote(250 + 10 * i, false, p)); - BEAST_EXPECT(!followingFalse.updateVote(250 + 10 * i, false, p)); + BEAST_EXPECT(!proposingTrue.updateVote(250 + (10 * i), true, p)); + BEAST_EXPECT(!proposingFalse.updateVote(250 + (10 * i), true, p)); + BEAST_EXPECT(!followingTrue.updateVote(250 + (10 * i), false, p)); + BEAST_EXPECT(!followingFalse.updateVote(250 + (10 * i), false, p)); BEAST_EXPECT(proposingTrue.getOurVote() == true); BEAST_EXPECT(proposingFalse.getOurVote() == 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 23f7610300..cf8c8e87ef 100644 --- a/src/test/consensus/NegativeUNL_test.cpp +++ b/src/test/consensus/NegativeUNL_test.cpp @@ -1,12 +1,11 @@ #include #include -#include #include #include #include -#include +#include #include namespace xrpl { @@ -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); @@ -782,7 +790,7 @@ class NegativeUNLVoteInternal_test : public beast::unit_test::suite history.walkHistoryAndAddValidations( [&](std::shared_ptr const& l, std::size_t idx) -> bool { // skip half my validations. - return !(history.UNLNodeIDs[idx] == myId && l->seq() % 2 == 0); + return history.UNLNodeIDs[idx] != myId || l->seq() % 2 != 0; }); NegativeUNLVote vote(myId, history.env.journal); BEAST_EXPECT(!vote.buildScoreTable( @@ -890,7 +898,7 @@ class NegativeUNLVoteInternal_test : public beast::unit_test::suite * @param numReEnable number of ReEnable candidates expected * @return true if the number of candidates meets expectation */ - bool + static bool checkCandidateSizes( NegativeUNLVote& vote, hash_set const& unl, @@ -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/consensus/Validations_test.cpp b/src/test/consensus/Validations_test.cpp index cf4498bd52..dc6dfe539c 100644 --- a/src/test/consensus/Validations_test.cpp +++ b/src/test/consensus/Validations_test.cpp @@ -373,7 +373,7 @@ class Validations_test : public beast::unit_test::suite [&](TestValidations& vals) { vals.getCurrentNodeIDs(); }, [&](TestValidations& vals) { vals.getPreferred(genesisLedger); }, [&](TestValidations& vals) { vals.getNodesAfter(ledgerA, ledgerA.id()); }}; - for (Trigger trigger : triggers) + for (Trigger const& trigger : triggers) { TestHarness harness(h.oracle); Node n = harness.makeNode(); @@ -569,6 +569,7 @@ class Validations_test : public beast::unit_test::suite std::uint32_t baseFee = 0; std::vector expectedFees; + expectedFees.reserve(expectedValidations.size()); for (auto const& val : expectedValidations) { expectedFees.push_back(val.loadFee().value_or(baseFee)); diff --git a/src/test/core/ClosureCounter_test.cpp b/src/test/core/ClosureCounter_test.cpp index fe3f0a219f..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() @@ -299,7 +299,7 @@ class ClosureCounter_test : public beast::unit_test::suite BEAST_EXPECT(voidCounter.count() == 0); // Wait for the thread to exit. - while (threadExited == false) + while (!threadExited) ; localThread.join(); } diff --git a/src/test/core/Config_test.cpp b/src/test/core/Config_test.cpp index e9f7354482..edcb67b767 100644 --- a/src/test/core/Config_test.cpp +++ b/src/test/core/Config_test.cpp @@ -358,8 +358,8 @@ port_wss_admin "/Users/dummy/xrpld/config/log/debug.log"); // Restore the environment variables. - h ? setenv("HOME", h, 1) : unsetenv("HOME"); - x ? setenv("XDG_CONFIG_HOME", x, 1) : unsetenv("XDG_CONFIG_HOME"); + (h != nullptr) ? setenv("HOME", h, 1) : unsetenv("HOME"); + (x != nullptr) ? setenv("XDG_CONFIG_HOME", x, 1) : unsetenv("XDG_CONFIG_HOME"); } // The XDG config directory is not set: the config file must be in a @@ -394,8 +394,8 @@ port_wss_admin "/Users/dummy/xrpld/config/log/debug.log"); // Restore the environment variables. - h ? setenv("HOME", h, 1) : unsetenv("HOME"); - if (x) + (h != nullptr) ? setenv("HOME", h, 1) : unsetenv("HOME"); + if (x != nullptr) setenv("XDG_CONFIG_HOME", x, 1); } } diff --git a/src/test/core/JobQueue_test.cpp b/src/test/core/JobQueue_test.cpp index bf6a5590e6..13142c299f 100644 --- a/src/test/core/JobQueue_test.cpp +++ b/src/test/core/JobQueue_test.cpp @@ -23,7 +23,7 @@ class JobQueue_test : public beast::unit_test::suite jQueue.addJob(jtCLIENT, "JobAddTest1", [&jobRan]() { jobRan = true; }) == true); // Wait for the Job to run. - while (jobRan == false) + while (!jobRan) ; } { diff --git a/src/test/csf/Sim.h b/src/test/csf/Sim.h index 3525258c59..e5f64cae1f 100644 --- a/src/test/csf/Sim.h +++ b/src/test/csf/Sim.h @@ -129,8 +129,8 @@ public: Nodes in the group are synchronized if they share the same last fully validated and last generated ledger. */ - bool - synchronized(PeerGroup const& g) const; + static bool + synchronized(PeerGroup const& g); /** Check whether all peers in the network are synchronized */ diff --git a/src/test/csf/impl/Sim.cpp b/src/test/csf/impl/Sim.cpp index 4fbee56f0f..a775dd30ff 100644 --- a/src/test/csf/impl/Sim.cpp +++ b/src/test/csf/impl/Sim.cpp @@ -33,7 +33,7 @@ Sim::synchronized() const } bool -Sim::synchronized(PeerGroup const& g) const +Sim::synchronized(PeerGroup const& g) { if (g.size() < 1) return true; diff --git a/src/test/csf/impl/ledgers.cpp b/src/test/csf/impl/ledgers.cpp index 33e9b123c5..2c5bf07880 100644 --- a/src/test/csf/impl/ledgers.cpp +++ b/src/test/csf/impl/ledgers.cpp @@ -123,7 +123,7 @@ LedgerOracle::lookup(Ledger::ID const& id) const } std::size_t -LedgerOracle::branches(std::set const& ledgers) const +LedgerOracle::branches(std::set const& ledgers) { // Tips always maintains the Ledgers with largest sequence number // along all known chains. diff --git a/src/test/csf/ledgers.h b/src/test/csf/ledgers.h index 9da1c2182a..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 @@ -278,8 +277,8 @@ public: O \--> B */ - std::size_t - branches(std::set const& ledgers) const; + static std::size_t + branches(std::set const& ledgers); }; /** Helper for writing unit tests with controlled ledger histories. diff --git a/src/test/jtx/AMMTest.h b/src/test/jtx/AMMTest.h index 78e26b9e40..dd18733ffd 100644 --- a/src/test/jtx/AMMTest.h +++ b/src/test/jtx/AMMTest.h @@ -96,11 +96,11 @@ protected: class AMMTest : public jtx::AMMTestBase { protected: - XRPAmount - reserve(jtx::Env& env, std::uint32_t count) const; + static XRPAmount + reserve(jtx::Env& env, std::uint32_t count); - XRPAmount - ammCrtFee(jtx::Env& env) const; + static XRPAmount + ammCrtFee(jtx::Env& env); /* Path_test */ /************************************************/ diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 2ac0ca7435..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. @@ -510,6 +510,7 @@ public: */ // VFALCO NOTE This should return a unit-less amount PrettyAmount + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) balance(Account const& account, Asset const& asset) const; PrettyAmount diff --git a/src/test/jtx/Env_test.cpp b/src/test/jtx/Env_test.cpp index bd40ac9a81..51abac8101 100644 --- a/src/test/jtx/Env_test.cpp +++ b/src/test/jtx/Env_test.cpp @@ -28,7 +28,7 @@ public: } // Declarations in Account.h - void + static void testAccount() { using namespace jtx; diff --git a/src/test/jtx/PathSet.h b/src/test/jtx/PathSet.h index a363f9dff9..c522ed635e 100644 --- a/src/test/jtx/PathSet.h +++ b/src/test/jtx/PathSet.h @@ -3,6 +3,7 @@ #include #include +#include #include namespace xrpl { diff --git a/src/test/jtx/TestHelpers.h b/src/test/jtx/TestHelpers.h index 2836748ec3..08e86b40ac 100644 --- a/src/test/jtx/TestHelpers.h +++ b/src/test/jtx/TestHelpers.h @@ -317,7 +317,7 @@ template Json::Value getAccountLines(Env& env, AccountID const& acctId, IOU... ious) { - auto const jrr = getAccountLines(env, acctId); + auto jrr = getAccountLines(env, acctId); Json::Value res; for (auto const& line : jrr[jss::lines]) { diff --git a/src/test/jtx/impl/AMM.cpp b/src/test/jtx/impl/AMM.cpp index 6b2042efda..7109a2131d 100644 --- a/src/test/jtx/impl/AMM.cpp +++ b/src/test/jtx/impl/AMM.cpp @@ -443,7 +443,7 @@ AMM::deposit( // If including asset1In and asset2In or tokens as // deposit min amounts then must set the flags // explicitly instead of relying on this logic. - if (!(jvFlags & tfDepositSubTx)) + if ((jvFlags & tfDepositSubTx) == 0u) { if (tokens && !asset1In) { @@ -573,7 +573,7 @@ AMM::withdraw( std::uint32_t jvFlags = 0; if (flags) jvFlags = *flags; - if (!(jvFlags & tfWithdrawSubTx)) + if ((jvFlags & tfWithdrawSubTx) == 0u) { if (tokens && !asset1Out) { @@ -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/AMMTest.cpp b/src/test/jtx/impl/AMMTest.cpp index ab8c1578a3..9d9a537210 100644 --- a/src/test/jtx/impl/AMMTest.cpp +++ b/src/test/jtx/impl/AMMTest.cpp @@ -119,7 +119,7 @@ AMMTestBase::testAMM(std::function const& cb, TestAM return defXRP; return a + XRP(1000); } - auto const defIOU = STAmount{a.issue(), 30000}; + auto defIOU = STAmount{a.issue(), 30000}; if (a <= defIOU) return defIOU; return a + STAmount{a.issue(), 1000}; @@ -149,13 +149,13 @@ AMMTestBase::testAMM(std::function const& cb, TestAM } XRPAmount -AMMTest::reserve(jtx::Env& env, std::uint32_t count) const +AMMTest::reserve(jtx::Env& env, std::uint32_t count) { return env.current()->fees().accountReserve(count); } XRPAmount -AMMTest::ammCrtFee(jtx::Env& env) const +AMMTest::ammCrtFee(jtx::Env& env) { return env.current()->fees().increment; } diff --git a/src/test/jtx/impl/Env.cpp b/src/test/jtx/impl/Env.cpp index 3217f67cbe..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); @@ -76,7 +76,7 @@ Env::AppBundle::~AppBundle() client.reset(); // Make sure all jobs finish, otherwise tests // might not get the coverage they expect. - if (app) + if (app != nullptr) { app->getJobQueue().rendezvous(); app->signalStop("~AppBundle"); @@ -218,6 +218,7 @@ Env::balance(Account const& account, MPTIssue const& mptIssue) const } PrettyAmount +// NOLINTNEXTLINE(readability-convert-member-functions-to-static) Env::balance(Account const& account, Asset const& asset) const { return std::visit([&](auto const& issue) { return balance(account, issue); }, asset.value()); @@ -468,7 +469,7 @@ Env::postconditions( // we didn't get the expected result. return; } - if (trace_) + if (trace_ != 0) { if (trace_ > 0) --trace_; @@ -636,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/Oracle.cpp b/src/test/jtx/impl/Oracle.cpp index 8bc456cd4e..0c9ddc8f0d 100644 --- a/src/test/jtx/impl/Oracle.cpp +++ b/src/test/jtx/impl/Oracle.cpp @@ -258,7 +258,7 @@ Oracle::set(UpdateArg const& arg) return s; assert(s.size() <= 20); // anything else must be 160-bit hex string - return strHex(s).append(40 - s.size() * 2, '0'); + return strHex(s).append(40 - (s.size() * 2), '0'); }; for (auto const& data : arg.series) { diff --git a/src/test/jtx/impl/TestHelpers.cpp b/src/test/jtx/impl/TestHelpers.cpp index 5e7a31adcd..e10a0c46d0 100644 --- a/src/test/jtx/impl/TestHelpers.cpp +++ b/src/test/jtx/impl/TestHelpers.cpp @@ -2,6 +2,7 @@ #include #include +#include #include namespace xrpl { 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/mpt.cpp b/src/test/jtx/impl/mpt.cpp index b6b08734c7..2b78777838 100644 --- a/src/test/jtx/impl/mpt.cpp +++ b/src/test/jtx/impl/mpt.cpp @@ -1,5 +1,6 @@ #include +#include #include #include @@ -44,7 +45,7 @@ MPTTester::MPTTester(Env& env, Account const& issuer, MPTInit const& arg) if (arg.fund) { env_.fund(arg.xrp, issuer_); - for (auto it : holders_) + for (auto const& it : holders_) env_.fund(arg.xrpHolders, it.second); } if (close_) @@ -52,7 +53,7 @@ MPTTester::MPTTester(Env& env, Account const& issuer, MPTInit const& arg) if (arg.fund) { env_.require(owners(issuer_, 0)); - for (auto it : holders_) + for (auto const& it : holders_) { if (issuer_.id() == it.second.id()) Throw("Issuer can't be holder"); @@ -369,7 +370,7 @@ MPTTester::set(MPTSet const& arg) .metadata = arg.metadata, .delegate = arg.delegate, .domainID = arg.domainID}); - if (submit(arg, jv) == tesSUCCESS && (arg.flags.value_or(0) || arg.mutableFlags)) + if (submit(arg, jv) == tesSUCCESS && ((arg.flags.value_or(0) != 0u) || arg.mutableFlags)) { auto require = [&](std::optional const& holder, bool unchanged) { auto flags = getFlags(holder); diff --git a/src/test/jtx/impl/multisign.cpp b/src/test/jtx/impl/multisign.cpp index ae39382824..02550b803c 100644 --- a/src/test/jtx/impl/multisign.cpp +++ b/src/test/jtx/impl/multisign.cpp @@ -83,7 +83,7 @@ msig::operator()(Env& env, JTx& jt) const jo[sfTxnSignature.getJsonName()] = strHex(Slice{sig.data(), sig.size()}); } }; - if (!subField) + if (subField == nullptr) { jt.mainSigners.emplace_back(callback); } diff --git a/src/test/jtx/impl/offer.cpp b/src/test/jtx/impl/offer.cpp index 251b659f3b..5a2264601a 100644 --- a/src/test/jtx/impl/offer.cpp +++ b/src/test/jtx/impl/offer.cpp @@ -17,7 +17,7 @@ offer( jv[jss::Account] = account.human(); jv[jss::TakerPays] = takerPays.getJson(JsonOptions::none); jv[jss::TakerGets] = takerGets.getJson(JsonOptions::none); - if (flags) + if (flags != 0u) jv[jss::Flags] = flags; jv[jss::TransactionType] = jss::OfferCreate; return jv; diff --git a/src/test/jtx/impl/owners.cpp b/src/test/jtx/impl/owners.cpp index 53f2302143..855c5b04ff 100644 --- a/src/test/jtx/impl/owners.cpp +++ b/src/test/jtx/impl/owners.cpp @@ -1,5 +1,7 @@ #include +#include + namespace xrpl { namespace detail { 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/impl/sig.cpp b/src/test/jtx/impl/sig.cpp index 850c5af781..1bdadc0bd3 100644 --- a/src/test/jtx/impl/sig.cpp +++ b/src/test/jtx/impl/sig.cpp @@ -10,7 +10,7 @@ sig::operator()(Env&, JTx& jt) const { if (!manual_) return; - if (!subField_) + if (subField_ == nullptr) jt.fill_sig = false; if (account_) { @@ -22,7 +22,7 @@ sig::operator()(Env&, JTx& jt) const jtx::sign(jtx.jv, account, sigObject); }; - if (!subField_) + if (subField_ == nullptr) { jt.mainSigners.emplace_back(callback); } diff --git a/src/test/jtx/mpt.h b/src/test/jtx/mpt.h index 3368d129c1..3990dd3087 100644 --- a/src/test/jtx/mpt.h +++ b/src/test/jtx/mpt.h @@ -291,7 +291,7 @@ private: env_.require(owners(issuer_, *arg.ownerCount)); if (arg.holderCount) { - for (auto it : holders_) + for (auto const& it : holders_) env_.require(owners(it.second, *arg.holderCount)); } return err; diff --git a/src/test/jtx/multisign.h b/src/test/jtx/multisign.h index 56d0b10906..b3f38cc453 100644 --- a/src/test/jtx/multisign.h +++ b/src/test/jtx/multisign.h @@ -22,7 +22,7 @@ struct signer std::optional tag; signer(Account account_, std::uint32_t weight_ = 1, std::optional tag_ = std::nullopt) - : weight(weight_), account(std::move(account_)), tag(std::move(tag_)) + : weight(weight_), account(std::move(account_)), tag(tag_) { } }; diff --git a/src/test/jtx/owners.h b/src/test/jtx/owners.h index 785a9347dd..3f54e0c55f 100644 --- a/src/test/jtx/owners.h +++ b/src/test/jtx/owners.h @@ -2,7 +2,7 @@ #include -#include +#include #include #include 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/jtx/vault.h b/src/test/jtx/vault.h index 43f975323a..748d3341a5 100644 --- a/src/test/jtx/vault.h +++ b/src/test/jtx/vault.h @@ -38,7 +38,7 @@ struct Vault uint256 id; }; - Json::Value + static Json::Value set(SetArgs const& args); struct DeleteArgs @@ -47,7 +47,7 @@ struct Vault uint256 id; }; - Json::Value + static Json::Value del(DeleteArgs const& args); struct DepositArgs @@ -57,7 +57,7 @@ struct Vault STAmount amount; }; - Json::Value + static Json::Value deposit(DepositArgs const& args); struct WithdrawArgs @@ -67,7 +67,7 @@ struct Vault STAmount amount; }; - Json::Value + static Json::Value withdraw(WithdrawArgs const& args); struct ClawbackArgs @@ -78,7 +78,7 @@ struct Vault std::optional amount{}; }; - Json::Value + static Json::Value clawback(ClawbackArgs const& args); }; diff --git a/src/test/ledger/Directory_test.cpp b/src/test/ledger/Directory_test.cpp index ec76b67e9c..aec472fc6f 100644 --- a/src/test/ledger/Directory_test.cpp +++ b/src/test/ledger/Directory_test.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,7 @@ struct Directory_test : public beast::unit_test::suite // Insert n empty pages, numbered [0, ... n - 1], in the // specified directory: - void + static void makePages(Sandbox& sb, uint256 const& base, std::uint64_t n) { for (std::uint64_t i = 0; i < n; ++i) @@ -203,7 +204,7 @@ struct Directory_test : public beast::unit_test::suite BEAST_EXPECT(dirIsEmpty(*env.closed(), keylet::ownerDir(alice))); - for (auto c : currencies) + for (auto const& c : currencies) { env(trust(charlie, c(50))); env.close(); @@ -273,7 +274,7 @@ struct Directory_test : public beast::unit_test::suite { for (int i = 0; i < dirNodeMaxEntries; ++i) { - env(offer_cancel(alice, firstOfferSeq + page * dirNodeMaxEntries + i)); + env(offer_cancel(alice, firstOfferSeq + (page * dirNodeMaxEntries) + i)); env.close(); } } diff --git a/src/test/ledger/PaymentSandbox_test.cpp b/src/test/ledger/PaymentSandbox_test.cpp index 2a0d74e3d9..df23381ed3 100644 --- a/src/test/ledger/PaymentSandbox_test.cpp +++ b/src/test/ledger/PaymentSandbox_test.cpp @@ -2,7 +2,8 @@ #include #include -#include +#include +#include #include #include @@ -87,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 bae29445c2..6e11508156 100644 --- a/src/test/ledger/View_test.cpp +++ b/src/test/ledger/View_test.cpp @@ -1,12 +1,14 @@ #include -#include #include #include +#include #include #include #include +#include +#include #include #include @@ -114,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); @@ -145,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); @@ -178,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)); @@ -244,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)); @@ -313,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); @@ -377,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); @@ -581,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); @@ -927,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; @@ -945,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/nodestore/NuDBFactory_test.cpp b/src/test/nodestore/NuDBFactory_test.cpp index 9a9b7d83bd..0aa910ce01 100644 --- a/src/test/nodestore/NuDBFactory_test.cpp +++ b/src/test/nodestore/NuDBFactory_test.cpp @@ -17,7 +17,7 @@ class NuDBFactory_test : public TestBase { private: // Helper function to create a Section with specified parameters - Section + static Section createSection(std::string const& path, std::string const& blockSize = "") { Section params; diff --git a/src/test/nodestore/Timing_test.cpp b/src/test/nodestore/Timing_test.cpp index d5c89dbcc9..fc8c042252 100644 --- a/src/test/nodestore/Timing_test.cpp +++ b/src/test/nodestore/Timing_test.cpp @@ -111,7 +111,7 @@ public: { b.clear(); b.reserve(size); - while (size--) + while ((size--) != 0u) b.emplace_back(obj(n++)); } }; @@ -524,7 +524,7 @@ public: , seq1_(1) , gen_(id + 1) , rand_(0, 99) - , recent_(params.items, params.items * 2 - 1) + , recent_(params.items, (params.items * 2) - 1) , older_(0, params.items - 1) { } @@ -643,7 +643,7 @@ public: Params params{}; params.items = default_items; params.threads = threads; - for (auto i = default_repeat; i--;) + for (auto i = default_repeat; (i--) != 0u;) { beast::temp_dir tempDir; Section config = parse(config_string); diff --git a/src/test/nodestore/import_test.cpp b/src/test/nodestore/import_test.cpp index e5f281486b..54d55e5ad0 100644 --- a/src/test/nodestore/import_test.cpp +++ b/src/test/nodestore/import_test.cpp @@ -333,7 +333,7 @@ public: options.max_open_files = 2000; // 5000? rocksdb::DB* pdb = nullptr; rocksdb::Status status = rocksdb::DB::OpenForReadOnly(options, from_path, &pdb); - if (!status.ok() || !pdb) + if (!status.ok() || (pdb == nullptr)) Throw("Can't open '" + from_path + "': " + status.ToString()); db.reset(pdb); } @@ -458,7 +458,7 @@ public: // Create empty buckets for (std::size_t i = 0; i < bn; ++i) { - bucket b(kh.block_size, buf.get() + i * kh.block_size, empty); + bucket b(kh.block_size, buf.get() + (i * kh.block_size), empty); } // Insert all keys into buckets // Iterate Data File @@ -484,10 +484,10 @@ public: std::uint8_t const* const key = is.data(dh.key_size); auto const h = hash(key, kh.key_size, kh.salt); auto const n = bucket_index(h, kh.buckets, kh.modulus); - p(log, npass * df_size + r.offset()); + p(log, (npass * df_size) + r.offset()); if (n < b0 || n >= b1) continue; - bucket b(kh.block_size, buf.get() + (n - b0) * kh.block_size); + bucket b(kh.block_size, buf.get() + ((n - b0) * kh.block_size)); maybe_spill(b, dw, ec); if (ec) Throw(ec); diff --git a/src/test/overlay/TMGetObjectByHash_test.cpp b/src/test/overlay/TMGetObjectByHash_test.cpp index 0624c7b088..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_); @@ -121,7 +121,7 @@ class TMGetObjectByHash_test : public beast::unit_test::suite return peer; } - std::shared_ptr + static std::shared_ptr createRequest(size_t const numObjects, Env& env) { // Store objects in the NodeStore that will be found during the query diff --git a/src/test/overlay/cluster_test.cpp b/src/test/overlay/cluster_test.cpp index 6fa4604f78..59fa22a442 100644 --- a/src/test/overlay/cluster_test.cpp +++ b/src/test/overlay/cluster_test.cpp @@ -29,7 +29,7 @@ public: return cluster; } - PublicKey + static PublicKey randomNode() { return derivePublicKey(KeyType::secp256k1, randomSecretKey()); diff --git a/src/test/overlay/compression_test.cpp b/src/test/overlay/compression_test.cpp index f784a91350..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 @@ -117,7 +117,7 @@ public: decompressed.begin())); } - std::shared_ptr + static std::shared_ptr buildManifests(int n) { auto manifests = std::make_shared(); @@ -143,7 +143,7 @@ public: return manifests; } - std::shared_ptr + static std::shared_ptr buildEndpoints(int n) { auto endpoints = std::make_shared(); @@ -196,7 +196,7 @@ public: return transaction; } - std::shared_ptr + static std::shared_ptr buildGetLedger() { auto getLedger = std::make_shared(); @@ -213,7 +213,7 @@ public: return getLedger; } - std::shared_ptr + static std::shared_ptr buildLedgerData(uint32_t n, Logs& logs) { auto ledgerData = std::make_shared(); @@ -251,7 +251,7 @@ public: return ledgerData; } - std::shared_ptr + static std::shared_ptr buildGetObjectByHash() { auto getObject = std::make_shared(); @@ -277,7 +277,7 @@ public: return getObject; } - std::shared_ptr + static std::shared_ptr buildValidatorList() { auto list = std::make_shared(); @@ -304,7 +304,7 @@ public: return list; } - std::shared_ptr + static std::shared_ptr buildValidatorListCollection() { auto list = std::make_shared(); diff --git a/src/test/overlay/reduce_relay_test.cpp b/src/test/overlay/reduce_relay_test.cpp index 8e50415aa9..895332b94f 100644 --- a/src/test/overlay/reduce_relay_test.cpp +++ b/src/test/overlay/reduce_relay_test.cpp @@ -362,7 +362,7 @@ public: { for (auto id : peers) { - assert(links_.find(id) != links_.end()); + assert(links_.contains(id)); f(*links_[id], message_); } } @@ -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 @@ -637,7 +637,7 @@ public: getSelectedPeer(PublicKey const& validator) { auto selected = slots_.getSelected(validator); - assert(selected.size()); + assert(!selected.empty()); return *selected.begin(); } @@ -673,7 +673,7 @@ private: Peers peers_; Peers peersCache_; reduce_relay::Slots slots_; - Logs& logs_; + ServiceRegistry& registry_; }; class Network @@ -785,7 +785,7 @@ public: } } - void + static void for_rand(std::uint32_t min, std::uint32_t max, std::function f) { auto size = max - min; @@ -879,14 +879,14 @@ protected: } /** Send squelch (if duration is set) or unsquelch (if duration not set) */ - Peer::id_t + static Peer::id_t sendSquelch( PublicKey const& validator, PeerWPtr const& peerPtr, std::optional duration) { protocol::TMSquelch squelch; - bool res = duration ? true : false; + bool res = static_cast(duration); squelch.set_squelch(res); squelch.set_validatorpubkey(validator.data(), validator.size()); if (res) @@ -1004,8 +1004,8 @@ protected: // take place because there is no peers in Squelched state in // any of the slots where the peer is in Selected state // (allCounting is true) - bool handled = (event.isSelected_ == false && !event.handled_) || - (event.isSelected_ == true && (event.handled_ || allCounting)); + bool handled = (!event.isSelected_ && !event.handled_) || + (event.isSelected_ && (event.handled_ || allCounting)); BEAST_EXPECT(handled); event.state_ = State::Off; event.isSelected_ = false; @@ -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 @@ -1499,7 +1498,7 @@ vp_base_squelch_max_selected_peers=2 { // make unique message hash to make the // slot's internal hash router accept the message - std::uint64_t mid = m * 1000 + peer; + std::uint64_t mid = (m * 1000) + peer; uint256 const message{mid}; slots.updateSlotAndSquelch( message, validator, peer, protocol::MessageType::mtVALIDATION); 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/protocol/MultiApiJson_test.cpp b/src/test/protocol/MultiApiJson_test.cpp index 0da511b976..5aafa19771 100644 --- a/src/test/protocol/MultiApiJson_test.cpp +++ b/src/test/protocol/MultiApiJson_test.cpp @@ -236,7 +236,7 @@ struct MultiApiJson_test : beast::unit_test::suite std::forward(v).visit(), // [](auto...) {}); }; - }(std::move(std::as_const(s1)))); + }(std::move(std::as_const(s1)))); // NOLINT(performance-move-const-arg) } { @@ -867,22 +867,22 @@ struct MultiApiJson_test : beast::unit_test::suite return !requires { std::forward(v).visit(1, [](Json::Value const&&) {}); }; - }(std::move(std::as_const(s1)))); + }(std::move(std::as_const(s1)))); // NOLINT(performance-move-const-arg) static_assert([](auto&& v) { return requires { std::forward(v).visit(1, [](Json::Value const&) {}); }; - }(std::move(std::as_const(s1)))); + }(std::move(std::as_const(s1)))); // NOLINT(performance-move-const-arg) static_assert([](auto&& v) { return !requires { std::forward(v).visit()(1, [](Json::Value const&&) {}); }; - }(std::move(std::as_const(s1)))); + }(std::move(std::as_const(s1)))); // NOLINT(performance-move-const-arg) static_assert([](auto&& v) { return requires { std::forward(v).visit()(1, [](Json::Value const&) {}); }; - }(std::move(std::as_const(s1)))); + }(std::move(std::as_const(s1)))); // NOLINT(performance-move-const-arg) // Missing const static_assert([](auto&& v) { diff --git a/src/test/protocol/PublicKey_test.cpp b/src/test/protocol/PublicKey_test.cpp index 053e945a7b..79c1356bb4 100644 --- a/src/test/protocol/PublicKey_test.cpp +++ b/src/test/protocol/PublicKey_test.cpp @@ -46,7 +46,7 @@ public: } } - blob + static blob sig(std::string const& hex) { blob b; @@ -54,7 +54,7 @@ public: return b; } - bool + static bool check(std::optional answer, std::string const& s) { return ecdsaCanonicality(makeSlice(sig(s))) == answer; diff --git a/src/test/protocol/STAmount_test.cpp b/src/test/protocol/STAmount_test.cpp index c9382d508a..4f652dddd9 100644 --- a/src/test/protocol/STAmount_test.cpp +++ b/src/test/protocol/STAmount_test.cpp @@ -21,7 +21,7 @@ public: } //-------------------------------------------------------------------------- - STAmount + static STAmount roundSelf(STAmount const& amount) { if (amount.native()) diff --git a/src/test/protocol/STParsedJSON_test.cpp b/src/test/protocol/STParsedJSON_test.cpp index 18e695d25d..974975d05f 100644 --- a/src/test/protocol/STParsedJSON_test.cpp +++ b/src/test/protocol/STParsedJSON_test.cpp @@ -11,7 +11,7 @@ namespace xrpl { class STParsedJSON_test : public beast::unit_test::suite { - bool + static bool parseJSONString(std::string const& json, Json::Value& to) { Json::Reader reader; diff --git a/src/test/protocol/SeqProxy_test.cpp b/src/test/protocol/SeqProxy_test.cpp index 9096fe7daf..7e7a21ab6e 100644 --- a/src/test/protocol/SeqProxy_test.cpp +++ b/src/test/protocol/SeqProxy_test.cpp @@ -42,7 +42,7 @@ struct SeqProxy_test : public beast::unit_test::suite } // Verify streaming. - bool + static bool streamTest(SeqProxy seqProx) { std::string const type{seqProx.isSeq() ? "sequence" : "ticket"}; diff --git a/src/test/resource/Logic_test.cpp b/src/test/resource/Logic_test.cpp index c555b92860..6d412b000f 100644 --- a/src/test/resource/Logic_test.cpp +++ b/src/test/resource/Logic_test.cpp @@ -44,7 +44,7 @@ public: //-------------------------------------------------------------------------- - void + static void createGossip(Gossip& gossip) { std::uint8_t const v(10 + rand_int(9)); @@ -182,7 +182,7 @@ public: } } } - if (readmitted == false) + if (!readmitted) { fail("Dropped Consumer left on blacklist too long"); return; diff --git a/src/test/rpc/AccountObjects_test.cpp b/src/test/rpc/AccountObjects_test.cpp index 435bbd37d5..905f8f2bb7 100644 --- a/src/test/rpc/AccountObjects_test.cpp +++ b/src/test/rpc/AccountObjects_test.cpp @@ -1313,7 +1313,7 @@ public: auto resp = env.rpc("json", "account_objects", to_string(params)); auto& accountObjects = resp[jss::result][jss::account_objects]; BEAST_EXPECT(!resp[jss::result].isMember(jss::error)); - BEAST_EXPECT(accountObjects.size() == accountObjectSize - limit * 2); + BEAST_EXPECT(accountObjects.size() == accountObjectSize - (limit * 2)); BEAST_EXPECT(!resp[jss::result].isMember(jss::marker)); } diff --git a/src/test/rpc/Book_test.cpp b/src/test/rpc/Book_test.cpp index 7ebe6e97ae..41442edb06 100644 --- a/src/test/rpc/Book_test.cpp +++ b/src/test/rpc/Book_test.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -14,7 +15,7 @@ namespace test { class Book_test : public beast::unit_test::suite { - std::string + static std::string getBookDir( jtx::Env& env, Issue const& in, @@ -1523,7 +1524,7 @@ public: auto USD = gw["USD"]; for (auto i = 0; i <= RPC::Tuning::bookOffers.rmax; i++) - env(offer(gw, XRP(50 + 1 * i), USD(1.0 + 0.1 * i))); + env(offer(gw, XRP(50 + (1 * i)), USD(1.0 + (0.1 * i)))); if (asAdmin) env.close(); diff --git a/src/test/rpc/DeliveredAmount_test.cpp b/src/test/rpc/DeliveredAmount_test.cpp index 00f8c54ee5..31b9b2aebf 100644 --- a/src/test/rpc/DeliveredAmount_test.cpp +++ b/src/test/rpc/DeliveredAmount_test.cpp @@ -76,7 +76,8 @@ public: bool checkExpectedCounters() const { - return !numExpectedAvailable_ && !numExpectedNotSet_ && !numExpectedSetUnavailable_; + return (numExpectedAvailable_ == 0) && (numExpectedNotSet_ == 0) && + (numExpectedSetUnavailable_ == 0); } // Check if the transaction has `delivered_amount` in the metaData as diff --git a/src/test/rpc/LedgerEntry_test.cpp b/src/test/rpc/LedgerEntry_test.cpp index eec114b71c..474f29da17 100644 --- a/src/test/rpc/LedgerEntry_test.cpp +++ b/src/test/rpc/LedgerEntry_test.cpp @@ -131,7 +131,7 @@ class LedgerEntry_test : public beast::unit_test::suite } } - std::vector + static std::vector getBadValues(FieldType fieldType) { static Json::Value const injectObject = []() { @@ -225,7 +225,7 @@ class LedgerEntry_test : public beast::unit_test::suite } } - Json::Value + static Json::Value getCorrectValue(Json::StaticString fieldName) { static Json::Value const twoAccountArray = []() { @@ -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; @@ -2189,7 +2189,7 @@ class LedgerEntry_test : public beast::unit_test::suite Account const bob{"bob"}; Env env{*this, envconfig([](auto cfg) { - cfg->START_UP = StartUpType::FRESH; + cfg->START_UP = StartUpType::Fresh; return cfg; })}; @@ -2382,7 +2382,7 @@ class LedgerEntry_test : public beast::unit_test::suite Account const bob{"bob"}; Env env{*this, envconfig([](auto cfg) { - cfg->START_UP = StartUpType::FRESH; + cfg->START_UP = StartUpType::Fresh; return cfg; })}; diff --git a/src/test/rpc/LedgerRPC_test.cpp b/src/test/rpc/LedgerRPC_test.cpp index 2f4a63a090..8f965aa2cf 100644 --- a/src/test/rpc/LedgerRPC_test.cpp +++ b/src/test/rpc/LedgerRPC_test.cpp @@ -40,7 +40,7 @@ class LedgerRPC_test : public beast::unit_test::suite // Corrupt a valid address by replacing the 10th character with '!'. // '!' is not part of the ripple alphabet. - std::string + static std::string makeBadAddress(std::string good) { std::string ret = std::move(good); 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/Roles_test.cpp b/src/test/rpc/Roles_test.cpp index a4f9de2284..e3d90a9c56 100644 --- a/src/test/rpc/Roles_test.cpp +++ b/src/test/rpc/Roles_test.cpp @@ -12,7 +12,7 @@ namespace test { class Roles_test : public beast::unit_test::suite { - bool + static bool isValidIpAddress(std::string const& addr) { boost::system::error_code ec; diff --git a/src/test/rpc/ServerInfo_test.cpp b/src/test/rpc/ServerInfo_test.cpp index 5bb2c31757..978b995ce8 100644 --- a/src/test/rpc/ServerInfo_test.cpp +++ b/src/test/rpc/ServerInfo_test.cpp @@ -93,7 +93,7 @@ admin = 127.0.0.1 Env env(*this); // Call NetworkOPs directly and set the admin flag to false. - auto const result = env.app().getOPs().getServerInfo(true, false, 0); + auto const result = env.app().getOPs().getServerInfo(true, false, false); // Expect that the admin ports are not included in the result. auto const& ports = result[jss::ports]; BEAST_EXPECT(ports.isArray() && ports.size() == 0); diff --git a/src/test/rpc/Simulate_test.cpp b/src/test/rpc/Simulate_test.cpp index 74f9b03111..e096b0479f 100644 --- a/src/test/rpc/Simulate_test.cpp +++ b/src/test/rpc/Simulate_test.cpp @@ -131,8 +131,8 @@ class Simulate_test : public beast::unit_test::suite BEAST_EXPECTS(env.current()->txCount() == 0, std::to_string(env.current()->txCount())); } - Json::Value - getJsonMetadata(Json::Value txResult) const + static Json::Value + getJsonMetadata(Json::Value txResult) { if (txResult.isMember(jss::meta_blob)) { diff --git a/src/test/rpc/Transaction_test.cpp b/src/test/rpc/Transaction_test.cpp index 2709900bf1..c53207e04d 100644 --- a/src/test/rpc/Transaction_test.cpp +++ b/src/test/rpc/Transaction_test.cpp @@ -19,7 +19,7 @@ namespace xrpl { class Transaction_test : public beast::unit_test::suite { - std::unique_ptr + static std::unique_ptr makeNetworkConfig(uint32_t networkID) { using namespace test::jtx; @@ -91,7 +91,7 @@ class Transaction_test : public beast::unit_test::suite result[jss::result][jss::status] == jss::error && result[jss::result][jss::error] == NOT_FOUND); - if (deltaEndSeq) + if (deltaEndSeq != 0) { BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool()); } @@ -332,7 +332,7 @@ class Transaction_test : public beast::unit_test::suite result[jss::result][jss::status] == jss::error && result[jss::result][jss::error] == NOT_FOUND); - if (deltaEndSeq) + if (deltaEndSeq != 0) { BEAST_EXPECT(!result[jss::result][jss::searched_all].asBool()); } 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/test/server/ServerStatus_test.cpp b/src/test/server/ServerStatus_test.cpp index 178b85b3e4..1a5da25d65 100644 --- a/src/test/server/ServerStatus_test.cpp +++ b/src/test/server/ServerStatus_test.cpp @@ -33,7 +33,7 @@ class ServerStatus_test : public beast::unit_test::suite, public beast::test::en { }; - auto + static auto makeConfig(std::string const& proto, bool admin = true, bool credentials = false) { auto const section_name = boost::starts_with(proto, "h") ? "port_rpc" : "port_ws"; @@ -69,7 +69,7 @@ class ServerStatus_test : public beast::unit_test::suite, public beast::test::en return p; } - auto + static auto makeWSUpgrade(std::string const& host, uint16_t port) { using namespace boost::asio; @@ -97,7 +97,7 @@ class ServerStatus_test : public beast::unit_test::suite, public beast::test::en return req; } - auto + static auto makeHTTPRequest( std::string const& host, uint16_t port, @@ -217,7 +217,7 @@ class ServerStatus_test : public beast::unit_test::suite, public beast::test::en return; } - auto + static auto makeAdminRequest( jtx::Env& env, std::string const& proto, diff --git a/src/test/server/Server_test.cpp b/src/test/server/Server_test.cpp index bce8bced60..b6ff180bd4 100644 --- a/src/test/server/Server_test.cpp +++ b/src/test/server/Server_test.cpp @@ -91,13 +91,13 @@ public: struct TestHandler { - bool + static bool onAccept(Session& session, boost::asio::ip::tcp::endpoint endpoint) { return true; } - Handoff + static Handoff onHandoff( Session& session, std::unique_ptr const& bundle, @@ -107,7 +107,7 @@ public: return Handoff{}; } - Handoff + static Handoff onHandoff( Session& session, http_request_type const& request, @@ -116,7 +116,7 @@ public: return Handoff{}; } - void + static void onRequest(Session& session) { session.write(std::string("Hello, world!\n")); @@ -303,13 +303,13 @@ public: testcase("stress test"); struct NullHandler { - bool + static bool onAccept(Session& session, boost::asio::ip::tcp::endpoint endpoint) { return true; } - Handoff + static Handoff onHandoff( Session& session, std::unique_ptr const& bundle, @@ -319,7 +319,7 @@ public: return Handoff{}; } - Handoff + static Handoff onHandoff( Session& session, http_request_type const& request, diff --git a/src/test/shamap/FetchPack_test.cpp b/src/test/shamap/FetchPack_test.cpp index 471ad91e95..ad86e066af 100644 --- a/src/test/shamap/FetchPack_test.cpp +++ b/src/test/shamap/FetchPack_test.cpp @@ -66,7 +66,7 @@ public: beast::Journal mJournal; }; - boost::intrusive_ptr + static boost::intrusive_ptr make_random_item(beast::xor_shift_engine& r) { Serializer s; @@ -75,10 +75,10 @@ public: return make_shamapitem(s.getSHA512Half(), s.slice()); } - void + static void add_random_items(std::size_t n, Table& t, beast::xor_shift_engine& r) { - while (n--) + while ((n--) != 0u) { auto const result(t.addItem(SHAMapNodeType::tnACCOUNT_STATE, make_random_item(r))); assert(result); diff --git a/src/tests/libxrpl/basics/RangeSet.cpp b/src/tests/libxrpl/basics/RangeSet.cpp index d0fc656368..41a33133f2 100644 --- a/src/tests/libxrpl/basics/RangeSet.cpp +++ b/src/tests/libxrpl/basics/RangeSet.cpp @@ -17,7 +17,7 @@ TEST(RangeSet, prevMissing) RangeSet set; for (std::uint32_t i = 0; i < 10; ++i) - set.insert(range(10 * i, 10 * i + 5)); + set.insert(range(10 * i, (10 * i) + 5)); for (std::uint32_t i = 1; i < 100; ++i) { diff --git a/src/tests/libxrpl/json/Value.cpp b/src/tests/libxrpl/json/Value.cpp index a7b7387ba1..943e517669 100644 --- a/src/tests/libxrpl/json/Value.cpp +++ b/src/tests/libxrpl/json/Value.cpp @@ -209,10 +209,10 @@ TEST(json_value, compare_strings) SCOPED_TRACE(line); EXPECT_EQ((lhs == rhs), lhsEqRhs); EXPECT_NE((lhs != rhs), lhsEqRhs); - EXPECT_EQ((lhs < rhs), (!(lhsEqRhs || !lhsLtRhs))); + EXPECT_EQ((lhs < rhs), (!lhsEqRhs && lhsLtRhs)); EXPECT_EQ((lhs <= rhs), (lhsEqRhs || lhsLtRhs)); EXPECT_EQ((lhs >= rhs), (lhsEqRhs || !lhsLtRhs)); - EXPECT_EQ((lhs > rhs), (!(lhsEqRhs || lhsLtRhs))); + EXPECT_EQ((lhs > rhs), (!lhsEqRhs && !lhsLtRhs)); }; Json::Value const null0; diff --git a/src/xrpld/app/consensus/RCLConsensus.cpp b/src/xrpld/app/consensus/RCLConsensus.cpp index 5a3d53dae0..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 @@ -997,7 +997,7 @@ RCLConsensus::Adaptor::validator() const void RCLConsensus::Adaptor::updateOperatingMode(std::size_t const positions) const { - if (!positions && app_.getOPs().isFull()) + if ((positions == 0u) && app_.getOPs().isFull()) app_.getOPs().setMode(OperatingMode::CONNECTED); } 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/RCLCxPeerPos.cpp b/src/xrpld/app/consensus/RCLCxPeerPos.cpp index cdb8350468..8f99dceea8 100644 --- a/src/xrpld/app/consensus/RCLCxPeerPos.cpp +++ b/src/xrpld/app/consensus/RCLCxPeerPos.cpp @@ -10,13 +10,13 @@ RCLCxPeerPos::RCLCxPeerPos( PublicKey const& publicKey, Slice const& signature, uint256 const& suppression, - Proposal&& proposal) - : publicKey_(publicKey), suppression_(suppression), proposal_(std::move(proposal)) + Proposal const& proposal) // trivially copyable + : publicKey_(publicKey), suppression_(suppression), proposal_(proposal) { // The maximum allowed size of a signature is 72 bytes; we verify // this elsewhere, but we want to be extra careful here: XRPL_ASSERT( - signature.size() != 0 && signature.size() <= signature_.capacity(), + !signature.empty() && signature.size() <= signature_.capacity(), "xrpl::RCLCxPeerPos::RCLCxPeerPos : valid signature size"); if (!signature.empty() && signature.size() <= signature_.capacity()) @@ -34,7 +34,7 @@ RCLCxPeerPos::getJson() const { auto ret = proposal().getJson(); - if (publicKey().size()) + if (publicKey().size() != 0u) ret[jss::peer_id] = toBase58(TokenType::NodePublic, publicKey()); return ret; diff --git a/src/xrpld/app/consensus/RCLCxPeerPos.h b/src/xrpld/app/consensus/RCLCxPeerPos.h index 5dad4a33eb..e334320826 100644 --- a/src/xrpld/app/consensus/RCLCxPeerPos.h +++ b/src/xrpld/app/consensus/RCLCxPeerPos.h @@ -40,7 +40,7 @@ public: PublicKey const& publicKey, Slice const& signature, uint256 const& suppress, - Proposal&& proposal); + Proposal const& proposal); // trivially copyable //! Verify the signing hash of the proposal bool diff --git a/src/xrpld/app/consensus/RCLValidations.cpp b/src/xrpld/app/consensus/RCLValidations.cpp index a968acb1a7..7bc16f194e 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 @@ -132,7 +131,7 @@ RCLValidationsAdaptor::acquire(LedgerHash const& hash) XRPL_ASSERT( ledger->header().hash == hash, "xrpl::RCLValidationsAdaptor::acquire : ledger hash match"); - return RCLValidatedLedger(std::move(ledger), j_); + return RCLValidatedLedger(ledger, j_); } void @@ -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..c8ea46cf7f 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")) { } @@ -27,7 +26,7 @@ make_OrderBookDB(ServiceRegistry& registry, OrderBookDBConfig const& config) void OrderBookDBImpl::setup(std::shared_ptr const& ledger) { - if (!standalone_ && registry_.getOPs().isNeedNetworkLedger()) + if (!standalone_ && registry_.get().getOPs().isNeedNetworkLedger()) { JLOG(j_.warn()) << "Eliding full order book update: no ledger"; return; @@ -57,8 +56,8 @@ OrderBookDBImpl::setup(std::shared_ptr const& ledger) } else { - registry_.getJobQueue().addJob( - jtUPDATE_PF, "OrderBookUpd" + std::to_string(ledger->seq()), [this, ledger]() { + registry_.get().getJobQueue().addJob( + jtUPDATE_PF, "OBUpd" + std::to_string(ledger->seq()), [this, ledger]() { update(ledger); }); } @@ -96,7 +95,7 @@ OrderBookDBImpl::update(std::shared_ptr const& ledger) { for (auto& sle : ledger->sles) { - if (registry_.isStopping()) + if (registry_.get().isStopping()) { JLOG(j_.info()) << "Update halted because the process is stopping"; seq_.store(0); @@ -168,7 +167,7 @@ OrderBookDBImpl::update(std::shared_ptr const& ledger) xrpDomainBooks_.swap(xrpDomainBooks); } - registry_.getLedgerMaster().newOrderBookDB(); + registry_.get().getLedgerMaster().newOrderBookDB(); } void @@ -250,7 +249,7 @@ OrderBookDBImpl::getBookSize(Issue const& issue, std::optional const& d } bool -OrderBookDBImpl::isBookToXRP(Issue const& issue, std::optional domain) +OrderBookDBImpl::isBookToXRP(Issue const& issue, std::optional const& domain) { std::lock_guard sl(mLock); if (domain) diff --git a/src/xrpld/app/ledger/OrderBookDBImpl.h b/src/xrpld/app/ledger/OrderBookDBImpl.h index d9043f942e..4dd413438e 100644 --- a/src/xrpld/app/ledger/OrderBookDBImpl.h +++ b/src/xrpld/app/ledger/OrderBookDBImpl.h @@ -48,7 +48,7 @@ public: getBookSize(Issue const& issue, std::optional const& domain = std::nullopt) override; bool - isBookToXRP(Issue const& issue, std::optional domain = std::nullopt) override; + isBookToXRP(Issue const& issue, std::optional const& domain = std::nullopt) override; // OrderBookDBImpl-specific methods void @@ -67,7 +67,7 @@ public: makeBookListeners(Book const&) override; private: - ServiceRegistry& registry_; + std::reference_wrapper registry_; int const pathSearchMax_; bool const standalone_; diff --git a/src/xrpld/app/ledger/detail/BuildLedger.cpp b/src/xrpld/app/ledger/detail/BuildLedger.cpp index 5ad72c7a69..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 @@ -138,11 +138,11 @@ applyTransactions( count += changes; // A non-retry pass made no changes - if (!changes && !certainRetry) + if ((changes == 0) && !certainRetry) break; // Stop retriable passes - if (!changes || (pass >= LEDGER_RETRY_PASSES)) + if ((changes == 0) || (pass >= LEDGER_RETRY_PASSES)) certainRetry = false; } 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 42d7f2ec6e..6253b33da3 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; @@ -195,7 +195,7 @@ LedgerMaster::isCaughtUp(std::string& reason) } std::uint32_t validClose = mValidLedgerSign.load(); std::uint32_t pubClose = mPubLedgerClose.load(); - if (!validClose || !pubClose) + if ((validClose == 0u) || (pubClose == 0u)) { reason = "No published ledger"; return false; @@ -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; @@ -410,7 +410,7 @@ LedgerMaster::storeLedger(std::shared_ptr ledger) { bool validated = ledger->header().validated; // Returns true if we already had the ledger - return mLedgerHistory.insert(std::move(ledger), validated); + return mLedgerHistory.insert(ledger, validated); } /** Apply held transactions to the open ledger @@ -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; }(); @@ -514,7 +514,7 @@ LedgerMaster::getFullValidatedRange(std::uint32_t& minVal, std::uint32_t& maxVal // published ledger which is. maxVal = mPubLedgerSeq.load(); - if (!maxVal) + if (maxVal == 0u) return false; std::optional maybeMin; @@ -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/LedgerToJson.cpp b/src/xrpld/app/ledger/detail/LedgerToJson.cpp index c0211059a1..a48756f9b6 100644 --- a/src/xrpld/app/ledger/detail/LedgerToJson.cpp +++ b/src/xrpld/app/ledger/detail/LedgerToJson.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -17,19 +18,19 @@ namespace { bool isFull(LedgerFill const& fill) { - return fill.options & LedgerFill::full; + return (fill.options & LedgerFill::full) != 0; } bool isExpanded(LedgerFill const& fill) { - return isFull(fill) || (fill.options & LedgerFill::expand); + return isFull(fill) || ((fill.options & LedgerFill::expand) != 0); } bool isBinary(LedgerFill const& fill) { - return fill.options & LedgerFill::binary; + return (fill.options & LedgerFill::binary) != 0; } void @@ -172,7 +173,7 @@ fillJsonTx( } } - if ((fill.options & LedgerFill::ownerFunds) && txn->getTxnType() == ttOFFER_CREATE) + if (((fill.options & LedgerFill::ownerFunds) != 0) && txn->getTxnType() == ttOFFER_CREATE) { auto const account = txn->getAccountID(sfAccount); auto const amount = txn->getFieldAmount(sfTakerGets); @@ -215,7 +216,7 @@ fillJsonTx(Json::Value& json, LedgerFill const& fill) catch (std::exception const& ex) { // Nothing the user can do about this. - if (fill.context) + if (fill.context != nullptr) { JLOG(fill.context->j.error()) << "Exception in " << __func__ << ": " << ex.what(); } @@ -303,13 +304,14 @@ fillJson(Json::Value& json, LedgerFill const& fill) !fill.ledger.open(), fill.ledger.header(), bFull, - (fill.context ? fill.context->apiVersion : RPC::apiMaximumSupportedVersion)); + ((fill.context != nullptr) ? fill.context->apiVersion + : RPC::apiMaximumSupportedVersion)); } - if (bFull || fill.options & LedgerFill::dumpTxrp) + if (bFull || ((fill.options & LedgerFill::dumpTxrp) != 0)) fillJsonTx(json, fill); - if (bFull || fill.options & LedgerFill::dumpState) + if (bFull || ((fill.options & LedgerFill::dumpState) != 0)) fillJsonState(json, fill); } @@ -321,7 +323,7 @@ addJson(Json::Value& json, LedgerFill const& fill) auto& object = json[jss::ledger] = Json::objectValue; fillJson(object, fill); - if ((fill.options & LedgerFill::dumpQueue) && !fill.txQueue.empty()) + if (((fill.options & LedgerFill::dumpQueue) != 0) && !fill.txQueue.empty()) fillJsonQueue(json, fill); } 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 b45dbd5ba9..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")) { } @@ -110,7 +110,7 @@ TransactionMaster::fetch( } else { - if (uCommitLedger) + if (uCommitLedger != 0u) iTx->setStatus(COMMITTED, uCommitLedger); txn = iTx->getSTransaction(); diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index 048ef0d9b4..0d8325be54 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_; @@ -781,8 +782,7 @@ public: { XRPL_ASSERT( relationalDatabase_, - "xrpl::ApplicationImp::getRelationalDatabase : non-null " - "relational database"); + "xrpl::ApplicationImp::getRelationalDatabase : non-null relational database"); return *relationalDatabase_; } @@ -797,7 +797,7 @@ public: serverOkay(std::string& reason) override; beast::Journal - journal(std::string const& name) override; + getJournal(std::string const& name) override; //-------------------------------------------------------------------------- @@ -1073,7 +1073,7 @@ public: } virtual std::optional const& - trapTxID() const override + getTrapTxID() const override { return trapTxID_; } @@ -1109,7 +1109,7 @@ private: setMaxDisallowedLedger(); Application& - app() override + getApp() override { return *this; } @@ -1213,22 +1213,22 @@ ApplicationImp::setup(boost::program_options::variables_map const& cmdline) auto const startUp = config_->START_UP; JLOG(m_journal.debug()) << "startUp: " << startUp; - if (startUp == StartUpType::FRESH) + if (startUp == StartUpType::Fresh) { JLOG(m_journal.info()) << "Starting new Ledger"; startGenesisLedger(); } else if ( - startUp == StartUpType::LOAD || startUp == StartUpType::LOAD_FILE || - startUp == StartUpType::REPLAY) + startUp == StartUpType::Load || startUp == StartUpType::LoadFile || + startUp == StartUpType::Replay) { JLOG(m_journal.info()) << "Loading specified Ledger"; if (!loadOldLedger( config_->START_LEDGER, - startUp == StartUpType::REPLAY, - startUp == StartUpType::LOAD_FILE, + startUp == StartUpType::Replay, + startUp == StartUpType::LoadFile, config_->TRAP_TX_HASH)) { JLOG(m_journal.error()) << "The specified ledger could not be loaded."; @@ -1244,7 +1244,7 @@ ApplicationImp::setup(boost::program_options::variables_map const& cmdline) } } } - else if (startUp == StartUpType::NETWORK) + else if (startUp == StartUpType::Network) { // This should probably become the default once we have a stable // network. @@ -1411,7 +1411,7 @@ ApplicationImp::setup(boost::program_options::variables_map const& cmdline) // // Execute start up rpc commands. // - for (auto cmd : config_->section(SECTION_RPC_STARTUP).lines()) + for (auto const& cmd : config_->section(SECTION_RPC_STARTUP).lines()) { Json::Reader jrReader; Json::Value jvCommand; @@ -1430,7 +1430,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 +1546,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. @@ -1635,15 +1635,19 @@ ApplicationImp::fdRequired() const void ApplicationImp::startGenesisLedger() { - std::vector const initialAmendments = (config_->START_UP == StartUpType::FRESH) + std::vector const initialAmendments = (config_->START_UP == StartUpType::Fresh) ? 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 +1661,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 +1734,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 +1777,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 +1858,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 +1886,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 +1904,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 +1966,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 +1977,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 +2098,7 @@ ApplicationImp::serverOkay(std::string& reason) } beast::Journal -ApplicationImp::journal(std::string const& name) +ApplicationImp::getJournal(std::string const& name) { return logs_->journal(name); } @@ -2127,7 +2144,7 @@ fixConfigPorts(Config& config, Endpoints const& endpoints) if (optPort) { std::uint16_t const port = beast::lexicalCast(*optPort); - if (!port) + if (port == 0u) section.set("port", std::to_string(ep.port())); } } 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/BasicApp.cpp b/src/xrpld/app/main/BasicApp.cpp index be0c158b85..2c5a2b0364 100644 --- a/src/xrpld/app/main/BasicApp.cpp +++ b/src/xrpld/app/main/BasicApp.cpp @@ -9,7 +9,7 @@ BasicApp::BasicApp(std::size_t numberOfThreads) work_.emplace(boost::asio::make_work_guard(io_context_)); threads_.reserve(numberOfThreads); - while (numberOfThreads--) + while ((numberOfThreads--) != 0u) { threads_.emplace_back([this, numberOfThreads]() { beast::setCurrentThreadName("io svc #" + std::to_string(numberOfThreads)); diff --git a/src/xrpld/app/main/GRPCServer.cpp b/src/xrpld/app/main/GRPCServer.cpp index a9810ae22b..130d0f01b9 100644 --- a/src/xrpld/app/main/GRPCServer.cpp +++ b/src/xrpld/app/main/GRPCServer.cpp @@ -16,8 +16,8 @@ getEndpoint(std::string const& peer) { try { - std::size_t first = peer.find_first_of(":"); - std::size_t last = peer.find_last_of(":"); + std::size_t first = peer.find_first_of(':'); + std::size_t last = peer.find_last_of(':'); std::string peerClean(peer); if (first != last) { @@ -56,7 +56,7 @@ GRPCServerImpl::CallData::CallData( , bindListener_(std::move(bindListener)) , handler_(std::move(handler)) , forward_(std::move(forward)) - , requiredCondition_(std::move(requiredCondition)) + , requiredCondition_(requiredCondition) , loadType_(std::move(loadType)) , secureGatewayIPs_(secureGatewayIPs) { @@ -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 03f8076ed1..570131b52d 100644 --- a/src/xrpld/app/main/Main.cpp +++ b/src/xrpld/app/main/Main.cpp @@ -282,6 +282,7 @@ runUnitTests( args.emplace_back("--unittest-child"); } + children.reserve(num_jobs); for (std::size_t i = 0; i < num_jobs; ++i) { children.emplace_back( @@ -295,7 +296,7 @@ runUnitTests( try { c.wait(); - if (c.exit_code()) + if (c.exit_code() != 0) ++bad_child_exits; } catch (...) @@ -309,7 +310,7 @@ runUnitTests( parent_runner.add_failures(terminated_child_exits); anyMissing(parent_runner, multi_selector(pattern)); - if (parent_runner.any_failed() || bad_child_exits) + if (parent_runner.any_failed() || (bad_child_exits != 0)) return EXIT_FAILURE; return EXIT_SUCCESS; } @@ -613,7 +614,7 @@ run(int argc, char** argv) if (vm.contains("start")) { - config->START_UP = StartUpType::FRESH; + config->START_UP = StartUpType::Fresh; } if (vm.contains("import")) @@ -624,7 +625,7 @@ run(int argc, char** argv) config->START_LEDGER = vm["ledger"].as(); if (vm.contains("replay")) { - config->START_UP = StartUpType::REPLAY; + config->START_UP = StartUpType::Replay; if (vm.contains("trap_tx_hash")) { uint256 tmp = {}; @@ -644,17 +645,17 @@ run(int argc, char** argv) } else { - config->START_UP = StartUpType::LOAD; + config->START_UP = StartUpType::Load; } } else if (vm.contains("ledgerfile")) { config->START_LEDGER = vm["ledgerfile"].as(); - config->START_UP = StartUpType::LOAD_FILE; + config->START_UP = StartUpType::LoadFile; } else if (vm.contains("load") || config->FAST_LOAD) { - config->START_UP = StartUpType::LOAD; + config->START_UP = StartUpType::Load; } if (vm.contains("trap_tx_hash") && !vm.contains("replay")) @@ -665,13 +666,13 @@ run(int argc, char** argv) if (vm.contains("net") && !config->FAST_LOAD) { - if ((config->START_UP == StartUpType::LOAD) || (config->START_UP == StartUpType::REPLAY)) + if ((config->START_UP == StartUpType::Load) || (config->START_UP == StartUpType::Replay)) { std::cerr << "Net and load/replay options are incompatible" << std::endl; return -1; } - config->START_UP = StartUpType::NETWORK; + config->START_UP = StartUpType::Network; } if (vm.contains("valid")) @@ -752,8 +753,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 +780,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 601ac7d060..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 @@ -140,7 +139,7 @@ private: * @param candidates the vector of candidates * @return the picked candidate */ - NodeID + static NodeID choose(uint256 const& randomPadData, std::vector const& candidates); /** diff --git a/src/xrpld/app/misc/NetworkOPs.cpp b/src/xrpld/app/misc/NetworkOPs.cpp index d709981c46..b323541362 100644 --- a/src/xrpld/app/misc/NetworkOPs.cpp +++ b/src/xrpld/app/misc/NetworkOPs.cpp @@ -43,11 +43,15 @@ #include #include #include +#include +#include +#include #include #include #include #include #include +#include #include #include #include @@ -185,7 +189,7 @@ class NetworkOPsImp final : public NetworkOPs ServerFeeSummary( XRPAmount fee, - TxQ::Metrics&& escalationMetrics, + TxQ::Metrics escalationMetrics, // trivially copyable LoadFeeTrack const& loadFeeTrack); bool operator!=(ServerFeeSummary const& b) const; @@ -212,27 +216,27 @@ public: JobQueue& job_queue, LedgerMaster& ledgerMaster, ValidatorKeys const& validatorKeys, - boost::asio::io_context& io_svc, + boost::asio::io_context& ioCtx, beast::Journal journal, beast::insight::Collector::ptr const& collector) : registry_(registry) , m_journal(journal) , m_localTX(make_LocalTxs()) , mMode(start_valid ? OperatingMode::FULL : OperatingMode::DISCONNECTED) - , heartbeatTimer_(io_svc) - , clusterTimer_(io_svc) - , accountHistoryTxTimer_(io_svc) + , heartbeatTimer_(ioCtx) + , clusterTimer_(ioCtx) + , accountHistoryTxTimer_(ioCtx) , mConsensus( - registry_.app(), + registry_.get().getApp(), make_FeeVote( - setup_FeeVote(registry_.app().config().section("voting")), - registry_.logs().journal("FeeVote")), + setup_FeeVote(registry_.get().getApp().config().section("voting")), + registry_.get().getJournal("FeeVote")), ledgerMaster, *m_localTX, registry.getInboundTransactions(), beast::get_abstract_clock(), validatorKeys, - registry_.logs().journal("LedgerConsensus")) + registry_.get().getJournal("LedgerConsensus")) , validatorPK_( validatorKeys.keys ? validatorKeys.keys->publicKey : decltype(validatorPK_){}) , validatorMasterPK_( @@ -686,7 +690,7 @@ private: void setAccountHistoryJobTimer(SubAccountHistoryInfoWeak subInfo); - ServiceRegistry& registry_; + std::reference_wrapper registry_; beast::Journal m_journal; std::unique_ptr m_localTX; @@ -873,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_.get().getApp().nodeIdentity(); return RFC1751::getWordFromBlob(id.first.data(), id.first.size()); }(); @@ -887,7 +891,7 @@ NetworkOPsImp::setStateTimer() setHeartbeatTimer(); // Only do this work if a cluster is configured - if (registry_.cluster().size() != 0) + if (registry_.get().getCluster().size() != 0) setClusterTimer(); } @@ -965,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_.get().getApp().getMasterMutex()}; // VFALCO NOTE This is for diagnosing a crash on exit - LoadManager& mgr(registry_.getLoadManager()); + LoadManager& mgr(registry_.get().getLoadManager()); mgr.heartbeat(); - std::size_t const numPeers = registry_.overlay().size(); + std::size_t const numPeers = registry_.get().getOverlay().size(); // do we have sufficient peers? If not, we are disconnected. if (numPeers < minPeerCount_) @@ -1027,7 +1031,7 @@ NetworkOPsImp::processHeartbeatTimer() CLOG(clog.ss()) << ". "; } - mConsensus.timerEntry(registry_.timeKeeper().closeTime(), clog.ss()); + mConsensus.timerEntry(registry_.get().getTimeKeeper().closeTime(), clog.ss()); CLOG(clog.ss()) << "consensus phase " << to_string(mLastConsensusPhase); ConsensusPhase const currPhase = mConsensus.phase(); @@ -1045,17 +1049,18 @@ NetworkOPsImp::processHeartbeatTimer() void NetworkOPsImp::processClusterTimer() { - if (registry_.cluster().size() == 0) + if (registry_.get().getCluster().size() == 0) return; using namespace std::chrono_literals; - bool const update = registry_.cluster().update( - registry_.app().nodeIdentity().first, + bool const update = registry_.get().getCluster().update( + registry_.get().getApp().nodeIdentity().first, "", - (m_ledgerMaster.getValidatedLedgerAge() <= 4min) ? registry_.getFeeTrack().getLocalFee() - : 0, - registry_.timeKeeper().now()); + (m_ledgerMaster.getValidatedLedgerAge() <= 4min) + ? registry_.get().getFeeTrack().getLocalFee() + : 0, + registry_.get().getTimeKeeper().now()); if (!update) { @@ -1065,7 +1070,7 @@ NetworkOPsImp::processClusterTimer() } protocol::TMCluster cluster; - registry_.cluster().for_each([&cluster](ClusterNode const& node) { + registry_.get().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()); @@ -1074,14 +1079,14 @@ NetworkOPsImp::processClusterTimer() n.set_nodename(node.name()); }); - Resource::Gossip gossip = registry_.getResourceManager().exportConsumers(); + Resource::Gossip gossip = registry_.get().getResourceManager().exportConsumers(); for (auto& item : gossip.items) { protocol::TMLoadSource& node = *cluster.add_loadsources(); node.set_name(to_string(item.address)); node.set_cost(item.balance); } - registry_.overlay().foreach( + registry_.get().getOverlay().foreach( send_if(std::make_shared(cluster, protocol::mtCLUSTER), peer_in_cluster())); setClusterTimer(); } @@ -1127,7 +1132,7 @@ NetworkOPsImp::submitTransaction(std::shared_ptr const& iTrans) auto const trans = sterilize(*iTrans); auto const txid = trans->getTransactionID(); - auto const flags = registry_.getHashRouter().getFlags(txid); + auto const flags = registry_.get().getHashRouter().getFlags(txid); if ((flags & HashRouterFlags::BAD) != HashRouterFlags::UNDEFINED) { @@ -1137,8 +1142,8 @@ NetworkOPsImp::submitTransaction(std::shared_ptr const& iTrans) try { - auto const [validity, reason] = - checkValidity(registry_.getHashRouter(), *trans, m_ledgerMaster.getValidatedRules()); + auto const [validity, reason] = checkValidity( + registry_.get().getHashRouter(), *trans, m_ledgerMaster.getValidatedRules()); if (validity != Validity::Valid) { @@ -1155,7 +1160,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_.get().getApp()); m_job_queue.addJob(jtTRANSACTION, "SubmitTxn", [this, tx]() { auto t = tx; @@ -1166,7 +1171,7 @@ NetworkOPsImp::submitTransaction(std::shared_ptr const& iTrans) bool NetworkOPsImp::preProcessTransaction(std::shared_ptr& transaction) { - auto const newFlags = registry_.getHashRouter().getFlags(transaction->getID()); + auto const newFlags = registry_.get().getHashRouter().getFlags(transaction->getID()); if ((newFlags & HashRouterFlags::BAD) != HashRouterFlags::UNDEFINED) { @@ -1187,14 +1192,15 @@ NetworkOPsImp::preProcessTransaction(std::shared_ptr& transaction) { transaction->setStatus(INVALID); transaction->setResult(temINVALID_FLAG); - registry_.getHashRouter().setFlags(transaction->getID(), HashRouterFlags::BAD); + registry_.get().getHashRouter().setFlags(transaction->getID(), HashRouterFlags::BAD); return false; } // NOTE ximinez - I think this check is redundant, // but I'm not 100% sure yet. // If so, only cost is looking up HashRouter flags. - auto const [validity, reason] = checkValidity(registry_.getHashRouter(), sttx, view->rules()); + auto const [validity, reason] = + checkValidity(registry_.get().getHashRouter(), sttx, view->rules()); XRPL_ASSERT( validity == Validity::Valid, "xrpl::NetworkOPsImp::processTransaction : valid validity"); @@ -1204,12 +1210,12 @@ NetworkOPsImp::preProcessTransaction(std::shared_ptr& transaction) JLOG(m_journal.info()) << "Transaction has bad signature: " << reason; transaction->setStatus(INVALID); transaction->setResult(temBAD_SIGNATURE); - registry_.getHashRouter().setFlags(transaction->getID(), HashRouterFlags::BAD); + registry_.get().getHashRouter().setFlags(transaction->getID(), HashRouterFlags::BAD); return false; } // canonicalize can change our pointer - registry_.getMasterTransaction().canonicalize(&transaction); + registry_.get().getMasterTransaction().canonicalize(&transaction); return true; } @@ -1316,7 +1322,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_.get().getApp()); if (transaction->getStatus() == INVALID) { @@ -1324,7 +1330,7 @@ NetworkOPsImp::processTransactionSet(CanonicalTXSet const& set) { JLOG(m_journal.trace()) << "Exception checking transaction: " << reason; } - registry_.getHashRouter().setFlags(tx->getTransactionID(), HashRouterFlags::BAD); + registry_.get().getHashRouter().setFlags(tx->getTransactionID(), HashRouterFlags::BAD); continue; } @@ -1402,13 +1408,12 @@ NetworkOPsImp::apply(std::unique_lock& batchLock) batchLock.unlock(); { - std::unique_lock masterLock{registry_.app().getMasterMutex(), std::defer_lock}; + std::unique_lock masterLock{registry_.get().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_.get().getOpenLedger().modify([&](OpenView& view, beast::Journal j) { for (TransactionStatus& e : transactions) { // we check before adding to the batch @@ -1419,8 +1424,8 @@ NetworkOPsImp::apply(std::unique_lock& batchLock) if (e.failType == FailHard::yes) flags |= tapFAIL_HARD; - auto const result = registry_.getTxQ().apply( - registry_.app(), view, e.transaction->getSTransaction(), flags, j); + auto const result = registry_.get().getTxQ().apply( + registry_.get().getApp(), view, e.transaction->getSTransaction(), flags, j); e.result = result.ter; e.applied = result.applied; changed = changed || result.applied; @@ -1435,7 +1440,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_.get().getOpenLedger().current(); for (TransactionStatus& e : transactions) { e.transaction->clearSubmitResult(); @@ -1449,7 +1454,10 @@ NetworkOPsImp::apply(std::unique_lock& batchLock) e.transaction->setResult(e.result); if (isTemMalformed(e.result)) - registry_.getHashRouter().setFlags(e.transaction->getID(), HashRouterFlags::BAD); + { + registry_.get().getHashRouter().setFlags( + e.transaction->getID(), HashRouterFlags::BAD); + } #ifdef DEBUG if (!isTesSuccess(e.result)) @@ -1484,7 +1492,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_.get().getApp()); if (t->getApplying()) break; submit_held.emplace_back(t, false, false, FailHard::no); @@ -1538,7 +1546,7 @@ NetworkOPsImp::apply(std::unique_lock& batchLock) // up!) // if (e.local || (ledgersLeft && ledgersLeft <= LocalTxs::holdLedgers) || - registry_.getHashRouter().setFlags( + registry_.get().getHashRouter().setFlags( e.transaction->getID(), HashRouterFlags::HELD)) { // transaction should be held @@ -1575,7 +1583,8 @@ NetworkOPsImp::apply(std::unique_lock& batchLock) (e.result == terQUEUED)) && !enforceFailHard) { - auto const toSkip = registry_.getHashRouter().shouldRelay(e.transaction->getID()); + auto const toSkip = + registry_.get().getHashRouter().shouldRelay(e.transaction->getID()); if (auto const sttx = *(e.transaction->getSTransaction()); toSkip && // Skip relaying if it's an inner batch txn. The flag should // only be set if the Batch feature is enabled. If Batch is @@ -1590,18 +1599,19 @@ 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_.get().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_.get().getOverlay().relay(e.transaction->getID(), tx, *toSkip); e.transaction->setBroadcast(); } } if (validatedLedgerIndex) { - auto [fee, accountSeq, availableSeq] = registry_.getTxQ().getTxRequiredFeeAndSeq( - *newOL, e.transaction->getSTransaction()); + auto [fee, accountSeq, availableSeq] = + registry_.get().getTxQ().getTxRequiredFeeAndSeq( + *newOL, e.transaction->getSTransaction()); e.transaction->setCurrentLedgerState( *validatedLedgerIndex, fee, accountSeq, availableSeq); } @@ -1685,12 +1695,12 @@ NetworkOPsImp::getOwnerInfo(std::shared_ptr lpLedger, AccountID uNodeDir = sleNode->getFieldU64(sfIndexNext); - if (uNodeDir) + if (uNodeDir != 0u) { sleNode = lpLedger->read(keylet::page(root, uNodeDir)); XRPL_ASSERT(sleNode, "xrpl::NetworkOPsImp::getOwnerInfo : read next page"); } - } while (uNodeDir); + } while (uNodeDir != 0u); } return jvObjects; @@ -1779,7 +1789,7 @@ NetworkOPsImp::checkLastClosedLedger(Overlay::PeerSequence const& peerList, uint //------------------------------------------------------------------------- // Determine preferred last closed ledger - auto& validations = registry_.getValidations(); + auto& validations = registry_.get().getValidations(); JLOG(m_journal.debug()) << "ValidationTrie " << Json::Compact(validations.getJsonTrie()); // Will rely on peer LCL if no trusted validations exist @@ -1827,7 +1837,7 @@ NetworkOPsImp::checkLastClosedLedger(Overlay::PeerSequence const& peerList, uint if (!consensus) { - consensus = registry_.getInboundLedgers().acquire( + consensus = registry_.get().getInboundLedgers().acquire( closedLedger, 0, InboundLedger::Reason::CONSENSUS); } @@ -1870,7 +1880,7 @@ NetworkOPsImp::switchLastClosedLedger(std::shared_ptr const& newLC clearNeedNetworkLedger(); // Update fee computations. - registry_.getTxQ().processClosedLedger(registry_.app(), *newLCL, true); + registry_.get().getTxQ().processClosedLedger(registry_.get().getApp(), *newLCL, true); // Caller must own master lock { @@ -1878,18 +1888,18 @@ NetworkOPsImp::switchLastClosedLedger(std::shared_ptr const& newLC // open ledger. Then apply local tx. auto retries = m_localTX->getTxSet(); - auto const lastVal = registry_.getLedgerMaster().getValidatedLedger(); + auto const lastVal = registry_.get().getLedgerMaster().getValidatedLedger(); std::optional rules; if (lastVal) { - rules = makeRulesGivenLedger(*lastVal, registry_.app().config().features); + rules = makeRulesGivenLedger(*lastVal, registry_.get().getApp().config().features); } else { - rules.emplace(registry_.app().config().features); + rules.emplace(registry_.get().getApp().config().features); } - registry_.openLedger().accept( - registry_.app(), + registry_.get().getOpenLedger().accept( + registry_.get().getApp(), *rules, newLCL, OrderedTxs({}), @@ -1899,7 +1909,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_.get().getTxQ().accept(registry_.get().getApp(), view); }); } @@ -1908,12 +1918,11 @@ 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_.get().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_.get().getOverlay().foreach( send_always(std::make_shared(s, protocol::mtSTATUS_CHANGE))); } @@ -1954,23 +1963,24 @@ NetworkOPsImp::beginConsensus( "xrpl::NetworkOPsImp::beginConsensus : closedLedger parent matches " "hash"); - registry_.validators().setNegativeUNL(prevLedger->negativeUNL()); - TrustChanges const changes = registry_.validators().updateTrusted( - registry_.getValidations().getCurrentNodeIDs(), + registry_.get().getValidators().setNegativeUNL(prevLedger->negativeUNL()); + TrustChanges const changes = registry_.get().getValidators().updateTrusted( + registry_.get().getValidations().getCurrentNodeIDs(), closingInfo.parentCloseTime, *this, - registry_.overlay(), - registry_.getHashRouter()); + registry_.get().getOverlay(), + registry_.get().getHashRouter()); if (!changes.added.empty() || !changes.removed.empty()) { - registry_.getValidations().trustChanged(changes.added, changes.removed); + registry_.get().getValidations().trustChanged(changes.added, changes.removed); // Update the AmendmentTable so it tracks the current validators. - registry_.getAmendmentTable().trustChanged(registry_.validators().getQuorumKeys().second); + registry_.get().getAmendmentTable().trustChanged( + registry_.get().getValidators().getQuorumKeys().second); } mConsensus.startRound( - registry_.timeKeeper().closeTime(), + registry_.get().getTimeKeeper().closeTime(), networkClosed, prevLedger, changes.removed, @@ -2010,33 +2020,30 @@ NetworkOPsImp::processTrustedProposal(RCLCxPeerPos peerPos) return false; } - return mConsensus.peerProposal(registry_.timeKeeper().closeTime(), peerPos); + return mConsensus.peerProposal(registry_.get().getTimeKeeper().closeTime(), peerPos); } void NetworkOPsImp::mapComplete(std::shared_ptr const& map, bool fromAcquire) { // We now have an additional transaction set - // either created locally during the consensus process - // or acquired from a peer - // Inform peers we have this set 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_.get().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_.get().getTimeKeeper().closeTime(), RCLTxSet{map}); } void 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_.get().getOverlay().getActivePeers()) { if (it && (it->getClosedLedgerHash() == deadLedger)) { @@ -2046,7 +2053,8 @@ NetworkOPsImp::endConsensus(std::unique_ptr const& clog) } uint256 networkClosed; - bool ledgerChange = checkLastClosedLedger(registry_.overlay().getActivePeers(), networkClosed); + bool ledgerChange = + checkLastClosedLedger(registry_.get().getOverlay().getActivePeers(), networkClosed); if (networkClosed.isZero()) { @@ -2076,7 +2084,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_.get().getTimeKeeper().now() < (current->header().parentCloseTime + 2 * current->header().closeTimeResolution)) { setMode(OperatingMode::FULL); @@ -2134,12 +2142,12 @@ NetworkOPsImp::pubManifest(Manifest const& mo) NetworkOPsImp::ServerFeeSummary::ServerFeeSummary( XRPAmount fee, - TxQ::Metrics&& escalationMetrics, + TxQ::Metrics escalationMetrics, // trivially copyable LoadFeeTrack const& loadFeeTrack) : loadFactorServer{loadFeeTrack.getLoadFactor()} , loadBaseServer{loadFeeTrack.getLoadBase()} , baseFee{fee} - , em{std::move(escalationMetrics)} + , em{escalationMetrics} { } @@ -2184,9 +2192,9 @@ NetworkOPsImp::pubServer() Json::Value jvObj(Json::objectValue); ServerFeeSummary f{ - registry_.openLedger().current()->fees().base, - registry_.getTxQ().getMetrics(*registry_.openLedger().current()), - registry_.getFeeTrack()}; + registry_.get().getOpenLedger().current()->fees().base, + registry_.get().getTxQ().getMetrics(*registry_.get().getOpenLedger().current()), + registry_.get().getFeeTrack()}; jvObj[jss::type] = "serverStatus"; jvObj[jss::server_status] = strOperatingMode(); @@ -2280,7 +2288,7 @@ NetworkOPsImp::pubValidation(std::shared_ptr const& val) jvObj[jss::flags] = val->getFlags(); jvObj[jss::signing_time] = *(*val)[~sfSigningTime]; jvObj[jss::data] = strHex(val->getSerializer().slice()); - jvObj[jss::network_id] = registry_.getNetworkIDService().getNetworkID(); + jvObj[jss::network_id] = registry_.get().getNetworkIDService().getNetworkID(); if (auto version = (*val)[~sfServerVersion]) jvObj[jss::server_version] = std::to_string(*version); @@ -2291,7 +2299,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_.get().getValidatorManifests().getMasterKey(signerPublic); if (masterKey != signerPublic) jvObj[jss::master_key] = toBase58(TokenType::NodePublic, masterKey); @@ -2400,12 +2408,12 @@ NetworkOPsImp::setMode(OperatingMode om) using namespace std::chrono_literals; if (om == OperatingMode::CONNECTED) { - if (registry_.getLedgerMaster().getValidatedLedgerAge() < 1min) + if (registry_.get().getLedgerMaster().getValidatedLedgerAge() < 1min) om = OperatingMode::SYNCING; } else if (om == OperatingMode::SYNCING) { - if (registry_.getLedgerMaster().getValidatedLedgerAge() >= 1min) + if (registry_.get().getLedgerMaster().getValidatedLedgerAge() >= 1min) om = OperatingMode::CONNECTED; } @@ -2441,7 +2449,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_.get().getApp(), val, source, bypassAccept, m_journal); } catch (std::exception const& e) { @@ -2464,7 +2472,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_.get().getValidators().getTrustedKey(val->getSignerPublic()); if (master) { ss << toBase58(TokenType::NodePublic, *master); @@ -2478,7 +2486,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_.get().getApp().config().RELAY_UNTRUSTED_VALIDATIONS == 1 || val->isTrusted(); } Json::Value @@ -2520,7 +2528,8 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) "One or more unsupported amendments have reached majority. " "Upgrade to the latest version before they are activated " "to avoid being amendment blocked."; - if (auto const expected = registry_.getAmendmentTable().firstUnsupportedExpected()) + if (auto const expected = + registry_.get().getAmendmentTable().firstUnsupportedExpected()) { auto& d = w[jss::details] = Json::objectValue; d[jss::expected_date] = expected->time_since_epoch().count(); @@ -2528,7 +2537,7 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) } } - if (warnings.size()) + if (warnings.size() != 0u) info[jss::warnings] = std::move(warnings); } @@ -2537,8 +2546,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_.get().getApp().config().SERVER_DOMAIN.empty()) + info[jss::server_domain] = registry_.get().getApp().config().SERVER_DOMAIN; info[jss::build_version] = BuildInfo::getVersionString(); @@ -2550,14 +2559,15 @@ 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_.get().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_.get().getApp().config().NODE_SIZE) { case 0: info[jss::node_size] = "tiny"; @@ -2576,7 +2586,7 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) break; } - auto when = registry_.validators().expires(); + auto when = registry_.get().getValidators().expires(); if (!human) { @@ -2594,7 +2604,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_.get().getValidators().count()); if (when) { @@ -2607,7 +2617,7 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) { x[jss::expiration] = to_string(*when); - if (*when > registry_.timeKeeper().now()) + if (*when > registry_.get().getTimeKeeper().now()) { x[jss::status] = "active"; } @@ -2633,12 +2643,13 @@ 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_.get().getApp().getIOLatency().count()); if (admin) { - if (auto const localPubKey = registry_.validators().localPublicKey(); - localPubKey && registry_.app().getValidationPublicKey()) + if (auto const localPubKey = registry_.get().getValidators().localPublicKey(); + localPubKey && registry_.get().getApp().getValidationPublicKey()) { info[jss::pubkey_validator] = toBase58(TokenType::NodePublic, localPubKey.value()); } @@ -2650,17 +2661,18 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) if (counters) { - info[jss::counters] = registry_.getPerfLog().countersJson(); + info[jss::counters] = registry_.get().getPerfLog().countersJson(); Json::Value nodestore(Json::objectValue); - registry_.getNodeStore().getCountsJson(nodestore); + registry_.get().getNodeStore().getCountsJson(nodestore); info[jss::counters][jss::nodestore] = nodestore; - info[jss::current_activities] = registry_.getPerfLog().currentJson(); + info[jss::current_activities] = registry_.get().getPerfLog().currentJson(); } - info[jss::pubkey_node] = toBase58(TokenType::NodePublic, registry_.app().nodeIdentity().first); + info[jss::pubkey_node] = + toBase58(TokenType::NodePublic, registry_.get().getApp().nodeIdentity().first); - info[jss::complete_ledgers] = registry_.getLedgerMaster().getCompleteLedgers(); + info[jss::complete_ledgers] = registry_.get().getLedgerMaster().getCompleteLedgers(); if (amendmentBlocked_) info[jss::amendment_blocked] = true; @@ -2670,7 +2682,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_.get().getOverlay().size()); Json::Value lastClose = Json::objectValue; lastClose[jss::proposers] = Json::UInt(mConsensus.prevProposers()); @@ -2692,13 +2704,14 @@ 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_.get().getOverlay().networkID()) info[jss::network_id] = static_cast(*netid); - auto const escalationMetrics = registry_.getTxQ().getMetrics(*registry_.openLedger().current()); + auto const escalationMetrics = + registry_.get().getTxQ().getMetrics(*registry_.get().getOpenLedger().current()); - auto const loadFactorServer = registry_.getFeeTrack().getLoadFactor(); - auto const loadBaseServer = registry_.getFeeTrack().getLoadBase(); + auto const loadFactorServer = registry_.get().getFeeTrack().getLoadFactor(); + auto const loadBaseServer = registry_.get().getFeeTrack().getLoadBase(); /* Scale the escalated fee level to unitless "load factor". In practice, this just strips the units, but it will continue to work correctly if either base value ever changes. */ @@ -2735,13 +2748,13 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) if (admin) { - std::uint32_t fee = registry_.getFeeTrack().getLocalFee(); + std::uint32_t fee = registry_.get().getFeeTrack().getLocalFee(); if (fee != loadBaseServer) info[jss::load_factor_local] = static_cast(fee) / loadBaseServer; - fee = registry_.getFeeTrack().getRemoteFee(); + fee = registry_.get().getFeeTrack().getRemoteFee(); if (fee != loadBaseServer) info[jss::load_factor_net] = static_cast(fee) / loadBaseServer; - fee = registry_.getFeeTrack().getClusterFee(); + fee = registry_.get().getFeeTrack().getClusterFee(); if (fee != loadBaseServer) info[jss::load_factor_cluster] = static_cast(fee) / loadBaseServer; } @@ -2793,7 +2806,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_.get().getTimeKeeper().closeOffset(); std::abs(closeOffset.count()) >= 60) l[jss::close_time_offset] = static_cast(closeOffset.count()); @@ -2806,7 +2819,7 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) else { auto lCloseTime = lpClosed->header().closeTime; - auto closeTime = registry_.timeKeeper().closeTime(); + auto closeTime = registry_.get().getTimeKeeper().closeTime(); if (lCloseTime <= closeTime) { using namespace std::chrono_literals; @@ -2838,10 +2851,11 @@ 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_.get().getOverlay().getJqTransOverflow()); + info[jss::peer_disconnects] = std::to_string(registry_.get().getOverlay().getPeerDisconnect()); info[jss::peer_disconnects_resources] = - std::to_string(registry_.overlay().getPeerDisconnectCharges()); + std::to_string(registry_.get().getOverlay().getPeerDisconnectCharges()); // This array must be sorted in increasing order. static constexpr std::array protocols{ @@ -2849,7 +2863,7 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) static_assert(std::is_sorted(std::begin(protocols), std::end(protocols))); { Json::Value ports{Json::arrayValue}; - for (auto const& port : registry_.getServerHandler().setup().ports) + for (auto const& port : registry_.get().getServerHandler().setup().ports) { // Don't publish admin ports for non-admin users if (!admin && @@ -2873,9 +2887,9 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) } } - if (registry_.app().config().exists(SECTION_PORT_GRPC)) + if (registry_.get().getApp().config().exists(SECTION_PORT_GRPC)) { - auto const& grpcSection = registry_.app().config().section(SECTION_PORT_GRPC); + auto const& grpcSection = registry_.get().getApp().config().section(SECTION_PORT_GRPC); auto const optPort = grpcSection.get("port"); if (optPort && grpcSection.get("ip")) { @@ -2894,13 +2908,13 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters) void NetworkOPsImp::clearLedgerFetch() { - registry_.getInboundLedgers().clearFailures(); + registry_.get().getInboundLedgers().clearFailures(); } Json::Value NetworkOPsImp::getLedgerFetchInfo() { - return registry_.getInboundLedgers().getInfo(); + return registry_.get().getInboundLedgers().getInfo(); } void @@ -2950,11 +2964,11 @@ NetworkOPsImp::pubLedger(std::shared_ptr const& lpAccepted) // Holes are filled across connection loss or other catastrophe std::shared_ptr alpAccepted = - registry_.getAcceptedLedgerCache().fetch(lpAccepted->header().hash); + registry_.get().getAcceptedLedgerCache().fetch(lpAccepted->header().hash); if (!alpAccepted) { alpAccepted = std::make_shared(lpAccepted); - registry_.getAcceptedLedgerCache().canonicalize_replace_client( + registry_.get().getAcceptedLedgerCache().canonicalize_replace_client( lpAccepted->header().hash, alpAccepted); } @@ -2978,10 +2992,10 @@ NetworkOPsImp::pubLedger(std::shared_ptr const& lpAccepted) jvObj[jss::ledger_time] = Json::Value::UInt(lpAccepted->header().closeTime.time_since_epoch().count()); - jvObj[jss::network_id] = registry_.getNetworkIDService().getNetworkID(); + jvObj[jss::network_id] = registry_.get().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(); @@ -2990,7 +3004,8 @@ NetworkOPsImp::pubLedger(std::shared_ptr const& lpAccepted) if (mMode >= OperatingMode::SYNCING) { - jvObj[jss::validated_ledgers] = registry_.getLedgerMaster().getCompleteLedgers(); + jvObj[jss::validated_ledgers] = + registry_.get().getLedgerMaster().getCompleteLedgers(); } auto it = mStreamMaps[sLedger].begin(); @@ -3062,9 +3077,9 @@ void NetworkOPsImp::reportFeeChange() { ServerFeeSummary f{ - registry_.openLedger().current()->fees().base, - registry_.getTxQ().getMetrics(*registry_.openLedger().current()), - registry_.getFeeTrack()}; + registry_.get().getOpenLedger().current()->fees().base, + registry_.get().getTxQ().getMetrics(*registry_.get().getOpenLedger().current()), + registry_.get().getFeeTrack()}; // only schedule the job if something has changed if (f != mLastFeeSummary) @@ -3125,7 +3140,7 @@ NetworkOPsImp::transJson( lookup.second && lookup.second->isFieldPresent(sfTransactionIndex)) { uint32_t const txnSeq = lookup.second->getFieldU32(sfTransactionIndex); - uint32_t netID = registry_.getNetworkIDService().getNetworkID(); + uint32_t netID = registry_.get().getNetworkIDService().getNetworkID(); if (transaction->isFieldPresent(sfNetworkID)) netID = transaction->getFieldU32(sfNetworkID); @@ -3164,8 +3179,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_.get().getJournal("View")); jvObj[jss::transaction][jss::owner_funds] = ownerFunds.getText(); } } @@ -3246,7 +3261,7 @@ NetworkOPsImp::pubValidatedTransaction( } if (transaction.getResult() == tesSUCCESS) - registry_.getOrderBookDB().processTxn(ledger, transaction, jvObj); + registry_.get().getOrderBookDB().processTxn(ledger, transaction, jvObj); pubAccountTransaction(ledger, transaction, last); } @@ -3553,7 +3568,7 @@ NetworkOPsImp::addAccountHistoryJob(SubAccountHistoryInfoWeak subInfo) static auto const databaseType = [&]() -> DatabaseType { // Use a dynamic_cast to return DatabaseType::None // on failure. - if (dynamic_cast(®istry_.getRelationalDatabase())) + if (dynamic_cast(®istry_.get().getRelationalDatabase())) { return DatabaseType::Sqlite; } @@ -3575,7 +3590,7 @@ NetworkOPsImp::addAccountHistoryJob(SubAccountHistoryInfoWeak subInfo) // LCOV_EXCL_STOP } - registry_.getJobQueue().addJob( + registry_.get().getJobQueue().addJob( jtCLIENT_ACCT_HIST, "HistTxStream", [this, dbType = databaseType, subInfo]() { auto const& accountId = subInfo.index_->accountId_; auto& lastLedgerSeq = subInfo.index_->historyLastLedgerSeq_; @@ -3656,11 +3671,10 @@ NetworkOPsImp::addAccountHistoryJob(SubAccountHistoryInfoWeak subInfo) switch (dbType) { case Sqlite: { - auto db = - safe_downcast(®istry_.getRelationalDatabase()); + auto& db = registry_.get().getRelationalDatabase(); RelationalDatabase::AccountTxPageOptions options{ - accountId, minLedger, maxLedger, marker, 0, true}; - return db->newestAccountTxPage(options); + accountId, {minLedger, maxLedger}, marker, 0, true}; + return db.newestAccountTxPage(options); } // LCOV_EXCL_START default: { @@ -3702,7 +3716,8 @@ NetworkOPsImp::addAccountHistoryJob(SubAccountHistoryInfoWeak subInfo) std::uint32_t validatedMin = UINT_MAX; std::uint32_t validatedMax = 0; auto haveSomeValidatedLedgers = - registry_.getLedgerMaster().getValidatedRange(validatedMin, validatedMax); + registry_.get().getLedgerMaster().getValidatedRange( + validatedMin, validatedMax); return haveSomeValidatedLedgers && validatedMin <= startLedgerSeq && lastLedgerSeq <= validatedMax; @@ -3749,7 +3764,7 @@ NetworkOPsImp::addAccountHistoryJob(SubAccountHistoryInfoWeak subInfo) return; } auto curTxLedger = - registry_.getLedgerMaster().getLedgerBySeq(tx->getLedger()); + registry_.get().getLedgerMaster().getLedgerBySeq(tx->getLedger()); if (!curTxLedger) { // LCOV_EXCL_START @@ -3895,7 +3910,7 @@ NetworkOPsImp::subAccountHistory(InfoSub::ref isrListener, AccountID const& acco simIterator->second.emplace(isrListener->getSeq(), ahi); } - auto const ledger = registry_.getLedgerMaster().getValidatedLedger(); + auto const ledger = registry_.get().getLedgerMaster().getValidatedLedger(); if (ledger) { subAccountHistoryStart(ledger, ahi); @@ -3955,7 +3970,7 @@ NetworkOPsImp::unsubAccountHistoryInternal( bool NetworkOPsImp::subBook(InfoSub::ref isrListener, Book const& book) { - if (auto listeners = registry_.getOrderBookDB().makeBookListeners(book)) + if (auto listeners = registry_.get().getOrderBookDB().makeBookListeners(book)) { listeners->addSubscriber(isrListener); } @@ -3971,7 +3986,7 @@ NetworkOPsImp::subBook(InfoSub::ref isrListener, Book const& book) bool NetworkOPsImp::unsubBook(std::uint64_t uSeq, Book const& book) { - if (auto listeners = registry_.getOrderBookDB().getBookListeners(book)) + if (auto listeners = registry_.get().getOrderBookDB().getBookListeners(book)) listeners->removeSubscriber(uSeq); return true; @@ -3990,7 +4005,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_.get().getTimeKeeper().closeTime(), consensusDelay); return m_ledgerMaster.getCurrentLedger()->header().seq; } @@ -4005,16 +4020,16 @@ 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(); - jvResult[jss::network_id] = registry_.getNetworkIDService().getNetworkID(); + jvResult[jss::network_id] = registry_.get().getNetworkIDService().getNetworkID(); } if ((mMode >= OperatingMode::SYNCING) && !isNeedNetworkLedger()) { - jvResult[jss::validated_ledgers] = registry_.getLedgerMaster().getCompleteLedgers(); + jvResult[jss::validated_ledgers] = registry_.get().getLedgerMaster().getCompleteLedgers(); } std::lock_guard sl(mSubLock); @@ -4034,7 +4049,7 @@ bool NetworkOPsImp::unsubLedger(std::uint64_t uSeq) { std::lock_guard sl(mSubLock); - return mStreamMaps[sLedger].erase(uSeq); + return mStreamMaps[sLedger].erase(uSeq) != 0u; } // <-- bool: true=erased, false=was not there @@ -4042,7 +4057,7 @@ bool NetworkOPsImp::unsubBookChanges(std::uint64_t uSeq) { std::lock_guard sl(mSubLock); - return mStreamMaps[sBookChanges].erase(uSeq); + return mStreamMaps[sBookChanges].erase(uSeq) != 0u; } // <-- bool: true=added, false=already there @@ -4058,7 +4073,7 @@ bool NetworkOPsImp::unsubManifests(std::uint64_t uSeq) { std::lock_guard sl(mSubLock); - return mStreamMaps[sManifests].erase(uSeq); + return mStreamMaps[sManifests].erase(uSeq) != 0u; } // <-- bool: true=added, false=already there @@ -4073,14 +4088,14 @@ NetworkOPsImp::subServer(InfoSub::ref isrListener, Json::Value& jvResult, bool a // CHECKME: is it necessary to provide a random number here? beast::rngfill(uRandom.begin(), uRandom.size(), crypto_prng()); - auto const& feeTrack = registry_.getFeeTrack(); + auto const& feeTrack = registry_.get().getFeeTrack(); jvResult[jss::random] = to_string(uRandom); jvResult[jss::server_status] = strOperatingMode(admin); jvResult[jss::load_base] = feeTrack.getLoadBase(); 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_.get().getApp().nodeIdentity().first); std::lock_guard sl(mSubLock); return mStreamMaps[sServer].emplace(isrListener->getSeq(), isrListener).second; @@ -4091,7 +4106,7 @@ bool NetworkOPsImp::unsubServer(std::uint64_t uSeq) { std::lock_guard sl(mSubLock); - return mStreamMaps[sServer].erase(uSeq); + return mStreamMaps[sServer].erase(uSeq) != 0u; } // <-- bool: true=added, false=already there @@ -4107,7 +4122,7 @@ bool NetworkOPsImp::unsubTransactions(std::uint64_t uSeq) { std::lock_guard sl(mSubLock); - return mStreamMaps[sTransactions].erase(uSeq); + return mStreamMaps[sTransactions].erase(uSeq) != 0u; } // <-- bool: true=added, false=already there @@ -4123,7 +4138,7 @@ bool NetworkOPsImp::unsubRTTransactions(std::uint64_t uSeq) { std::lock_guard sl(mSubLock); - return mStreamMaps[sRTTransactions].erase(uSeq); + return mStreamMaps[sRTTransactions].erase(uSeq) != 0u; } // <-- bool: true=added, false=already there @@ -4145,7 +4160,7 @@ bool NetworkOPsImp::unsubValidations(std::uint64_t uSeq) { std::lock_guard sl(mSubLock); - return mStreamMaps[sValidations].erase(uSeq); + return mStreamMaps[sValidations].erase(uSeq) != 0u; } // <-- bool: true=added, false=already there @@ -4161,7 +4176,7 @@ bool NetworkOPsImp::unsubPeerStatus(std::uint64_t uSeq) { std::lock_guard sl(mSubLock); - return mStreamMaps[sPeerStatus].erase(uSeq); + return mStreamMaps[sPeerStatus].erase(uSeq) != 0u; } // <-- bool: true=added, false=already there @@ -4177,7 +4192,7 @@ bool NetworkOPsImp::unsubConsensus(std::uint64_t uSeq) { std::lock_guard sl(mSubLock); - return mStreamMaps[sConsensusPhase].erase(uSeq); + return mStreamMaps[sConsensusPhase].erase(uSeq) != 0u; } InfoSub::pointer @@ -4267,7 +4282,7 @@ NetworkOPsImp::getBookPage( STAmount saDirRate; auto const rate = transferRate(view, book.out.account); - auto viewJ = registry_.journal("View"); + auto viewJ = registry_.get().getJournal("View"); while (!bDone && iLimit-- > 0) { @@ -4628,7 +4643,7 @@ NetworkOPsImp::StateAccounting::json(Json::Value& obj) const state[jss::duration_us] = std::to_string(counters[i].dur.count()); } obj[jss::server_state_duration_us] = std::to_string(current.count()); - if (initialSync) + if (initialSync != 0u) obj[jss::initial_sync_duration_us] = std::to_string(initialSync); } @@ -4640,11 +4655,11 @@ make_NetworkOPs( NetworkOPs::clock_type& clock, bool standalone, std::size_t minPeerCount, - bool startvalid, - JobQueue& job_queue, + bool startValid, + JobQueue& jobQueue, LedgerMaster& ledgerMaster, ValidatorKeys const& validatorKeys, - boost::asio::io_context& io_svc, + boost::asio::io_context& ioCtx, beast::Journal journal, beast::insight::Collector::ptr const& collector) { @@ -4653,11 +4668,11 @@ make_NetworkOPs( clock, standalone, minPeerCount, - startvalid, - job_queue, + startValid, + jobQueue, ledgerMaster, validatorKeys, - io_svc, + ioCtx, journal, collector); } 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 13746369f5..6460d99686 100644 --- a/src/xrpld/app/misc/SHAMapStoreImp.cpp +++ b/src/xrpld/app/misc/SHAMapStoreImp.cpp @@ -93,7 +93,7 @@ SHAMapStoreImp::SHAMapStoreImp( get_if_exists(section, "online_delete", deleteInterval_); - if (deleteInterval_) + if (deleteInterval_ != 0u) { // Configuration that affects the behavior of online delete get_if_exists(section, "delete_batch", deleteBatch_); @@ -138,7 +138,7 @@ SHAMapStoreImp::makeNodeStore(int readThreads) auto nscfg = app_.config().section(ConfigSection::nodeDatabase()); std::unique_ptr db; - if (deleteInterval_) + if (deleteInterval_ != 0u) { SavedState state = state_db_.getState(); auto writableBackend = makeBackendRotating(state.writableDb); @@ -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; @@ -209,7 +209,7 @@ SHAMapStoreImp::copyNode(std::uint64_t& nodeCount, SHAMapTreeNode const& node) // Copy a single record from node to dbRotating_ dbRotating_->fetchNodeObject( node.getHash().as_uint256(), 0, NodeStore::FetchType::synchronous, true); - if (!(++nodeCount % checkHealthInterval_)) + if ((++nodeCount % checkHealthInterval_) == 0u) { if (healthWait() == stopping) return false; @@ -254,7 +254,7 @@ SHAMapStoreImp::run() } LedgerIndex const validatedSeq = validatedLedger->header().seq; - if (!lastRotated) + if (lastRotated == 0u) { lastRotated = validatedSeq; state_db_.setLastRotated(lastRotated); @@ -386,15 +386,15 @@ SHAMapStoreImp::dbPaths() it != boost::filesystem::directory_iterator(); ++it) { - if (!state.writableDb.compare(it->path().string())) + if (state.writableDb.compare(it->path().string()) == 0) { writableDbExists = true; } - else if (!state.archiveDb.compare(it->path().string())) + else if (state.archiveDb.compare(it->path().string()) == 0) { archiveDbExists = true; } - else if (!dbPrefix_.compare(it->path().stem().string())) + else if (dbPrefix_.compare(it->path().stem().string()) == 0) { pathsToDelete.push_back(it->path()); } @@ -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; } @@ -608,7 +608,7 @@ SHAMapStoreImp::minimumOnline() const { // minimumOnline_ with 0 value is equivalent to unknown/not set. // Don't attempt to acquire ledgers if that value is unknown. - if (deleteInterval_ && minimumOnline_) + if ((deleteInterval_ != 0u) && (minimumOnline_ != 0u)) return minimumOnline_.load(); return app_.getLedgerMaster().minSqlSeq(); } diff --git a/src/xrpld/app/misc/TxQ.h b/src/xrpld/app/misc/TxQ.h index 4f02d6d617..7c441867ea 100644 --- a/src/xrpld/app/misc/TxQ.h +++ b/src/xrpld/app/misc/TxQ.h @@ -693,12 +693,12 @@ private: }; // Helper function returns requiredFeeLevel. - FeeLevel64 + static FeeLevel64 getRequiredFeeLevel( OpenView& view, ApplyFlags flags, FeeMetrics::Snapshot const& metricsSnapshot, - std::lock_guard const& lock) const; + std::lock_guard const& lock); // Helper function for TxQ::apply. If a transaction's fee is high enough, // attempt to directly apply that transaction to the ledger. 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/AmendmentTable.cpp b/src/xrpld/app/misc/detail/AmendmentTable.cpp index 2b7005f4cc..7569fa13b5 100644 --- a/src/xrpld/app/misc/detail/AmendmentTable.cpp +++ b/src/xrpld/app/misc/detail/AmendmentTable.cpp @@ -675,7 +675,7 @@ AmendmentTableImpl::unVeto(uint256 const& amendment) std::lock_guard lock(mutex_); AmendmentState* const s = get(amendment, lock); - if (!s || s->vote != AmendmentVote::down) + if ((s == nullptr) || s->vote != AmendmentVote::down) return false; s->vote = AmendmentVote::up; persistVote(amendment, s->name, s->vote); @@ -707,7 +707,7 @@ AmendmentTableImpl::isEnabled(uint256 const& amendment) const { std::lock_guard lock(mutex_); AmendmentState const* s = get(amendment, lock); - return s && s->enabled; + return (s != nullptr) && s->enabled; } bool @@ -715,7 +715,7 @@ AmendmentTableImpl::isSupported(uint256 const& amendment) const { std::lock_guard lock(mutex_); AmendmentState const* s = get(amendment, lock); - return s && s->supported; + return (s != nullptr) && s->supported; } bool @@ -946,7 +946,7 @@ AmendmentTableImpl::injectJson( v[jss::count] = votesFor; v[jss::validations] = votesTotal; - if (votesNeeded) + if (votesNeeded != 0) v[jss::threshold] = votesNeeded; } } @@ -974,7 +974,7 @@ AmendmentTableImpl::getJson(uint256 const& amendmentID, bool isAdmin) const { std::lock_guard lock(mutex_); AmendmentState const* a = get(amendmentID, lock); - if (a) + if (a != nullptr) { Json::Value& jAmendment = (ret[to_string(amendmentID)] = Json::objectValue); injectJson(jAmendment, amendmentID, *a, isAdmin, lock); diff --git a/src/xrpld/app/misc/detail/Transaction.cpp b/src/xrpld/app/misc/detail/Transaction.cpp index 35b49504d5..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 { @@ -133,7 +133,7 @@ Transaction::getJson(JsonOptions options, bool binary) const Json::Value ret(mTransaction->getJson(options & ~JsonOptions::include_date, binary)); // NOTE Binary STTx::getJson output might not be a JSON object - if (ret.isObject() && mLedgerIndex) + if (ret.isObject() && (mLedgerIndex != 0u)) { if (!(options & JsonOptions::disable_API_prior_V2)) { diff --git a/src/xrpld/app/misc/detail/TxQ.cpp b/src/xrpld/app/misc/detail/TxQ.cpp index 020fa501d5..c03ef6872e 100644 --- a/src/xrpld/app/misc/detail/TxQ.cpp +++ b/src/xrpld/app/misc/detail/TxQ.cpp @@ -121,7 +121,7 @@ TxQ::FeeMetrics::update( txnsExpected_ = std::min(next, maximumTxnCount_.value_or(next)); } - if (!size) + if (size == 0) { escalationMultiplier_ = setup.minimumEscalationMultiplier; } @@ -185,16 +185,16 @@ sumOfFirstSquares(std::size_t xIn) } // Unit tests for sumOfSquares() -static_assert(sumOfFirstSquares(1).first == true); +static_assert(sumOfFirstSquares(1).first); static_assert(sumOfFirstSquares(1).second == 1); -static_assert(sumOfFirstSquares(2).first == true); +static_assert(sumOfFirstSquares(2).first); static_assert(sumOfFirstSquares(2).second == 5); -static_assert(sumOfFirstSquares(0x1FFFFF).first == true, ""); +static_assert(sumOfFirstSquares(0x1FFFFF).first, ""); static_assert(sumOfFirstSquares(0x1FFFFF).second == 0x2AAAA8AAAAB00000ul, ""); -static_assert(sumOfFirstSquares(0x200000).first == false, ""); +static_assert(!sumOfFirstSquares(0x200000).first, ""); static_assert(sumOfFirstSquares(0x200000).second == std::numeric_limits::max(), ""); } // namespace detail @@ -308,10 +308,11 @@ TxQ::MaybeTx& TxQ::TxQAccount::add(MaybeTx&& txn) { auto const seqProx = txn.seqProxy; + [[maybe_unused]] auto const* txnPtr = &txn; auto result = transactions.emplace(seqProx, std::move(txn)); XRPL_ASSERT(result.second, "xrpl::TxQ::TxQAccount::add : emplace succeeded"); - XRPL_ASSERT(&result.first->second != &txn, "xrpl::TxQ::TxQAccount::add : transaction moved"); + XRPL_ASSERT(&result.first->second != txnPtr, "xrpl::TxQ::TxQAccount::add : transaction moved"); return result.first->second; } @@ -357,7 +358,7 @@ TxQ::canBeHeld( // queue yet, but should be added in the future. // tapFAIL_HARD transactions are never held if (tx.isFieldPresent(sfPreviousTxnID) || tx.isFieldPresent(sfAccountTxnID) || - (flags & tapFAIL_HARD)) + ((flags & tapFAIL_HARD) != 0u)) return telCAN_NOT_QUEUE; { @@ -1591,7 +1592,7 @@ TxQ::getRequiredFeeLevel( OpenView& view, ApplyFlags flags, FeeMetrics::Snapshot const& metricsSnapshot, - std::lock_guard const& lock) const + std::lock_guard const& lock) { return FeeMetrics::scaleFeeLevel(metricsSnapshot, view); } @@ -1769,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/ValidatorList.cpp b/src/xrpld/app/misc/detail/ValidatorList.cpp index 386b96387e..abf64a4a93 100644 --- a/src/xrpld/app/misc/detail/ValidatorList.cpp +++ b/src/xrpld/app/misc/detail/ValidatorList.cpp @@ -137,7 +137,7 @@ ValidatorList::load( JLOG(j_.debug()) << "Loading configured trusted validator list publisher keys"; std::size_t count = 0; - for (auto key : publisherKeys) + for (auto const& key : publisherKeys) { JLOG(j_.trace()) << "Processing '" << key << "'"; @@ -181,7 +181,7 @@ ValidatorList::load( { // Want truncated result when dividing an odd integer listThreshold_ = (publisherLists_.size() < 3) ? 1 // - : publisherLists_.size() / 2 + 1; + : (publisherLists_.size() / 2) + 1; JLOG(j_.debug()) << "Validator list threshold computed as " << listThreshold_; } @@ -699,11 +699,11 @@ ValidatorList::sendValidatorList( { messageVersion = 1; } - if (!messageVersion) + if (messageVersion == 0u) return; auto const [newPeerSequence, numVLs] = buildValidatorListMessages( messageVersion, peerSequence, maxSequence, rawVersion, rawManifest, blobInfos, messages); - if (newPeerSequence) + if (newPeerSequence != 0u) { XRPL_ASSERT( !messages.empty(), @@ -1256,7 +1256,7 @@ ValidatorList::loadLists() continue; auto size = file_size(fullPath, ec); - if (!ec && !size) + if (!ec && (size == 0u)) { // Treat an empty file as a missing file, because // nobody else is going to write it. @@ -1406,7 +1406,7 @@ ValidatorList::getListedKey(PublicKey const& identity) const { std::shared_lock read_lock{mutex_}; - auto const pubKey = validatorManifests_.getMasterKey(identity); + auto pubKey = validatorManifests_.getMasterKey(identity); if (keyListings_.contains(pubKey)) return pubKey; return std::nullopt; @@ -1415,7 +1415,7 @@ ValidatorList::getListedKey(PublicKey const& identity) const std::optional ValidatorList::getTrustedKey(ValidatorList::shared_lock const&, PublicKey const& identity) const { - auto const pubKey = validatorManifests_.getMasterKey(identity); + auto pubKey = validatorManifests_.getMasterKey(identity); if (trustedMasterKeys_.contains(pubKey)) return pubKey; return std::nullopt; @@ -1433,7 +1433,7 @@ bool ValidatorList::trustedPublisher(PublicKey const& identity) const { std::shared_lock read_lock{mutex_}; - return identity.size() && publisherLists_.contains(identity) && + return (identity.size() != 0u) && publisherLists_.contains(identity) && publisherLists_.at(identity).status < PublisherStatus::revoked; } @@ -1484,7 +1484,7 @@ ValidatorList::removePublisherList( std::size_t ValidatorList::count(ValidatorList::shared_lock const&) const { - return publisherLists_.size() + (!localPublisherList.list.empty()); + return publisherLists_.size() + static_cast(!localPublisherList.list.empty()); } std::size_t @@ -1649,7 +1649,7 @@ ValidatorList::getJson() const future.validFrom > timeKeeper_.now() + 600s, "xrpl::ValidatorList::getJson : minimum valid from"); } - if (remaining.size()) + if (remaining.size() != 0u) curr[jss::remaining] = std::move(remaining); } diff --git a/src/xrpld/app/misc/detail/ValidatorSite.cpp b/src/xrpld/app/misc/detail/ValidatorSite.cpp index 8db29c0bb0..b93a1b8007 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); } @@ -227,12 +227,13 @@ ValidatorSite::makeRequest( { } }; - auto onFetch = - [this, siteIdx, timeoutCancel]( - error_code const& err, endpoint_type const& endpoint, detail::response_type&& resp) { - timeoutCancel(); - onSiteFetch(err, endpoint, std::move(resp), siteIdx); - }; + auto onFetch = [this, siteIdx, timeoutCancel]( + error_code const& err, + endpoint_type const& endpoint, + detail::response_type const& resp) { + timeoutCancel(); + onSiteFetch(err, endpoint, resp, siteIdx); + }; auto onFetchFile = [this, siteIdx, timeoutCancel]( error_code const& err, std::string const& resp) { @@ -394,8 +395,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/misc/make_NetworkOPs.h b/src/xrpld/app/misc/make_NetworkOPs.h index 7dce966f04..e250a147b7 100644 --- a/src/xrpld/app/misc/make_NetworkOPs.h +++ b/src/xrpld/app/misc/make_NetworkOPs.h @@ -21,11 +21,11 @@ make_NetworkOPs( NetworkOPs::clock_type& clock, bool standalone, std::size_t minPeerCount, - bool start_valid, - JobQueue& job_queue, + bool startValid, + JobQueue& jobQueue, LedgerMaster& ledgerMaster, ValidatorKeys const& validatorKeys, - boost::asio::io_context& io_svc, + boost::asio::io_context& ioCtx, beast::Journal journal, beast::insight::Collector::ptr const& collector); diff --git a/src/xrpld/app/rdb/backend/SQLiteDatabase.h b/src/xrpld/app/rdb/backend/SQLiteDatabase.h index 462b62de6e..05e0175732 100644 --- a/src/xrpld/app/rdb/backend/SQLiteDatabase.h +++ b/src/xrpld/app/rdb/backend/SQLiteDatabase.h @@ -327,10 +327,10 @@ public: * @param id Hash of the transaction. * @param range Range of ledgers to check, if present. * @param ec Default error code value. - * @return Transaction and its metadata if found, otherwise TxSearched::all + * @return Transaction and its metadata if found, otherwise TxSearched::All * if a range is provided and all ledgers from the range are present - * in the database, TxSearched::some if a range is provided and not - * all ledgers are present, TxSearched::unknown if the range is not + * in the database, TxSearched::Some if a range is provided and not + * all ledgers are present, TxSearched::Unknown if the range is not * provided or a deserializing error occurred. In the last case the * error code is returned via the ec parameter, in other cases the * default error code is not changed. @@ -405,7 +405,7 @@ public: transactionDbHasSpace(Config const& config); private: - ServiceRegistry& registry_; + std::reference_wrapper registry_; bool useTxTables_; beast::Journal j_; std::unique_ptr ledgerDb_, txdb_; diff --git a/src/xrpld/app/rdb/backend/detail/Node.cpp b/src/xrpld/app/rdb/backend/detail/Node.cpp index 09b4ebc241..926c01b8b3 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 @@ -69,8 +70,8 @@ makeLedgerDBs( boost::format("PRAGMA cache_size=-%d;") % kilobytes(config.getValueFor(SizedItem::txnDBCache))); - if (!setup.standAlone || setup.startUp == StartUpType::LOAD || - setup.startUp == StartUpType::LOAD_FILE || setup.startUp == StartUpType::REPLAY) + if (!setup.standAlone || setup.startUp == StartUpType::Load || + setup.startUp == StartUpType::LoadFile || setup.startUp == StartUpType::Replay) { // Check if AccountTransactions has primary key std::string cid, name, type; @@ -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; } @@ -674,16 +675,16 @@ transactionsSQL( std::string maxClause; std::string minClause; - if (options.maxLedger) + if (options.ledgerRange.max != 0u) { maxClause = boost::str( - boost::format("AND AccountTransactions.LedgerSeq <= '%u'") % options.maxLedger); + boost::format("AND AccountTransactions.LedgerSeq <= '%u'") % options.ledgerRange.max); } - if (options.minLedger) + if (options.ledgerRange.min != 0u) { minClause = boost::str( - boost::format("AND AccountTransactions.LedgerSeq >= '%u'") % options.minLedger); + boost::format("AND AccountTransactions.LedgerSeq >= '%u'") % options.ledgerRange.min); } std::string sql; @@ -1020,14 +1021,14 @@ accountTxPage( ORDER BY AccountTransactions.LedgerSeq %s, AccountTransactions.TxnSeq %s LIMIT %u;)")) % - toBase58(options.account) % options.minLedger % options.maxLedger % order % order % - queryLimit); + toBase58(options.account) % options.ledgerRange.min % options.ledgerRange.max % order % + order % queryLimit); } else { char const* const compare = forward ? ">=" : "<="; - std::uint32_t const minLedger = forward ? findLedger + 1 : options.minLedger; - std::uint32_t const maxLedger = forward ? options.maxLedger : findLedger - 1; + std::uint32_t const minLedger = forward ? findLedger + 1 : options.ledgerRange.min; + std::uint32_t const maxLedger = forward ? options.ledgerRange.max : findLedger - 1; auto b58acct = toBase58(options.account); sql = boost::str( @@ -1191,7 +1192,7 @@ getTransaction( auto const got_data = session.got_data(); if ((!got_data || txn != soci::i_ok || meta != soci::i_ok) && !range) - return TxSearched::unknown; + return TxSearched::Unknown; if (!got_data) { @@ -1204,10 +1205,10 @@ getTransaction( soci::into(count, rti); if (!session.got_data() || rti != soci::i_ok) - return TxSearched::some; + return TxSearched::Some; - return count == (range->last() - range->first() + 1) ? TxSearched::all - : TxSearched::some; + return count == (range->last() - range->first() + 1) ? TxSearched::All + : TxSearched::Some; } convert(sociRawTxnBlob, rawTxn); @@ -1229,13 +1230,13 @@ 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; } - return TxSearched::unknown; + return TxSearched::Unknown; } bool diff --git a/src/xrpld/app/rdb/backend/detail/Node.h b/src/xrpld/app/rdb/backend/detail/Node.h index cb49a373bd..5fbabeca47 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 { @@ -377,10 +377,10 @@ newestAccountTxPage( * @param id Hash of the transaction. * @param range Range of ledgers to check, if present. * @param ec Default value of error code. - * @return Transaction and its metadata if found, TxSearched::all if range + * @return Transaction and its metadata if found, TxSearched::All if range * given and all ledgers from range are present in the database, - * TxSearched::some if range given and not all ledgers are present, - * TxSearched::unknown if range not given or deserializing error + * TxSearched::Some if range given and not all ledgers are present, + * TxSearched::Unknown if range not given or deserializing error * occurred. In the last case error code modified in ec link * parameter, in other cases default error code remained. */ diff --git a/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp b/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp index 4f5365ea01..90d3b5a8e4 100644 --- a/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp +++ b/src/xrpld/app/rdb/backend/detail/SQLiteDatabase.cpp @@ -178,7 +178,8 @@ SQLiteDatabase::saveValidatedLedger(std::shared_ptr const& ledger, { if (existsLedger()) { - if (!detail::saveValidatedLedger(*ledgerDb_, txdb_, registry_.app(), ledger, current)) + if (!detail::saveValidatedLedger( + *ledgerDb_, txdb_, registry_.get().getApp(), ledger, current)) return false; } @@ -314,7 +315,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_.get().getApp(), startIndex, 20).first; if (!res.empty()) return res; @@ -329,12 +330,13 @@ SQLiteDatabase::getOldestAccountTxs(AccountTxOptions const& options) if (!useTxTables_) return {}; - LedgerMaster& ledgerMaster = registry_.getLedgerMaster(); + LedgerMaster& ledgerMaster = registry_.get().getLedgerMaster(); if (existsTransaction()) { auto db = checkoutTransaction(); - return detail::getOldestAccountTxs(*db, registry_.app(), ledgerMaster, options, j_).first; + return detail::getOldestAccountTxs(*db, registry_.get().getApp(), ledgerMaster, options, j_) + .first; } return {}; @@ -346,12 +348,13 @@ SQLiteDatabase::getNewestAccountTxs(AccountTxOptions const& options) if (!useTxTables_) return {}; - LedgerMaster& ledgerMaster = registry_.getLedgerMaster(); + LedgerMaster& ledgerMaster = registry_.get().getLedgerMaster(); if (existsTransaction()) { auto db = checkoutTransaction(); - return detail::getNewestAccountTxs(*db, registry_.app(), ledgerMaster, options, j_).first; + return detail::getNewestAccountTxs(*db, registry_.get().getApp(), ledgerMaster, options, j_) + .first; } return {}; @@ -366,7 +369,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_.get().getApp(), options, j_).first; } return {}; @@ -381,7 +384,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_.get().getApp(), options, j_).first; } return {}; @@ -395,14 +398,15 @@ 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_.get().getApp()), std::placeholders::_1); AccountTxs ret; - auto onTransaction = - [&ret, &app = registry_.app()]( - 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); - }; + auto onTransaction = [&ret, &app = registry_.get().getApp()]( + std::uint32_t ledger_index, + std::string const& status, + Blob const& rawTxn, + Blob const& rawMeta) { + convertBlobsToTxResult(ret, ledger_index, status, rawTxn, rawMeta, app); + }; if (existsTransaction()) { @@ -424,14 +428,15 @@ 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_.get().getApp()), std::placeholders::_1); AccountTxs ret; - auto onTransaction = - [&ret, &app = registry_.app()]( - 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); - }; + auto onTransaction = [&ret, &app = registry_.get().getApp()]( + std::uint32_t ledger_index, + std::string const& status, + Blob const& rawTxn, + Blob const& rawMeta) { + convertBlobsToTxResult(ret, ledger_index, status, rawTxn, rawMeta, app); + }; if (existsTransaction()) { @@ -453,7 +458,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_.get().getApp()), std::placeholders::_1); MetaTxsList ret; auto onTransaction = [&ret]( @@ -481,7 +486,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_.get().getApp()), std::placeholders::_1); MetaTxsList ret; auto onTransaction = [&ret]( @@ -508,15 +513,15 @@ SQLiteDatabase::getTransaction( error_code_i& ec) { if (!useTxTables_) - return TxSearched::unknown; + return TxSearched::Unknown; if (existsTransaction()) { auto db = checkoutTransaction(); - return detail::getTransaction(*db, registry_.app(), id, range, ec); + return detail::getTransaction(*db, registry_.get().getApp(), id, range, ec); } - return TxSearched::unknown; + return TxSearched::Unknown; } SQLiteDatabase::SQLiteDatabase(SQLiteDatabase&& rhs) noexcept @@ -604,10 +609,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..78a35c6bc1 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. @@ -126,7 +134,7 @@ public: // Entries from [ips_fixed] config stanza std::vector IPS_FIXED; - StartUpType START_UP = StartUpType::NORMAL; + StartUpType START_UP = StartUpType::Normal; bool START_VALID = false; @@ -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/core/detail/Config.cpp b/src/xrpld/core/detail/Config.cpp index 52186ca9da..c7179c181b 100644 --- a/src/xrpld/core/detail/Config.cpp +++ b/src/xrpld/core/detail/Config.cpp @@ -204,13 +204,13 @@ getSingleSection( { auto const pmtEntries = getIniFileSection(secSource, strSection); - if (pmtEntries && pmtEntries->size() == 1) + if ((pmtEntries != nullptr) && pmtEntries->size() == 1) { strValue = (*pmtEntries)[0]; return true; } - if (pmtEntries) + if (pmtEntries != nullptr) { JLOG(j.warn()) << "Section '" << strSection << "': requires 1 line not " << pmtEntries->size() << " lines."; @@ -415,7 +415,7 @@ checkZeroPorts(Config const& config) if (optResult) { auto const port = beast::lexicalCast(*optResult); - if (!port) + if (port == 0u) { std::stringstream ss; ss << "Invalid value '" << *optResult << "' for key 'port' in [" << name << "]"; @@ -999,30 +999,30 @@ Config::loadFromString(std::string const& fileContents) auto entries = getIniFileSection(iniFile, SECTION_VALIDATORS); - if (entries) + if (entries != nullptr) section(SECTION_VALIDATORS).append(*entries); auto valKeyEntries = getIniFileSection(iniFile, SECTION_VALIDATOR_KEYS); - if (valKeyEntries) + if (valKeyEntries != nullptr) section(SECTION_VALIDATOR_KEYS).append(*valKeyEntries); auto valSiteEntries = getIniFileSection(iniFile, SECTION_VALIDATOR_LIST_SITES); - if (valSiteEntries) + if (valSiteEntries != nullptr) section(SECTION_VALIDATOR_LIST_SITES).append(*valSiteEntries); auto valListKeys = getIniFileSection(iniFile, SECTION_VALIDATOR_LIST_KEYS); - if (valListKeys) + if (valListKeys != nullptr) section(SECTION_VALIDATOR_LIST_KEYS).append(*valListKeys); auto valListThreshold = getIniFileSection(iniFile, SECTION_VALIDATOR_LIST_THRESHOLD); - if (valListThreshold) + if (valListThreshold != nullptr) section(SECTION_VALIDATOR_LIST_THRESHOLD).append(*valListThreshold); - if (!entries && !valKeyEntries && !valListKeys) + if ((entries == nullptr) && (valKeyEntries == nullptr) && (valListKeys == nullptr)) { Throw( "The file specified in [" SECTION_VALIDATORS_FILE @@ -1315,7 +1315,7 @@ setup_DatabaseCon(Config const& c, std::optional j) if (page_size < 512 || page_size > 65536) Throw("Invalid page_size. Must be between 512 and 65536."); - if (page_size & (page_size - 1)) + if ((page_size & (page_size - 1)) != 0) Throw("Invalid page_size. Must be a power of 2."); } diff --git a/src/xrpld/overlay/Message.h b/src/xrpld/overlay/Message.h index 30650d384c..df59656ac2 100644 --- a/src/xrpld/overlay/Message.h +++ b/src/xrpld/overlay/Message.h @@ -91,7 +91,7 @@ private: * currently LZ4 only. If None then the message is uncompressed. * @param uncompressedBytes Size of the uncompressed message */ - void + static void setHeader( std::uint8_t* in, std::uint32_t payloadBytes, @@ -112,8 +112,8 @@ private: * @param in Payload header pointer * @return Message type */ - int - getType(std::uint8_t const* in) const; + static int + getType(std::uint8_t const* in); }; } // namespace xrpl 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/Message.cpp b/src/xrpld/overlay/detail/Message.cpp index 754545f04a..4d043500c7 100644 --- a/src/xrpld/overlay/detail/Message.cpp +++ b/src/xrpld/overlay/detail/Message.cpp @@ -103,6 +103,7 @@ Message::compress() if (compressedSize < (messageBytes - (headerBytesCompressed - headerBytes))) { bufferCompressed_.resize(headerBytesCompressed + compressedSize); + // NOLINTNEXTLINE(readability-suspicious-call-argument) setHeader(bufferCompressed_.data(), compressedSize, type, Algorithm::LZ4, messageBytes); } else @@ -199,7 +200,7 @@ Message::getBuffer(Compressed tryCompressed) } int -Message::getType(std::uint8_t const* in) const +Message::getType(std::uint8_t const* in) { int type = (static_cast(*(in + 4)) << 8) + *(in + 5); return type; diff --git a/src/xrpld/overlay/detail/OverlayImpl.cpp b/src/xrpld/overlay/detail/OverlayImpl.cpp index d9077686ec..b4b0686ac8 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)) { @@ -810,19 +811,19 @@ OverlayImpl::processCrawl(http_request_type const& req, Handoff& handoff) msg.insert("Connection", "close"); msg.body()["version"] = Json::Value(2u); - if (setup_.crawlOptions & CrawlOptions::Overlay) + if ((setup_.crawlOptions & CrawlOptions::Overlay) != 0u) { msg.body()["overlay"] = getOverlayInfo(); } - if (setup_.crawlOptions & CrawlOptions::ServerInfo) + if ((setup_.crawlOptions & CrawlOptions::ServerInfo) != 0u) { msg.body()["server"] = getServerInfo(); } - if (setup_.crawlOptions & CrawlOptions::ServerCounts) + if ((setup_.crawlOptions & CrawlOptions::ServerCounts) != 0u) { msg.body()["counts"] = getServerCounts(); } - if (setup_.crawlOptions & CrawlOptions::Unl) + if ((setup_.crawlOptions & CrawlOptions::Unl) != 0u) { msg.body()["unl"] = getUnlInfo(); } @@ -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) { @@ -1014,7 +1015,7 @@ OverlayImpl::getActivePeers() const Overlay::PeerSequence ret; ret.reserve(size()); - for_each([&ret](std::shared_ptr const& sp) { ret.emplace_back(std::move(sp)); }); + for_each([&ret](std::shared_ptr const& sp) { ret.emplace_back(sp); }); return ret; } @@ -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()); @@ -1222,7 +1223,7 @@ OverlayImpl::relay( // relay to all disabled and some randomly selected enabled that // do not have the transaction. auto const enabledTarget = app_.config().TX_REDUCE_RELAY_MIN_PEERS + - (total - minRelay) * app_.config().TX_RELAY_PERCENTAGE / 100; + ((total - minRelay) * app_.config().TX_RELAY_PERCENTAGE / 100); txMetrics_.addMetrics(enabledTarget, toSkip.size(), disabled); @@ -1301,7 +1302,7 @@ void OverlayImpl::autoConnect() { auto const result = m_peerFinder->autoconnect(); - for (auto addr : result) + for (auto const& addr : result) connect(addr); } diff --git a/src/xrpld/overlay/detail/OverlayImpl.h b/src/xrpld/overlay/detail/OverlayImpl.h index b77b4e69aa..c816f24e0c 100644 --- a/src/xrpld/overlay/detail/OverlayImpl.h +++ b/src/xrpld/overlay/detail/OverlayImpl.h @@ -429,7 +429,7 @@ private: http_request_type const& request, address_type remote_address); - std::shared_ptr + static std::shared_ptr makeErrorResponse( std::shared_ptr const& slot, http_request_type const& request, diff --git a/src/xrpld/overlay/detail/PeerImp.cpp b/src/xrpld/overlay/detail/PeerImp.cpp index 7ed8c45453..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()); }); @@ -1509,7 +1509,7 @@ PeerImp::onMessage(std::shared_ptr const& m) } } else if ( - !m->has_ledgerhash() && !m->has_ledgerseq() && !(ltype && *ltype == protocol::ltCLOSED)) + !m->has_ledgerhash() && !m->has_ledgerseq() && (!ltype || *ltype != protocol::ltCLOSED)) { badData("Invalid request"); return; @@ -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( @@ -3376,7 +3376,7 @@ PeerImp::processLedgerRequest(std::shared_ptr const& m) } } - if (!map) + if (map == nullptr) { JLOG(p_journal_.warn()) << "processLedgerRequest: Unable to find map"; return; 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/overlay/detail/ProtocolMessage.h b/src/xrpld/overlay/detail/ProtocolMessage.h index 2442e48031..ac06b10292 100644 --- a/src/xrpld/overlay/detail/ProtocolMessage.h +++ b/src/xrpld/overlay/detail/ProtocolMessage.h @@ -237,7 +237,7 @@ template < std::shared_ptr parseMessageContent(MessageHeader const& header, Buffers const& buffers) { - auto const m = std::make_shared(); + auto m = std::make_shared(); ZeroCopyInputStream stream(buffers); stream.Skip(header.header_size); diff --git a/src/xrpld/peerfinder/detail/Logic.h b/src/xrpld/peerfinder/detail/Logic.h index 39f1ca6ae6..8f49da6c4f 100644 --- a/src/xrpld/peerfinder/detail/Logic.h +++ b/src/xrpld/peerfinder/detail/Logic.h @@ -452,7 +452,7 @@ public: std::vector autoconnect() { - std::vector const none; + std::vector none; std::lock_guard _(lock_); @@ -1011,7 +1011,7 @@ public: { int count(0); std::lock_guard _(lock_); - for (auto addr : list) + for (auto const& addr : list) { if (bootcache_.insertStatic(addr)) ++count; diff --git a/src/xrpld/peerfinder/detail/PeerfinderConfig.cpp b/src/xrpld/peerfinder/detail/PeerfinderConfig.cpp index cc74018fc0..4de03c6ca6 100644 --- a/src/xrpld/peerfinder/detail/PeerfinderConfig.cpp +++ b/src/xrpld/peerfinder/detail/PeerfinderConfig.cpp @@ -78,7 +78,7 @@ Config::makeConfig( // Servers with peer privacy don't want to allow incoming connections config.wantIncoming = (!config.peerPrivate) && (port != 0); - if (!cfg.PEERS_OUT_MAX && !cfg.PEERS_IN_MAX) + if ((cfg.PEERS_OUT_MAX == 0u) && (cfg.PEERS_IN_MAX == 0u)) { if (cfg.PEERS_MAX != 0) config.maxPeers = cfg.PEERS_MAX; diff --git a/src/xrpld/perflog/detail/PerfLogImp.cpp b/src/xrpld/perflog/detail/PerfLogImp.cpp index fc9ef70830..960fdcb3ac 100644 --- a/src/xrpld/perflog/detail/PerfLogImp.cpp +++ b/src/xrpld/perflog/detail/PerfLogImp.cpp @@ -70,8 +70,8 @@ PerfLogImp::Counters::countersJson() const Rpc value; { std::lock_guard lock(proc.second.mutex); - if (!proc.second.value.started && !proc.second.value.finished && - !proc.second.value.errored) + if ((proc.second.value.started == 0u) && (proc.second.value.finished == 0u) && + (proc.second.value.errored == 0u)) { continue; } @@ -90,7 +90,7 @@ PerfLogImp::Counters::countersJson() const rpcobj[proc.first] = p; } - if (totalRpc.started) + if (totalRpc.started != 0u) { Json::Value totalRpcJson(Json::objectValue); totalRpcJson[jss::started] = std::to_string(totalRpc.started); @@ -108,8 +108,8 @@ PerfLogImp::Counters::countersJson() const Jq value; { std::lock_guard lock(proc.second.mutex); - if (!proc.second.value.queued && !proc.second.value.started && - !proc.second.value.finished) + if ((proc.second.value.queued == 0u) && (proc.second.value.started == 0u) && + (proc.second.value.finished == 0u)) { continue; } @@ -130,7 +130,7 @@ PerfLogImp::Counters::countersJson() const jobQueueObj[JobTypes::name(proc.first)] = j; } - if (totalJq.queued) + if (totalJq.queued != 0u) { Json::Value totalJqJson(Json::objectValue); totalJqJson[jss::queued] = std::to_string(totalJq.queued); 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/rpc/detail/DeliveredAmount.cpp b/src/xrpld/rpc/detail/DeliveredAmount.cpp index 3e89edc1f9..e2f5bd8cd9 100644 --- a/src/xrpld/rpc/detail/DeliveredAmount.cpp +++ b/src/xrpld/rpc/detail/DeliveredAmount.cpp @@ -71,13 +71,8 @@ canHaveDeliveredAmount( TxType const tt{serializedTx->getTxnType()}; // Transaction type should be ttPAYMENT, ttACCOUNT_DELETE or ttCHECK_CASH // and if the transaction failed nothing could have been delivered. - if ((tt == ttPAYMENT || tt == ttCHECK_CASH || tt == ttACCOUNT_DELETE) && - transactionMeta.getResultTER() == tesSUCCESS) - { - return true; - } - - return false; + return (tt == ttPAYMENT || tt == ttCHECK_CASH || tt == ttACCOUNT_DELETE) && + transactionMeta.getResultTER() == tesSUCCESS; } void diff --git a/src/xrpld/rpc/detail/Handler.cpp b/src/xrpld/rpc/detail/Handler.cpp index 04cf0420b7..0f95e69d3f 100644 --- a/src/xrpld/rpc/detail/Handler.cpp +++ b/src/xrpld/rpc/detail/Handler.cpp @@ -150,7 +150,7 @@ private: // Use with equal_range to enforce that API range of a newly added handler // does not overlap with API range of an existing handler with same name - [[nodiscard]] bool + [[nodiscard]] static bool overlappingApiVersion( std::pair range, unsigned minVer, diff --git a/src/xrpld/app/paths/PathRequest.cpp b/src/xrpld/rpc/detail/PathRequest.cpp similarity index 97% rename from src/xrpld/app/paths/PathRequest.cpp rename to src/xrpld/rpc/detail/PathRequest.cpp index f82a207552..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) @@ -191,7 +190,7 @@ PathRequest::isValid(std::shared_ptr const& crCache) } else { - bool const disallowXRP(sleDest->getFlags() & lsfDisallowXRP); + bool const disallowXRP((sleDest->getFlags() & lsfDisallowXRP) != 0u); auto usDestCurrID = accountDestCurrencies(*raDstAccount, crCache, !disallowXRP); @@ -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())) { @@ -609,7 +608,7 @@ PathRequest::findPaths( after four source currencies, 50 - (4 * 4) = 34. */ int const size = sourceCurrencies.size(); - consumer_.charge({std::clamp(size * size + 34, 50, 400), "path update"}); + consumer_.charge({std::clamp((size * size) + 34, 50, 400), "path update"}); return true; } 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 98% rename from src/xrpld/app/paths/Pathfinder.cpp rename to src/xrpld/rpc/detail/Pathfinder.cpp index c777fcb2f7..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) @@ -615,7 +614,7 @@ Pathfinder::getBestPaths( ++pathsIterator; auto iPathsLeft = maxPaths - bestPaths.size(); - if (!(iPathsLeft > 0 || fullLiquidityPath.empty())) + if (iPathsLeft <= 0 && !fullLiquidityPath.empty()) break; if (path.empty()) @@ -850,7 +849,7 @@ Pathfinder::isNoRipple( auto const flag((toAccount > fromAccount) ? lsfHighNoRipple : lsfLowNoRipple); - return sleRipple && (sleRipple->getFieldU32(sfFlags) & flag); + return sleRipple && ((sleRipple->getFieldU32(sfFlags) & flag) != 0u); } // Does this path end on an account-to-account link whose last account has @@ -864,7 +863,7 @@ Pathfinder::isNoRippleOut(STPath const& currentPath) // Last link must be an account. STPathElement const& endElement = currentPath.back(); - if (!(endElement.getNodeType() & STPathElement::typeAccount)) + if ((endElement.getNodeType() & STPathElement::typeAccount) == 0u) return false; // If there's only one item in the path, return true if that item specifies @@ -911,7 +910,7 @@ Pathfinder::addLink( << " completePaths size=" << mCompletePaths.size(); JLOG(j_.trace()) << currentPath.getJson(JsonOptions::none); - if (addFlags & afADD_ACCOUNTS) + if ((addFlags & afADD_ACCOUNTS) != 0u) { // add accounts if (bOnXRP) @@ -930,10 +929,10 @@ Pathfinder::addLink( if (sleEnd) { - bool const bRequireAuth(sleEnd->getFieldU32(sfFlags) & lsfRequireAuth); + bool const bRequireAuth((sleEnd->getFieldU32(sfFlags) & lsfRequireAuth) != 0u); bool const bIsEndCurrency(uEndCurrency == mDstAmount.getCurrency()); bool const bIsNoRippleOut(isNoRippleOut(currentPath)); - bool const bDestOnly(addFlags & afAC_LAST); + bool const bDestOnly((addFlags & afAC_LAST) != 0u); if (auto const lines = mRLCache->getRippleLines( uEndAccount, @@ -1012,7 +1011,7 @@ Pathfinder::addLink( bIsEndCurrency, mEffectiveDst, continueCallback); - if (out) + if (out != 0) candidates.push_back({out, acct}); } } @@ -1060,10 +1059,10 @@ Pathfinder::addLink( } } } - if (addFlags & afADD_BOOKS) + if ((addFlags & afADD_BOOKS) != 0u) { // add order books - if (addFlags & afOB_XRP) + if ((addFlags & afOB_XRP) != 0u) { // to XRP only if (!bOnXRP && app_.getOrderBookDB().isBookToXRP({uEndCurrency, uEndIssuer}, mDomain)) 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/RPCCall.cpp b/src/xrpld/rpc/detail/RPCCall.cpp index cd36208294..5c57f96d79 100644 --- a/src/xrpld/rpc/detail/RPCCall.cpp +++ b/src/xrpld/rpc/detail/RPCCall.cpp @@ -149,6 +149,7 @@ private: using parseFuncPtr = Json::Value (RPCParser::*)(Json::Value const& jvParams); Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseAsIs(Json::Value const& jvParams) { Json::Value v(Json::objectValue); @@ -160,6 +161,7 @@ private: } Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseInternal(Json::Value const& jvParams) { Json::Value v(Json::objectValue); @@ -176,6 +178,7 @@ private: } Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseManifest(Json::Value const& jvParams) { if (jvParams.size() == 1) @@ -196,6 +199,7 @@ private: // fetch_info [clear] Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseFetchInfo(Json::Value const& jvParams) { Json::Value jvRequest(Json::objectValue); @@ -286,6 +290,7 @@ private: // // Mnemonic: taker pays --> offer --> taker gets Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseBookOffers(Json::Value const& jvParams) { Json::Value jvRequest(Json::objectValue); @@ -335,7 +340,7 @@ private: try { int bProof = jvParams[5u].asInt(); - if (bProof) + if (bProof != 0) jvRequest[jss::proof] = true; } catch (std::exception const&) @@ -352,11 +357,12 @@ private: // can_delete [||now|always|never] Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseCanDelete(Json::Value const& jvParams) { Json::Value jvRequest(Json::objectValue); - if (!jvParams.size()) + if (jvParams.size() == 0u) return jvRequest; std::string input = jvParams[0u].asString(); @@ -374,6 +380,7 @@ private: // connect [port] Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseConnect(Json::Value const& jvParams) { Json::Value jvRequest(Json::objectValue); @@ -388,7 +395,7 @@ private: // handle case where there is one argument of the form ip:port if (std::count(ip.begin(), ip.end(), ':') == 1) { - std::size_t colon = ip.find_last_of(":"); + std::size_t colon = ip.find_last_of(':'); jvRequest[jss::ip] = std::string{ip, 0, colon}; jvRequest[jss::port] = Json::Value{std::string{ip, colon + 1}}.asUInt(); return jvRequest; @@ -402,6 +409,7 @@ private: // deposit_authorized // [ [, ...]] Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseDepositAuthorized(Json::Value const& jvParams) { Json::Value jvRequest(Json::objectValue); @@ -424,6 +432,7 @@ private: // Return an error for attempting to subscribe/unsubscribe via RPC. Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseEvented(Json::Value const& jvParams) { return rpcError(rpcNO_EVENTS); @@ -431,6 +440,7 @@ private: // feature [] [accept|reject] Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseFeature(Json::Value const& jvParams) { Json::Value jvRequest(Json::objectValue); @@ -464,11 +474,12 @@ private: // get_counts [] Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseGetCounts(Json::Value const& jvParams) { Json::Value jvRequest(Json::objectValue); - if (jvParams.size()) + if (jvParams.size() != 0u) jvRequest[jss::min_count] = jvParams[0u].asUInt(); return jvRequest; @@ -477,6 +488,7 @@ private: // sign_for offline // sign_for Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseSignFor(Json::Value const& jvParams) { bool const bOffline = 4 == jvParams.size() && jvParams[3u].asString() == "offline"; @@ -546,11 +558,9 @@ private: jv.isMember(jss::ripplerpc) && jv[jss::ripplerpc] == "2.0" && jv.isMember(jss::id) && jv.isMember(jss::method)) { - if (jv.isMember(jss::params) && - !(jv[jss::params].isNull() || jv[jss::params].isArray() || - jv[jss::params].isObject())) - return false; - return true; + return !jv.isMember(jss::params) || + (jv[jss::params].isNull() || jv[jss::params].isArray() || + jv[jss::params].isObject()); } } return false; @@ -608,11 +618,12 @@ private: // ledger [id|index|current|closed|validated] [full|tx] Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseLedger(Json::Value const& jvParams) { Json::Value jvRequest(Json::objectValue); - if (!jvParams.size()) + if (jvParams.size() == 0u) { return jvRequest; } @@ -637,6 +648,7 @@ private: // ledger_header | Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseLedgerId(Json::Value const& jvParams) { Json::Value jvRequest(Json::objectValue); @@ -657,6 +669,7 @@ private: // ledger_entry [id] [] Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseLedgerEntry(Json::Value const& jvParams) { Json::Value jvRequest{Json::objectValue}; @@ -674,6 +687,7 @@ private: // specified severity log_level : Set specified // partition to specified severity Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseLogLevel(Json::Value const& jvParams) { Json::Value jvRequest(Json::objectValue); @@ -722,6 +736,7 @@ private: // channel_authorize: [] Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseChannelAuthorize(Json::Value const& jvParams) { Json::Value jvRequest(Json::objectValue); @@ -765,6 +780,7 @@ private: // channel_verify Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseChannelVerify(Json::Value const& jvParams) { std::string const strPk = jvParams[0u].asString(); @@ -793,6 +809,7 @@ private: } Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseAccountRaw2(Json::Value const& jvParams, char const* const acc2Field) { std::array accFields{{jss::account, acc2Field}}; @@ -800,7 +817,8 @@ private: Json::Value jvRequest(Json::objectValue); for (auto i = 0; i < nParams; ++i) { - std::string strParam = jvParams[i].asString(); + // This was non-const. see comment below + std::string const strParam = jvParams[i].asString(); if (i == 1 && strParam.empty()) continue; @@ -810,7 +828,10 @@ private: { if (parseBase58(strParam)) { - jvRequest[accFields[i]] = std::move(strParam); + // TODO: this was std::move'd before but it does not work in practice. + // We would need a Value(std::string&&) for it to work. + // See https://github.com/XRPLF/rippled/issues/6677 + jvRequest[accFields[i]] = strParam; } else { @@ -830,6 +851,7 @@ private: // TODO: Get index from an alternate syntax: rXYZ: Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseAccountRaw1(Json::Value const& jvParams) { std::string strIdent = jvParams[0u].asString(); @@ -850,6 +872,7 @@ private: } Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseVault(Json::Value const& jvParams) { std::string strVaultID = jvParams[0u].asString(); @@ -868,6 +891,7 @@ private: // peer_reservations_add [] Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parsePeerReservationsAdd(Json::Value const& jvParams) { Json::Value jvRequest; @@ -881,6 +905,7 @@ private: // peer_reservations_del Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parsePeerReservationsDel(Json::Value const& jvParams) { Json::Value jvRequest; @@ -916,6 +941,7 @@ private: // simulate [binary] // simulate [binary] Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseSimulate(Json::Value const& jvParams) { Json::Value txJSON; @@ -947,6 +973,7 @@ private: // submit // submit Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseSignSubmit(Json::Value const& jvParams) { Json::Value txJSON; @@ -996,6 +1023,7 @@ private: // // submit_multisigned Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseSubmitMultiSigned(Json::Value const& jvParams) { if (1 == jvParams.size()) @@ -1015,6 +1043,7 @@ private: // transaction_entry Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseTransactionEntry(Json::Value const& jvParams) { // Parameter count should have already been verified. @@ -1040,6 +1069,7 @@ private: // tx Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseTx(Json::Value const& jvParams) { Json::Value jvRequest{Json::objectValue}; @@ -1072,6 +1102,7 @@ private: // tx_history Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseTxHistory(Json::Value const& jvParams) { Json::Value jvRequest{Json::objectValue}; @@ -1088,11 +1119,12 @@ private: // (e.g. .bash_history) and it may be leaked via the process status command // (i.e. ps). Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseValidationCreate(Json::Value const& jvParams) { Json::Value jvRequest{Json::objectValue}; - if (jvParams.size()) + if (jvParams.size() != 0u) jvRequest[jss::secret] = jvParams[0u].asString(); return jvRequest; @@ -1102,11 +1134,12 @@ private: // is only for testing. Master seeds should only be generated // randomly. Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseWalletPropose(Json::Value const& jvParams) { Json::Value jvRequest{Json::objectValue}; - if (jvParams.size()) + if (jvParams.size() != 0u) jvRequest[jss::passphrase] = jvParams[0u].asString(); return jvRequest; @@ -1117,6 +1150,7 @@ private: // ]] Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseGatewayBalances(Json::Value const& jvParams) { unsigned int index = 0; @@ -1159,6 +1193,7 @@ private: // server_definitions [hash] Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseServerDefinitions(Json::Value const& jvParams) { Json::Value jvRequest{Json::objectValue}; @@ -1173,6 +1208,7 @@ private: // server_info [counters] Json::Value + // NOLINTNEXTLINE(readability-convert-member-functions-to-static) parseServerInfo(Json::Value const& jvParams) { Json::Value jvRequest(Json::objectValue); @@ -1542,8 +1578,8 @@ rpcClient( return jvRequest[jss::method].asString(); return jvRequest.isArray() ? "batch" : args[0]; }(), - jvParams, // Parsed, execute. - setup.client.secure != 0, // Use SSL + jvParams, // Parsed, execute. + static_cast(setup.client.secure) != 0, // Use SSL config.quiet(), logs, std::bind(RPCCallImp::callRPCHandler, &jvOutput, std::placeholders::_1), diff --git a/src/xrpld/rpc/detail/RPCHandler.cpp b/src/xrpld/rpc/detail/RPCHandler.cpp index 840ebd5946..eea24ab0c0 100644 --- a/src/xrpld/rpc/detail/RPCHandler.cpp +++ b/src/xrpld/rpc/detail/RPCHandler.cpp @@ -137,7 +137,7 @@ fillHandler(JsonContext& context, Handler const*& result) JLOG(context.j.trace()) << "REQUEST:" << context.params; auto handler = getHandler(context.apiVersion, context.app.config().BETA_RPC_API, strCommand); - if (!handler) + if (handler == nullptr) return rpcUNKNOWN_COMMAND; if (handler->role_ == Role::ADMIN && context.role != Role::ADMIN) @@ -228,7 +228,7 @@ roleRequired(unsigned int version, bool betaEnabled, std::string const& method) { auto handler = RPC::getHandler(version, betaEnabled, method); - if (!handler) + if (handler == nullptr) return Role::FORBID; return handler->role_; diff --git a/src/xrpld/rpc/detail/RPCHelpers.cpp b/src/xrpld/rpc/detail/RPCHelpers.cpp index 832ff778e1..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 @@ -100,7 +100,7 @@ readLimitField(unsigned int& limit, Tuning::LimitRange const& range, JsonContext return std::nullopt; auto const& jvLimit = context.params[jss::limit]; - if (!(jvLimit.isUInt() || (jvLimit.isInt() && jvLimit.asInt() >= 0))) + if (!jvLimit.isUInt() && (!jvLimit.isInt() || jvLimit.asInt() < 0)) return RPC::expected_field_error(jss::limit, "unsigned integer"); limit = jvLimit.asUInt(); diff --git a/src/xrpld/rpc/detail/RPCLedgerHelpers.cpp b/src/xrpld/rpc/detail/RPCLedgerHelpers.cpp index 54ff515894..2216affa6f 100644 --- a/src/xrpld/rpc/detail/RPCLedgerHelpers.cpp +++ b/src/xrpld/rpc/detail/RPCLedgerHelpers.cpp @@ -375,7 +375,7 @@ getOrAcquireLedger(RPC::JsonContext const& context) auto& ledgerMaster = context.app.getLedgerMaster(); LedgerHash ledgerHash; - if ((hasHash + hasIndex) != 1) + if ((static_cast(hasHash) + static_cast(hasIndex)) != 1) { return Unexpected( RPC::make_param_error( @@ -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 97% rename from src/xrpld/app/paths/RippleLineCache.cpp rename to src/xrpld/rpc/detail/RippleLineCache.cpp index ac3e28e579..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 { @@ -84,7 +84,7 @@ RippleLineCache::getRippleLines(AccountID const& accountID, LineDirection direct } XRPL_ASSERT( - !it->second || (it->second->size() > 0), + !it->second || (!it->second->empty()), "xrpl::RippleLineCache::getRippleLines : null or nonempty lines"); auto const size = it->second ? it->second->size() : 0; JLOG(journal_.trace()) << "getRippleLines for ledger " << ledger_->header().seq << " found " 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 f5187d6285..ca026104cf 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 @@ -80,7 +79,7 @@ authorized(Port const& port, std::map const& h) std::string strUserPass64 = it->second.substr(6); boost::trim(strUserPass64); std::string strUserPass = base64_decode(strUserPass64); - std::string::size_type nColon = strUserPass.find(":"); + std::string::size_type nColon = strUserPass.find(':'); if (nColon == std::string::npos) return false; std::string strUser = strUserPass.substr(0, nColon); @@ -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")); @@ -126,14 +125,14 @@ ServerHandler::setup(Setup const& setup, beast::Journal journal) if (auto it = endpoints_.find(port.name); it != endpoints_.end()) { auto const endpointPort = it->second.port(); - if (!port.port) + if (port.port == 0u) port.port = endpointPort; - if (!setup_.client.port && + if ((setup_.client.port == 0u) && (port.protocol.count("http") > 0 || port.protocol.count("https") > 0)) setup_.client.port = endpointPort; - if (!setup_.overlay.port() && (port.protocol.count("peer") > 0)) + if ((setup_.overlay.port() == 0u) && (port.protocol.count("peer") > 0)) setup_.overlay.port(endpointPort); } } @@ -163,7 +162,7 @@ ServerHandler::onAccept(Session& session, boost::asio::ip::tcp::endpoint endpoin return ++count_[port]; }(); - if (port.limit && c >= port.limit) + if ((port.limit != 0) && c >= port.limit) { JLOG(m_journal.trace()) << port.name << " is full; dropping " << endpoint; return false; @@ -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; { @@ -1135,7 +1134,7 @@ parse_Ports(Config const& config, std::ostream& log) // Remove the peer protocol, and if that would // leave the port empty, remove the port as well - if (p.erase("peer") && p.empty()) + if ((p.erase("peer") != 0u) && p.empty()) { it = result.erase(it); } diff --git a/src/xrpld/rpc/detail/TransactionSign.cpp b/src/xrpld/rpc/detail/TransactionSign.cpp index 80c608dbbf..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 @@ -79,7 +78,7 @@ public: AccountID const& getSigner() const { - if (!multiSigningAcctID_) + if (multiSigningAcctID_ == nullptr) LogicError("Accessing unknown SigningForParams::getSigner()"); return *multiSigningAcctID_; } @@ -207,7 +206,7 @@ checkPayment( if (!dstAccountID) return RPC::invalid_field_error("tx_json.Destination"); - if (params.isMember(jss::build_path) && ((doPath == false) || amount.holds())) + if (params.isMember(jss::build_path) && ((!doPath) || amount.holds())) { return RPC::make_error( rpcINVALID_PARAMS, "Field 'build_path' not allowed in this context."); @@ -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); @@ -428,7 +427,7 @@ transactionPreProcessImpl( : nullptr; if (signatureTarget) { - if (!signatureTemplate) + if (signatureTemplate == nullptr) { // Invalid target field return RPC::make_error(rpcINVALID_PARAMS, signatureTarget->get().getName()); } @@ -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 96% rename from src/xrpld/app/paths/TrustLine.cpp rename to src/xrpld/rpc/detail/TrustLine.cpp index 6c54aa52d7..c2bc152448 100644 --- a/src/xrpld/app/paths/TrustLine.cpp +++ b/src/xrpld/rpc/detail/TrustLine.cpp @@ -1,5 +1,6 @@ -#include +#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/AMMInfo.cpp b/src/xrpld/rpc/handlers/AMMInfo.cpp index 42e44f004d..9204f48907 100644 --- a/src/xrpld/rpc/handlers/AMMInfo.cpp +++ b/src/xrpld/rpc/handlers/AMMInfo.cpp @@ -139,7 +139,7 @@ doAMMInfo(RPC::JsonContext& context) issue2 = (*amm)[sfAsset2].get(); } - return ValuesFromContextParams{accountID, *issue1, *issue2, std::move(amm)}; + return ValuesFromContextParams{accountID, *issue1, *issue2, amm}; }; auto const r = getValuesFromContextParams(); diff --git a/src/xrpld/rpc/handlers/AccountChannels.cpp b/src/xrpld/rpc/handlers/AccountChannels.cpp index d2c3d4546d..7bf8a03f21 100644 --- a/src/xrpld/rpc/handlers/AccountChannels.cpp +++ b/src/xrpld/rpc/handlers/AccountChannels.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -66,7 +67,7 @@ doAccountChannels(RPC::JsonContext& context) { return rpcError(rpcACT_MALFORMED); } - AccountID const accountID{std::move(id.value())}; + AccountID const accountID{id.value()}; if (!ledger->exists(keylet::account(accountID))) return rpcError(rpcACT_NOT_FOUND); diff --git a/src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp b/src/xrpld/rpc/handlers/AccountCurrenciesHandler.cpp index 2ec1e20875..e509a72862 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 @@ -44,7 +44,7 @@ doAccountCurrencies(RPC::JsonContext& context) RPC::inject_error(rpcACT_MALFORMED, result); return result; } - auto const accountID{std::move(id.value())}; + auto const accountID{id.value()}; if (!ledger->exists(keylet::account(accountID))) return rpcError(rpcACT_NOT_FOUND); diff --git a/src/xrpld/rpc/handlers/AccountInfo.cpp b/src/xrpld/rpc/handlers/AccountInfo.cpp index f144c934ec..becaea8a51 100644 --- a/src/xrpld/rpc/handlers/AccountInfo.cpp +++ b/src/xrpld/rpc/handlers/AccountInfo.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -101,7 +102,7 @@ doAccountInfo(RPC::JsonContext& context) RPC::inject_error(rpcACT_MALFORMED, result); return result; } - auto const accountID{std::move(id.value())}; + auto const accountID{id.value()}; static constexpr std::array, 9> lsFlags{ {{"defaultRipple", lsfDefaultRipple}, @@ -289,9 +290,9 @@ doAccountInfo(RPC::JsonContext& context) jvQueueTx.append(std::move(jvTx)); } - if (seqCount) + if (seqCount != 0u) jvQueueData[jss::sequence_count] = seqCount; - if (ticketCount) + if (ticketCount != 0u) jvQueueData[jss::ticket_count] = ticketCount; if (lowestSeq) jvQueueData[jss::lowest_sequence] = *lowestSeq; diff --git a/src/xrpld/rpc/handlers/AccountLines.cpp b/src/xrpld/rpc/handlers/AccountLines.cpp index 952141fb8d..f7fc9bdd2d 100644 --- a/src/xrpld/rpc/handlers/AccountLines.cpp +++ b/src/xrpld/rpc/handlers/AccountLines.cpp @@ -1,10 +1,11 @@ -#include #include #include #include +#include #include #include +#include #include #include #include @@ -80,7 +81,7 @@ doAccountLines(RPC::JsonContext& context) RPC::inject_error(rpcACT_MALFORMED, result); return result; } - auto const accountID{std::move(id.value())}; + auto const accountID{id.value()}; if (!ledger->exists(keylet::account(accountID))) return rpcError(rpcACT_NOT_FOUND); diff --git a/src/xrpld/rpc/handlers/AccountOffers.cpp b/src/xrpld/rpc/handlers/AccountOffers.cpp index 842cac71eb..517c0728e9 100644 --- a/src/xrpld/rpc/handlers/AccountOffers.cpp +++ b/src/xrpld/rpc/handlers/AccountOffers.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -55,7 +56,7 @@ doAccountOffers(RPC::JsonContext& context) RPC::inject_error(rpcACT_MALFORMED, result); return result; } - auto const accountID{std::move(id.value())}; + auto const accountID{id.value()}; // Get info on account. result[jss::account] = toBase58(accountID); diff --git a/src/xrpld/rpc/handlers/AccountTx.cpp b/src/xrpld/rpc/handlers/AccountTx.cpp index d7bffe5d95..e120c98523 100644 --- a/src/xrpld/rpc/handlers/AccountTx.cpp +++ b/src/xrpld/rpc/handlers/AccountTx.cpp @@ -133,7 +133,7 @@ getLedgerRange(RPC::Context& context, std::optional const& ledg // Does request specify a ledger or ledger range? if (ledgerSpecifier) { - auto const status = std::visit( + auto status = std::visit( [&](auto const& ls) -> RPC::Status { using T = std::decay_t; if constexpr (std::is_same_v) @@ -167,7 +167,7 @@ getLedgerRange(RPC::Context& context, std::optional const& ledg else { std::shared_ptr ledgerView; - auto const status = getLedger(ledgerView, ls, context); + auto status = getLedger(ledgerView, ls, context); if (!ledgerView) { return status; @@ -211,12 +211,7 @@ doAccountTxHelp(RPC::Context& context, AccountTxArgs const& args) result.marker = args.marker; RelationalDatabase::AccountTxPageOptions options = { - args.account, - result.ledgerRange.min, - result.ledgerRange.max, - result.marker, - args.limit, - isUnlimited(context.role)}; + args.account, result.ledgerRange, result.marker, args.limit, isUnlimited(context.role)}; auto& db = context.app.getRelationalDatabase(); diff --git a/src/xrpld/rpc/handlers/CanDelete.cpp b/src/xrpld/rpc/handlers/CanDelete.cpp index 91466c2583..052ebdf745 100644 --- a/src/xrpld/rpc/handlers/CanDelete.cpp +++ b/src/xrpld/rpc/handlers/CanDelete.cpp @@ -49,7 +49,7 @@ doCanDelete(RPC::JsonContext& context) else if (canDeleteStr == "now") { canDeleteSeq = context.app.getSHAMapStore().getLastRotated(); - if (!canDeleteSeq) + if (canDeleteSeq == 0u) return RPC::make_error(rpcNOT_READY); } else if (uint256 lh; lh.parseHex(canDeleteStr)) 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/DepositAuthorized.cpp b/src/xrpld/rpc/handlers/DepositAuthorized.cpp index 7ab7e30c8a..fb1c0db884 100644 --- a/src/xrpld/rpc/handlers/DepositAuthorized.cpp +++ b/src/xrpld/rpc/handlers/DepositAuthorized.cpp @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include #include #include @@ -35,7 +35,7 @@ doDepositAuthorized(RPC::JsonContext& context) auto srcID = parseBase58(params[jss::source_account].asString()); if (!srcID) return rpcError(rpcACT_MALFORMED); - auto const srcAcct{std::move(srcID.value())}; + auto const srcAcct{srcID.value()}; // Validate destination_account. if (!params.isMember(jss::destination_account)) @@ -49,7 +49,7 @@ doDepositAuthorized(RPC::JsonContext& context) auto dstID = parseBase58(params[jss::destination_account].asString()); if (!dstID) return rpcError(rpcACT_MALFORMED); - auto const dstAcct{std::move(dstID.value())}; + auto const dstAcct{dstID.value()}; // Validate ledger. std::shared_ptr ledger; @@ -73,7 +73,7 @@ doDepositAuthorized(RPC::JsonContext& context) return result; } - bool const reqAuth = (sleDest->getFlags() & lsfDepositAuth) && (srcAcct != dstAcct); + bool const reqAuth = ((sleDest->getFlags() & lsfDepositAuth) != 0u) && (srcAcct != dstAcct); bool const credentialsPresent = params.isMember(jss::credentials); std::set> sorted; @@ -122,7 +122,7 @@ doDepositAuthorized(RPC::JsonContext& context) return result; } - if (!(sleCred->getFlags() & lsfAccepted)) + if ((sleCred->getFlags() & lsfAccepted) == 0u) { RPC::inject_error(rpcBAD_CREDENTIALS, "credentials aren't accepted", result); return result; 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 60e031c812..8d03a3961d 100644 --- a/src/xrpld/rpc/handlers/GatewayBalances.cpp +++ b/src/xrpld/rpc/handlers/GatewayBalances.cpp @@ -1,9 +1,10 @@ #include -#include #include #include +#include #include +#include #include #include #include @@ -54,7 +55,7 @@ doGatewayBalances(RPC::JsonContext& context) auto id = parseBase58(strIdent); if (!id) return rpcError(rpcACT_MALFORMED); - auto const accountID{std::move(id.value())}; + auto const accountID{id.value()}; context.loadType = Resource::feeHeavyBurdenRPC; result[jss::account] = toBase58(accountID); @@ -75,7 +76,7 @@ doGatewayBalances(RPC::JsonContext& context) { if (auto id = parseBase58(j.asString()); id) { - hotWallets.insert(std::move(id.value())); + hotWallets.insert(id.value()); return true; } } diff --git a/src/xrpld/rpc/handlers/GetAggregatePrice.cpp b/src/xrpld/rpc/handlers/GetAggregatePrice.cpp index 4fc8e360fc..4979c21f42 100644 --- a/src/xrpld/rpc/handlers/GetAggregatePrice.cpp +++ b/src/xrpld/rpc/handlers/GetAggregatePrice.cpp @@ -56,7 +56,7 @@ iteratePriceData( if (prevChain == chain) return; - if (!oracle || f(*oracle) || isNew) + if ((oracle == nullptr) || f(*oracle) || isNew) return; if (++history > maxHistory) @@ -218,6 +218,12 @@ doGetAggregatePrice(RPC::JsonContext& context) return result; } + // Get the ledger + std::shared_ptr ledger; + result = RPC::lookupLedger(ledger, context); + if (!ledger) + return result; // LCOV_EXCL_LINE + // Collect the dataset into bimap keyed by lastUpdateTime and // STAmount (Number is int64 and price is uint64) Prices prices; @@ -238,11 +244,6 @@ doGetAggregatePrice(RPC::JsonContext& context) return result; } - std::shared_ptr ledger; - result = RPC::lookupLedger(ledger, context); - if (!ledger) - return result; // LCOV_EXCL_LINE - auto const sle = ledger->read(keylet::oracle(*account, *documentID)); iteratePriceData(context, sle, [&](STObject const& node) { auto const& series = node.getFieldArray(sfPriceDataSeries); @@ -284,8 +285,8 @@ doGetAggregatePrice(RPC::JsonContext& context) if (auto const threshold = std::get(timeThreshold)) { // threshold defines an acceptable range {max,min} of lastUpdateTime as - // {latestTime, latestTime - threshold}, the prices with lastUpdateTime - // greater than (latestTime - threshold) are erased. + // {latestTime, latestTime - threshold}. Prices with lastUpdateTime + // less than (latestTime - threshold) are erased (outdated prices). auto const oldestTime = prices.left.rbegin()->first; auto const upperBound = latestTime > threshold ? (latestTime - threshold) : oldestTime; if (upperBound > oldestTime) 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/LedgerEntry.cpp b/src/xrpld/rpc/handlers/LedgerEntry.cpp index 8e3b7f214d..c7a47a0517 100644 --- a/src/xrpld/rpc/handlers/LedgerEntry.cpp +++ b/src/xrpld/rpc/handlers/LedgerEntry.cpp @@ -7,8 +7,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -328,7 +328,7 @@ parseDepositPreauth( "malformedAuthorizedCredentials", jss::authorized_credentials, "array"); } - return keylet::depositPreauth(*owner, std::move(sorted)).key; + return keylet::depositPreauth(*owner, sorted).key; } static Expected diff --git a/src/xrpld/rpc/handlers/LedgerEntryHelpers.h b/src/xrpld/rpc/handlers/LedgerEntryHelpers.h index 683e6ebb5a..9182c9cfd7 100644 --- a/src/xrpld/rpc/handlers/LedgerEntryHelpers.h +++ b/src/xrpld/rpc/handlers/LedgerEntryHelpers.h @@ -20,10 +20,9 @@ Unexpected missingFieldError(Json::StaticString const field, std::optional err = std::nullopt) { Json::Value json = Json::objectValue; - auto error = RPC::missing_field_message(std::string(field.c_str())); json[jss::error] = err.value_or("malformedRequest"); json[jss::error_code] = rpcINVALID_PARAMS; - json[jss::error_message] = std::move(error); + json[jss::error_message] = RPC::missing_field_message(std::string(field.c_str())); return Unexpected(json); } @@ -31,10 +30,9 @@ Unexpected invalidFieldError(std::string const& err, Json::StaticString const field, std::string const& type) { Json::Value json = Json::objectValue; - auto error = RPC::expected_field_message(field, type); json[jss::error] = err; json[jss::error_code] = rpcINVALID_PARAMS; - json[jss::error_message] = std::move(error); + json[jss::error_message] = RPC::expected_field_message(field, type); return Unexpected(json); } @@ -118,7 +116,7 @@ parseHexBlob(Json::Value const& param, std::size_t maxLength) if (!param.isString()) return std::nullopt; - auto const blob = strUnHex(param.asString()); + auto blob = strUnHex(param.asString()); if (!blob || blob->empty() || blob->size() > maxLength) return std::nullopt; diff --git a/src/xrpld/rpc/handlers/LedgerHandler.cpp b/src/xrpld/rpc/handlers/LedgerHandler.cpp index 43c9780bb0..cd70cb064a 100644 --- a/src/xrpld/rpc/handlers/LedgerHandler.cpp +++ b/src/xrpld/rpc/handlers/LedgerHandler.cpp @@ -103,7 +103,7 @@ LedgerHandler::writeResult(Json::Value& value) "and update your request. Field `type` is deprecated."; } - if (warnings.size()) + if (warnings.size() != 0u) value[jss::warnings] = std::move(warnings); } 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/NFTOffers.cpp b/src/xrpld/rpc/handlers/NFTOffers.cpp index 3af7c28f9e..5fe2e3bede 100644 --- a/src/xrpld/rpc/handlers/NFTOffers.cpp +++ b/src/xrpld/rpc/handlers/NFTOffers.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/src/xrpld/rpc/handlers/NoRippleCheck.cpp b/src/xrpld/rpc/handlers/NoRippleCheck.cpp index f21a67a31d..c3e36280a6 100644 --- a/src/xrpld/rpc/handlers/NoRippleCheck.cpp +++ b/src/xrpld/rpc/handlers/NoRippleCheck.cpp @@ -1,11 +1,12 @@ #include -#include #include #include #include +#include #include #include +#include #include #include #include @@ -97,7 +98,7 @@ doNoRippleCheck(RPC::JsonContext& context) RPC::inject_error(rpcACT_MALFORMED, result); return result; } - auto const accountID{std::move(id.value())}; + auto const accountID{id.value()}; auto const sle = ledger->read(keylet::account(accountID)); if (!sle) return rpcError(rpcACT_NOT_FOUND); @@ -106,16 +107,16 @@ doNoRippleCheck(RPC::JsonContext& context) Json::Value& problems = (result["problems"] = Json::arrayValue); - bool bDefaultRipple = sle->getFieldU32(sfFlags) & lsfDefaultRipple; + bool bDefaultRipple = (sle->getFieldU32(sfFlags) & lsfDefaultRipple) != 0u; - if (bDefaultRipple & !roleGateway) + if ((static_cast(bDefaultRipple) & static_cast(!roleGateway)) != 0) { problems.append( "You appear to have set your default ripple flag even though you " "are not a gateway. This is not recommended unless you are " "experimenting"); } - else if (roleGateway & !bDefaultRipple) + else if ((static_cast(roleGateway) & static_cast(!bDefaultRipple)) != 0) { problems.append("You should immediately set your default ripple flag"); if (transactions) 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/ServerDefinitions.cpp b/src/xrpld/rpc/handlers/ServerDefinitions.cpp index 24abd69a02..2f11e18efb 100644 --- a/src/xrpld/rpc/handlers/ServerDefinitions.cpp +++ b/src/xrpld/rpc/handlers/ServerDefinitions.cpp @@ -24,7 +24,7 @@ namespace detail { class ServerDefinitions { private: - std::string + static std::string // translate e.g. STI_LEDGERENTRY to LedgerEntry translate(std::string const& inp); @@ -93,7 +93,7 @@ ServerDefinitions::translate(std::string const& inp) // convert snake_case to CamelCase for (;;) { - pos = inpToProcess.find("_"); + pos = inpToProcess.find('_'); if (pos == std::string::npos) pos = inpToProcess.size(); std::string token = inpToProcess.substr(0, pos); 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/Tx.cpp b/src/xrpld/rpc/handlers/Tx.cpp index 482b7e3bf1..211372db45 100644 --- a/src/xrpld/rpc/handlers/Tx.cpp +++ b/src/xrpld/rpc/handlers/Tx.cpp @@ -42,7 +42,7 @@ struct TxResult std::optional ctid; std::optional closeTime; std::optional ledgerHash; - TxSearched searchedAll = TxSearched::unknown; + TxSearched searchedAll = TxSearched::Unknown; }; struct TxArgs @@ -77,7 +77,7 @@ doTxHelp(RPC::Context& context, TxArgs args) using TxPair = std::pair, std::shared_ptr>; - result.searchedAll = TxSearched::unknown; + result.searchedAll = TxSearched::Unknown; std::variant v; if (args.ctid) @@ -172,10 +172,10 @@ populateJsonResponse( // handle errors if (error.toErrorCode() != rpcSUCCESS) { - if (error.toErrorCode() == rpcTXN_NOT_FOUND && result.searchedAll != TxSearched::unknown) + if (error.toErrorCode() == rpcTXN_NOT_FOUND && result.searchedAll != TxSearched::Unknown) { response = Json::Value(Json::objectValue); - response[jss::searched_all] = (result.searchedAll == TxSearched::all); + response[jss::searched_all] = (result.searchedAll == TxSearched::All); error.inject(response); } else 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))