From c258d76c807ede5b0c3d132c598ac598dc81d7e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 3 Oct 2024 18:27:16 +0200 Subject: [PATCH 01/47] Update checkout action --- .github/actions/restore-git-mtimes/action.yml | 2 +- .github/workflows/analyzers.yml | 6 +++--- .github/workflows/build_deploy.yml | 10 +++++----- .github/workflows/changelog.yml | 2 +- .github/workflows/code_sanitizers.yml | 4 ++-- .github/workflows/coverage.yml | 2 +- .github/workflows/develop_branch_dockers_deploy.yml | 2 +- .github/workflows/flamegraphs.yml | 2 +- .github/workflows/prepare_release.yml | 2 +- .github/workflows/unit_tests.yml | 6 +++--- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/actions/restore-git-mtimes/action.yml b/.github/actions/restore-git-mtimes/action.yml index 714c720215..e16c8aa56a 100644 --- a/.github/actions/restore-git-mtimes/action.yml +++ b/.github/actions/restore-git-mtimes/action.yml @@ -3,7 +3,7 @@ description: "Restore file modification timestamps from git commit timestamps" runs: using: "composite" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: repository: "MestreLion/git-tools" ref: a42a069bc755f0fa81316965335cb33dbf22a968 # pin latest commit diff --git a/.github/workflows/analyzers.yml b/.github/workflows/analyzers.yml index 52d9bb3829..c258f12986 100644 --- a/.github/workflows/analyzers.yml +++ b/.github/workflows/analyzers.yml @@ -8,7 +8,7 @@ jobs: if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository steps: - name: Checkout - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3.1.0 + uses: actions/checkout@v4 - name: Installing clang-format env: @@ -28,7 +28,7 @@ jobs: if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository steps: - name: Checkout - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3.1.0 + uses: actions/checkout@v4 - name: Setup Python uses: actions/setup-python@13ae5bb136fac2878aff31522b9efb785519f984 #v4.3.0 @@ -50,6 +50,6 @@ jobs: runs-on: ubuntu-20.04 if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3.1.0 + - uses: actions/checkout@v4 - name: Run code-inspector run: ci/code-inspector-check.sh diff --git a/.github/workflows/build_deploy.yml b/.github/workflows/build_deploy.yml index 2670a6fd9a..f233ed83b2 100644 --- a/.github/workflows/build_deploy.yml +++ b/.github/workflows/build_deploy.yml @@ -19,7 +19,7 @@ jobs: ci_tag: ${{ steps.set_vars.outputs.ci_tag }} tag_created: ${{ steps.set_vars.outputs.tag_created }} steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3.1.0 + - uses: actions/checkout@v4 - name: Set the tag and version id: tag_set run: | @@ -44,7 +44,7 @@ jobs: network: ["TEST", "BETA", "LIVE"] steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3.1.0 + - uses: actions/checkout@v4 with: submodules: "recursive" ref: ${{ needs.prepare_build.outputs.ci_tag }} @@ -77,7 +77,7 @@ jobs: matrix: network: ["TEST", "BETA", "LIVE"] steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3.1.0 + - uses: actions/checkout@v4 with: submodules: "recursive" ref: ${{ needs.prepare_build.outputs.ci_tag }} @@ -117,7 +117,7 @@ jobs: DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} IS_RELEASE_BUILD: ${{ github.event.inputs.is_release_build || 'false' }} steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3.1.0 + - uses: actions/checkout@v4 with: submodules: "recursive" ref: ${{ needs.prepare_build.outputs.ci_tag }} @@ -150,7 +150,7 @@ jobs: matrix: network: ["TEST", "BETA", "LIVE"] steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3.1.0 + - uses: actions/checkout@v4 with: submodules: "recursive" ref: ${{ needs.prepare_build.outputs.ci_tag }} diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index ac236ddbea..91a2da739b 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -37,7 +37,7 @@ jobs: echo "REPO_TO_RUN=${{ github.event.inputs.repo }}" >> $GITHUB_ENV echo "MODE=${{ github.event.inputs.mode }}" >> $GITHUB_ENV - name: Checks out the required workflow files (workflow repo) - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3.1.0 + uses: actions/checkout@v4 with: ref: ${{ github.ref }} repository: ${{ github.repository }} diff --git a/.github/workflows/code_sanitizers.yml b/.github/workflows/code_sanitizers.yml index 4c8d632f76..1a6ae97b7f 100644 --- a/.github/workflows/code_sanitizers.yml +++ b/.github/workflows/code_sanitizers.yml @@ -35,7 +35,7 @@ jobs: if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: "recursive" @@ -91,7 +91,7 @@ jobs: if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: "recursive" diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 1079804f04..cbdeffeeff 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -24,7 +24,7 @@ jobs: continue-on-error: true timeout-minutes: 60 steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3.1.0 + - uses: actions/checkout@v4 with: submodules: "recursive" - name: Fetch Deps diff --git a/.github/workflows/develop_branch_dockers_deploy.yml b/.github/workflows/develop_branch_dockers_deploy.yml index f69ee795be..18ce83de7a 100644 --- a/.github/workflows/develop_branch_dockers_deploy.yml +++ b/.github/workflows/develop_branch_dockers_deploy.yml @@ -9,7 +9,7 @@ jobs: linux_job: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 #v3.1.0 + - uses: actions/checkout@v4 with: submodules: "recursive" - name: Fetch Deps diff --git a/.github/workflows/flamegraphs.yml b/.github/workflows/flamegraphs.yml index 877b081214..a0166fb857 100644 --- a/.github/workflows/flamegraphs.yml +++ b/.github/workflows/flamegraphs.yml @@ -22,7 +22,7 @@ jobs: if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: "recursive" diff --git a/.github/workflows/prepare_release.yml b/.github/workflows/prepare_release.yml index d705041980..6b0903c6de 100644 --- a/.github/workflows/prepare_release.yml +++ b/.github/workflows/prepare_release.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Checkout repository - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v4 with: ref: ${{ github.ref }} fetch-depth: 0 diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 5fafc9b93c..7e42a115b4 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -20,7 +20,7 @@ jobs: if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: "recursive" @@ -66,7 +66,7 @@ jobs: if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: "recursive" @@ -115,7 +115,7 @@ jobs: if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: submodules: "recursive" From a65ce7a28c741be61efac0a1082f04e0c8311da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 3 Oct 2024 18:28:30 +0200 Subject: [PATCH 02/47] Formula qt5 was renamed to qt@5 --- ci/prepare/macos/prepare.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/prepare/macos/prepare.sh b/ci/prepare/macos/prepare.sh index b66fedaac7..da5ad9cb58 100755 --- a/ci/prepare/macos/prepare.sh +++ b/ci/prepare/macos/prepare.sh @@ -1,7 +1,7 @@ #!/bin/bash set -euox pipefail -#Homebrew randomly fails to update. Retry 5 times with 15s interval +# Homebrew randomly fails to update. Retry 5 times with 15s interval for i in {1..5}; do brew update && break || { echo "Update failed, retrying..."; sleep 15; }; done brew install coreutils @@ -10,4 +10,4 @@ brew install qt@5 brew link qt@5 # Workaround: https://github.com/Homebrew/homebrew-core/issues/8392 -echo "$(brew --prefix qt5)/bin" >> $GITHUB_PATH \ No newline at end of file +echo "$(brew --prefix qt@5)/bin" >> $GITHUB_PATH \ No newline at end of file From 0a1003cda49a13e19f17e0e81dd40292052a47ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 3 Oct 2024 18:34:11 +0200 Subject: [PATCH 03/47] Fix 'as' and 'FROM' keywords' casing do not match --- docker/node/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/node/Dockerfile b/docker/node/Dockerfile index 8f11e14489..5cee44c922 100644 --- a/docker/node/Dockerfile +++ b/docker/node/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:22.04 as builder +FROM ubuntu:22.04 AS builder ARG COMPILER=gcc ARG NANO_NETWORK=live @@ -10,7 +10,7 @@ RUN /tmp/prepare/prepare.sh COPY ./ /tmp/src WORKDIR /tmp/src -#Define ARGs for ci/build-node.sh +# Define ARGs for ci/build-node.sh ARG BUILD_TYPE=RelWithDebInfo ARG NANO_TEST=OFF ARG NANO_TRACING=OFF From eb23460aafe8cf298502bd3170d04457104db5d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 3 Oct 2024 18:32:26 +0200 Subject: [PATCH 04/47] Friendly job names in build & deploy workflow --- .github/workflows/build_deploy.yml | 42 +++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build_deploy.yml b/.github/workflows/build_deploy.yml index f233ed83b2..24da36bc1e 100644 --- a/.github/workflows/build_deploy.yml +++ b/.github/workflows/build_deploy.yml @@ -1,7 +1,7 @@ name: Build & Deploy on: schedule: - - cron: "0 0 * * 3,6" + - cron: "0 0 * * 3,6" # Every Wednesday and Saturday at 00:00 workflow_dispatch: inputs: is_release_build: @@ -14,12 +14,15 @@ env: jobs: prepare_build: + name: Prepare Build runs-on: ubuntu-22.04 outputs: ci_tag: ${{ steps.set_vars.outputs.ci_tag }} tag_created: ${{ steps.set_vars.outputs.tag_created }} steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 + - name: Set the tag and version id: tag_set run: | @@ -27,14 +30,15 @@ jobs: env: GITHUB_ACTOR: ${{ github.actor }} IS_RELEASE_BUILD: ${{ github.event.inputs.is_release_build || 'false' }} + - name: Set output id: set_vars run: | echo "ci_tag=$CI_TAG" >> $GITHUB_OUTPUT echo "tag_created=$TAG_CREATED" >> $GITHUB_OUTPUT - osx_job: + name: macOS [${{ matrix.network }}] needs: prepare_build if: ${{ needs.prepare_build.outputs.tag_created == 'true' }} runs-on: macOS-14 @@ -43,19 +47,22 @@ jobs: matrix: network: ["TEST", "BETA", "LIVE"] steps: - - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 with: submodules: "recursive" ref: ${{ needs.prepare_build.outputs.ci_tag }} repository: ${{ github.repository }} + - name: Prepare run: ci/prepare/macos/prepare.sh + - name: Build Artifact run: ci/build-deploy.sh "/tmp/qt/lib/cmake/Qt5"; env: NETWORK: ${{ matrix.network }} CI_TAG: ${{ needs.prepare_build.outputs.ci_tag }} + - name: Deploy Artifact run: ci/actions/deploy.sh env: @@ -66,9 +73,9 @@ jobs: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_DEFAULT_REGION: us-east-2 - linux_job: + name: Linux [${{ matrix.network }}] needs: prepare_build if: ${{ needs.prepare_build.outputs.tag_created == 'true' }} runs-on: ubuntu-22.04 @@ -77,13 +84,16 @@ jobs: matrix: network: ["TEST", "BETA", "LIVE"] steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 with: submodules: "recursive" ref: ${{ needs.prepare_build.outputs.ci_tag }} repository: ${{ github.repository }} + - name: Prepare run: sudo -E ci/prepare/linux/prepare.sh + - name: Build Artifact run: ci/build-deploy.sh "/usr/lib/x86_64-linux-gnu/cmake/Qt5" env: @@ -101,8 +111,8 @@ jobs: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_DEFAULT_REGION: us-east-2 - linux_docker_job: + name: Docker [${{ matrix.network }}] needs: prepare_build if: ${{ needs.prepare_build.outputs.tag_created == 'true' }} runs-on: ubuntu-22.04 @@ -117,21 +127,25 @@ jobs: DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} IS_RELEASE_BUILD: ${{ github.event.inputs.is_release_build || 'false' }} steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 with: submodules: "recursive" ref: ${{ needs.prepare_build.outputs.ci_tag }} repository: ${{ github.repository }} + - name: Build Docker run: ci/actions/linux/docker-build.sh env: NETWORK: ${{ matrix.network }} - - name: Deploy Docker Hub + + - name: Deploy Docker (Docker Hub) if: env.DOCKER_PASSWORD != '' run: ci/actions/linux/docker-deploy.sh env: NETWORK: ${{ matrix.network }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + - name: Deploy Docker (ghcr.io) run: ci/actions/linux/ghcr-deploy.sh env: @@ -140,8 +154,8 @@ jobs: DOCKER_USER: ${{ github.repository_owner }} DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} - windows_job: + name: Windows [${{ matrix.network }}] needs: prepare_build if: ${{ needs.prepare_build.outputs.tag_created == 'true' }} runs-on: windows-latest @@ -150,18 +164,22 @@ jobs: matrix: network: ["TEST", "BETA", "LIVE"] steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 with: submodules: "recursive" ref: ${{ needs.prepare_build.outputs.ci_tag }} repository: ${{ github.repository }} + - name: Prepare run: ci/prepare/windows/prepare.ps1 + - name: Build Artifact run: ci/actions/windows/build.ps1 env: CSC_LINK: ${{ secrets.CSC_LINK }} CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }} + - name: Deploy Artifact run: ci/actions/windows/deploy.ps1 env: From 7914c7c55de6930bc820b7e7b1baa61958fcc529 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Sat, 5 Oct 2024 22:05:17 +0200 Subject: [PATCH 05/47] Removed waiting on vote_generator_threshold --- nano/core_test/toml.cpp | 3 --- nano/node/nodeconfig.cpp | 7 ------- nano/node/nodeconfig.hpp | 1 - nano/node/vote_generator.cpp | 7 ++----- 4 files changed, 2 insertions(+), 16 deletions(-) diff --git a/nano/core_test/toml.cpp b/nano/core_test/toml.cpp index 617f655af0..45107a3706 100644 --- a/nano/core_test/toml.cpp +++ b/nano/core_test/toml.cpp @@ -191,7 +191,6 @@ TEST (toml, daemon_config_deserialize_defaults) ASSERT_EQ (conf.node.unchecked_cutoff_time, defaults.node.unchecked_cutoff_time); ASSERT_EQ (conf.node.use_memory_pools, defaults.node.use_memory_pools); ASSERT_EQ (conf.node.vote_generator_delay, defaults.node.vote_generator_delay); - ASSERT_EQ (conf.node.vote_generator_threshold, defaults.node.vote_generator_threshold); ASSERT_EQ (conf.node.vote_minimum, defaults.node.vote_minimum); ASSERT_EQ (conf.node.work_peers, defaults.node.work_peers); ASSERT_EQ (conf.node.work_threads, defaults.node.work_threads); @@ -456,7 +455,6 @@ TEST (toml, daemon_config_deserialize_no_defaults) unchecked_cutoff_time = 999 use_memory_pools = false vote_generator_delay = 999 - vote_generator_threshold = 9 vote_minimum = "999" work_peers = ["dev.org:999"] work_threads = 999 @@ -700,7 +698,6 @@ TEST (toml, daemon_config_deserialize_no_defaults) ASSERT_NE (conf.node.unchecked_cutoff_time, defaults.node.unchecked_cutoff_time); ASSERT_NE (conf.node.use_memory_pools, defaults.node.use_memory_pools); ASSERT_NE (conf.node.vote_generator_delay, defaults.node.vote_generator_delay); - ASSERT_NE (conf.node.vote_generator_threshold, defaults.node.vote_generator_threshold); ASSERT_NE (conf.node.vote_minimum, defaults.node.vote_minimum); ASSERT_NE (conf.node.work_peers, defaults.node.work_peers); ASSERT_NE (conf.node.work_threads, defaults.node.work_threads); diff --git a/nano/node/nodeconfig.cpp b/nano/node/nodeconfig.cpp index ee2d8b3c8d..5ceb3a6fa4 100644 --- a/nano/node/nodeconfig.cpp +++ b/nano/node/nodeconfig.cpp @@ -120,7 +120,6 @@ nano::error nano::node_config::serialize_toml (nano::tomlconfig & toml) const toml.put ("allow_local_peers", allow_local_peers, "Enable or disable local host peering.\ntype:bool"); toml.put ("vote_minimum", vote_minimum.to_string_dec (), "Local representatives do not vote if the delegated weight is under this threshold. Saves on system resources.\ntype:string,amount,raw"); toml.put ("vote_generator_delay", vote_generator_delay.count (), "Delay before votes are sent to allow for efficient bundling of hashes in votes.\ntype:milliseconds"); - toml.put ("vote_generator_threshold", vote_generator_threshold, "Number of bundled hashes required for an additional generator delay.\ntype:uint64,[1..11]"); toml.put ("unchecked_cutoff_time", unchecked_cutoff_time.count (), "Number of seconds before deleting an unchecked entry.\nWarning: lower values (e.g., 3600 seconds, or 1 hour) may result in unsuccessful bootstraps, especially a bootstrap from scratch.\ntype:seconds"); toml.put ("tcp_io_timeout", tcp_io_timeout.count (), "Timeout for TCP connect-, read- and write operations.\nWarning: a low value (e.g., below 5 seconds) may result in TCP connections failing.\ntype:seconds"); toml.put ("pow_sleep_interval", pow_sleep_interval.count (), "Time to sleep between batch work generation attempts. Reduces max CPU usage at the expense of a longer generation time.\ntype:nanoseconds"); @@ -484,8 +483,6 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml) toml.get ("vote_generator_delay", delay_l); vote_generator_delay = std::chrono::milliseconds (delay_l); - toml.get ("vote_generator_threshold", vote_generator_threshold); - auto block_processor_batch_max_time_l = block_processor_batch_max_time.count (); toml.get ("block_processor_batch_max_time", block_processor_batch_max_time_l); block_processor_batch_max_time = std::chrono::milliseconds (block_processor_batch_max_time_l); @@ -600,10 +597,6 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml) { toml.get_error ().set ("bandwidth_limit unbounded = 0, default = 10485760, max = 18446744073709551615"); } - if (vote_generator_threshold < 1 || vote_generator_threshold > 11) - { - toml.get_error ().set ("vote_generator_threshold must be a number between 1 and 11"); - } if (max_work_generate_multiplier < 1) { toml.get_error ().set ("max_work_generate_multiplier must be greater than or equal to 1"); diff --git a/nano/node/nodeconfig.hpp b/nano/node/nodeconfig.hpp index 2692030497..c25700d852 100644 --- a/nano/node/nodeconfig.hpp +++ b/nano/node/nodeconfig.hpp @@ -73,7 +73,6 @@ class node_config nano::amount vote_minimum{ nano::Knano_ratio }; // 1000 nano nano::amount rep_crawler_weight_minimum{ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" }; std::chrono::milliseconds vote_generator_delay{ std::chrono::milliseconds (100) }; - unsigned vote_generator_threshold{ 3 }; nano::amount online_weight_minimum{ 60000 * nano::Knano_ratio }; // 60 million nano /* * The minimum vote weight that a representative must have for its vote to be counted. diff --git a/nano/node/vote_generator.cpp b/nano/node/vote_generator.cpp index 00947ccec0..6f2e996a6e 100644 --- a/nano/node/vote_generator.cpp +++ b/nano/node/vote_generator.cpp @@ -293,7 +293,7 @@ void nano::vote_generator::run () { broadcast (lock); } - else if (!requests.empty ()) + if (!requests.empty ()) { auto request (requests.front ()); requests.pop_front (); @@ -302,10 +302,7 @@ void nano::vote_generator::run () else { condition.wait_for (lock, config.vote_generator_delay, [this] () { return this->candidates.size () >= nano::network::confirm_ack_hashes_max; }); - if (candidates.size () >= config.vote_generator_threshold && candidates.size () < nano::network::confirm_ack_hashes_max) - { - condition.wait_for (lock, config.vote_generator_delay, [this] () { return this->candidates.size () >= nano::network::confirm_ack_hashes_max; }); - } + if (!candidates.empty ()) { broadcast (lock); From d831937f12fd59f98cdab2401ec15237b19d6a92 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 16 Sep 2024 13:27:52 +0100 Subject: [PATCH 06/47] Extract function to create a random filename. --- nano/secure/utility.cpp | 8 ++++++-- nano/secure/utility.hpp | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/nano/secure/utility.cpp b/nano/secure/utility.cpp index ac974d9f56..a2dabd5e3b 100644 --- a/nano/secure/utility.cpp +++ b/nano/secure/utility.cpp @@ -47,7 +47,7 @@ std::filesystem::path nano::working_path (nano::networks network) return result; } -std::filesystem::path nano::unique_path (nano::networks network) +std::filesystem::path nano::random_filename () { std::random_device rd; std::mt19937 gen (rd ()); @@ -61,8 +61,12 @@ std::filesystem::path nano::unique_path (nano::networks network) { random_string += hex_chars[dis (gen)]; } + return std::filesystem::path{ random_string }; +} - auto result = working_path (network) / random_string; +std::filesystem::path nano::unique_path (nano::networks network) +{ + auto result = working_path (network) / random_filename (); std::filesystem::create_directories (result); diff --git a/nano/secure/utility.hpp b/nano/secure/utility.hpp index abb70df840..90953eea01 100644 --- a/nano/secure/utility.hpp +++ b/nano/secure/utility.hpp @@ -9,6 +9,8 @@ namespace nano std::filesystem::path app_path (); // OS-specific way of finding a path to a home directory. std::filesystem::path working_path (nano::networks network = nano::network_constants::active_network); +// Construct a random filename +std::filesystem::path random_filename (); // Get a unique path within the home directory, used for testing. // Any directories created at this location will be removed when a test finishes. std::filesystem::path unique_path (nano::networks network = nano::network_constants::active_network); From 057cacd6fd2166f12ac48bd290acadca7f7d0596 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 26 Sep 2024 12:29:38 +0100 Subject: [PATCH 07/47] Extracting block_w_sideband to its own file --- nano/store/CMakeLists.txt | 1 + nano/store/block.hpp | 7 +------ nano/store/block_w_sideband.hpp | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 nano/store/block_w_sideband.hpp diff --git a/nano/store/CMakeLists.txt b/nano/store/CMakeLists.txt index 68cde103a1..19ae4cf2ef 100644 --- a/nano/store/CMakeLists.txt +++ b/nano/store/CMakeLists.txt @@ -2,6 +2,7 @@ add_library( nano_store account.hpp block.hpp + block_w_sideband.hpp component.hpp confirmation_height.hpp db_val.hpp diff --git a/nano/store/block.hpp b/nano/store/block.hpp index 91b60babc2..17f92669d0 100644 --- a/nano/store/block.hpp +++ b/nano/store/block.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -15,12 +16,6 @@ class block_hash; } namespace nano::store { -class block_w_sideband -{ -public: - std::shared_ptr block; - nano::block_sideband sideband; -}; /** * Manages block storage and iteration */ diff --git a/nano/store/block_w_sideband.hpp b/nano/store/block_w_sideband.hpp new file mode 100644 index 0000000000..e83bd71d5c --- /dev/null +++ b/nano/store/block_w_sideband.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include + +#include + +namespace nano +{ +class block; +} +namespace nano::store +{ +class block_w_sideband +{ +public: + std::shared_ptr block; + nano::block_sideband sideband; +}; +} From b7b0395a03e1c1a8ff51b842e5ab9e975c0c569a Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Mon, 7 Oct 2024 22:13:54 +0200 Subject: [PATCH 08/47] Simplified vote_generator logic --- nano/node/vote_generator.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/nano/node/vote_generator.cpp b/nano/node/vote_generator.cpp index 6f2e996a6e..00dccfd570 100644 --- a/nano/node/vote_generator.cpp +++ b/nano/node/vote_generator.cpp @@ -289,25 +289,19 @@ void nano::vote_generator::run () nano::unique_lock lock{ mutex }; while (!stopped) { - if (candidates.size () >= nano::network::confirm_ack_hashes_max) + condition.wait_for (lock, config.vote_generator_delay, [this] () { return this->candidates.size () >= nano::network::confirm_ack_hashes_max || !requests.empty (); }); + + if (!candidates.empty ()) { broadcast (lock); } + if (!requests.empty ()) { auto request (requests.front ()); requests.pop_front (); reply (lock, std::move (request)); } - else - { - condition.wait_for (lock, config.vote_generator_delay, [this] () { return this->candidates.size () >= nano::network::confirm_ack_hashes_max; }); - - if (!candidates.empty ()) - { - broadcast (lock); - } - } } } From 75bee9463db9fc3782562f6f1e45310de0cca5cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 7 Oct 2024 22:18:11 +0200 Subject: [PATCH 09/47] Log test system exceptions (#4746) --- nano/test_common/system.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index c89eb88094..c0a9831cf0 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -351,7 +351,20 @@ std::error_code nano::test::system::poll_until_true (std::chrono::nanoseconds de deadline_set (deadline_a); while (!ec && !predicate_a ()) { - ec = poll (); + try + { + ec = poll (); + } + catch (std::exception const & ex) + { + std::cerr << "Error running IO: " << ex.what () << std::endl; + ec = nano::error_system::generic; + } + catch (...) + { + std::cerr << "Unknown error running IO" << std::endl; + ec = nano::error_system::generic; + } } return ec; } From d30dcea56b29301164f3a096007de2d1395c40ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 3 May 2024 11:44:28 +0200 Subject: [PATCH 10/47] Dead code `tcp_channels::modify` --- nano/core_test/peer_container.cpp | 8 ++------ nano/node/transport/tcp_channels.cpp | 12 ------------ nano/node/transport/tcp_channels.hpp | 1 - 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/nano/core_test/peer_container.cpp b/nano/core_test/peer_container.cpp index 5418ba98c8..44f7993b7a 100644 --- a/nano/core_test/peer_container.cpp +++ b/nano/core_test/peer_container.cpp @@ -79,16 +79,12 @@ TEST (peer_container, tcp_channel_cleanup_works) ASSERT_NE (nullptr, channel1); // set the last packet sent for channel1 only to guarantee it contains a value. // it won't be necessarily the same use by the cleanup cutoff time - node1.network.tcp_channels.modify (channel1, [&now] (auto channel) { - channel->set_last_packet_sent (now - std::chrono::seconds (5)); - }); + channel1->set_last_packet_sent (now - std::chrono::seconds (5)); auto channel2 = nano::test::establish_tcp (system, node1, outer_node2->network.endpoint ()); ASSERT_NE (nullptr, channel2); // set the last packet sent for channel2 only to guarantee it contains a value. // it won't be necessarily the same use by the cleanup cutoff time - node1.network.tcp_channels.modify (channel2, [&now] (auto channel) { - channel->set_last_packet_sent (now + std::chrono::seconds (1)); - }); + channel2->set_last_packet_sent (now + std::chrono::seconds (1)); ASSERT_EQ (2, node1.network.size ()); ASSERT_EQ (2, node1.network.tcp_channels.size ()); diff --git a/nano/node/transport/tcp_channels.cpp b/nano/node/transport/tcp_channels.cpp index 7a41280563..2d1f147f03 100644 --- a/nano/node/transport/tcp_channels.cpp +++ b/nano/node/transport/tcp_channels.cpp @@ -417,18 +417,6 @@ void nano::transport::tcp_channels::list (std::deque const & channel_a, std::function const &)> modify_callback_a) -{ - nano::lock_guard lock{ mutex }; - auto existing (channels.get ().find (channel_a->get_tcp_endpoint ())); - if (existing != channels.get ().end ()) - { - channels.get ().modify (existing, [modify_callback = std::move (modify_callback_a)] (channel_entry & wrapper_a) { - modify_callback (wrapper_a.channel); - }); - } -} - void nano::transport::tcp_channels::start_tcp (nano::endpoint const & endpoint) { node.tcp_listener.connect (endpoint.address (), endpoint.port ()); diff --git a/nano/node/transport/tcp_channels.hpp b/nano/node/transport/tcp_channels.hpp index 7afd89fc79..0e18d75e82 100644 --- a/nano/node/transport/tcp_channels.hpp +++ b/nano/node/transport/tcp_channels.hpp @@ -50,7 +50,6 @@ class tcp_channels final bool track_reachout (nano::endpoint const &); void purge (std::chrono::steady_clock::time_point cutoff_deadline); void list (std::deque> &, uint8_t = 0, bool = true); - void modify (std::shared_ptr const &, std::function const &)>); void keepalive (); std::optional sample_keepalive (); From 28bc44d95019b7efc9c812cb20b4b269ad47f53d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 3 May 2024 11:41:29 +0200 Subject: [PATCH 11/47] Cleanup channel endpoints --- nano/core_test/network.cpp | 5 ++--- nano/core_test/node.cpp | 8 ++++---- nano/core_test/request_aggregator.cpp | 2 +- nano/core_test/telemetry.cpp | 18 +++++++++--------- nano/core_test/websocket.cpp | 2 +- nano/node/bootstrap/bootstrap_connections.cpp | 4 ++-- nano/node/bootstrap/bootstrap_legacy.cpp | 2 +- nano/node/json_handler.cpp | 2 +- nano/node/message_processor.cpp | 2 +- nano/node/network.cpp | 4 ++-- nano/node/repcrawler.cpp | 2 +- nano/node/telemetry.cpp | 2 +- nano/node/transport/channel.cpp | 17 ++++++++--------- nano/node/transport/channel.hpp | 6 +++--- nano/node/transport/fake.hpp | 7 +------ nano/node/transport/inproc.hpp | 7 +------ nano/node/transport/tcp_channel.cpp | 6 +++--- nano/node/transport/tcp_channel.hpp | 11 +++-------- nano/node/transport/tcp_channels.cpp | 4 ++-- nano/node/transport/tcp_channels.hpp | 2 +- nano/node/websocket.cpp | 2 +- nano/qt/qt.cpp | 2 +- nano/rpc_test/rpc.cpp | 2 +- nano/slow_test/node.cpp | 8 ++++---- 24 files changed, 55 insertions(+), 72 deletions(-) diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index eb4713f946..9254e8cd10 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -1024,14 +1024,13 @@ TEST (network, loopback_channel) auto & node2 = *system.nodes[1]; nano::transport::inproc::channel channel1 (node1, node1); ASSERT_EQ (channel1.get_type (), nano::transport::transport_type::loopback); - ASSERT_EQ (channel1.get_endpoint (), node1.network.endpoint ()); - ASSERT_EQ (channel1.get_tcp_endpoint (), nano::transport::map_endpoint_to_tcp (node1.network.endpoint ())); + ASSERT_EQ (channel1.get_remote_endpoint (), node1.network.endpoint ()); ASSERT_EQ (channel1.get_network_version (), node1.network_params.network.protocol_version); ASSERT_EQ (channel1.get_node_id (), node1.node_id.pub); ASSERT_EQ (channel1.get_node_id_optional ().value_or (0), node1.node_id.pub); nano::transport::inproc::channel channel2 (node2, node2); ++node1.network.port; - ASSERT_NE (channel1.get_endpoint (), node1.network.endpoint ()); + ASSERT_NE (channel1.get_remote_endpoint (), node1.network.endpoint ()); } // Ensure the network filters messages with the incorrect magic number diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 54d1ef29f6..c7654c895e 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -2704,7 +2704,7 @@ TEST (node, peer_history_restart) ASSERT_TIMELY (10s, !node2->network.empty ()); // Confirm that the peers match with the endpoints we are expecting auto list (node2->network.list (2)); - ASSERT_EQ (node1->network.endpoint (), list[0]->get_endpoint ()); + ASSERT_EQ (node1->network.endpoint (), list[0]->get_remote_endpoint ()); ASSERT_EQ (1, node2->network.size ()); system.stop_node (*node2); } @@ -2727,7 +2727,7 @@ TEST (node, peer_history_restart) ASSERT_TIMELY (10s, !node3->network.empty ()); // Confirm that the peers match with the endpoints we are expecting auto list (node3->network.list (2)); - ASSERT_EQ (node1->network.endpoint (), list[0]->get_endpoint ()); + ASSERT_EQ (node1->network.endpoint (), list[0]->get_remote_endpoint ()); ASSERT_EQ (1, node3->network.size ()); system.stop_node (*node3); } @@ -2789,11 +2789,11 @@ TEST (node, bidirectional_tcp) ASSERT_EQ (1, node2->network.size ()); auto list1 (node1->network.list (1)); ASSERT_EQ (nano::transport::transport_type::tcp, list1[0]->get_type ()); - ASSERT_NE (node2->network.endpoint (), list1[0]->get_endpoint ()); // Ephemeral port + ASSERT_NE (node2->network.endpoint (), list1[0]->get_remote_endpoint ()); // Ephemeral port ASSERT_EQ (node2->node_id.pub, list1[0]->get_node_id ()); auto list2 (node2->network.list (1)); ASSERT_EQ (nano::transport::transport_type::tcp, list2[0]->get_type ()); - ASSERT_EQ (node1->network.endpoint (), list2[0]->get_endpoint ()); + ASSERT_EQ (node1->network.endpoint (), list2[0]->get_remote_endpoint ()); ASSERT_EQ (node1->node_id.pub, list2[0]->get_node_id ()); // Test block propagation from node 1 nano::keypair key; diff --git a/nano/core_test/request_aggregator.cpp b/nano/core_test/request_aggregator.cpp index b0da7dd3b6..2f85074e40 100644 --- a/nano/core_test/request_aggregator.cpp +++ b/nano/core_test/request_aggregator.cpp @@ -230,7 +230,7 @@ TEST (request_aggregator, two_endpoints) auto dummy_channel1 = std::make_shared (node1, node1); auto dummy_channel2 = std::make_shared (node2, node2); - ASSERT_NE (nano::transport::map_endpoint_to_v6 (dummy_channel1->get_endpoint ()), nano::transport::map_endpoint_to_v6 (dummy_channel2->get_endpoint ())); + ASSERT_NE (nano::transport::map_endpoint_to_v6 (dummy_channel1->get_remote_endpoint ()), nano::transport::map_endpoint_to_v6 (dummy_channel2->get_remote_endpoint ())); std::vector> request{ { send1->hash (), send1->root () } }; diff --git a/nano/core_test/telemetry.cpp b/nano/core_test/telemetry.cpp index 4ebe65c5c9..d5b898b5b9 100644 --- a/nano/core_test/telemetry.cpp +++ b/nano/core_test/telemetry.cpp @@ -68,18 +68,18 @@ TEST (telemetry, basic) ASSERT_NE (nullptr, channel); std::optional telemetry_data; - ASSERT_TIMELY (5s, telemetry_data = node_client->telemetry.get_telemetry (channel->get_endpoint ())); + ASSERT_TIMELY (5s, telemetry_data = node_client->telemetry.get_telemetry (channel->get_remote_endpoint ())); ASSERT_EQ (node_server->get_node_id (), telemetry_data->node_id); // Check the metrics are correct ASSERT_TRUE (nano::test::compare_telemetry (*telemetry_data, *node_server)); // Call again straight away - auto telemetry_data_2 = node_client->telemetry.get_telemetry (channel->get_endpoint ()); + auto telemetry_data_2 = node_client->telemetry.get_telemetry (channel->get_remote_endpoint ()); ASSERT_TRUE (telemetry_data_2); // Call again straight away - auto telemetry_data_3 = node_client->telemetry.get_telemetry (channel->get_endpoint ()); + auto telemetry_data_3 = node_client->telemetry.get_telemetry (channel->get_remote_endpoint ()); ASSERT_TRUE (telemetry_data_3); // we expect at least one consecutive repeat of telemetry @@ -89,7 +89,7 @@ TEST (telemetry, basic) WAIT (3s); std::optional telemetry_data_4; - ASSERT_TIMELY (5s, telemetry_data_4 = node_client->telemetry.get_telemetry (channel->get_endpoint ())); + ASSERT_TIMELY (5s, telemetry_data_4 = node_client->telemetry.get_telemetry (channel->get_remote_endpoint ())); ASSERT_NE (*telemetry_data, *telemetry_data_4); } @@ -120,13 +120,13 @@ TEST (telemetry, disconnected) ASSERT_NE (nullptr, channel); // Ensure telemetry is available before disconnecting - ASSERT_TIMELY (5s, node_client->telemetry.get_telemetry (channel->get_endpoint ())); + ASSERT_TIMELY (5s, node_client->telemetry.get_telemetry (channel->get_remote_endpoint ())); system.stop_node (*node_server); ASSERT_TRUE (channel); // Ensure telemetry from disconnected peer is removed - ASSERT_TIMELY (5s, !node_client->telemetry.get_telemetry (channel->get_endpoint ())); + ASSERT_TIMELY (5s, !node_client->telemetry.get_telemetry (channel->get_remote_endpoint ())); } TEST (telemetry, dos_tcp) @@ -185,14 +185,14 @@ TEST (telemetry, disable_metrics) node_client->telemetry.trigger (); - ASSERT_NEVER (1s, node_client->telemetry.get_telemetry (channel->get_endpoint ())); + ASSERT_NEVER (1s, node_client->telemetry.get_telemetry (channel->get_remote_endpoint ())); // It should still be able to receive metrics though auto channel1 = node_server->network.find_node_id (node_client->get_node_id ()); ASSERT_NE (nullptr, channel1); std::optional telemetry_data; - ASSERT_TIMELY (5s, telemetry_data = node_server->telemetry.get_telemetry (channel1->get_endpoint ())); + ASSERT_TIMELY (5s, telemetry_data = node_server->telemetry.get_telemetry (channel1->get_remote_endpoint ())); ASSERT_TRUE (nano::test::compare_telemetry (*telemetry_data, *node_client)); } @@ -237,7 +237,7 @@ TEST (telemetry, maker_pruning) ASSERT_NE (nullptr, channel); std::optional telemetry_data; - ASSERT_TIMELY (5s, telemetry_data = node_client->telemetry.get_telemetry (channel->get_endpoint ())); + ASSERT_TIMELY (5s, telemetry_data = node_client->telemetry.get_telemetry (channel->get_remote_endpoint ())); ASSERT_EQ (node_server->get_node_id (), telemetry_data->node_id); // Ensure telemetry response indicates pruned node diff --git a/nano/core_test/websocket.cpp b/nano/core_test/websocket.cpp index dacfd7b10e..50d30d9534 100644 --- a/nano/core_test/websocket.cpp +++ b/nano/core_test/websocket.cpp @@ -1005,7 +1005,7 @@ TEST (websocket, telemetry) auto channel = node1->network.find_node_id (node2->get_node_id ()); ASSERT_NE (channel, nullptr); - ASSERT_TIMELY (5s, node1->telemetry.get_telemetry (channel->get_endpoint ())); + ASSERT_TIMELY (5s, node1->telemetry.get_telemetry (channel->get_remote_endpoint ())); ASSERT_TIMELY_EQ (10s, future.wait_for (0s), std::future_status::ready); diff --git a/nano/node/bootstrap/bootstrap_connections.cpp b/nano/node/bootstrap/bootstrap_connections.cpp index dfbdff12f9..358538a651 100644 --- a/nano/node/bootstrap/bootstrap_connections.cpp +++ b/nano/node/bootstrap/bootstrap_connections.cpp @@ -102,7 +102,7 @@ void nano::bootstrap_connections::pool_connection (std::shared_ptr lock{ mutex }; auto const & socket_l = client_a->socket; - if (!stopped && !client_a->pending_stop && !node.network.excluded_peers.check (client_a->channel->get_tcp_endpoint ())) + if (!stopped && !client_a->pending_stop && !node.network.excluded_peers.check (client_a->channel->get_remote_endpoint ())) { socket_l->set_timeout (node.network_params.network.idle_timeout); // Push into idle deque @@ -138,7 +138,7 @@ std::shared_ptr nano::bootstrap_connections::find_connec std::shared_ptr result; for (auto i (idle.begin ()), end (idle.end ()); i != end && !stopped; ++i) { - if ((*i)->channel->get_tcp_endpoint () == endpoint_a) + if ((*i)->channel->get_remote_endpoint () == endpoint_a) { result = *i; idle.erase (i); diff --git a/nano/node/bootstrap/bootstrap_legacy.cpp b/nano/node/bootstrap/bootstrap_legacy.cpp index 6ceb30394b..47368eccf2 100644 --- a/nano/node/bootstrap/bootstrap_legacy.cpp +++ b/nano/node/bootstrap/bootstrap_legacy.cpp @@ -138,7 +138,7 @@ bool nano::bootstrap_attempt_legacy::request_frontier (nano::unique_lockchannel->get_tcp_endpoint (); + endpoint_frontier_request = connection_l->channel->get_remote_endpoint (); std::future future; { auto this_l = std::dynamic_pointer_cast (shared_from_this ()); diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 198bdeac13..d8a253a7ab 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -2991,7 +2991,7 @@ void nano::json_handler::peers () bool const peer_details = request.get ("peer_details", false); auto peers_list (node.network.list (std::numeric_limits::max ())); std::sort (peers_list.begin (), peers_list.end (), [] (auto const & lhs, auto const & rhs) { - return lhs->get_endpoint () < rhs->get_endpoint (); + return lhs->get_remote_endpoint () < rhs->get_remote_endpoint (); }); for (auto i (peers_list.begin ()), n (peers_list.end ()); i != n; ++i) { diff --git a/nano/node/message_processor.cpp b/nano/node/message_processor.cpp index bf3dce51a0..469c55bd18 100644 --- a/nano/node/message_processor.cpp +++ b/nano/node/message_processor.cpp @@ -175,7 +175,7 @@ class process_visitor : public nano::message_visitor if (peer0.address () == boost::asio::ip::address_v6{} && peer0.port () != 0) { // TODO: Remove this as we do not need to establish a second connection to the same peer - nano::endpoint new_endpoint (channel->get_tcp_endpoint ().address (), peer0.port ()); + nano::endpoint new_endpoint (channel->get_remote_endpoint ().address (), peer0.port ()); node.network.merge_peer (new_endpoint); // Remember this for future forwarding to other peers diff --git a/nano/node/network.cpp b/nano/node/network.cpp index d780f634e8..7b0435bd2c 100644 --- a/nano/node/network.cpp +++ b/nano/node/network.cpp @@ -504,14 +504,14 @@ void nano::network::erase (nano::transport::channel const & channel_a) auto const channel_type = channel_a.get_type (); if (channel_type == nano::transport::transport_type::tcp) { - tcp_channels.erase (channel_a.get_tcp_endpoint ()); + tcp_channels.erase (channel_a.get_remote_endpoint ()); } } void nano::network::exclude (std::shared_ptr const & channel) { // Add to peer exclusion list - excluded_peers.add (channel->get_tcp_endpoint ()); + excluded_peers.add (channel->get_remote_endpoint ()); // Disconnect erase (*channel); diff --git a/nano/node/repcrawler.cpp b/nano/node/repcrawler.cpp index 16d72b17a1..b3dc58c405 100644 --- a/nano/node/repcrawler.cpp +++ b/nano/node/repcrawler.cpp @@ -102,7 +102,7 @@ void nano::rep_crawler::validate_and_process (nano::unique_lock & l rep.last_response = std::chrono::steady_clock::now (); // Update if representative channel was changed - if (rep.channel->get_endpoint () != channel->get_endpoint ()) + if (rep.channel->get_remote_endpoint () != channel->get_remote_endpoint ()) { debug_assert (rep.account == vote->account); updated = true; diff --git a/nano/node/telemetry.cpp b/nano/node/telemetry.cpp index 1ae2a59be0..593454241f 100644 --- a/nano/node/telemetry.cpp +++ b/nano/node/telemetry.cpp @@ -96,7 +96,7 @@ void nano::telemetry::process (const nano::telemetry_ack & telemetry, const std: nano::unique_lock lock{ mutex }; - const auto endpoint = channel->get_endpoint (); + const auto endpoint = channel->get_remote_endpoint (); if (auto it = telemetries.get ().find (endpoint); it != telemetries.get ().end ()) { diff --git a/nano/node/transport/channel.cpp b/nano/node/transport/channel.cpp index 1837044490..60c758ba54 100644 --- a/nano/node/transport/channel.cpp +++ b/nano/node/transport/channel.cpp @@ -51,21 +51,20 @@ void nano::transport::channel::set_peering_endpoint (nano::endpoint endpoint) nano::endpoint nano::transport::channel::get_peering_endpoint () const { - nano::unique_lock lock{ channel_mutex }; - if (peering_endpoint) { - return *peering_endpoint; - } - else - { - lock.unlock (); - return get_endpoint (); + nano::lock_guard lock{ channel_mutex }; + if (peering_endpoint) + { + return *peering_endpoint; + } } + return get_remote_endpoint (); } void nano::transport::channel::operator() (nano::object_stream & obs) const { - obs.write ("endpoint", get_endpoint ()); + obs.write ("remote_endpoint", get_remote_endpoint ()); + obs.write ("local_endpoint", get_local_endpoint ()); obs.write ("peering_endpoint", get_peering_endpoint ()); obs.write ("node_id", get_node_id ().to_node_id ()); } diff --git a/nano/node/transport/channel.hpp b/nano/node/transport/channel.hpp index e01cc8c579..cb04586660 100644 --- a/nano/node/transport/channel.hpp +++ b/nano/node/transport/channel.hpp @@ -40,10 +40,10 @@ class channel virtual void close () = 0; - virtual std::string to_string () const = 0; - virtual nano::endpoint get_endpoint () const = 0; - virtual nano::tcp_endpoint get_tcp_endpoint () const = 0; + virtual nano::endpoint get_remote_endpoint () const = 0; virtual nano::endpoint get_local_endpoint () const = 0; + + virtual std::string to_string () const = 0; virtual nano::transport::transport_type get_type () const = 0; virtual bool max (nano::transport::traffic_type = nano::transport::traffic_type::generic) diff --git a/nano/node/transport/fake.hpp b/nano/node/transport/fake.hpp index a1c95b55f5..d9ce585cbb 100644 --- a/nano/node/transport/fake.hpp +++ b/nano/node/transport/fake.hpp @@ -30,16 +30,11 @@ namespace transport endpoint = endpoint_a; } - nano::endpoint get_endpoint () const override + nano::endpoint get_remote_endpoint () const override { return endpoint; } - nano::tcp_endpoint get_tcp_endpoint () const override - { - return nano::transport::map_endpoint_to_tcp (endpoint); - } - nano::endpoint get_local_endpoint () const override { return endpoint; diff --git a/nano/node/transport/inproc.hpp b/nano/node/transport/inproc.hpp index 9ae5670293..d93fbed2d5 100644 --- a/nano/node/transport/inproc.hpp +++ b/nano/node/transport/inproc.hpp @@ -22,16 +22,11 @@ namespace transport std::string to_string () const override; - nano::endpoint get_endpoint () const override + nano::endpoint get_remote_endpoint () const override { return endpoint; } - nano::tcp_endpoint get_tcp_endpoint () const override - { - return nano::transport::map_endpoint_to_tcp (endpoint); - } - nano::endpoint get_local_endpoint () const override { return endpoint; diff --git a/nano/node/transport/tcp_channel.cpp b/nano/node/transport/tcp_channel.cpp index 57f8811ba4..3d4d063838 100644 --- a/nano/node/transport/tcp_channel.cpp +++ b/nano/node/transport/tcp_channel.cpp @@ -28,12 +28,12 @@ void nano::transport::tcp_channel::update_endpoints () { nano::lock_guard lk (channel_mutex); - debug_assert (endpoint == nano::endpoint{}); // Not initialized endpoint value + debug_assert (remote_endpoint == nano::endpoint{}); // Not initialized endpoint value debug_assert (local_endpoint == nano::endpoint{}); // Not initialized endpoint value if (auto socket_l = socket.lock ()) { - endpoint = socket_l->remote_endpoint (); + remote_endpoint = socket_l->remote_endpoint (); local_endpoint = socket_l->local_endpoint (); } } @@ -90,7 +90,7 @@ void nano::transport::tcp_channel::send_buffer (nano::shared_const_buffer const std::string nano::transport::tcp_channel::to_string () const { - return nano::util::to_str (get_tcp_endpoint ()); + return nano::util::to_str (get_remote_endpoint ()); } void nano::transport::tcp_channel::operator() (nano::object_stream & obs) const diff --git a/nano/node/transport/tcp_channel.hpp b/nano/node/transport/tcp_channel.hpp index b72db56546..ea77f48115 100644 --- a/nano/node/transport/tcp_channel.hpp +++ b/nano/node/transport/tcp_channel.hpp @@ -24,15 +24,10 @@ class tcp_channel : public nano::transport::channel, public std::enable_shared_f std::string to_string () const override; - nano::endpoint get_endpoint () const override - { - return nano::transport::map_tcp_to_endpoint (get_tcp_endpoint ()); - } - - nano::tcp_endpoint get_tcp_endpoint () const override + nano::endpoint get_remote_endpoint () const override { nano::lock_guard lk (channel_mutex); - return endpoint; + return remote_endpoint; } nano::endpoint get_local_endpoint () const override @@ -77,7 +72,7 @@ class tcp_channel : public nano::transport::channel, public std::enable_shared_f std::weak_ptr socket; private: - nano::endpoint endpoint; + nano::endpoint remote_endpoint; nano::endpoint local_endpoint; public: // Logging diff --git a/nano/node/transport/tcp_channels.cpp b/nano/node/transport/tcp_channels.cpp index 2d1f147f03..4b983cb7bb 100644 --- a/nano/node/transport/tcp_channels.cpp +++ b/nano/node/transport/tcp_channels.cpp @@ -196,9 +196,9 @@ void nano::transport::tcp_channels::random_fill (std::array & auto j (target_a.begin ()); for (auto i (peers.begin ()), n (peers.end ()); i != n; ++i, ++j) { - debug_assert ((*i)->get_endpoint ().address ().is_v6 ()); + debug_assert ((*i)->get_remote_endpoint ().address ().is_v6 ()); debug_assert (j < target_a.end ()); - *j = (*i)->get_endpoint (); + *j = (*i)->get_remote_endpoint (); } } diff --git a/nano/node/transport/tcp_channels.hpp b/nano/node/transport/tcp_channels.hpp index 0e18d75e82..1b6f1e363d 100644 --- a/nano/node/transport/tcp_channels.hpp +++ b/nano/node/transport/tcp_channels.hpp @@ -80,7 +80,7 @@ class tcp_channels final } nano::tcp_endpoint endpoint () const { - return channel->get_tcp_endpoint (); + return channel->get_remote_endpoint (); } std::chrono::steady_clock::time_point last_bootstrap_attempt () const { diff --git a/nano/node/websocket.cpp b/nano/node/websocket.cpp index 76d19aa80d..d2b8eab72d 100644 --- a/nano/node/websocket.cpp +++ b/nano/node/websocket.cpp @@ -1050,7 +1050,7 @@ nano::websocket_server::websocket_server (nano::websocket::config & config_a, na if (server->any_subscriber (nano::websocket::topic::telemetry)) { nano::websocket::message_builder builder; - server->broadcast (builder.telemetry_received (telemetry_data, channel->get_endpoint ())); + server->broadcast (builder.telemetry_received (telemetry_data, channel->get_remote_endpoint ())); } }); diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index b7e1e13be1..763a6e5cf0 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -1944,7 +1944,7 @@ void nano_qt::advanced_actions::refresh_peers () peers_model->removeRows (0, peers_model->rowCount ()); auto list (wallet.node.network.list (std::numeric_limits::max ())); std::sort (list.begin (), list.end (), [] (auto const & lhs, auto const & rhs) { - return lhs->get_endpoint () < rhs->get_endpoint (); + return lhs->get_remote_endpoint () < rhs->get_remote_endpoint (); }); for (auto i (list.begin ()), n (list.end ()); i != n; ++i) { diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 5539efc96b..1efdeacaff 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -6786,7 +6786,7 @@ TEST (rpc, telemetry_all) auto channel = node1->network.find_node_id (node->get_node_id ()); ASSERT_TRUE (channel); - ASSERT_TIMELY (10s, node1->telemetry.get_telemetry (channel->get_endpoint ())); + ASSERT_TIMELY (10s, node1->telemetry.get_telemetry (channel->get_remote_endpoint ())); boost::property_tree::ptree request; request.put ("action", "telemetry"); diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index 4e4781d412..945b661cf7 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -1383,7 +1383,7 @@ namespace transport // Pick first peer to be consistent auto peer = data.node->network.tcp_channels.channels[0].channel; - auto maybe_telemetry = data.node->telemetry.get_telemetry (peer->get_endpoint ()); + auto maybe_telemetry = data.node->telemetry.get_telemetry (peer->get_remote_endpoint ()); if (maybe_telemetry) { callback_process (shared_data, data, node_data, maybe_telemetry->timestamp); @@ -1513,7 +1513,7 @@ TEST (telemetry, cache_read_and_timeout) ASSERT_NE (channel, nullptr); node_client->telemetry.trigger (); - ASSERT_TIMELY (5s, telemetry_data = node_client->telemetry.get_telemetry (channel->get_endpoint ())); + ASSERT_TIMELY (5s, telemetry_data = node_client->telemetry.get_telemetry (channel->get_remote_endpoint ())); auto responses = node_client->telemetry.get_all_telemetries (); ASSERT_TRUE (!responses.empty ()); @@ -1536,7 +1536,7 @@ TEST (telemetry, cache_read_and_timeout) // Request telemetry metrics again node_client->telemetry.trigger (); - ASSERT_TIMELY (5s, telemetry_data = node_client->telemetry.get_telemetry (channel->get_endpoint ())); + ASSERT_TIMELY (5s, telemetry_data = node_client->telemetry.get_telemetry (channel->get_remote_endpoint ())); responses = node_client->telemetry.get_all_telemetries (); ASSERT_TRUE (!responses.empty ()); @@ -1611,7 +1611,7 @@ TEST (telemetry, many_nodes) for (auto const & peer : peers) { std::optional telemetry_data; - ASSERT_TIMELY (5s, telemetry_data = node_client->telemetry.get_telemetry (peer->get_endpoint ())); + ASSERT_TIMELY (5s, telemetry_data = node_client->telemetry.get_telemetry (peer->get_remote_endpoint ())); telemetry_datas.push_back (*telemetry_data); } From 0990dc73064ea358c45df2df976cdf211279c5e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 3 May 2024 11:51:31 +0200 Subject: [PATCH 12/47] Encapsulate channel mutex --- nano/node/transport/channel.cpp | 4 ++-- nano/node/transport/channel.hpp | 25 ++++++++++++------------- nano/node/transport/tcp_channel.cpp | 4 +--- nano/node/transport/tcp_channel.hpp | 4 ++-- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/nano/node/transport/channel.cpp b/nano/node/transport/channel.cpp index 60c758ba54..7a3328100f 100644 --- a/nano/node/transport/channel.cpp +++ b/nano/node/transport/channel.cpp @@ -45,14 +45,14 @@ void nano::transport::channel::send (nano::message & message_a, std::function lock{ channel_mutex }; + nano::lock_guard lock{ mutex }; peering_endpoint = endpoint; } nano::endpoint nano::transport::channel::get_peering_endpoint () const { { - nano::lock_guard lock{ channel_mutex }; + nano::lock_guard lock{ mutex }; if (peering_endpoint) { return *peering_endpoint; diff --git a/nano/node/transport/channel.hpp b/nano/node/transport/channel.hpp index cb04586660..157b240cfa 100644 --- a/nano/node/transport/channel.hpp +++ b/nano/node/transport/channel.hpp @@ -58,49 +58,49 @@ class channel std::chrono::steady_clock::time_point get_last_bootstrap_attempt () const { - nano::lock_guard lk (channel_mutex); + nano::lock_guard lock{ mutex }; return last_bootstrap_attempt; } void set_last_bootstrap_attempt (std::chrono::steady_clock::time_point const time_a) { - nano::lock_guard lk (channel_mutex); + nano::lock_guard lock{ mutex }; last_bootstrap_attempt = time_a; } std::chrono::steady_clock::time_point get_last_packet_received () const { - nano::lock_guard lk (channel_mutex); + nano::lock_guard lock{ mutex }; return last_packet_received; } void set_last_packet_received (std::chrono::steady_clock::time_point const time_a) { - nano::lock_guard lk (channel_mutex); + nano::lock_guard lock{ mutex }; last_packet_received = time_a; } std::chrono::steady_clock::time_point get_last_packet_sent () const { - nano::lock_guard lk (channel_mutex); + nano::lock_guard lock{ mutex }; return last_packet_sent; } void set_last_packet_sent (std::chrono::steady_clock::time_point const time_a) { - nano::lock_guard lk (channel_mutex); + nano::lock_guard lock{ mutex }; last_packet_sent = time_a; } boost::optional get_node_id_optional () const { - nano::lock_guard lk (channel_mutex); + nano::lock_guard lock{ mutex }; return node_id; } nano::account get_node_id () const { - nano::lock_guard lk (channel_mutex); + nano::lock_guard lock{ mutex }; if (node_id.is_initialized ()) { return node_id.get (); @@ -113,7 +113,7 @@ class channel void set_node_id (nano::account node_id_a) { - nano::lock_guard lk (channel_mutex); + nano::lock_guard lock{ mutex }; node_id = node_id_a; } @@ -130,7 +130,9 @@ class channel nano::endpoint get_peering_endpoint () const; void set_peering_endpoint (nano::endpoint endpoint); - mutable nano::mutex channel_mutex; +protected: + nano::node & node; + mutable nano::mutex mutex; private: std::chrono::steady_clock::time_point last_bootstrap_attempt{ std::chrono::steady_clock::time_point () }; @@ -140,9 +142,6 @@ class channel std::atomic network_version{ 0 }; std::optional peering_endpoint{}; -protected: - nano::node & node; - public: // Logging virtual void operator() (nano::object_stream &) const; }; diff --git a/nano/node/transport/tcp_channel.cpp b/nano/node/transport/tcp_channel.cpp index 3d4d063838..cd0f3645bc 100644 --- a/nano/node/transport/tcp_channel.cpp +++ b/nano/node/transport/tcp_channel.cpp @@ -16,8 +16,6 @@ nano::transport::tcp_channel::tcp_channel (nano::node & node_a, std::weak_ptr lk{ channel_mutex }; - // Close socket. Exception: socket is used by tcp_server if (auto socket_l = socket.lock ()) { socket_l->close (); @@ -26,7 +24,7 @@ nano::transport::tcp_channel::~tcp_channel () void nano::transport::tcp_channel::update_endpoints () { - nano::lock_guard lk (channel_mutex); + nano::lock_guard lock{ mutex }; debug_assert (remote_endpoint == nano::endpoint{}); // Not initialized endpoint value debug_assert (local_endpoint == nano::endpoint{}); // Not initialized endpoint value diff --git a/nano/node/transport/tcp_channel.hpp b/nano/node/transport/tcp_channel.hpp index ea77f48115..3936e3e9ac 100644 --- a/nano/node/transport/tcp_channel.hpp +++ b/nano/node/transport/tcp_channel.hpp @@ -26,13 +26,13 @@ class tcp_channel : public nano::transport::channel, public std::enable_shared_f nano::endpoint get_remote_endpoint () const override { - nano::lock_guard lk (channel_mutex); + nano::lock_guard lock{ mutex }; return remote_endpoint; } nano::endpoint get_local_endpoint () const override { - nano::lock_guard lk (channel_mutex); + nano::lock_guard lock{ mutex }; return local_endpoint; } From 934cd6eba57e2a66457d96fdfd1dab5e412fca3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 7 Oct 2024 22:55:16 +0200 Subject: [PATCH 13/47] Use std:::optional --- nano/node/json_handler.cpp | 4 ++-- nano/node/transport/channel.hpp | 13 +++---------- nano/qt/qt.cpp | 4 ++-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index d8a253a7ab..a0232c3428 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -3003,9 +3003,9 @@ void nano::json_handler::peers () boost::property_tree::ptree pending_tree; pending_tree.put ("protocol_version", std::to_string (channel->get_network_version ())); auto node_id_l (channel->get_node_id_optional ()); - if (node_id_l.is_initialized ()) + if (node_id_l.has_value ()) { - pending_tree.put ("node_id", node_id_l.get ().to_node_id ()); + pending_tree.put ("node_id", node_id_l.value ().to_node_id ()); } else { diff --git a/nano/node/transport/channel.hpp b/nano/node/transport/channel.hpp index 157b240cfa..2dbe3c8487 100644 --- a/nano/node/transport/channel.hpp +++ b/nano/node/transport/channel.hpp @@ -92,7 +92,7 @@ class channel last_packet_sent = time_a; } - boost::optional get_node_id_optional () const + std::optional get_node_id_optional () const { nano::lock_guard lock{ mutex }; return node_id; @@ -101,14 +101,7 @@ class channel nano::account get_node_id () const { nano::lock_guard lock{ mutex }; - if (node_id.is_initialized ()) - { - return node_id.get (); - } - else - { - return 0; - } + return node_id.value_or (0); } void set_node_id (nano::account node_id_a) @@ -138,7 +131,7 @@ class channel std::chrono::steady_clock::time_point last_bootstrap_attempt{ std::chrono::steady_clock::time_point () }; std::chrono::steady_clock::time_point last_packet_received{ std::chrono::steady_clock::now () }; std::chrono::steady_clock::time_point last_packet_sent{ std::chrono::steady_clock::now () }; - boost::optional node_id{ boost::none }; + std::optional node_id{}; std::atomic network_version{ 0 }; std::optional peering_endpoint{}; diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 763a6e5cf0..aefd693bd0 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -1959,9 +1959,9 @@ void nano_qt::advanced_actions::refresh_peers () items.push_back (version); QString node_id (""); auto node_id_l (channel->get_node_id_optional ()); - if (node_id_l.is_initialized ()) + if (node_id_l.has_value ()) { - node_id = node_id_l.get ().to_account ().c_str (); + node_id = node_id_l.value ().to_account ().c_str (); } items.push_back (new QStandardItem (node_id)); peers_model->appendRow (items); From c22851b107f43dd6619b2399d9255ec4198ff05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:35:28 +0200 Subject: [PATCH 14/47] Generated vote size histogram (#4751) --- nano/lib/stats_enums.hpp | 2 ++ nano/node/vote_generator.cpp | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nano/lib/stats_enums.hpp b/nano/lib/stats_enums.hpp index c8f3e5f81e..6bf38cd5ef 100644 --- a/nano/lib/stats_enums.hpp +++ b/nano/lib/stats_enums.hpp @@ -540,6 +540,8 @@ enum class sample active_election_duration, bootstrap_tag_duration, rep_response_time, + vote_generator_final_hashes, + vote_generator_hashes, _last // Must be the last enum }; diff --git a/nano/node/vote_generator.cpp b/nano/node/vote_generator.cpp index 00947ccec0..8166b8c305 100644 --- a/nano/node/vote_generator.cpp +++ b/nano/node/vote_generator.cpp @@ -124,15 +124,12 @@ void nano::vote_generator::process_batch (std::deque & batch) if (is_final) { transaction_variant_t transaction_variant{ ledger.tx_begin_write (nano::store::writer::voting_final) }; - verify_batch (transaction_variant, batch); - // Commit write transaction } else { transaction_variant_t transaction_variant{ ledger.tx_begin_read () }; - verify_batch (transaction_variant, batch); } @@ -208,9 +205,10 @@ void nano::vote_generator::broadcast (nano::unique_lock & lock_a) if (!hashes.empty ()) { lock_a.unlock (); - vote (hashes, roots, [this] (auto const & vote_a) { - this->broadcast_action (vote_a); - this->stats.inc (nano::stat::type::vote_generator, nano::stat::detail::generator_broadcasts); + vote (hashes, roots, [this] (auto const & generated_vote) { + stats.inc (nano::stat::type::vote_generator, nano::stat::detail::generator_broadcasts); + stats.sample (is_final ? nano::stat::sample::vote_generator_final_hashes : nano::stat::sample::vote_generator_hashes, generated_vote->hashes.size (), { 0, nano::network::confirm_ack_hashes_max }); + broadcast_action (generated_vote); }); lock_a.lock (); } From 11e9581a25d89b6eff2325839c5f21fbfa63c473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:40:38 +0200 Subject: [PATCH 15/47] Avoid unnecessary notices --- ci/tests/run-system-tests.sh | 2 +- ci/tests/show-sanitizer-reports.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/tests/run-system-tests.sh b/ci/tests/run-system-tests.sh index 496fad7f3e..4027e15a48 100755 --- a/ci/tests/run-system-tests.sh +++ b/ci/tests/run-system-tests.sh @@ -44,7 +44,7 @@ for script in ${NANO_SYSTEST_DIR}/*.sh; do done if [ $overall_status -eq 0 ]; then - echo "::notice::All systests passed" + echo "All systests passed" else echo "::error::Some systests failed" exit 1 diff --git a/ci/tests/show-sanitizer-reports.sh b/ci/tests/show-sanitizer-reports.sh index ba4f92d608..f29e6db75f 100755 --- a/ci/tests/show-sanitizer-reports.sh +++ b/ci/tests/show-sanitizer-reports.sh @@ -19,7 +19,7 @@ if [[ ${#reports[@]} -gt 0 ]]; then issue_reported=true done else - echo "::notice::No report has been generated." + echo "No report has been generated." fi echo "issue_reported=${issue_reported}" >> $GITHUB_OUTPUT @@ -28,6 +28,6 @@ if $issue_reported; then echo "::error::Issues were reported in the sanitizer report." exit 1 else - echo "::notice::No issues found in the sanitizer reports." + echo "No issues found in the sanitizer reports." exit 0 fi \ No newline at end of file From e821dd4e94b4e646f046986286742d309fc86f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:00:59 +0200 Subject: [PATCH 16/47] Log hashes of executables as notice messages --- ci/actions/deploy.sh | 12 +++++------- ci/actions/windows/deploy.ps1 | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ci/actions/deploy.sh b/ci/actions/deploy.sh index cc6f754fe4..2a19973905 100755 --- a/ci/actions/deploy.sh +++ b/ci/actions/deploy.sh @@ -20,8 +20,6 @@ case "${NETWORK}" in esac if [[ -n "${S3_BUILD_DIRECTORY}" ]]; then - - DIRECTORY="${S3_BUILD_DIRECTORY}/${BUILD}" else DIRECTORY=$BUILD @@ -33,7 +31,7 @@ if [[ "$OS" == 'Linux' && "$IS_RPM_DEPLOY" -eq "1" ]]; then for rpm in $RPMS; do SHA=$(sha256sum ${rpm}) - echo "Hash: $SHA" + echo "::notice::Hash: $SHA" echo $SHA > ${GITHUB_WORKSPACE}/$(basename "${rpm}.sha256") aws s3 cp ${rpm} s3://${S3_BUCKET_NAME}/$DIRECTORY/binaries/$(basename "${rpm}") --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers @@ -42,7 +40,7 @@ if [[ "$OS" == 'Linux' && "$IS_RPM_DEPLOY" -eq "1" ]]; then for srpm in $SRPMS; do SHA=$(sha256sum ${srpm}) - echo "Hash: $SHA" + echo "::notice::Hash: $SHA" echo $SHA > ${GITHUB_WORKSPACE}/$(basename "${srpm}).sha256") aws s3 cp ${srpm} s3://${S3_BUCKET_NAME}/$DIRECTORY/source/$(basename "${srpm}") --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers @@ -50,11 +48,11 @@ if [[ "$OS" == 'Linux' && "$IS_RPM_DEPLOY" -eq "1" ]]; then done elif [[ "$OS" == 'Linux' ]]; then SHA=$(sha256sum $GITHUB_WORKSPACE/build/nano-node-*-Linux.tar.bz2) - echo "Hash: $SHA" + echo "::notice::Hash: $SHA" echo $SHA >$GITHUB_WORKSPACE/nano-node-$TAG-Linux.tar.bz2.sha256 SHA=$(sha256sum $GITHUB_WORKSPACE/build/nano-node-*-Linux.deb) - echo "Hash: $SHA" + echo "::notice::Hash: $SHA" echo $SHA >$GITHUB_WORKSPACE/nano-node-$TAG-Linux.deb.sha256 aws s3 cp $GITHUB_WORKSPACE/build/nano-node-*-Linux.tar.bz2 s3://${S3_BUCKET_NAME}/$DIRECTORY/binaries/nano-node-$TAG-Linux.tar.bz2 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers @@ -63,7 +61,7 @@ elif [[ "$OS" == 'Linux' ]]; then aws s3 cp $GITHUB_WORKSPACE/nano-node-$TAG-Linux.deb.sha256 s3://${S3_BUCKET_NAME}/$DIRECTORY/binaries/nano-node-$TAG-Linux.deb.sha256 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers else SHA=$(sha256sum $GITHUB_WORKSPACE/build/nano-node-*-Darwin.dmg) - echo "Hash: $SHA" + echo "::notice::Hash: $SHA" echo $SHA >$GITHUB_WORKSPACE/build/nano-node-$TAG-Darwin.dmg.sha256 aws s3 cp $GITHUB_WORKSPACE/build/nano-node-*-Darwin.dmg s3://${S3_BUCKET_NAME}/$DIRECTORY/binaries/nano-node-$TAG-Darwin.dmg --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers diff --git a/ci/actions/windows/deploy.ps1 b/ci/actions/windows/deploy.ps1 index 4a859ecebf..6b53357bb7 100644 --- a/ci/actions/windows/deploy.ps1 +++ b/ci/actions/windows/deploy.ps1 @@ -27,8 +27,8 @@ $zip_hash = ((Get-FileHash $zip).hash)+" "+(split-path -Path $zip -Resolve -leaf $exe_hash | Out-file -FilePath "$exe.sha256" $zip_hash | Out-file -FilePath "$zip.sha256" -Write-Output "Hash: $exe_hash" -Write-Output "Hash: $zip_hash" +Write-Output "::notice::Hash: $exe_hash" +Write-Output "::notice::Hash: $zip_hash" aws s3 cp "$exe" s3://$env:S3_BUCKET_NAME/$directory/binaries/nano-node-$env:TAG-win64.exe --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers aws s3 cp "$exe.sha256" s3://$env:S3_BUCKET_NAME/$directory/binaries/nano-node-$env:TAG-win64.exe.sha256 --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers From 885447fedb8f08e1a4d2d7175aa1b0b4c7290e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:03:38 +0200 Subject: [PATCH 17/47] Use channel as telemetry data key (#4697) * Use channel as telemetry data key * Erase dead channels --- nano/lib/stats_enums.hpp | 1 + nano/node/telemetry.cpp | 19 ++++++++++--------- nano/node/telemetry.hpp | 15 +++++++++++---- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/nano/lib/stats_enums.hpp b/nano/lib/stats_enums.hpp index 6bf38cd5ef..ee9d8799dc 100644 --- a/nano/lib/stats_enums.hpp +++ b/nano/lib/stats_enums.hpp @@ -369,6 +369,7 @@ enum class detail failed_send_telemetry_req, empty_payload, cleanup_outdated, + erase_stale, // vote generator generator_broadcasts, diff --git a/nano/node/telemetry.cpp b/nano/node/telemetry.cpp index 1ae2a59be0..d7c659dcee 100644 --- a/nano/node/telemetry.cpp +++ b/nano/node/telemetry.cpp @@ -96,14 +96,11 @@ void nano::telemetry::process (const nano::telemetry_ack & telemetry, const std: nano::unique_lock lock{ mutex }; - const auto endpoint = channel->get_endpoint (); - - if (auto it = telemetries.get ().find (endpoint); it != telemetries.get ().end ()) + if (auto it = telemetries.get ().find (channel); it != telemetries.get ().end ()) { stats.inc (nano::stat::type::telemetry, nano::stat::detail::update); - telemetries.get ().modify (it, [&telemetry, &endpoint] (auto & entry) { - debug_assert (entry.endpoint == endpoint); + telemetries.get ().modify (it, [&telemetry, &channel] (auto & entry) { entry.data = telemetry.data; entry.last_updated = std::chrono::steady_clock::now (); }); @@ -111,7 +108,7 @@ void nano::telemetry::process (const nano::telemetry_ack & telemetry, const std: else { stats.inc (nano::stat::type::telemetry, nano::stat::detail::insert); - telemetries.get ().insert ({ endpoint, telemetry.data, std::chrono::steady_clock::now (), channel }); + telemetries.get ().insert ({ channel, telemetry.data, std::chrono::steady_clock::now () }); if (telemetries.size () > max_size) { @@ -247,10 +244,14 @@ void nano::telemetry::cleanup () // Remove if telemetry data is stale if (!check_timeout (entry)) { - stats.inc (nano::stat::type::telemetry, nano::stat::detail::cleanup_outdated); + stats.inc (nano::stat::type::telemetry, nano::stat::detail::erase_stale); + return true; // Erase + } + if (!entry.channel->alive ()) + { + stats.inc (nano::stat::type::telemetry, nano::stat::detail::erase_dead); return true; // Erase } - return false; // Do not erase }); } @@ -283,7 +284,7 @@ std::unordered_map nano::telemetry::get_al { if (check_timeout (entry)) { - result[entry.endpoint] = entry.data; + result[entry.endpoint ()] = entry.data; } } return result; diff --git a/nano/node/telemetry.hpp b/nano/node/telemetry.hpp index 6262cb25e2..7a615e7e2a 100644 --- a/nano/node/telemetry.hpp +++ b/nano/node/telemetry.hpp @@ -86,10 +86,14 @@ class telemetry private: struct entry { - nano::endpoint endpoint; + std::shared_ptr channel; nano::telemetry_data data; std::chrono::steady_clock::time_point last_updated; - std::shared_ptr channel; + + nano::endpoint endpoint () const + { + return channel->get_endpoint (); + } }; private: @@ -110,13 +114,16 @@ class telemetry private: // clang-format off class tag_sequenced {}; + class tag_channel {}; class tag_endpoint {}; using ordered_telemetries = boost::multi_index_container>, - mi::hashed_unique, - mi::member> + mi::ordered_unique, + mi::member, &entry::channel>>, + mi::hashed_non_unique, + mi::const_mem_fun> >>; // clang-format on From 9807e86b639635e5d2572332048d0bc2e78c3e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:22:21 +0200 Subject: [PATCH 18/47] Track election confirm stats --- nano/lib/stats_enums.hpp | 2 ++ nano/node/election.cpp | 2 ++ nano/node/node.cpp | 2 ++ 3 files changed, 6 insertions(+) diff --git a/nano/lib/stats_enums.hpp b/nano/lib/stats_enums.hpp index ee9d8799dc..d855b02950 100644 --- a/nano/lib/stats_enums.hpp +++ b/nano/lib/stats_enums.hpp @@ -249,6 +249,8 @@ enum class detail generate_vote_final, broadcast_block_initial, broadcast_block_repeat, + confirm_once, + confirm_once_failed, // election types manual, diff --git a/nano/node/election.cpp b/nano/node/election.cpp index 98fa9ba491..48b856a608 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -56,6 +56,7 @@ void nano::election::confirm_once (nano::unique_lock & lock_a) node.active.recently_confirmed.put (qualified_root, status_l.winner->hash ()); + node.stats.inc (nano::stat::type::election, nano::stat::detail::confirm_once); node.logger.trace (nano::log::type::election, nano::log::detail::election_confirmed, nano::log::arg{ "id", id }, nano::log::arg{ "qualified_root", qualified_root }, @@ -74,6 +75,7 @@ void nano::election::confirm_once (nano::unique_lock & lock_a) } else { + node.stats.inc (nano::stat::type::election, nano::stat::detail::confirm_once_failed); lock_a.unlock (); } } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 3cda7ce369..438298239d 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1143,6 +1143,8 @@ void nano::node::ongoing_online_weight_calculation () void nano::node::process_confirmed (nano::election_status const & status_a, uint64_t iteration_a) { + stats.inc (nano::stat::type::process_confirmed, nano::stat::detail::initiate); + auto hash (status_a.winner->hash ()); decltype (iteration_a) const num_iters = (config.block_processor_batch_max_time / network_params.node.process_confirmed_interval) * 4; if (auto block_l = ledger.any.block_get (ledger.tx_begin_read (), hash)) From 2badf066470bb1d082c6ade98d65ea528569d0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Sat, 12 Oct 2024 13:30:12 +0200 Subject: [PATCH 19/47] Stats for `node::process_confirmed ()` --- nano/lib/stats_enums.hpp | 3 +++ nano/node/node.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/nano/lib/stats_enums.hpp b/nano/lib/stats_enums.hpp index d855b02950..ee5629ad4b 100644 --- a/nano/lib/stats_enums.hpp +++ b/nano/lib/stats_enums.hpp @@ -93,6 +93,7 @@ enum class type message_processor, message_processor_overfill, message_processor_type, + process_confirmed, _last // Must be the last enum }; @@ -134,6 +135,8 @@ enum class detail cemented, cooldown, empty, + done, + retry, // processing queue queue, diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 438298239d..346c20ae10 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1149,12 +1149,15 @@ void nano::node::process_confirmed (nano::election_status const & status_a, uint decltype (iteration_a) const num_iters = (config.block_processor_batch_max_time / network_params.node.process_confirmed_interval) * 4; if (auto block_l = ledger.any.block_get (ledger.tx_begin_read (), hash)) { + stats.inc (nano::stat::type::process_confirmed, nano::stat::detail::done); logger.trace (nano::log::type::node, nano::log::detail::process_confirmed, nano::log::arg{ "block", block_l }); confirming_set.add (block_l->hash ()); } else if (iteration_a < num_iters) { + stats.inc (nano::stat::type::process_confirmed, nano::stat::detail::retry); + iteration_a++; std::weak_ptr node_w (shared ()); election_workers.add_timed_task (std::chrono::steady_clock::now () + network_params.node.process_confirmed_interval, [node_w, status_a, iteration_a] () { @@ -1166,6 +1169,8 @@ void nano::node::process_confirmed (nano::election_status const & status_a, uint } else { + stats.inc (nano::stat::type::process_confirmed, nano::stat::detail::timeout); + // Do some cleanup due to this block never being processed by confirmation height processor active.remove_election_winner_details (hash); } From 0747d4afe46878b357fa08f43376c56f505e30c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Sat, 12 Oct 2024 11:59:17 +0200 Subject: [PATCH 20/47] Handle rollbacks when cementing --- nano/node/confirming_set.cpp | 8 ++++++++ nano/secure/ledger.cpp | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index c499e35057..da342a4e52 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -180,6 +181,13 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) stats.inc (nano::stat::type::confirming_set, nano::stat::detail::cementing); + // The block might be rolled back before it's fully cemented + if (!ledger.any.block_exists (transaction, hash)) + { + stats.inc (nano::stat::type::confirming_set, nano::stat::detail::missing_block); + break; + } + auto added = ledger.confirm (transaction, hash, config.max_blocks); if (!added.empty ()) { diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index efe7c5ad86..cba173a6c8 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -865,7 +865,10 @@ std::deque> nano::ledger::confirm (secure::write_tr bool refreshed = transaction.refresh_if_needed (); if (refreshed) { - release_assert (any.block_exists (transaction, target_hash), "block was rolled back during cementing"); + if (!any.block_exists (transaction, target_hash)) + { + break; // Block was rolled back during cementing + } } // Early return might leave parts of the dependency tree unconfirmed From b7ba1eb08a4b2c54dd87a204f8df4afb47f63e17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:27:12 +0200 Subject: [PATCH 21/47] Rework cemented notification --- nano/node/active_elections.cpp | 18 +++++++++--------- nano/node/confirming_set.cpp | 22 +++++++++++----------- nano/node/confirming_set.hpp | 12 ++++-------- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index 134c649dfa..2f04243f78 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -30,17 +30,17 @@ nano::active_elections::active_elections (nano::node & node_a, nano::confirming_ { count_by_behavior.fill (0); // Zero initialize array - confirming_set.batch_cemented.add ([this] (nano::confirming_set::cemented_notification const & notification) { + confirming_set.batch_cemented.add ([this] (auto const & cemented) { + auto transaction = node.ledger.tx_begin_read (); + for (auto const & [block, confirmation_root] : cemented) { - auto transaction = node.ledger.tx_begin_read (); - for (auto const & [block, confirmation_root] : notification.cemented) - { - transaction.refresh_if_needed (); - - block_cemented_callback (transaction, block, confirmation_root); - } + transaction.refresh_if_needed (); + block_cemented_callback (transaction, block, confirmation_root); } - for (auto const & hash : notification.already_cemented) + }); + + confirming_set.already_cemented.add ([this] (auto const & already_cemented) { + for (auto const & hash : already_cemented) { block_already_cemented_callback (hash); } diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index da342a4e52..1d2aa2facc 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -12,8 +12,8 @@ nano::confirming_set::confirming_set (confirming_set_config const & config_a, na stats{ stats_a }, notification_workers{ 1, nano::thread_role::name::confirmation_height_notifications } { - batch_cemented.add ([this] (auto const & notification) { - for (auto const & [block, confirmation_root] : notification.cemented) + batch_cemented.add ([this] (auto const & cemented) { + for (auto const & [block, confirmation_root] : cemented) { cemented_observers.notify (block); } @@ -124,17 +124,17 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) std::deque cemented; std::deque already; - auto batch = next_batch (256); + auto batch = next_batch (batch_size); lock.unlock (); - auto notify = [this, &cemented, &already] () { - cemented_notification notification{}; - notification.cemented.swap (cemented); - notification.already_cemented.swap (already); + auto notify = [this, &cemented] () { + std::deque batch; + batch.swap (cemented); std::unique_lock lock{ mutex }; + // It's possible that ledger cementing happens faster than the notifications can be processed by other components, cooldown here while (notification_workers.num_queued_tasks () >= config.max_queued_notifications) { stats.inc (nano::stat::type::confirming_set, nano::stat::detail::cooldown); @@ -145,9 +145,9 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) } } - notification_workers.push_task ([this, notification = std::move (notification)] () { + notification_workers.push_task ([this, batch = std::move (batch)] () { stats.inc (nano::stat::type::confirming_set, nano::stat::detail::notify); - batch_cemented.notify (notification); + batch_cemented.notify (batch); }); }; @@ -211,9 +211,9 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) } notify (); - release_assert (cemented.empty ()); - release_assert (already.empty ()); + + already_cemented.notify (already); } nano::container_info nano::confirming_set::container_info () const diff --git a/nano/node/confirming_set.hpp b/nano/node/confirming_set.hpp index e5ef4857f1..b9e568db4b 100644 --- a/nano/node/confirming_set.hpp +++ b/nano/node/confirming_set.hpp @@ -48,16 +48,10 @@ class confirming_set final nano::container_info container_info () const; public: // Events - // Observers will be called once ledger has blocks marked as confirmed using cemented_t = std::pair, nano::block_hash>; // + nano::observer_set const &> batch_cemented; + nano::observer_set const &> already_cemented; - struct cemented_notification - { - std::deque cemented; - std::deque already_cemented; - }; - - nano::observer_set batch_cemented; nano::observer_set> cemented_observers; private: // Dependencies @@ -79,5 +73,7 @@ class confirming_set final mutable std::mutex mutex; std::condition_variable condition; std::thread thread; + + static size_t constexpr batch_size = 256; }; } From 155cb1c2526036defc14d65e9c043871d65632dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:18:53 +0200 Subject: [PATCH 22/47] Keep election in confirming set --- nano/node/active_elections.cpp | 2 +- nano/node/confirming_set.cpp | 27 ++++++++++----------- nano/node/confirming_set.hpp | 43 ++++++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index 2f04243f78..a8fb6469bc 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -32,7 +32,7 @@ nano::active_elections::active_elections (nano::node & node_a, nano::confirming_ confirming_set.batch_cemented.add ([this] (auto const & cemented) { auto transaction = node.ledger.tx_begin_read (); - for (auto const & [block, confirmation_root] : cemented) + for (auto const & [block, confirmation_root, election] : cemented) { transaction.refresh_if_needed (); block_cemented_callback (transaction, block, confirmation_root); diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index 1d2aa2facc..f7a0125340 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -13,9 +13,9 @@ nano::confirming_set::confirming_set (confirming_set_config const & config_a, na notification_workers{ 1, nano::thread_role::name::confirmation_height_notifications } { batch_cemented.add ([this] (auto const & cemented) { - for (auto const & [block, confirmation_root] : cemented) + for (auto const & context : cemented) { - cemented_observers.notify (block); + cemented_observers.notify (context.block); } }); } @@ -25,12 +25,12 @@ nano::confirming_set::~confirming_set () debug_assert (!thread.joinable ()); } -void nano::confirming_set::add (nano::block_hash const & hash) +void nano::confirming_set::add (nano::block_hash const & hash, std::shared_ptr const & election) { bool added = false; { std::lock_guard lock{ mutex }; - auto [it, inserted] = set.insert (hash); + auto [it, inserted] = set.push_back ({ hash, election }); added = inserted; } if (added) @@ -71,7 +71,7 @@ void nano::confirming_set::stop () bool nano::confirming_set::exists (nano::block_hash const & hash) const { std::lock_guard lock{ mutex }; - return set.count (hash) != 0; + return set.get ().contains (hash); } std::size_t nano::confirming_set::size () const @@ -100,17 +100,16 @@ void nano::confirming_set::run () } } -std::deque nano::confirming_set::next_batch (size_t max_count) +auto nano::confirming_set::next_batch (size_t max_count) -> std::deque { debug_assert (!mutex.try_lock ()); debug_assert (!set.empty ()); - std::deque results; + std::deque results; while (!set.empty () && results.size () < max_count) { - auto it = set.begin (); - results.push_back (*it); - set.erase (it); + results.push_back (set.front ()); + set.pop_front (); } return results; } @@ -121,7 +120,7 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) debug_assert (!mutex.try_lock ()); debug_assert (!set.empty ()); - std::deque cemented; + std::deque cemented; std::deque already; auto batch = next_batch (batch_size); @@ -129,7 +128,7 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) lock.unlock (); auto notify = [this, &cemented] () { - std::deque batch; + std::deque batch; batch.swap (cemented); std::unique_lock lock{ mutex }; @@ -164,7 +163,7 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) { auto transaction = ledger.tx_begin_write (nano::store::writer::confirmation_height); - for (auto const & hash : batch) + for (auto const & [hash, election] : batch) { do { @@ -195,7 +194,7 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) stats.add (nano::stat::type::confirming_set, nano::stat::detail::cemented, added.size ()); for (auto & block : added) { - cemented.emplace_back (block, hash); + cemented.push_back ({ block, hash, election }); } } else diff --git a/nano/node/confirming_set.hpp b/nano/node/confirming_set.hpp index b9e568db4b..5eb429672e 100644 --- a/nano/node/confirming_set.hpp +++ b/nano/node/confirming_set.hpp @@ -4,6 +4,13 @@ #include #include #include +#include + +#include +#include +#include +#include +#include #include #include @@ -11,6 +18,8 @@ #include #include +namespace mi = boost::multi_index; + namespace nano { class confirming_set_config final @@ -40,7 +49,7 @@ class confirming_set final void stop (); // Adds a block to the set of blocks to be confirmed - void add (nano::block_hash const & hash); + void add (nano::block_hash const & hash, std::shared_ptr const & election = nullptr); // Added blocks will remain in this set until after ledger has them marked as confirmed. bool exists (nano::block_hash const & hash) const; std::size_t size () const; @@ -48,8 +57,14 @@ class confirming_set final nano::container_info container_info () const; public: // Events - using cemented_t = std::pair, nano::block_hash>; // - nano::observer_set const &> batch_cemented; + struct context + { + std::shared_ptr block; + nano::block_hash confirmation_root; + std::shared_ptr election; + }; + + nano::observer_set const &> batch_cemented; nano::observer_set const &> already_cemented; nano::observer_set> cemented_observers; @@ -60,12 +75,30 @@ class confirming_set final nano::stats & stats; private: + struct entry + { + nano::block_hash hash; + std::shared_ptr election; + }; + void run (); void run_batch (std::unique_lock &); - std::deque next_batch (size_t max_count); + std::deque next_batch (size_t max_count); private: - std::unordered_set set; + // clang-format off + class tag_hash {}; + class tag_sequenced {}; + + using ordered_entries = boost::multi_index_container>, + mi::hashed_unique, + mi::member> + >>; + // clang-format on + + ordered_entries set; nano::thread_pool notification_workers; From b44040347b58007acf4a8bf1a476895a4d2a9afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:19:01 +0200 Subject: [PATCH 23/47] Rename `exists ()` to `contains ()` --- nano/core_test/active_elections.cpp | 2 +- nano/core_test/confirming_set.cpp | 4 ++-- nano/node/confirming_set.cpp | 2 +- nano/node/confirming_set.hpp | 2 +- nano/node/json_handler.cpp | 2 +- nano/node/node.cpp | 8 ++++---- nano/node/wallet.cpp | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/nano/core_test/active_elections.cpp b/nano/core_test/active_elections.cpp index 6c13d4a02c..05c243aa3e 100644 --- a/nano/core_test/active_elections.cpp +++ b/nano/core_test/active_elections.cpp @@ -1224,7 +1224,7 @@ TEST (active_elections, activate_inactive) ASSERT_NE (nullptr, election); election->force_confirm (); - ASSERT_TIMELY (5s, !node.confirming_set.exists (send2->hash ())); + ASSERT_TIMELY (5s, !node.confirming_set.contains (send2->hash ())); ASSERT_TIMELY (5s, node.block_confirmed (send2->hash ())); ASSERT_TIMELY (5s, node.block_confirmed (send->hash ())); diff --git a/nano/core_test/confirming_set.cpp b/nano/core_test/confirming_set.cpp index 7d25017874..46e7b914a1 100644 --- a/nano/core_test/confirming_set.cpp +++ b/nano/core_test/confirming_set.cpp @@ -30,7 +30,7 @@ TEST (confirming_set, add_exists) nano::confirming_set confirming_set{ config, ctx.ledger (), ctx.stats () }; auto send = ctx.blocks ()[0]; confirming_set.add (send->hash ()); - ASSERT_TRUE (confirming_set.exists (send->hash ())); + ASSERT_TRUE (confirming_set.contains (send->hash ())); } TEST (confirming_set, process_one) @@ -242,7 +242,7 @@ TEST (confirmation_callback, dependent_election) // Wait for blocks to be confirmed in ledger, callbacks will happen after ASSERT_TIMELY_EQ (5s, 3, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in)); // Once the item added to the confirming set no longer exists, callbacks have completed - ASSERT_TIMELY (5s, !node->confirming_set.exists (send2->hash ())); + ASSERT_TIMELY (5s, !node->confirming_set.contains (send2->hash ())); ASSERT_TIMELY_EQ (5s, 1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out)); ASSERT_TIMELY_EQ (5s, 1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_conf_height, nano::stat::dir::out)); diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index f7a0125340..de92e853a9 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -68,7 +68,7 @@ void nano::confirming_set::stop () notification_workers.stop (); } -bool nano::confirming_set::exists (nano::block_hash const & hash) const +bool nano::confirming_set::contains (nano::block_hash const & hash) const { std::lock_guard lock{ mutex }; return set.get ().contains (hash); diff --git a/nano/node/confirming_set.hpp b/nano/node/confirming_set.hpp index 5eb429672e..00329fea83 100644 --- a/nano/node/confirming_set.hpp +++ b/nano/node/confirming_set.hpp @@ -51,7 +51,7 @@ class confirming_set final // Adds a block to the set of blocks to be confirmed void add (nano::block_hash const & hash, std::shared_ptr const & election = nullptr); // Added blocks will remain in this set until after ledger has them marked as confirmed. - bool exists (nano::block_hash const & hash) const; + bool contains (nano::block_hash const & hash) const; std::size_t size () const; nano::container_info container_info () const; diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 198bdeac13..8b75b9d0f7 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -1187,7 +1187,7 @@ void nano::json_handler::block_confirm () if (!node.ledger.confirmed.block_exists_or_pruned (transaction, hash)) { // Start new confirmation for unconfirmed (or not being confirmed) block - if (!node.confirming_set.exists (hash)) + if (!node.confirming_set.contains (hash)) { node.start_election (std::move (block_l)); } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 346c20ae10..5871f2cff8 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1104,14 +1104,14 @@ void nano::node::start_election (std::shared_ptr const & block) scheduler.manual.push (block); } -bool nano::node::block_confirmed (nano::block_hash const & hash_a) +bool nano::node::block_confirmed (nano::block_hash const & hash) { - return ledger.confirmed.block_exists_or_pruned (ledger.tx_begin_read (), hash_a); + return ledger.confirmed.block_exists_or_pruned (ledger.tx_begin_read (), hash); } -bool nano::node::block_confirmed_or_being_confirmed (nano::secure::transaction const & transaction, nano::block_hash const & hash_a) +bool nano::node::block_confirmed_or_being_confirmed (nano::secure::transaction const & transaction, nano::block_hash const & hash) { - return confirming_set.exists (hash_a) || ledger.confirmed.block_exists_or_pruned (transaction, hash_a); + return confirming_set.contains (hash) || ledger.confirmed.block_exists_or_pruned (transaction, hash); } bool nano::node::block_confirmed_or_being_confirmed (nano::block_hash const & hash_a) diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 837a2ca417..716f78ee2f 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -1201,7 +1201,7 @@ bool nano::wallet::search_receivable (store::transaction const & wallet_transact // Receive confirmed block receive_async (hash, representative, amount, account, [] (std::shared_ptr const &) {}); } - else if (!wallets.node.confirming_set.exists (hash)) + else if (!wallets.node.confirming_set.contains (hash)) { auto block = wallets.node.ledger.any.block_get (block_transaction, hash); if (block) From e456b2282b14686687a659989bc81f96d60ffb2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:30:57 +0200 Subject: [PATCH 24/47] Remove `election_winner_details` --- nano/core_test/confirming_set.cpp | 27 ---------- nano/core_test/ledger_confirm.cpp | 23 -------- nano/lib/stats_enums.hpp | 1 + nano/node/active_elections.cpp | 87 ++++++++----------------------- nano/node/active_elections.hpp | 13 +---- nano/node/election.cpp | 24 ++++----- nano/node/node.cpp | 1 - nano/slow_test/node.cpp | 9 ---- 8 files changed, 37 insertions(+), 148 deletions(-) diff --git a/nano/core_test/confirming_set.cpp b/nano/core_test/confirming_set.cpp index 46e7b914a1..a2b3d60803 100644 --- a/nano/core_test/confirming_set.cpp +++ b/nano/core_test/confirming_set.cpp @@ -111,7 +111,6 @@ TEST (confirmation_callback, observer_callbacks) ASSERT_EQ (2, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in)); ASSERT_EQ (3, node->ledger.cemented_count ()); - ASSERT_EQ (0, node->active.election_winner_details_size ()); } // The callback and confirmation history should only be updated after confirmation height is set (and not just after voting) @@ -186,7 +185,6 @@ TEST (confirmation_callback, confirmed_history) ASSERT_TIMELY_EQ (5s, 1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); ASSERT_TIMELY_EQ (5s, 2, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in)); ASSERT_EQ (3, node->ledger.cemented_count ()); - ASSERT_EQ (0, node->active.election_winner_details_size ()); } TEST (confirmation_callback, dependent_election) @@ -248,29 +246,4 @@ TEST (confirmation_callback, dependent_election) ASSERT_TIMELY_EQ (5s, 1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_conf_height, nano::stat::dir::out)); ASSERT_TIMELY_EQ (5s, 1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out)); ASSERT_EQ (4, node->ledger.cemented_count ()); - - ASSERT_EQ (0, node->active.election_winner_details_size ()); -} - -TEST (confirmation_callback, election_winner_details_clearing_node_process_confirmed) -{ - // Make sure election_winner_details is also cleared if the block never enters the confirmation height processor from node::process_confirmed - nano::test::system system (1); - auto node = system.nodes.front (); - - nano::block_builder builder; - auto send = builder - .send () - .previous (nano::dev::genesis->hash ()) - .destination (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount - nano::Knano_ratio) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*system.work.generate (nano::dev::genesis->hash ())) - .build (); - // Add to election_winner_details. Use an unrealistic iteration so that it should fall into the else case and do a cleanup - node->active.add_election_winner_details (send->hash (), nullptr); - nano::election_status election; - election.winner = send; - node->process_confirmed (election, 1000000); - ASSERT_EQ (0, node->active.election_winner_details_size ()); } diff --git a/nano/core_test/ledger_confirm.cpp b/nano/core_test/ledger_confirm.cpp index 1301c9ff95..f9bfeff998 100644 --- a/nano/core_test/ledger_confirm.cpp +++ b/nano/core_test/ledger_confirm.cpp @@ -752,29 +752,6 @@ TEST (ledger_confirm, observers) ASSERT_EQ (2, node1->ledger.cemented_count ()); } -TEST (ledger_confirm, election_winner_details_clearing_node_process_confirmed) -{ - // Make sure election_winner_details is also cleared if the block never enters the confirmation height processor from node::process_confirmed - nano::test::system system (1); - auto node = system.nodes.front (); - - nano::block_builder builder; - auto send = builder - .send () - .previous (nano::dev::genesis->hash ()) - .destination (nano::dev::genesis_key.pub) - .balance (nano::dev::constants.genesis_amount - nano::Knano_ratio) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*system.work.generate (nano::dev::genesis->hash ())) - .build (); - // Add to election_winner_details. Use an unrealistic iteration so that it should fall into the else case and do a cleanup - node->active.add_election_winner_details (send->hash (), nullptr); - nano::election_status election; - election.winner = send; - node->process_confirmed (election, 1000000); - ASSERT_EQ (0, node->active.election_winner_details_size ()); -} - TEST (ledger_confirm, pruned_source) { nano::test::system system; diff --git a/nano/lib/stats_enums.hpp b/nano/lib/stats_enums.hpp index ee5629ad4b..ea8c07780f 100644 --- a/nano/lib/stats_enums.hpp +++ b/nano/lib/stats_enums.hpp @@ -412,6 +412,7 @@ enum class detail // active_elections started, stopped, + confirm_dependent, // unchecked put, diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index a8fb6469bc..feafab86bf 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -25,24 +25,16 @@ nano::active_elections::active_elections (nano::node & node_a, nano::confirming_ confirming_set{ confirming_set_a }, block_processor{ block_processor_a }, recently_confirmed{ config.confirmation_cache }, - recently_cemented{ config.confirmation_history_size }, - election_time_to_live{ node_a.network_params.network.is_dev_network () ? 0s : 2s } + recently_cemented{ config.confirmation_history_size } { count_by_behavior.fill (0); // Zero initialize array confirming_set.batch_cemented.add ([this] (auto const & cemented) { auto transaction = node.ledger.tx_begin_read (); - for (auto const & [block, confirmation_root, election] : cemented) + for (auto const & [block, confirmation_root, source_election] : cemented) { transaction.refresh_if_needed (); - block_cemented_callback (transaction, block, confirmation_root); - } - }); - - confirming_set.already_cemented.add ([this] (auto const & already_cemented) { - for (auto const & hash : already_cemented) - { - block_already_cemented_callback (hash); + block_cemented (transaction, block, confirmation_root, source_election); } }); @@ -91,28 +83,31 @@ void nano::active_elections::stop () clear (); } -void nano::active_elections::block_cemented_callback (nano::secure::transaction const & transaction, std::shared_ptr const & block, nano::block_hash const & confirmation_root) +void nano::active_elections::block_cemented (nano::secure::transaction const & transaction, std::shared_ptr const & block, nano::block_hash const & confirmation_root, std::shared_ptr const & source_election) { debug_assert (node.block_confirmed (block->hash ())); - if (auto election_l = election (block->qualified_root ())) + // Dependent elections are implicitly confirmed when their block is cemented + auto dependend_election = election (block->qualified_root ()); + if (dependend_election) { - election_l->try_confirm (block->hash ()); + node.stats.inc (nano::stat::type::active_elections, nano::stat::detail::confirm_dependent); + dependend_election->try_confirm (block->hash ()); } - auto election = remove_election_winner_details (block->hash ()); + nano::election_status status; std::vector votes; status.winner = block; - if (election) - { - status = election->get_status (); - votes = election->votes_with_weight (); - } - if (block->hash () == confirmation_root) + + // Check if the currently cemented block was part of an election that triggered the confirmation + if (source_election && source_election->qualified_root == block->qualified_root ()) { + status = source_election->get_status (); + debug_assert (status.winner->hash () == block->hash ()); + votes = source_election->votes_with_weight (); status.type = nano::election_status_type::active_confirmed_quorum; } - else if (election) + else if (dependend_election) { status.type = nano::election_status_type::active_confirmation_height; } @@ -120,12 +115,16 @@ void nano::active_elections::block_cemented_callback (nano::secure::transaction { status.type = nano::election_status_type::inactive_confirmation_height; } + recently_cemented.put (status); node.stats.inc (nano::stat::type::active_elections, nano::stat::detail::cemented); node.stats.inc (nano::stat::type::active_elections_cemented, to_stat_detail (status.type)); - node.logger.trace (nano::log::type::active_elections, nano::log::detail::active_cemented, nano::log::arg{ "election", election }); + node.logger.trace (nano::log::type::active_elections, nano::log::detail::active_cemented, + nano::log::arg{ "block", block }, + nano::log::arg{ "confirmation_root", confirmation_root }, + nano::log::arg{ "source_election", source_election }); notify_observers (transaction, status, votes); @@ -185,39 +184,6 @@ void nano::active_elections::activate_successors (nano::secure::transaction cons } } -void nano::active_elections::add_election_winner_details (nano::block_hash const & hash_a, std::shared_ptr const & election_a) -{ - nano::lock_guard guard{ election_winner_details_mutex }; - election_winner_details.emplace (hash_a, election_a); -} - -std::shared_ptr nano::active_elections::remove_election_winner_details (nano::block_hash const & hash_a) -{ - std::shared_ptr result; - { - nano::lock_guard guard{ election_winner_details_mutex }; - auto existing = election_winner_details.find (hash_a); - if (existing != election_winner_details.end ()) - { - result = existing->second; - election_winner_details.erase (existing); - } - } - - vacancy_update (); - - return result; -} - -void nano::active_elections::block_already_cemented_callback (nano::block_hash const & hash_a) -{ - // Depending on timing there is a situation where the election_winner_details is not reset. - // This can happen when a block wins an election, and the block is confirmed + observer - // called before the block hash gets added to election_winner_details. If the block is confirmed - // callbacks have already been done, so we can safely just remove it. - remove_election_winner_details (hash_a); -} - int64_t nano::active_elections::limit (nano::election_behavior behavior) const { switch (behavior) @@ -265,7 +231,7 @@ int64_t nano::active_elections::vacancy (nano::election_behavior behavior) const }; auto election_winners_vacancy = [this] () -> int64_t { - return static_cast (config.max_election_winners) - static_cast (election_winner_details_size ()); + return static_cast (config.max_election_winners) - static_cast (confirming_set.size ()); }; return std::min (election_vacancy (behavior), election_winners_vacancy ()); @@ -572,12 +538,6 @@ bool nano::active_elections::publish (std::shared_ptr const & block return result; } -std::size_t nano::active_elections::election_winner_details_size () const -{ - nano::lock_guard guard{ election_winner_details_mutex }; - return election_winner_details.size (); -} - void nano::active_elections::clear () { // TODO: Call erased_callback for each election @@ -595,7 +555,6 @@ nano::container_info nano::active_elections::container_info () const nano::container_info info; info.put ("roots", roots.size ()); - info.put ("election_winner_details", election_winner_details_size ()); info.put ("normal", static_cast (count_by_behavior[nano::election_behavior::priority])); info.put ("hinted", static_cast (count_by_behavior[nano::election_behavior::hinted])); info.put ("optimistic", static_cast (count_by_behavior[nano::election_behavior::optimistic])); diff --git a/nano/node/active_elections.hpp b/nano/node/active_elections.hpp index 222d5d278d..1a76cf0448 100644 --- a/nano/node/active_elections.hpp +++ b/nano/node/active_elections.hpp @@ -123,10 +123,6 @@ class active_elections final int64_t vacancy (nano::election_behavior behavior) const; std::function vacancy_update{ [] () {} }; - std::size_t election_winner_details_size () const; - void add_election_winner_details (nano::block_hash const &, std::shared_ptr const &); - std::shared_ptr remove_election_winner_details (nano::block_hash const &); - nano::container_info container_info () const; private: @@ -139,8 +135,7 @@ class active_elections final std::vector> list_active_impl (std::size_t) const; void activate_successors (nano::secure::transaction const &, std::shared_ptr const & block); void notify_observers (nano::secure::transaction const &, nano::election_status const & status, std::vector const & votes) const; - void block_cemented_callback (nano::secure::transaction const &, std::shared_ptr const & block, nano::block_hash const & confirmation_root); - void block_already_cemented_callback (nano::block_hash const & hash); + void block_cemented (nano::secure::transaction const &, std::shared_ptr const & block, nano::block_hash const & confirmation_root, std::shared_ptr const & source_election); private: // Dependencies active_elections_config const & config; @@ -157,12 +152,6 @@ class active_elections final mutable nano::mutex mutex{ mutex_identifier (mutexes::active) }; private: - mutable nano::mutex election_winner_details_mutex{ mutex_identifier (mutexes::election_winner_details) }; - std::unordered_map> election_winner_details; - - // Maximum time an election can be kept active if it is extending the container - std::chrono::seconds const election_time_to_live; - /** Keeps track of number of elections by election behavior (normal, hinted, optimistic) */ nano::enum_array count_by_behavior{}; diff --git a/nano/node/election.cpp b/nano/node/election.cpp index 48b856a608..a8a392dbe5 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -35,18 +35,16 @@ nano::election::election (nano::node & node_a, std::shared_ptr cons last_blocks.emplace (block_a->hash (), block_a); } -void nano::election::confirm_once (nano::unique_lock & lock_a) +void nano::election::confirm_once (nano::unique_lock & lock) { - debug_assert (lock_a.owns_lock ()); + debug_assert (lock.owns_lock ()); + debug_assert (!mutex.try_lock ()); - // This must be kept above the setting of election state, as dependent confirmed elections require up to date changes to election_winner_details - nano::unique_lock election_winners_lk{ node.active.election_winner_details_mutex }; - auto just_confirmed = state_m != nano::election_state::confirmed; + bool just_confirmed = state_m != nano::election_state::confirmed; state_m = nano::election_state::confirmed; - if (just_confirmed && (node.active.election_winner_details.count (status.winner->hash ()) == 0)) + + if (just_confirmed) { - node.active.election_winner_details.emplace (status.winner->hash (), shared_from_this ()); - election_winners_lk.unlock (); status.election_end = std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()); status.election_duration = std::chrono::duration_cast (std::chrono::steady_clock::now () - election_start); status.confirmation_request_count = confirmation_request_count; @@ -62,11 +60,11 @@ void nano::election::confirm_once (nano::unique_lock & lock_a) nano::log::arg{ "qualified_root", qualified_root }, nano::log::arg{ "status", current_status_locked () }); - lock_a.unlock (); + node.confirming_set.add (status_l.winner->hash (), shared_from_this ()); - node.election_workers.push_task ([node_l = node.shared (), status_l, confirmation_action_l = confirmation_action] () { - node_l->process_confirmed (status_l); + lock.unlock (); + node.election_workers.push_task ([status_l, confirmation_action_l = confirmation_action] () { if (confirmation_action_l) { confirmation_action_l (status_l.winner); @@ -76,7 +74,7 @@ void nano::election::confirm_once (nano::unique_lock & lock_a) else { node.stats.inc (nano::stat::type::election, nano::stat::detail::confirm_once_failed); - lock_a.unlock (); + lock.unlock (); } } @@ -416,6 +414,7 @@ void nano::election::confirm_if_quorum (nano::unique_lock & lock_a) if (final_weight >= node.online_reps.delta ()) { confirm_once (lock_a); + debug_assert (!lock_a.owns_lock ()); } } } @@ -429,6 +428,7 @@ void nano::election::try_confirm (nano::block_hash const & hash) if (!confirmed_locked ()) { confirm_once (election_lock); + debug_assert (!election_lock.owns_lock ()); } } } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 5871f2cff8..b84f7539dd 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1172,7 +1172,6 @@ void nano::node::process_confirmed (nano::election_status const & status_a, uint stats.inc (nano::stat::type::process_confirmed, nano::stat::detail::timeout); // Do some cleanup due to this block never being processed by confirmation height processor - active.remove_election_winner_details (hash); } } diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index 4e4781d412..a51881b6d4 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -717,7 +717,6 @@ TEST (confirmation_height, many_accounts_single_confirmation) ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed_unbounded, nano::stat::dir::in), 0); ASSERT_TIMELY_EQ (40s, (node->ledger.cemented_count () - 1), node->stats.count (nano::stat::type::confirmation_observer, nano::stat::dir::out)); - ASSERT_TIMELY_EQ (10s, node->active.election_winner_details_size (), 0); } TEST (confirmation_height, many_accounts_many_confirmations) @@ -792,8 +791,6 @@ TEST (confirmation_height, many_accounts_many_confirmations) ASSERT_EQ (cemented_count, node->ledger.cemented_count ()); ASSERT_TIMELY_EQ (20s, (node->ledger.cemented_count () - 1), node->stats.count (nano::stat::type::confirmation_observer, nano::stat::dir::out)); - - ASSERT_TIMELY_EQ (10s, node->active.election_winner_details_size (), 0); } TEST (confirmation_height, long_chains) @@ -939,7 +936,6 @@ TEST (confirmation_height, long_chains) ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed_unbounded, nano::stat::dir::in), 0); ASSERT_TIMELY_EQ (40s, (node->ledger.cemented_count () - 1), node->stats.count (nano::stat::type::confirmation_observer, nano::stat::dir::out)); - ASSERT_TIMELY_EQ (10s, node->active.election_winner_details_size (), 0); } TEST (confirmation_height, dynamic_algorithm) @@ -987,7 +983,6 @@ TEST (confirmation_height, dynamic_algorithm) ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in), num_blocks); ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed_bounded, nano::stat::dir::in), 1); ASSERT_EQ (node->ledger.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed_unbounded, nano::stat::dir::in), num_blocks - 1); - ASSERT_TIMELY_EQ (10s, node->active.election_winner_details_size (), 0); } TEST (confirmation_height, many_accounts_send_receive_self) @@ -1118,10 +1113,6 @@ TEST (confirmation_height, many_accounts_send_receive_self) } system.deadline_set (60s); - while (node->active.election_winner_details_size () > 0) - { - ASSERT_NO_ERROR (system.poll ()); - } } // Same as the many_accounts_send_receive_self test, except works on the confirmation height processor directly From 2fa01e22d7c6d117fc0ac184c5ca0c25c0ac471c Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Tue, 15 Oct 2024 23:00:30 +0200 Subject: [PATCH 25/47] Update to RocksDb V9.7.2 (#4753) --- submodules/rocksdb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/rocksdb b/submodules/rocksdb index 41214f0b4e..d9787264a8 160000 --- a/submodules/rocksdb +++ b/submodules/rocksdb @@ -1 +1 @@ -Subproject commit 41214f0b4e05aa8123583968df039c0d35228a4f +Subproject commit d9787264a8eb0528966ded06499dff46a4f8739c From 9ff68c1cfa0b6a14e39125577c92a34c7ee03a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:54:21 +0200 Subject: [PATCH 26/47] Fix mismatched channel owners (#4750) * Move `node.inbound ()` * Assert channel owner * Fix tests --- nano/core_test/bootstrap_server.cpp | 24 +++++++-------- nano/core_test/network.cpp | 8 ++--- nano/core_test/node.cpp | 47 ++++++++++++++--------------- nano/core_test/telemetry.cpp | 4 +-- nano/core_test/websocket.cpp | 4 +-- nano/node/network.cpp | 8 ----- nano/node/network.hpp | 1 - nano/node/node.cpp | 10 ++++++ nano/node/node.hpp | 1 + nano/node/transport/channel.cpp | 5 +++ nano/node/transport/channel.hpp | 2 ++ nano/node/transport/inproc.cpp | 2 +- 12 files changed, 62 insertions(+), 54 deletions(-) diff --git a/nano/core_test/bootstrap_server.cpp b/nano/core_test/bootstrap_server.cpp index 4f37d25e43..659ecd46ba 100644 --- a/nano/core_test/bootstrap_server.cpp +++ b/nano/core_test/bootstrap_server.cpp @@ -92,7 +92,7 @@ TEST (bootstrap_server, serve_account_blocks) request.payload = request_payload; request.update_header (); - node.network.inbound (request, nano::test::fake_channel (node)); + node.inbound (request, nano::test::fake_channel (node)); ASSERT_TIMELY_EQ (5s, responses.size (), 1); @@ -137,7 +137,7 @@ TEST (bootstrap_server, serve_hash) request.payload = request_payload; request.update_header (); - node.network.inbound (request, nano::test::fake_channel (node)); + node.inbound (request, nano::test::fake_channel (node)); ASSERT_TIMELY_EQ (5s, responses.size (), 1); @@ -182,7 +182,7 @@ TEST (bootstrap_server, serve_hash_one) request.payload = request_payload; request.update_header (); - node.network.inbound (request, nano::test::fake_channel (node)); + node.inbound (request, nano::test::fake_channel (node)); ASSERT_TIMELY_EQ (5s, responses.size (), 1); @@ -221,7 +221,7 @@ TEST (bootstrap_server, serve_end_of_chain) request.payload = request_payload; request.update_header (); - node.network.inbound (request, nano::test::fake_channel (node)); + node.inbound (request, nano::test::fake_channel (node)); ASSERT_TIMELY_EQ (5s, responses.size (), 1); @@ -260,7 +260,7 @@ TEST (bootstrap_server, serve_missing) request.payload = request_payload; request.update_header (); - node.network.inbound (request, nano::test::fake_channel (node)); + node.inbound (request, nano::test::fake_channel (node)); ASSERT_TIMELY_EQ (5s, responses.size (), 1); @@ -303,7 +303,7 @@ TEST (bootstrap_server, serve_multiple) request.payload = request_payload; request.update_header (); - node.network.inbound (request, nano::test::fake_channel (node)); + node.inbound (request, nano::test::fake_channel (node)); } } @@ -359,7 +359,7 @@ TEST (bootstrap_server, serve_account_info) request.payload = request_payload; request.update_header (); - node.network.inbound (request, nano::test::fake_channel (node)); + node.inbound (request, nano::test::fake_channel (node)); ASSERT_TIMELY_EQ (5s, responses.size (), 1); @@ -405,7 +405,7 @@ TEST (bootstrap_server, serve_account_info_missing) request.payload = request_payload; request.update_header (); - node.network.inbound (request, nano::test::fake_channel (node)); + node.inbound (request, nano::test::fake_channel (node)); ASSERT_TIMELY_EQ (5s, responses.size (), 1); @@ -450,7 +450,7 @@ TEST (bootstrap_server, serve_frontiers) request.payload = request_payload; request.update_header (); - node.network.inbound (request, nano::test::fake_channel (node)); + node.inbound (request, nano::test::fake_channel (node)); ASSERT_TIMELY_EQ (5s, responses.size (), 1); @@ -503,7 +503,7 @@ TEST (bootstrap_server, serve_frontiers_invalid_count) request.payload = request_payload; request.update_header (); - node.network.inbound (request, nano::test::fake_channel (node)); + node.inbound (request, nano::test::fake_channel (node)); } ASSERT_TIMELY_EQ (5s, node.stats.count (nano::stat::type::bootstrap_server, nano::stat::detail::invalid), 1); @@ -521,7 +521,7 @@ TEST (bootstrap_server, serve_frontiers_invalid_count) request.payload = request_payload; request.update_header (); - node.network.inbound (request, nano::test::fake_channel (node)); + node.inbound (request, nano::test::fake_channel (node)); } ASSERT_TIMELY_EQ (5s, node.stats.count (nano::stat::type::bootstrap_server, nano::stat::detail::invalid), 2); @@ -539,7 +539,7 @@ TEST (bootstrap_server, serve_frontiers_invalid_count) request.payload = request_payload; request.update_header (); - node.network.inbound (request, nano::test::fake_channel (node)); + node.inbound (request, nano::test::fake_channel (node)); } ASSERT_TIMELY_EQ (5s, node.stats.count (nano::stat::type::bootstrap_server, nano::stat::detail::invalid), 3); diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index eb4713f946..c06b28bfd2 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -377,7 +377,7 @@ TEST (receivable_processor, confirm_insufficient_pos) nano::confirm_ack con1{ nano::dev::network_params.network, vote }; auto channel1 = std::make_shared (node1, node1); ASSERT_EQ (1, election->votes ().size ()); - node1.network.inbound (con1, channel1); + node1.inbound (con1, channel1); ASSERT_TIMELY_EQ (5s, 2, election->votes ().size ()) ASSERT_FALSE (election->confirmed ()); } @@ -402,7 +402,7 @@ TEST (receivable_processor, confirm_sufficient_pos) nano::confirm_ack con1{ nano::dev::network_params.network, vote }; auto channel1 = std::make_shared (node1, node1); ASSERT_EQ (1, election->votes ().size ()); - node1.network.inbound (con1, channel1); + node1.inbound (con1, channel1); ASSERT_TIMELY_EQ (5s, 2, election->votes ().size ()) ASSERT_TRUE (election->confirmed ()); } @@ -743,10 +743,10 @@ TEST (network, duplicate_revert_publish) auto channel = nano::test::establish_tcp (system, *other_node, node.network.endpoint ()); ASSERT_NE (nullptr, channel); ASSERT_EQ (0, publish.digest); - node.network.inbound (publish, channel); + node.inbound (publish, nano::test::fake_channel (node)); ASSERT_TRUE (node.network.filter.apply (bytes.data (), bytes.size ())); publish.digest = digest; - node.network.inbound (publish, channel); + node.inbound (publish, nano::test::fake_channel (node)); ASSERT_FALSE (node.network.filter.apply (bytes.data (), bytes.size ())); } diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 54d1ef29f6..86cb7d2581 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -688,16 +688,15 @@ TEST (node, fork_flip) .work (*system.work.generate (nano::dev::genesis->hash ())) .build (); nano::publish publish2{ nano::dev::network_params.network, send2 }; - auto ignored_channel = nano::test::fake_channel (node1); - node1.network.inbound (publish1, ignored_channel); - node2.network.inbound (publish2, ignored_channel); + node1.inbound (publish1, nano::test::fake_channel (node1)); + node2.inbound (publish2, nano::test::fake_channel (node2)); ASSERT_TIMELY_EQ (5s, 1, node1.active.size ()); ASSERT_TIMELY_EQ (5s, 1, node2.active.size ()); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); // Fill nodes with forked blocks - node1.network.inbound (publish2, ignored_channel); + node1.inbound (publish2, nano::test::fake_channel (node1)); ASSERT_TIMELY (5s, node1.active.active (*send2)); - node2.network.inbound (publish1, ignored_channel); + node2.inbound (publish1, nano::test::fake_channel (node2)); ASSERT_TIMELY (5s, node2.active.active (*send1)); auto election1 (node2.active.election (nano::qualified_root (nano::dev::genesis->hash (), nano::dev::genesis->hash ()))); ASSERT_NE (nullptr, election1); @@ -829,7 +828,7 @@ TEST (node, fork_open) .build (); nano::publish publish1{ nano::dev::network_params.network, send1 }; auto channel1 = std::make_shared (node); - node.network.inbound (publish1, channel1); + node.inbound (publish1, channel1); ASSERT_TIMELY (5s, (election = node.active.election (publish1.block->qualified_root ())) != nullptr); election->force_confirm (); ASSERT_TIMELY (5s, node.active.empty () && node.block_confirmed (publish1.block->hash ())); @@ -848,7 +847,7 @@ TEST (node, fork_open) .work (*system.work.generate (key1.pub)) .build (); nano::publish publish2{ nano::dev::network_params.network, open1 }; - node.network.inbound (publish2, channel1); + node.inbound (publish2, channel1); ASSERT_TIMELY_EQ (5s, 1, node.active.size ()); // create 2nd open block, which is a fork of open1 block @@ -860,7 +859,7 @@ TEST (node, fork_open) .work (*system.work.generate (key1.pub)) .build (); nano::publish publish3{ nano::dev::network_params.network, open2 }; - node.network.inbound (publish3, channel1); + node.inbound (publish3, channel1); ASSERT_TIMELY (5s, (election = node.active.election (publish3.block->qualified_root ())) != nullptr); // we expect to find 2 blocks in the election and we expect the first block to be the winner just because it was first @@ -1856,14 +1855,14 @@ TEST (node, DISABLED_local_votes_cache) nano::confirm_req message1{ nano::dev::network_params.network, send1->hash (), send1->root () }; nano::confirm_req message2{ nano::dev::network_params.network, send2->hash (), send2->root () }; auto channel = std::make_shared (node); - node.network.inbound (message1, channel); + node.inbound (message1, channel); ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::requests, nano::stat::detail::requests_generated_votes), 1); - node.network.inbound (message2, channel); + node.inbound (message2, channel); ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::requests, nano::stat::detail::requests_generated_votes), 2); for (auto i (0); i < 100; ++i) { - node.network.inbound (message1, channel); - node.network.inbound (message2, channel); + node.inbound (message1, channel); + node.inbound (message2, channel); } // Make sure a new vote was not generated ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::requests, nano::stat::detail::requests_generated_votes), 2); @@ -1873,7 +1872,7 @@ TEST (node, DISABLED_local_votes_cache) ASSERT_EQ (nano::block_status::progress, node.ledger.process (transaction, send3)); } nano::confirm_req message3{ nano::dev::network_params.network, send3->hash (), send3->root () }; - node.network.inbound (message3, channel); + node.inbound (message3, channel); ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::requests, nano::stat::detail::requests_generated_votes), 3); ASSERT_TIMELY (3s, !node.history.votes (send1->root (), send1->hash ()).empty ()); ASSERT_TIMELY (3s, !node.history.votes (send2->root (), send2->hash ()).empty ()); @@ -1881,7 +1880,7 @@ TEST (node, DISABLED_local_votes_cache) // All requests should be served from the cache for (auto i (0); i < 100; ++i) { - node.network.inbound (message3, channel); + node.inbound (message3, channel); } ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::requests, nano::stat::detail::requests_generated_votes), 3); } @@ -1935,26 +1934,26 @@ TEST (node, DISABLED_local_votes_cache_batch) nano::confirm_req message{ nano::dev::network_params.network, batch }; auto channel = std::make_shared (node); // Generates and sends one vote for both hashes which is then cached - node.network.inbound (message, channel); + node.inbound (message, channel); ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out), 1); ASSERT_EQ (1, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out)); ASSERT_FALSE (node.history.votes (send2->root (), send2->hash ()).empty ()); ASSERT_FALSE (node.history.votes (receive1->root (), receive1->hash ()).empty ()); // Only one confirm_ack should be sent if all hashes are part of the same vote - node.network.inbound (message, channel); + node.inbound (message, channel); ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out), 2); ASSERT_EQ (2, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out)); // Test when votes are different node.history.erase (send2->root ()); node.history.erase (receive1->root ()); - node.network.inbound (nano::confirm_req{ nano::dev::network_params.network, send2->hash (), send2->root () }, channel); + node.inbound (nano::confirm_req{ nano::dev::network_params.network, send2->hash (), send2->root () }, channel); ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out), 3); ASSERT_EQ (3, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out)); - node.network.inbound (nano::confirm_req{ nano::dev::network_params.network, receive1->hash (), receive1->root () }, channel); + node.inbound (nano::confirm_req{ nano::dev::network_params.network, receive1->hash (), receive1->root () }, channel); ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out), 4); ASSERT_EQ (4, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out)); // There are two different votes, so both should be sent in response - node.network.inbound (message, channel); + node.inbound (message, channel); ASSERT_TIMELY_EQ (3s, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out), 6); ASSERT_EQ (6, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out)); } @@ -1975,7 +1974,7 @@ TEST (node, DISABLED_local_votes_cache_generate_new_vote) // Send a confirm req for genesis block to node nano::confirm_req message1{ nano::dev::network_params.network, nano::dev::genesis->hash (), nano::dev::genesis->root () }; auto channel = std::make_shared (node); - node.network.inbound (message1, channel); + node.inbound (message1, channel); // check that the node generated a vote for the genesis block and that it is stored in the local vote cache and it is the only vote ASSERT_TIMELY (5s, !node.history.votes (nano::dev::genesis->root (), nano::dev::genesis->hash ()).empty ()); @@ -1998,7 +1997,7 @@ TEST (node, DISABLED_local_votes_cache_generate_new_vote) // One of the hashes is cached std::vector> roots_hashes{ std::make_pair (nano::dev::genesis->hash (), nano::dev::genesis->root ()), std::make_pair (send1->hash (), send1->root ()) }; nano::confirm_req message2{ nano::dev::network_params.network, roots_hashes }; - node.network.inbound (message2, channel); + node.inbound (message2, channel); ASSERT_TIMELY (3s, !node.history.votes (send1->root (), send1->hash ()).empty ()); auto votes2 (node.history.votes (send1->root (), send1->hash ())); ASSERT_EQ (1, votes2.size ()); @@ -2441,13 +2440,13 @@ TEST (node, fork_election_invalid_block_signature) .build (); auto channel1 = std::make_shared (node1); - node1.network.inbound (nano::publish{ nano::dev::network_params.network, send1 }, channel1); + node1.inbound (nano::publish{ nano::dev::network_params.network, send1 }, channel1); ASSERT_TIMELY (5s, node1.active.active (send1->qualified_root ())); auto election (node1.active.election (send1->qualified_root ())); ASSERT_NE (nullptr, election); ASSERT_EQ (1, election->blocks ().size ()); - node1.network.inbound (nano::publish{ nano::dev::network_params.network, send3 }, channel1); - node1.network.inbound (nano::publish{ nano::dev::network_params.network, send2 }, channel1); + node1.inbound (nano::publish{ nano::dev::network_params.network, send3 }, channel1); + node1.inbound (nano::publish{ nano::dev::network_params.network, send2 }, channel1); ASSERT_TIMELY (3s, election->blocks ().size () > 1); ASSERT_EQ (election->blocks ()[send2->hash ()]->block_signature (), send2->block_signature ()); } diff --git a/nano/core_test/telemetry.cpp b/nano/core_test/telemetry.cpp index 4ebe65c5c9..750d18b99b 100644 --- a/nano/core_test/telemetry.cpp +++ b/nano/core_test/telemetry.cpp @@ -253,7 +253,7 @@ TEST (telemetry, invalid_signature) telemetry.block_count = 9999; // Change data so signature is no longer valid auto message = nano::telemetry_ack{ nano::dev::network_params.network, telemetry }; - node.network.inbound (message, nano::test::fake_channel (node)); + node.inbound (message, nano::test::fake_channel (node)); ASSERT_TIMELY (5s, node.stats.count (nano::stat::type::telemetry, nano::stat::detail::invalid_signature) > 0); ASSERT_ALWAYS (1s, node.stats.count (nano::stat::type::telemetry, nano::stat::detail::process) == 0) @@ -267,7 +267,7 @@ TEST (telemetry, mismatched_node_id) auto telemetry = node.local_telemetry (); auto message = nano::telemetry_ack{ nano::dev::network_params.network, telemetry }; - node.network.inbound (message, nano::test::fake_channel (node, /* node id */ { 123 })); + node.inbound (message, nano::test::fake_channel (node, /* node id */ { 123 })); ASSERT_TIMELY (5s, node.stats.count (nano::stat::type::telemetry, nano::stat::detail::node_id_mismatch) > 0); ASSERT_ALWAYS (1s, node.stats.count (nano::stat::type::telemetry, nano::stat::detail::process) == 0) diff --git a/nano/core_test/websocket.cpp b/nano/core_test/websocket.cpp index dacfd7b10e..5305b518e1 100644 --- a/nano/core_test/websocket.cpp +++ b/nano/core_test/websocket.cpp @@ -165,7 +165,7 @@ TEST (websocket, started_election) .build (); nano::publish publish1{ nano::dev::network_params.network, send1 }; auto channel1 = std::make_shared (*node1); - node1->network.inbound (publish1, channel1); + node1->inbound (publish1, channel1); ASSERT_TIMELY (1s, node1->active.election (send1->qualified_root ())); ASSERT_TIMELY_EQ (5s, future.wait_for (0s), std::future_status::ready); @@ -213,7 +213,7 @@ TEST (websocket, stopped_election) .build (); nano::publish publish1{ nano::dev::network_params.network, send1 }; auto channel1 = std::make_shared (*node1); - node1->network.inbound (publish1, channel1); + node1->inbound (publish1, channel1); ASSERT_TIMELY (5s, node1->active.election (send1->qualified_root ())); node1->active.erase (*send1); diff --git a/nano/node/network.cpp b/nano/node/network.cpp index d780f634e8..a764f45309 100644 --- a/nano/node/network.cpp +++ b/nano/node/network.cpp @@ -314,14 +314,6 @@ void nano::network::flood_block_many (std::deque> b } } -void nano::network::inbound (const nano::message & message, const std::shared_ptr & channel) -{ - debug_assert (message.header.network == node.network_params.network.current_network); - debug_assert (message.header.version_using >= node.network_params.network.protocol_version_min); - - node.message_processor.process (message, channel); -} - // Send keepalives to all the peers we've been notified of void nano::network::merge_peers (std::array const & peers_a) { diff --git a/nano/node/network.hpp b/nano/node/network.hpp index f8aac622b0..5aa6ec8772 100644 --- a/nano/node/network.hpp +++ b/nano/node/network.hpp @@ -127,7 +127,6 @@ class network final void erase (nano::transport::channel const &); /** Disconnects and adds peer to exclusion list */ void exclude (std::shared_ptr const & channel); - void inbound (nano::message const &, std::shared_ptr const &); nano::container_info container_info () const; diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 3cda7ce369..ceb034f361 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -518,6 +518,16 @@ void nano::node::keepalive (std::string const & address_a, uint16_t port_a) }); } +void nano::node::inbound (const nano::message & message, const std::shared_ptr & channel) +{ + debug_assert (channel->owner () == shared_from_this ()); // This node should be the channel owner + + debug_assert (message.header.network == network_params.network.current_network); + debug_assert (message.header.version_using >= network_params.network.protocol_version_min); + + message_processor.process (message, channel); +} + void nano::node::process_active (std::shared_ptr const & incoming) { block_processor.add (incoming); diff --git a/nano/node/node.hpp b/nano/node/node.hpp index c411b6d9a5..af5f0e41d0 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -94,6 +94,7 @@ class node final : public std::enable_shared_from_this bool copy_with_compaction (std::filesystem::path const &); void keepalive (std::string const &, uint16_t); int store_version (); + void inbound (nano::message const &, std::shared_ptr const &); void process_confirmed (nano::election_status const &, uint64_t = 0); void process_active (std::shared_ptr const &); std::optional process_local (std::shared_ptr const &); diff --git a/nano/node/transport/channel.cpp b/nano/node/transport/channel.cpp index 1837044490..6c31d95b52 100644 --- a/nano/node/transport/channel.cpp +++ b/nano/node/transport/channel.cpp @@ -63,6 +63,11 @@ nano::endpoint nano::transport::channel::get_peering_endpoint () const } } +std::shared_ptr nano::transport::channel::owner () const +{ + return node.shared (); +} + void nano::transport::channel::operator() (nano::object_stream & obs) const { obs.write ("endpoint", get_endpoint ()); diff --git a/nano/node/transport/channel.hpp b/nano/node/transport/channel.hpp index e01cc8c579..184168823b 100644 --- a/nano/node/transport/channel.hpp +++ b/nano/node/transport/channel.hpp @@ -130,6 +130,8 @@ class channel nano::endpoint get_peering_endpoint () const; void set_peering_endpoint (nano::endpoint endpoint); + std::shared_ptr owner () const; + mutable nano::mutex channel_mutex; private: diff --git a/nano/node/transport/inproc.cpp b/nano/node/transport/inproc.cpp index c1cf7a5b9f..abeca40067 100644 --- a/nano/node/transport/inproc.cpp +++ b/nano/node/transport/inproc.cpp @@ -44,7 +44,7 @@ void nano::transport::inproc::channel::send_buffer (nano::shared_const_buffer co // process message { node.stats.inc (nano::stat::type::message, to_stat_detail (message_a->type ()), nano::stat::dir::in); - destination.network.inbound (*message_a, remote_channel); + destination.inbound (*message_a, remote_channel); } }); From b9f02254d089cff922fb7f98c8bdb350909065ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:01:00 +0200 Subject: [PATCH 27/47] Fix test --- nano/core_test/active_elections.cpp | 18 +++++------------- nano/node/active_elections.cpp | 8 ++------ nano/node/confirming_set.cpp | 7 ++++++- nano/node/confirming_set.hpp | 5 +++-- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/nano/core_test/active_elections.cpp b/nano/core_test/active_elections.cpp index 05c243aa3e..9bd1d6c204 100644 --- a/nano/core_test/active_elections.cpp +++ b/nano/core_test/active_elections.cpp @@ -1398,6 +1398,8 @@ TEST (active_elections, bound_election_winners) nano::node_config config = system.default_config (); // Set election winner limit to a low value config.active_elections.max_election_winners = 5; + // Large batch size would complicate this testcase + config.confirming_set.batch_size = 1; auto & node = *system.add_node (config); // Start elections for a couple of blocks, number of elections is larger than the election winner set limit @@ -1411,22 +1413,12 @@ TEST (active_elections, bound_election_winners) auto guard = node.ledger.tx_begin_write (nano::store::writer::testing); // Ensure that when the number of election winners reaches the limit, AEC vacancy reflects that + // Confirming more elections should make the vacancy negative ASSERT_TRUE (node.active.vacancy (nano::election_behavior::priority) > 0); - int index = 0; - for (; index < config.active_elections.max_election_winners; ++index) - { - auto election = node.vote_router.election (blocks[index]->hash ()); - ASSERT_TRUE (election); - election->force_confirm (); - } - - ASSERT_TIMELY_EQ (5s, node.active.vacancy (nano::election_behavior::priority), 0); - - // Confirming more elections should make the vacancy negative - for (; index < blocks.size (); ++index) + for (auto const & block : blocks) { - auto election = node.vote_router.election (blocks[index]->hash ()); + auto election = node.vote_router.election (block->hash ()); ASSERT_TRUE (election); election->force_confirm (); } diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index feafab86bf..0cc4953f0e 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -40,13 +40,9 @@ nano::active_elections::active_elections (nano::node & node_a, nano::confirming_ // Notify elections about alternative (forked) blocks block_processor.block_processed.add ([this] (auto const & result, auto const & context) { - switch (result) + if (result == nano::block_status::fork) { - case nano::block_status::fork: - publish (context.block); - break; - default: - break; + publish (context.block); } }); } diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index de92e853a9..d669153bbb 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -48,6 +48,11 @@ void nano::confirming_set::start () { debug_assert (!thread.joinable ()); + if (!config.enable) + { + return; + } + thread = std::thread{ [this] () { nano::thread_role::set (nano::thread_role::name::confirmation_height); run (); @@ -123,7 +128,7 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) std::deque cemented; std::deque already; - auto batch = next_batch (batch_size); + auto batch = next_batch (config.batch_size); lock.unlock (); diff --git a/nano/node/confirming_set.hpp b/nano/node/confirming_set.hpp index 00329fea83..7085b5baa3 100644 --- a/nano/node/confirming_set.hpp +++ b/nano/node/confirming_set.hpp @@ -28,6 +28,9 @@ class confirming_set_config final // TODO: Serialization & deserialization public: + bool enable{ true }; + size_t batch_size{ 256 }; + /** Maximum number of dependent blocks to be stored in memory during processing */ size_t max_blocks{ 128 * 1024 }; size_t max_queued_notifications{ 8 }; @@ -106,7 +109,5 @@ class confirming_set final mutable std::mutex mutex; std::condition_variable condition; std::thread thread; - - static size_t constexpr batch_size = 256; }; } From c440cc1c8d4d593364f4ef0c7039f1f60b92f3e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:49:48 +0200 Subject: [PATCH 28/47] Log digest of docker image --- ci/actions/linux/docker-impl/docker-common.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ci/actions/linux/docker-impl/docker-common.sh b/ci/actions/linux/docker-impl/docker-common.sh index 912558b12c..c3e6b1c29d 100755 --- a/ci/actions/linux/docker-impl/docker-common.sh +++ b/ci/actions/linux/docker-impl/docker-common.sh @@ -134,7 +134,22 @@ docker_login() push_docker_image() { local image_name=$1 + + # Log the image name before pushing + echo "Pushing image: $image_name" + + # Push the image "$scripts"/custom-timeout.sh 30 docker push "$image_name" + + # After pushing, get the digest from the local image manifest + local digest + digest=$(docker image inspect --format='{{index .RepoDigests 0}}' "$image_name") + + if [ -n "$digest" ]; then + echo "::notice::Hash: $digest $image_name" + else + echo "::error::Could not retrieve digest for image $image_name" + fi } deploy_env_images() @@ -154,7 +169,7 @@ deploy_tags() local exclude_pattern=$2 local tags=$(docker images --format '{{.Repository}}:{{.Tag }}' | grep "$repo" | grep -vE "$exclude_pattern") - #Debug list all tags + # Debug list all tags docker images --format '{{.Repository}}:{{.Tag }}' for tag in $tags; do From 6542a7851f57edcbec2925d0fe812fb404f437ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:30:05 +0200 Subject: [PATCH 29/47] Fix confirming set contains check --- nano/node/confirming_set.cpp | 13 ++++++++++++- nano/node/confirming_set.hpp | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index d669153bbb..40216e447f 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -76,7 +76,7 @@ void nano::confirming_set::stop () bool nano::confirming_set::contains (nano::block_hash const & hash) const { std::lock_guard lock{ mutex }; - return set.get ().contains (hash); + return set.get ().contains (hash) || current.contains (hash); } std::size_t nano::confirming_set::size () const @@ -130,6 +130,13 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) auto batch = next_batch (config.batch_size); + // Keep track of the blocks we're currently cementing, so that the .contains (...) check is accurate + debug_assert (current.empty ()); + for (auto const & [hash, election] : batch) + { + current.insert (hash); + } + lock.unlock (); auto notify = [this, &cemented] () { @@ -218,6 +225,10 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) release_assert (cemented.empty ()); already_cemented.notify (already); + + lock.lock (); + current.clear (); + lock.unlock (); } nano::container_info nano::confirming_set::container_info () const diff --git a/nano/node/confirming_set.hpp b/nano/node/confirming_set.hpp index 7085b5baa3..71214e56dd 100644 --- a/nano/node/confirming_set.hpp +++ b/nano/node/confirming_set.hpp @@ -102,6 +102,7 @@ class confirming_set final // clang-format on ordered_entries set; + std::unordered_set current; nano::thread_pool notification_workers; From 46696f7646a3708c7a607f3850d1d99719b84da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 17 Oct 2024 23:19:17 +0200 Subject: [PATCH 30/47] Debug log cemented blocks --- nano/core_test/confirming_set.cpp | 8 ++++---- nano/lib/logging_enums.hpp | 1 + nano/lib/stats_enums.hpp | 1 + nano/node/confirming_set.cpp | 22 +++++++++++++++++++--- nano/node/confirming_set.hpp | 3 ++- nano/node/node.cpp | 2 +- nano/test_common/ledger_context.cpp | 9 +++++++-- nano/test_common/ledger_context.hpp | 5 +++-- 8 files changed, 38 insertions(+), 13 deletions(-) diff --git a/nano/core_test/confirming_set.cpp b/nano/core_test/confirming_set.cpp index a2b3d60803..ee7302eba6 100644 --- a/nano/core_test/confirming_set.cpp +++ b/nano/core_test/confirming_set.cpp @@ -20,14 +20,14 @@ TEST (confirming_set, construction) { auto ctx = nano::test::ledger_empty (); nano::confirming_set_config config{}; - nano::confirming_set confirming_set{ config, ctx.ledger (), ctx.stats () }; + nano::confirming_set confirming_set{ config, ctx.ledger (), ctx.stats (), ctx.logger () }; } TEST (confirming_set, add_exists) { auto ctx = nano::test::ledger_send_receive (); nano::confirming_set_config config{}; - nano::confirming_set confirming_set{ config, ctx.ledger (), ctx.stats () }; + nano::confirming_set confirming_set{ config, ctx.ledger (), ctx.stats (), ctx.logger () }; auto send = ctx.blocks ()[0]; confirming_set.add (send->hash ()); ASSERT_TRUE (confirming_set.contains (send->hash ())); @@ -37,7 +37,7 @@ TEST (confirming_set, process_one) { auto ctx = nano::test::ledger_send_receive (); nano::confirming_set_config config{}; - nano::confirming_set confirming_set{ config, ctx.ledger (), ctx.stats () }; + nano::confirming_set confirming_set{ config, ctx.ledger (), ctx.stats (), ctx.logger () }; std::atomic count = 0; std::mutex mutex; std::condition_variable condition; @@ -54,7 +54,7 @@ TEST (confirming_set, process_multiple) { auto ctx = nano::test::ledger_send_receive (); nano::confirming_set_config config{}; - nano::confirming_set confirming_set{ config, ctx.ledger (), ctx.stats () }; + nano::confirming_set confirming_set{ config, ctx.ledger (), ctx.stats (), ctx.logger () }; std::atomic count = 0; std::mutex mutex; std::condition_variable condition; diff --git a/nano/lib/logging_enums.hpp b/nano/lib/logging_enums.hpp index 922c62baa1..85136b98b7 100644 --- a/nano/lib/logging_enums.hpp +++ b/nano/lib/logging_enums.hpp @@ -82,6 +82,7 @@ enum class type message_processor, local_block_broadcaster, monitor, + confirming_set, // bootstrap bulk_pull_client, diff --git a/nano/lib/stats_enums.hpp b/nano/lib/stats_enums.hpp index ea8c07780f..1e3889d180 100644 --- a/nano/lib/stats_enums.hpp +++ b/nano/lib/stats_enums.hpp @@ -505,6 +505,7 @@ enum class detail already_cemented, cementing, cemented_hash, + cementing_failed, // election_state passive, diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index 40216e447f..4d8d145084 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -6,10 +7,11 @@ #include #include -nano::confirming_set::confirming_set (confirming_set_config const & config_a, nano::ledger & ledger_a, nano::stats & stats_a) : +nano::confirming_set::confirming_set (confirming_set_config const & config_a, nano::ledger & ledger_a, nano::stats & stats_a, nano::logger & logger_a) : config{ config_a }, ledger{ ledger_a }, stats{ stats_a }, + logger{ logger_a }, notification_workers{ 1, nano::thread_role::name::confirmation_height_notifications } { batch_cemented.add ([this] (auto const & cemented) { @@ -177,6 +179,8 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) auto transaction = ledger.tx_begin_write (nano::store::writer::confirmation_height); for (auto const & [hash, election] : batch) { + size_t cemented_count = 0; + bool success = false; do { transaction.refresh_if_needed (); @@ -208,6 +212,7 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) { cemented.push_back ({ block, hash, election }); } + cemented_count += added.size (); } else { @@ -215,9 +220,20 @@ void nano::confirming_set::run_batch (std::unique_lock & lock) already.push_back (hash); debug_assert (ledger.confirmed.block_exists (transaction, hash)); } - } while (!ledger.confirmed.block_exists (transaction, hash)); - stats.inc (nano::stat::type::confirming_set, nano::stat::detail::cemented_hash); + success = ledger.confirmed.block_exists (transaction, hash); + } while (!success); + + if (success) + { + stats.inc (nano::stat::type::confirming_set, nano::stat::detail::cemented_hash); + logger.debug (nano::log::type::confirming_set, "Cemented block: {} (total cemented: {})", hash.to_string (), cemented_count); + } + else + { + stats.inc (nano::stat::type::confirming_set, nano::stat::detail::cementing_failed); + logger.debug (nano::log::type::confirming_set, "Failed to cement block: {}", hash.to_string ()); + } } } diff --git a/nano/node/confirming_set.hpp b/nano/node/confirming_set.hpp index 71214e56dd..99569ce1e6 100644 --- a/nano/node/confirming_set.hpp +++ b/nano/node/confirming_set.hpp @@ -45,7 +45,7 @@ class confirming_set final friend class confirmation_height_pruned_source_Test; public: - confirming_set (confirming_set_config const &, nano::ledger &, nano::stats &); + confirming_set (confirming_set_config const &, nano::ledger &, nano::stats &, nano::logger &); ~confirming_set (); void start (); @@ -76,6 +76,7 @@ class confirming_set final confirming_set_config const & config; nano::ledger & ledger; nano::stats & stats; + nano::logger & logger; private: struct entry diff --git a/nano/node/node.cpp b/nano/node/node.cpp index b84f7539dd..da9b9c5dfd 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -115,7 +115,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy port_mapping_impl{ std::make_unique (*this) }, port_mapping{ *port_mapping_impl }, block_processor (*this), - confirming_set_impl{ std::make_unique (config.confirming_set, ledger, stats) }, + confirming_set_impl{ std::make_unique (config.confirming_set, ledger, stats, logger) }, confirming_set{ *confirming_set_impl }, active_impl{ std::make_unique (*this, confirming_set, block_processor) }, active{ *active_impl }, diff --git a/nano/test_common/ledger_context.cpp b/nano/test_common/ledger_context.cpp index 578aaa6342..e9a6b33c49 100644 --- a/nano/test_common/ledger_context.cpp +++ b/nano/test_common/ledger_context.cpp @@ -4,8 +4,8 @@ #include nano::test::ledger_context::ledger_context (std::deque> && blocks) : - store_m{ nano::make_store (logger, nano::unique_path (), nano::dev::constants) }, - stats_m{ logger }, + store_m{ nano::make_store (logger_m, nano::unique_path (), nano::dev::constants) }, + stats_m{ logger_m }, ledger_m{ *store_m, stats_m, nano::dev::constants }, blocks_m{ blocks }, pool_m{ nano::dev::network_params.network, 1 } @@ -35,6 +35,11 @@ nano::stats & nano::test::ledger_context::stats () return stats_m; } +nano::logger & nano::test::ledger_context::logger () +{ + return logger_m; +} + std::deque> const & nano::test::ledger_context::blocks () const { return blocks_m; diff --git a/nano/test_common/ledger_context.hpp b/nano/test_common/ledger_context.hpp index 8edca08508..62b376a4fd 100644 --- a/nano/test_common/ledger_context.hpp +++ b/nano/test_common/ledger_context.hpp @@ -16,12 +16,13 @@ class ledger_context ledger_context (std::deque> && blocks = std::deque>{}); nano::ledger & ledger (); nano::store::component & store (); - nano::stats & stats (); std::deque> const & blocks () const; nano::work_pool & pool (); + nano::stats & stats (); + nano::logger & logger (); private: - nano::logger logger; + nano::logger logger_m; std::unique_ptr store_m; nano::stats stats_m; nano::ledger ledger_m; From 4b9a64211f48d6c44637490c341de240cdde9a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 18 Oct 2024 00:09:37 +0200 Subject: [PATCH 31/47] Use `node::process_confirmed ()` --- nano/core_test/confirming_set.cpp | 3 +-- nano/core_test/election_scheduler.cpp | 4 ++-- nano/core_test/node.cpp | 12 ++++++------ nano/node/election.cpp | 8 +++++--- nano/node/node.cpp | 27 +++++++++++++-------------- nano/node/node.hpp | 2 +- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/nano/core_test/confirming_set.cpp b/nano/core_test/confirming_set.cpp index ee7302eba6..596f65444c 100644 --- a/nano/core_test/confirming_set.cpp +++ b/nano/core_test/confirming_set.cpp @@ -170,8 +170,7 @@ TEST (confirmation_callback, confirmed_history) ASSERT_TIMELY (10s, !node->store.write_queue.contains (nano::store::writer::confirmation_height)); - auto transaction = node->ledger.tx_begin_read (); - ASSERT_TRUE (node->ledger.confirmed.block_exists (transaction, send->hash ())); + ASSERT_TIMELY (5s, node->ledger.confirmed.block_exists (node->ledger.tx_begin_read (), send->hash ())); ASSERT_TIMELY_EQ (10s, node->active.size (), 0); ASSERT_TIMELY_EQ (10s, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out), 1); diff --git a/nano/core_test/election_scheduler.cpp b/nano/core_test/election_scheduler.cpp index 56c1a5c7b8..14f840d4fa 100644 --- a/nano/core_test/election_scheduler.cpp +++ b/nano/core_test/election_scheduler.cpp @@ -195,7 +195,7 @@ TEST (election_scheduler, no_vacancy) .work (*system.work.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, node.process (send)); - node.process_confirmed (nano::election_status{ send }); + node.process_confirmed (send->hash ()); auto receive = builder.make_block () .account (key.pub) @@ -207,7 +207,7 @@ TEST (election_scheduler, no_vacancy) .work (*system.work.generate (key.pub)) .build (); ASSERT_EQ (nano::block_status::progress, node.process (receive)); - node.process_confirmed (nano::election_status{ receive }); + node.process_confirmed (receive->hash ()); ASSERT_TIMELY (5s, nano::test::confirmed (node, { send, receive })); diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 54d1ef29f6..218ceb23d8 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -3564,9 +3564,9 @@ TEST (node, pruning_automatic) ASSERT_TIMELY (5s, node1.block (send2->hash ()) != nullptr); // Force-confirm both blocks - node1.process_confirmed (nano::election_status{ send1 }); + node1.process_confirmed (send1->hash ()); ASSERT_TIMELY (5s, node1.block_confirmed (send1->hash ())); - node1.process_confirmed (nano::election_status{ send2 }); + node1.process_confirmed (send2->hash ()); ASSERT_TIMELY (5s, node1.block_confirmed (send2->hash ())); // Check pruning result @@ -3615,9 +3615,9 @@ TEST (node, DISABLED_pruning_age) node1.process_active (send2); // Force-confirm both blocks - node1.process_confirmed (nano::election_status{ send1 }); + node1.process_confirmed (send1->hash ()); ASSERT_TIMELY (5s, node1.block_confirmed (send1->hash ())); - node1.process_confirmed (nano::election_status{ send2 }); + node1.process_confirmed (send2->hash ()); ASSERT_TIMELY (5s, node1.block_confirmed (send2->hash ())); // Three blocks in total, nothing pruned yet @@ -3676,9 +3676,9 @@ TEST (node, DISABLED_pruning_depth) node1.process_active (send2); // Force-confirm both blocks - node1.process_confirmed (nano::election_status{ send1 }); + node1.process_confirmed (send1->hash ()); ASSERT_TIMELY (5s, node1.block_confirmed (send1->hash ())); - node1.process_confirmed (nano::election_status{ send2 }); + node1.process_confirmed (send2->hash ()); ASSERT_TIMELY (5s, node1.block_confirmed (send2->hash ())); // Three blocks in total, nothing pruned yet diff --git a/nano/node/election.cpp b/nano/node/election.cpp index a8a392dbe5..93b9e8f7dc 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -60,11 +60,13 @@ void nano::election::confirm_once (nano::unique_lock & lock) nano::log::arg{ "qualified_root", qualified_root }, nano::log::arg{ "status", current_status_locked () }); - node.confirming_set.add (status_l.winner->hash (), shared_from_this ()); - lock.unlock (); - node.election_workers.push_task ([status_l, confirmation_action_l = confirmation_action] () { + node.election_workers.push_task ([this_l = shared_from_this (), status_l, confirmation_action_l = confirmation_action] () { + // This is necessary if the winner of the election is one of the forks. + // In that case the winning block is not yet in the ledger and cementing needs to wait for rollbacks to complete. + this_l->node.process_confirmed (status_l.winner->hash (), this_l); + if (confirmation_action_l) { confirmation_action_l (status_l.winner); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index da9b9c5dfd..c6f550c98f 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1141,30 +1141,28 @@ void nano::node::ongoing_online_weight_calculation () ongoing_online_weight_calculation_queue (); } -void nano::node::process_confirmed (nano::election_status const & status_a, uint64_t iteration_a) +// TODO: Replace this with a queue of some sort. Blocks submitted here could be in a limbo for a while: neither part of an active election nor cemented +void nano::node::process_confirmed (nano::block_hash hash, std::shared_ptr election, uint64_t iteration) { stats.inc (nano::stat::type::process_confirmed, nano::stat::detail::initiate); - auto hash (status_a.winner->hash ()); - decltype (iteration_a) const num_iters = (config.block_processor_batch_max_time / network_params.node.process_confirmed_interval) * 4; - if (auto block_l = ledger.any.block_get (ledger.tx_begin_read (), hash)) + // Limit the maximum number of iterations to avoid getting stuck + uint64_t const max_iterations = (config.block_processor_batch_max_time / network_params.node.process_confirmed_interval) * 4; + + if (auto block = ledger.any.block_get (ledger.tx_begin_read (), hash)) { stats.inc (nano::stat::type::process_confirmed, nano::stat::detail::done); - logger.trace (nano::log::type::node, nano::log::detail::process_confirmed, nano::log::arg{ "block", block_l }); + logger.trace (nano::log::type::node, nano::log::detail::process_confirmed, nano::log::arg{ "block", block }); - confirming_set.add (block_l->hash ()); + confirming_set.add (block->hash (), election); } - else if (iteration_a < num_iters) + else if (iteration < max_iterations) { stats.inc (nano::stat::type::process_confirmed, nano::stat::detail::retry); - iteration_a++; - std::weak_ptr node_w (shared ()); - election_workers.add_timed_task (std::chrono::steady_clock::now () + network_params.node.process_confirmed_interval, [node_w, status_a, iteration_a] () { - if (auto node_l = node_w.lock ()) - { - node_l->process_confirmed (status_a, iteration_a); - } + // Try again later + election_workers.add_timed_task (std::chrono::steady_clock::now () + network_params.node.process_confirmed_interval, [this, hash, election, iteration] () { + process_confirmed (hash, election, iteration + 1); }); } else @@ -1172,6 +1170,7 @@ void nano::node::process_confirmed (nano::election_status const & status_a, uint stats.inc (nano::stat::type::process_confirmed, nano::stat::detail::timeout); // Do some cleanup due to this block never being processed by confirmation height processor + active.recently_confirmed.erase (hash); } } diff --git a/nano/node/node.hpp b/nano/node/node.hpp index c411b6d9a5..9a79d5bdd0 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -94,7 +94,7 @@ class node final : public std::enable_shared_from_this bool copy_with_compaction (std::filesystem::path const &); void keepalive (std::string const &, uint16_t); int store_version (); - void process_confirmed (nano::election_status const &, uint64_t = 0); + void process_confirmed (nano::block_hash, std::shared_ptr = nullptr, uint64_t iteration = 0); void process_active (std::shared_ptr const &); std::optional process_local (std::shared_ptr const &); void process_local_async (std::shared_ptr const &); From cd5b6bd91f9e4245c7802787601829081832c76a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:13:03 +0200 Subject: [PATCH 32/47] Pass explicit dependencies to election schedulers --- nano/node/node.cpp | 2 +- nano/node/scheduler/component.cpp | 8 ++++---- nano/node/scheduler/component.hpp | 4 +--- nano/node/scheduler/priority.cpp | 31 +++++++++++++++++-------------- nano/node/scheduler/priority.hpp | 5 ++++- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 3cb0e03534..991b5c9cd8 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -137,7 +137,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy generator{ *generator_impl }, final_generator_impl{ std::make_unique (config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* final */ true) }, final_generator{ *final_generator_impl }, - scheduler_impl{ std::make_unique (*this) }, + scheduler_impl{ std::make_unique (config, *this, ledger, active, online_reps, vote_cache, stats, logger) }, scheduler{ *scheduler_impl }, aggregator_impl{ std::make_unique (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) }, aggregator{ *aggregator_impl }, diff --git a/nano/node/scheduler/component.cpp b/nano/node/scheduler/component.cpp index de3f7469cb..97c5926df3 100644 --- a/nano/node/scheduler/component.cpp +++ b/nano/node/scheduler/component.cpp @@ -5,11 +5,11 @@ #include #include -nano::scheduler::component::component (nano::node & node) : - hinted_impl{ std::make_unique (node.config.hinted_scheduler, node, node.vote_cache, node.active, node.online_reps, node.stats) }, +nano::scheduler::component::component (nano::node_config & node_config, nano::node & node, nano::ledger & ledger, nano::active_elections & active, nano::online_reps & online_reps, nano::vote_cache & vote_cache, nano::stats & stats, nano::logger & logger) : + hinted_impl{ std::make_unique (node_config.hinted_scheduler, node, vote_cache, active, online_reps, stats) }, manual_impl{ std::make_unique (node) }, - optimistic_impl{ std::make_unique (node.config.optimistic_scheduler, node, node.ledger, node.active, node.network_params.network, node.stats) }, - priority_impl{ std::make_unique (node, node.stats) }, + optimistic_impl{ std::make_unique (node_config.optimistic_scheduler, node, ledger, active, node_config.network_params.network, stats) }, + priority_impl{ std::make_unique (node_config, node, ledger, active, stats, logger) }, hinted{ *hinted_impl }, manual{ *manual_impl }, optimistic{ *optimistic_impl }, diff --git a/nano/node/scheduler/component.hpp b/nano/node/scheduler/component.hpp index 090b4f6985..35b4a1b6d5 100644 --- a/nano/node/scheduler/component.hpp +++ b/nano/node/scheduler/component.hpp @@ -10,12 +10,10 @@ namespace nano::scheduler class component final { public: - explicit component (nano::node & node); + component (nano::node_config &, nano::node &, nano::ledger &, nano::active_elections &, nano::online_reps &, nano::vote_cache &, nano::stats &, nano::logger &); ~component (); - // Starts all schedulers void start (); - // Stops all schedulers void stop (); nano::container_info container_info () const; diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index b209a2c59c..571753e9fb 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -7,10 +7,13 @@ #include #include -nano::scheduler::priority::priority (nano::node & node_a, nano::stats & stats_a) : - config{ node_a.config.priority_scheduler }, +nano::scheduler::priority::priority (nano::node_config & node_config, nano::node & node_a, nano::ledger & ledger_a, nano::active_elections & active_a, nano::stats & stats_a, nano::logger & logger_a) : + config{ node_config.priority_scheduler }, node{ node_a }, - stats{ stats_a } + ledger{ ledger_a }, + active{ active_a }, + stats{ stats_a }, + logger{ logger_a } { std::vector minimums; @@ -34,11 +37,11 @@ nano::scheduler::priority::priority (nano::node & node_a, nano::stats & stats_a) build_region (uint128_t{ 1 } << 116, uint128_t{ 1 } << 120, 2); minimums.push_back (uint128_t{ 1 } << 120); - node.logger.debug (nano::log::type::election_scheduler, "Number of buckets: {}", minimums.size ()); + logger.debug (nano::log::type::election_scheduler, "Number of buckets: {}", minimums.size ()); for (size_t i = 0u, n = minimums.size (); i < n; ++i) { - auto bucket = std::make_unique (minimums[i], node.config.priority_bucket, node.active, stats); + auto bucket = std::make_unique (minimums[i], node_config.priority_bucket, active, stats); buckets.emplace_back (std::move (bucket)); } } @@ -85,11 +88,11 @@ void nano::scheduler::priority::stop () bool nano::scheduler::priority::activate (secure::transaction const & transaction, nano::account const & account) { debug_assert (!account.is_zero ()); - auto info = node.ledger.any.account_get (transaction, account); + auto info = ledger.any.account_get (transaction, account); if (info) { nano::confirmation_height_info conf_info; - node.store.confirmation_height.get (transaction, account, conf_info); + ledger.store.confirmation_height.get (transaction, account, conf_info); if (conf_info.height < info->block_count) { return activate (transaction, account, *info, conf_info); @@ -103,14 +106,14 @@ bool nano::scheduler::priority::activate (secure::transaction const & transactio { debug_assert (conf_info.frontier != account_info.head); - auto hash = conf_info.height == 0 ? account_info.open_block : node.ledger.any.block_successor (transaction, conf_info.frontier).value (); - auto block = node.ledger.any.block_get (transaction, hash); + auto hash = conf_info.height == 0 ? account_info.open_block : ledger.any.block_successor (transaction, conf_info.frontier).value (); + auto block = ledger.any.block_get (transaction, hash); release_assert (block != nullptr); - if (node.ledger.dependents_confirmed (transaction, *block)) + if (ledger.dependents_confirmed (transaction, *block)) { auto const balance = block->balance (); - auto const previous_balance = node.ledger.any.block_balance (transaction, conf_info.frontier).value_or (0); + auto const previous_balance = ledger.any.block_balance (transaction, conf_info.frontier).value_or (0); auto const balance_priority = std::max (balance, previous_balance); bool added = false; @@ -120,8 +123,8 @@ bool nano::scheduler::priority::activate (secure::transaction const & transactio } if (added) { - node.stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activated); - node.logger.trace (nano::log::type::election_scheduler, nano::log::detail::block_activated, + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activated); + logger.trace (nano::log::type::election_scheduler, nano::log::detail::block_activated, nano::log::arg{ "account", account.to_account () }, // TODO: Convert to lazy eval nano::log::arg{ "block", block }, nano::log::arg{ "time", account_info.modified }, @@ -131,7 +134,7 @@ bool nano::scheduler::priority::activate (secure::transaction const & transactio } else { - node.stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activate_full); + stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activate_full); } return true; // Activated diff --git a/nano/node/scheduler/priority.hpp b/nano/node/scheduler/priority.hpp index 727598184c..0cf0252f5e 100644 --- a/nano/node/scheduler/priority.hpp +++ b/nano/node/scheduler/priority.hpp @@ -26,7 +26,7 @@ class priority_config class priority final { public: - priority (nano::node &, nano::stats &); + priority (nano::node_config &, nano::node &, nano::ledger &, nano::active_elections &, nano::stats &, nano::logger &); ~priority (); void start (); @@ -48,7 +48,10 @@ class priority final private: // Dependencies priority_config const & config; nano::node & node; + nano::ledger & ledger; + nano::active_elections & active; nano::stats & stats; + nano::logger & logger; private: void run (); From d834d933714201a9eb0b46638de35dbe7e73520b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:03:48 +0200 Subject: [PATCH 33/47] Use `vacancy_updated` event --- nano/core_test/active_elections.cpp | 4 +++- nano/node/active_elections.cpp | 7 +++---- nano/node/active_elections.hpp | 5 ++++- nano/node/node.cpp | 7 ------- nano/node/scheduler/component.cpp | 6 ++++++ 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/nano/core_test/active_elections.cpp b/nano/core_test/active_elections.cpp index 9bd1d6c204..32bc538da1 100644 --- a/nano/core_test/active_elections.cpp +++ b/nano/core_test/active_elections.cpp @@ -1308,7 +1308,9 @@ TEST (active_elections, vacancy) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*system.work.generate (nano::dev::genesis->hash ())) .build (); - node.active.vacancy_update = [&updated] () { updated = true; }; + node.active.vacancy_updated.add ([&updated] () { + updated = true; + }); ASSERT_EQ (nano::block_status::progress, node.process (send)); ASSERT_EQ (1, node.active.vacancy (nano::election_behavior::priority)); ASSERT_EQ (0, node.active.size ()); diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index 0cc4953f0e..861e7e7ef8 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -312,7 +312,7 @@ void nano::active_elections::cleanup_election (nano::unique_lock & entry.erased_callback (election); } - vacancy_update (); + vacancy_updated.notify (); for (auto const & [hash, block] : blocks_l) { @@ -435,7 +435,7 @@ nano::election_insertion_result nano::active_elections::insert (std::shared_ptr< node.vote_cache_processor.trigger (hash); node.observers.active_started.notify (hash); - vacancy_update (); + vacancy_updated.notify (); } // Votes are generated for inserted or ongoing elections @@ -541,8 +541,7 @@ void nano::active_elections::clear () nano::lock_guard guard{ mutex }; roots.clear (); } - - vacancy_update (); + vacancy_updated.notify (); } nano::container_info nano::active_elections::container_info () const diff --git a/nano/node/active_elections.hpp b/nano/node/active_elections.hpp index 1a76cf0448..e3a1a8b4ca 100644 --- a/nano/node/active_elections.hpp +++ b/nano/node/active_elections.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -121,10 +122,12 @@ class active_elections final * How many election slots are available for specified election type */ int64_t vacancy (nano::election_behavior behavior) const; - std::function vacancy_update{ [] () {} }; nano::container_info container_info () const; +public: // Events + nano::observer_set<> vacancy_updated; + private: void request_loop (); void request_confirm (nano::unique_lock &); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 991b5c9cd8..f2f22608e1 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -187,13 +187,6 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy if (!init_error ()) { - // Notify election schedulers when AEC frees election slot - active.vacancy_update = [this] () { - scheduler.priority.notify (); - scheduler.hinted.notify (); - scheduler.optimistic.notify (); - }; - wallets.observer = [this] (bool active) { observers.wallet.notify (active); }; diff --git a/nano/node/scheduler/component.cpp b/nano/node/scheduler/component.cpp index 97c5926df3..560594b019 100644 --- a/nano/node/scheduler/component.cpp +++ b/nano/node/scheduler/component.cpp @@ -15,6 +15,12 @@ nano::scheduler::component::component (nano::node_config & node_config, nano::no optimistic{ *optimistic_impl }, priority{ *priority_impl } { + // Notify election schedulers when AEC frees election slot + active.vacancy_updated.add ([this] () { + priority.notify (); + hinted.notify (); + optimistic.notify (); + }); } nano::scheduler::component::~component () From d22b69c934e25ceb24680ba7480132feba172350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:13:58 +0200 Subject: [PATCH 34/47] Activate accounts with freshly processed blocks --- nano/node/node.cpp | 2 +- nano/node/process_live_dispatcher.cpp | 6 ------ nano/node/scheduler/component.cpp | 4 ++-- nano/node/scheduler/component.hpp | 2 +- nano/node/scheduler/priority.cpp | 19 ++++++++++++++++--- nano/node/scheduler/priority.hpp | 3 ++- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index f2f22608e1..86a4fa1673 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -137,7 +137,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy generator{ *generator_impl }, final_generator_impl{ std::make_unique (config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* final */ true) }, final_generator{ *final_generator_impl }, - scheduler_impl{ std::make_unique (config, *this, ledger, active, online_reps, vote_cache, stats, logger) }, + scheduler_impl{ std::make_unique (config, *this, ledger, block_processor, active, online_reps, vote_cache, stats, logger) }, scheduler{ *scheduler_impl }, aggregator_impl{ std::make_unique (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) }, aggregator{ *aggregator_impl }, diff --git a/nano/node/process_live_dispatcher.cpp b/nano/node/process_live_dispatcher.cpp index 60a80e2154..1f00b23249 100644 --- a/nano/node/process_live_dispatcher.cpp +++ b/nano/node/process_live_dispatcher.cpp @@ -43,12 +43,6 @@ void nano::process_live_dispatcher::inspect (nano::block_status const & result, void nano::process_live_dispatcher::process_live (nano::block const & block, secure::transaction const & transaction) { - // Start collecting quorum on block - if (ledger.dependents_confirmed (transaction, block)) - { - scheduler.activate (transaction, block.account ()); - } - if (websocket.server && websocket.server->any_subscriber (nano::websocket::topic::new_unconfirmed_block)) { websocket.server->broadcast (nano::websocket::message_builder ().new_block_arrived (block)); diff --git a/nano/node/scheduler/component.cpp b/nano/node/scheduler/component.cpp index 560594b019..f0352a390a 100644 --- a/nano/node/scheduler/component.cpp +++ b/nano/node/scheduler/component.cpp @@ -5,11 +5,11 @@ #include #include -nano::scheduler::component::component (nano::node_config & node_config, nano::node & node, nano::ledger & ledger, nano::active_elections & active, nano::online_reps & online_reps, nano::vote_cache & vote_cache, nano::stats & stats, nano::logger & logger) : +nano::scheduler::component::component (nano::node_config & node_config, nano::node & node, nano::ledger & ledger, nano::block_processor & block_processor, nano::active_elections & active, nano::online_reps & online_reps, nano::vote_cache & vote_cache, nano::stats & stats, nano::logger & logger) : hinted_impl{ std::make_unique (node_config.hinted_scheduler, node, vote_cache, active, online_reps, stats) }, manual_impl{ std::make_unique (node) }, optimistic_impl{ std::make_unique (node_config.optimistic_scheduler, node, ledger, active, node_config.network_params.network, stats) }, - priority_impl{ std::make_unique (node_config, node, ledger, active, stats, logger) }, + priority_impl{ std::make_unique (node_config, node, ledger, block_processor, active, stats, logger) }, hinted{ *hinted_impl }, manual{ *manual_impl }, optimistic{ *optimistic_impl }, diff --git a/nano/node/scheduler/component.hpp b/nano/node/scheduler/component.hpp index 35b4a1b6d5..40a53d0f19 100644 --- a/nano/node/scheduler/component.hpp +++ b/nano/node/scheduler/component.hpp @@ -10,7 +10,7 @@ namespace nano::scheduler class component final { public: - component (nano::node_config &, nano::node &, nano::ledger &, nano::active_elections &, nano::online_reps &, nano::vote_cache &, nano::stats &, nano::logger &); + component (nano::node_config &, nano::node &, nano::ledger &, nano::block_processor &, nano::active_elections &, nano::online_reps &, nano::vote_cache &, nano::stats &, nano::logger &); ~component (); void start (); diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index 571753e9fb..beb360d62f 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -7,10 +7,11 @@ #include #include -nano::scheduler::priority::priority (nano::node_config & node_config, nano::node & node_a, nano::ledger & ledger_a, nano::active_elections & active_a, nano::stats & stats_a, nano::logger & logger_a) : +nano::scheduler::priority::priority (nano::node_config & node_config, nano::node & node_a, nano::ledger & ledger_a, nano::block_processor & block_processor_a, nano::active_elections & active_a, nano::stats & stats_a, nano::logger & logger_a) : config{ node_config.priority_scheduler }, node{ node_a }, ledger{ ledger_a }, + block_processor{ block_processor_a }, active{ active_a }, stats{ stats_a }, logger{ logger_a } @@ -44,6 +45,19 @@ nano::scheduler::priority::priority (nano::node_config & node_config, nano::node auto bucket = std::make_unique (minimums[i], node_config.priority_bucket, active, stats); buckets.emplace_back (std::move (bucket)); } + + // Activate accounts with fresh blocks + block_processor.batch_processed.add ([this] (auto const & batch) { + auto transaction = ledger.tx_begin_read (); + for (auto const & [result, context] : batch) + { + if (result == nano::block_status::progress) + { + release_assert (context.block != nullptr); + activate (transaction, context.block->account ()); + } + } + }); } nano::scheduler::priority::~priority () @@ -88,8 +102,7 @@ void nano::scheduler::priority::stop () bool nano::scheduler::priority::activate (secure::transaction const & transaction, nano::account const & account) { debug_assert (!account.is_zero ()); - auto info = ledger.any.account_get (transaction, account); - if (info) + if (auto info = ledger.any.account_get (transaction, account)) { nano::confirmation_height_info conf_info; ledger.store.confirmation_height.get (transaction, account, conf_info); diff --git a/nano/node/scheduler/priority.hpp b/nano/node/scheduler/priority.hpp index 0cf0252f5e..8cdeac02c5 100644 --- a/nano/node/scheduler/priority.hpp +++ b/nano/node/scheduler/priority.hpp @@ -26,7 +26,7 @@ class priority_config class priority final { public: - priority (nano::node_config &, nano::node &, nano::ledger &, nano::active_elections &, nano::stats &, nano::logger &); + priority (nano::node_config &, nano::node &, nano::ledger &, nano::block_processor &, nano::active_elections &, nano::stats &, nano::logger &); ~priority (); void start (); @@ -49,6 +49,7 @@ class priority final priority_config const & config; nano::node & node; nano::ledger & ledger; + nano::block_processor & block_processor; nano::active_elections & active; nano::stats & stats; nano::logger & logger; From f2198c9c0c220a35182b62fc8e62fd7f6a3b5ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 17 Oct 2024 17:34:53 +0200 Subject: [PATCH 35/47] Activate successors of cemented blocks --- nano/core_test/active_elections.cpp | 4 ++-- nano/node/active_elections.cpp | 20 -------------------- nano/node/active_elections.hpp | 1 - nano/node/node.cpp | 2 +- nano/node/scheduler/component.cpp | 4 ++-- nano/node/scheduler/component.hpp | 2 +- nano/node/scheduler/priority.cpp | 29 ++++++++++++++++++++++++++++- nano/node/scheduler/priority.hpp | 8 +++++--- 8 files changed, 39 insertions(+), 31 deletions(-) diff --git a/nano/core_test/active_elections.cpp b/nano/core_test/active_elections.cpp index 32bc538da1..f592ea133c 100644 --- a/nano/core_test/active_elections.cpp +++ b/nano/core_test/active_elections.cpp @@ -1232,8 +1232,8 @@ TEST (active_elections, activate_inactive) ASSERT_TIMELY_EQ (5s, 1, node.stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out)); ASSERT_ALWAYS_EQ (50ms, 0, node.stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_conf_height, nano::stat::dir::out)); - // The first block was not active so no activation takes place - ASSERT_FALSE (node.active.active (open->qualified_root ()) || node.block_confirmed_or_being_confirmed (open->hash ())); + // Cementing of send should activate open + ASSERT_TIMELY (5s, node.active.active (open->qualified_root ())); } TEST (active_elections, list_active) diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index 861e7e7ef8..c161038e4a 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -123,15 +123,6 @@ void nano::active_elections::block_cemented (nano::secure::transaction const & t nano::log::arg{ "source_election", source_election }); notify_observers (transaction, status, votes); - - bool cemented_bootstrap_count_reached = node.ledger.cemented_count () >= node.ledger.bootstrap_weight_max_blocks; - bool was_active = status.type == nano::election_status_type::active_confirmed_quorum || status.type == nano::election_status_type::active_confirmation_height; - - // Next-block activations are only done for blocks with previously active elections - if (cemented_bootstrap_count_reached && was_active && !node.flags.disable_activate_successors) - { - activate_successors (transaction, block); - } } void nano::active_elections::notify_observers (nano::secure::transaction const & transaction, nano::election_status const & status, std::vector const & votes) const @@ -169,17 +160,6 @@ void nano::active_elections::notify_observers (nano::secure::transaction const & } } -void nano::active_elections::activate_successors (nano::secure::transaction const & transaction, std::shared_ptr const & block) -{ - node.scheduler.priority.activate (transaction, block->account ()); - - // Start or vote for the next unconfirmed block in the destination account - if (block->is_send () && !block->destination ().is_zero () && block->destination () != block->account ()) - { - node.scheduler.priority.activate (transaction, block->destination ()); - } -} - int64_t nano::active_elections::limit (nano::election_behavior behavior) const { switch (behavior) diff --git a/nano/node/active_elections.hpp b/nano/node/active_elections.hpp index e3a1a8b4ca..049f41428d 100644 --- a/nano/node/active_elections.hpp +++ b/nano/node/active_elections.hpp @@ -136,7 +136,6 @@ class active_elections final nano::stat::type completion_type (nano::election const & election) const; // Returns a list of elections sorted by difficulty, mutex must be locked std::vector> list_active_impl (std::size_t) const; - void activate_successors (nano::secure::transaction const &, std::shared_ptr const & block); void notify_observers (nano::secure::transaction const &, nano::election_status const & status, std::vector const & votes) const; void block_cemented (nano::secure::transaction const &, std::shared_ptr const & block, nano::block_hash const & confirmation_root, std::shared_ptr const & source_election); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 86a4fa1673..313a187685 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -137,7 +137,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy generator{ *generator_impl }, final_generator_impl{ std::make_unique (config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* final */ true) }, final_generator{ *final_generator_impl }, - scheduler_impl{ std::make_unique (config, *this, ledger, block_processor, active, online_reps, vote_cache, stats, logger) }, + scheduler_impl{ std::make_unique (config, *this, ledger, block_processor, active, online_reps, vote_cache, confirming_set, stats, logger) }, scheduler{ *scheduler_impl }, aggregator_impl{ std::make_unique (config.request_aggregator, *this, stats, generator, final_generator, history, ledger, wallets, vote_router) }, aggregator{ *aggregator_impl }, diff --git a/nano/node/scheduler/component.cpp b/nano/node/scheduler/component.cpp index f0352a390a..2d8cf5633a 100644 --- a/nano/node/scheduler/component.cpp +++ b/nano/node/scheduler/component.cpp @@ -5,11 +5,11 @@ #include #include -nano::scheduler::component::component (nano::node_config & node_config, nano::node & node, nano::ledger & ledger, nano::block_processor & block_processor, nano::active_elections & active, nano::online_reps & online_reps, nano::vote_cache & vote_cache, nano::stats & stats, nano::logger & logger) : +nano::scheduler::component::component (nano::node_config & node_config, nano::node & node, nano::ledger & ledger, nano::block_processor & block_processor, nano::active_elections & active, nano::online_reps & online_reps, nano::vote_cache & vote_cache, nano::confirming_set & confirming_set, nano::stats & stats, nano::logger & logger) : hinted_impl{ std::make_unique (node_config.hinted_scheduler, node, vote_cache, active, online_reps, stats) }, manual_impl{ std::make_unique (node) }, optimistic_impl{ std::make_unique (node_config.optimistic_scheduler, node, ledger, active, node_config.network_params.network, stats) }, - priority_impl{ std::make_unique (node_config, node, ledger, block_processor, active, stats, logger) }, + priority_impl{ std::make_unique (node_config, node, ledger, block_processor, active, confirming_set, stats, logger) }, hinted{ *hinted_impl }, manual{ *manual_impl }, optimistic{ *optimistic_impl }, diff --git a/nano/node/scheduler/component.hpp b/nano/node/scheduler/component.hpp index 40a53d0f19..96de3d94ae 100644 --- a/nano/node/scheduler/component.hpp +++ b/nano/node/scheduler/component.hpp @@ -10,7 +10,7 @@ namespace nano::scheduler class component final { public: - component (nano::node_config &, nano::node &, nano::ledger &, nano::block_processor &, nano::active_elections &, nano::online_reps &, nano::vote_cache &, nano::stats &, nano::logger &); + component (nano::node_config &, nano::node &, nano::ledger &, nano::block_processor &, nano::active_elections &, nano::online_reps &, nano::vote_cache &, nano::confirming_set &, nano::stats &, nano::logger &); ~component (); void start (); diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index beb360d62f..4063ce60d3 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -7,12 +7,13 @@ #include #include -nano::scheduler::priority::priority (nano::node_config & node_config, nano::node & node_a, nano::ledger & ledger_a, nano::block_processor & block_processor_a, nano::active_elections & active_a, nano::stats & stats_a, nano::logger & logger_a) : +nano::scheduler::priority::priority (nano::node_config & node_config, nano::node & node_a, nano::ledger & ledger_a, nano::block_processor & block_processor_a, nano::active_elections & active_a, nano::confirming_set & confirming_set_a, nano::stats & stats_a, nano::logger & logger_a) : config{ node_config.priority_scheduler }, node{ node_a }, ledger{ ledger_a }, block_processor{ block_processor_a }, active{ active_a }, + confirming_set{ confirming_set_a }, stats{ stats_a }, logger{ logger_a } { @@ -58,6 +59,21 @@ nano::scheduler::priority::priority (nano::node_config & node_config, nano::node } } }); + + // Activate successors of cemented blocks + confirming_set.batch_cemented.add ([this] (auto const & batch) { + if (node.flags.disable_activate_successors) + { + return; + } + + auto transaction = ledger.tx_begin_read (); + for (auto const & context : batch) + { + release_assert (context.block != nullptr); + activate_successors (transaction, *context.block); + } + }); } nano::scheduler::priority::~priority () @@ -157,6 +173,17 @@ bool nano::scheduler::priority::activate (secure::transaction const & transactio return false; // Not activated } +bool nano::scheduler::priority::activate_successors (secure::transaction const & transaction, nano::block const & block) +{ + bool result = activate (transaction, block.account ()); + // Start or vote for the next unconfirmed block in the destination account + if (block.is_send () && !block.destination ().is_zero () && block.destination () != block.account ()) + { + result |= activate (transaction, block.destination ()); + } + return result; +} + void nano::scheduler::priority::notify () { condition.notify_all (); diff --git a/nano/node/scheduler/priority.hpp b/nano/node/scheduler/priority.hpp index 8cdeac02c5..0e901de991 100644 --- a/nano/node/scheduler/priority.hpp +++ b/nano/node/scheduler/priority.hpp @@ -26,7 +26,7 @@ class priority_config class priority final { public: - priority (nano::node_config &, nano::node &, nano::ledger &, nano::block_processor &, nano::active_elections &, nano::stats &, nano::logger &); + priority (nano::node_config &, nano::node &, nano::ledger &, nano::block_processor &, nano::active_elections &, nano::confirming_set &, nano::stats &, nano::logger &); ~priority (); void start (); @@ -36,8 +36,9 @@ class priority final * Activates the first unconfirmed block of \p account_a * @return true if account was activated */ - bool activate (secure::transaction const &, nano::account const &); - bool activate (secure::transaction const &, nano::account const &, nano::account_info const &, nano::confirmation_height_info const &); + bool activate (nano::secure::transaction const &, nano::account const &); + bool activate (nano::secure::transaction const &, nano::account const &, nano::account_info const &, nano::confirmation_height_info const &); + bool activate_successors (nano::secure::transaction const &, nano::block const &); void notify (); std::size_t size () const; @@ -51,6 +52,7 @@ class priority final nano::ledger & ledger; nano::block_processor & block_processor; nano::active_elections & active; + nano::confirming_set & confirming_set; nano::stats & stats; nano::logger & logger; From b6efeb699ad4329c1b4824d96f2dadab60fa0b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 18 Oct 2024 13:57:58 +0200 Subject: [PATCH 36/47] Cleanup --- nano/node/active_elections.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index c161038e4a..6536b2c474 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -29,6 +29,7 @@ nano::active_elections::active_elections (nano::node & node_a, nano::confirming_ { count_by_behavior.fill (0); // Zero initialize array + // Cementing blocks might implicitly confirm dependent elections confirming_set.batch_cemented.add ([this] (auto const & cemented) { auto transaction = node.ledger.tx_begin_read (); for (auto const & [block, confirmation_root, source_election] : cemented) @@ -39,10 +40,13 @@ nano::active_elections::active_elections (nano::node & node_a, nano::confirming_ }); // Notify elections about alternative (forked) blocks - block_processor.block_processed.add ([this] (auto const & result, auto const & context) { - if (result == nano::block_status::fork) + block_processor.batch_processed.add ([this] (auto const & batch) { + for (auto const & [result, context] : batch) { - publish (context.block); + if (result == nano::block_status::fork) + { + publish (context.block); + } } }); } From 82d9d2d323abf2821032b7d88d21b3369957b814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:17:04 +0200 Subject: [PATCH 37/47] Process cemented elections with exclusive lock to avoid races --- nano/node/active_elections.cpp | 42 +++++++++++++++++++++++++--------- nano/node/active_elections.hpp | 12 ++++++---- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index 6536b2c474..4d8c953f56 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -31,11 +31,24 @@ nano::active_elections::active_elections (nano::node & node_a, nano::confirming_ // Cementing blocks might implicitly confirm dependent elections confirming_set.batch_cemented.add ([this] (auto const & cemented) { - auto transaction = node.ledger.tx_begin_read (); - for (auto const & [block, confirmation_root, source_election] : cemented) + std::deque results; { - transaction.refresh_if_needed (); - block_cemented (transaction, block, confirmation_root, source_election); + // Process all cemented blocks while holding the lock to avoid races where an election for a block that is already cemented is inserted + nano::lock_guard guard{ mutex }; + for (auto const & [block, confirmation_root, source_election] : cemented) + { + auto result = block_cemented (block, confirmation_root, source_election); + results.push_back (result); + } + } + { + // TODO: This could be offloaded to a separate notification worker, profiling is needed + auto transaction = node.ledger.tx_begin_read (); + for (auto const & [status, votes] : results) + { + transaction.refresh_if_needed (); + notify_observers (transaction, status, votes); + } } }); @@ -83,16 +96,17 @@ void nano::active_elections::stop () clear (); } -void nano::active_elections::block_cemented (nano::secure::transaction const & transaction, std::shared_ptr const & block, nano::block_hash const & confirmation_root, std::shared_ptr const & source_election) +auto nano::active_elections::block_cemented (std::shared_ptr const & block, nano::block_hash const & confirmation_root, std::shared_ptr const & source_election) -> block_cemented_result { + debug_assert (!mutex.try_lock ()); debug_assert (node.block_confirmed (block->hash ())); // Dependent elections are implicitly confirmed when their block is cemented - auto dependend_election = election (block->qualified_root ()); + auto dependend_election = election_impl (block->qualified_root ()); if (dependend_election) { node.stats.inc (nano::stat::type::active_elections, nano::stat::detail::confirm_dependent); - dependend_election->try_confirm (block->hash ()); + dependend_election->try_confirm (block->hash ()); // TODO: This should either confirm or cancel the election } nano::election_status status; @@ -126,7 +140,7 @@ void nano::active_elections::block_cemented (nano::secure::transaction const & t nano::log::arg{ "confirmation_root", confirmation_root }, nano::log::arg{ "source_election", source_election }); - notify_observers (transaction, status, votes); + return { status, votes }; } void nano::active_elections::notify_observers (nano::secure::transaction const & transaction, nano::election_status const & status, std::vector const & votes) const @@ -443,11 +457,17 @@ bool nano::active_elections::active (nano::block const & block_a) const return roots.get ().find (block_a.qualified_root ()) != roots.get ().end (); } -std::shared_ptr nano::active_elections::election (nano::qualified_root const & root_a) const +std::shared_ptr nano::active_elections::election (nano::qualified_root const & root) const { - std::shared_ptr result; nano::lock_guard lock{ mutex }; - auto existing = roots.get ().find (root_a); + return election_impl (root); +} + +std::shared_ptr nano::active_elections::election_impl (nano::qualified_root const & root) const +{ + debug_assert (!mutex.try_lock ()); + std::shared_ptr result; + auto existing = roots.get ().find (root); if (existing != roots.get ().end ()) { result = existing->election; diff --git a/nano/node/active_elections.hpp b/nano/node/active_elections.hpp index 049f41428d..8b831112b9 100644 --- a/nano/node/active_elections.hpp +++ b/nano/node/active_elections.hpp @@ -105,7 +105,7 @@ class active_elections final bool active (nano::qualified_root const &) const; std::shared_ptr election (nano::qualified_root const &) const; // Returns a list of elections sorted by difficulty - std::vector> list_active (std::size_t = std::numeric_limits::max ()); + std::vector> list_active (std::size_t max_count = std::numeric_limits::max ()); bool erase (nano::block const &); bool erase (nano::qualified_root const &); bool empty () const; @@ -133,11 +133,13 @@ class active_elections final void request_confirm (nano::unique_lock &); // Erase all blocks from active and, if not confirmed, clear digests from network filters void cleanup_election (nano::unique_lock & lock_a, std::shared_ptr); - nano::stat::type completion_type (nano::election const & election) const; - // Returns a list of elections sorted by difficulty, mutex must be locked - std::vector> list_active_impl (std::size_t) const; + + using block_cemented_result = std::pair>; + block_cemented_result block_cemented (std::shared_ptr const & block, nano::block_hash const & confirmation_root, std::shared_ptr const & source_election); void notify_observers (nano::secure::transaction const &, nano::election_status const & status, std::vector const & votes) const; - void block_cemented (nano::secure::transaction const &, std::shared_ptr const & block, nano::block_hash const & confirmation_root, std::shared_ptr const & source_election); + + std::shared_ptr election_impl (nano::qualified_root const &) const; + std::vector> list_active_impl (std::size_t max_count) const; private: // Dependencies active_elections_config const & config; From d78f53927d221ddbb4e9ab0ff16b98a6d00c5317 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 10 Oct 2024 13:19:54 +0200 Subject: [PATCH 38/47] Remove unnecessary FQNs --- nano/store/iterator_impl.hpp | 10 +++--- nano/store/lmdb/iterator.hpp | 54 ++++++++++++++++----------------- nano/store/rocksdb/iterator.hpp | 20 ++++++------ 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/nano/store/iterator_impl.hpp b/nano/store/iterator_impl.hpp index 48130d14ed..8daf89eadc 100644 --- a/nano/store/iterator_impl.hpp +++ b/nano/store/iterator_impl.hpp @@ -11,14 +11,14 @@ template class iterator_impl { public: - explicit iterator_impl (nano::store::transaction const & transaction_a) : - transaction{ transaction_a }, + explicit iterator_impl (transaction const & transaction_a) : + txn{ transaction_a }, transaction_epoch{ transaction_a.epoch () } { } virtual ~iterator_impl () { - debug_assert (transaction_epoch == transaction.epoch (), "invalid iterator-transaction lifetime detected"); + debug_assert (transaction_epoch == txn.epoch (), "invalid iterator-transaction lifetime detected"); } virtual iterator_impl & operator++ () = 0; @@ -37,7 +37,7 @@ class iterator_impl } protected: - nano::store::transaction const & transaction; - nano::store::transaction::epoch_t const transaction_epoch; + transaction const & txn; + transaction::epoch_t const transaction_epoch; }; } diff --git a/nano/store/lmdb/iterator.hpp b/nano/store/lmdb/iterator.hpp index 3c2fe197c7..621d698082 100644 --- a/nano/store/lmdb/iterator.hpp +++ b/nano/store/lmdb/iterator.hpp @@ -14,8 +14,8 @@ template class iterator : public iterator_impl { public: - iterator (store::transaction const & transaction_a, env const & env_a, MDB_dbi db_a, MDB_val const & val_a = MDB_val{}, bool const direction_asc = true) : - nano::store::iterator_impl (transaction_a) + iterator (transaction const & transaction_a, env const & env_a, MDB_dbi db_a, MDB_val const & val_a = MDB_val{}, bool const direction_asc = true) : + iterator_impl (transaction_a) { auto status (mdb_cursor_open (env_a.tx (transaction_a), db_a, &cursor)); release_assert (status == 0); @@ -47,14 +47,14 @@ class iterator : public iterator_impl iterator () = default; - iterator (nano::store::lmdb::iterator && other_a) + iterator (iterator && other_a) { cursor = other_a.cursor; other_a.cursor = nullptr; current = other_a.current; } - iterator (nano::store::lmdb::iterator const &) = delete; + iterator (iterator const &) = delete; ~iterator () { @@ -64,7 +64,7 @@ class iterator : public iterator_impl } } - store::iterator_impl & operator++ () override + iterator_impl & operator++ () override { debug_assert (cursor != nullptr); auto status (mdb_cursor_get (cursor, ¤t.first.value, ¤t.second.value, MDB_NEXT)); @@ -80,7 +80,7 @@ class iterator : public iterator_impl return *this; } - store::iterator_impl & operator-- () override + iterator_impl & operator-- () override { debug_assert (cursor != nullptr); auto status (mdb_cursor_get (cursor, ¤t.first.value, ¤t.second.value, MDB_PREV)); @@ -101,9 +101,9 @@ class iterator : public iterator_impl return ¤t; } - bool operator== (nano::store::lmdb::iterator const & base_a) const + bool operator== (iterator const & base_a) const { - auto const other_a (boost::polymorphic_downcast const *> (&base_a)); + auto const other_a (boost::polymorphic_downcast const *> (&base_a)); auto result (current.first.data () == other_a->current.first.data ()); debug_assert (!result || (current.first.size () == other_a->current.first.size ())); debug_assert (!result || (current.second.data () == other_a->current.second.data ())); @@ -111,9 +111,9 @@ class iterator : public iterator_impl return result; } - bool operator== (store::iterator_impl const & base_a) const override + bool operator== (iterator_impl const & base_a) const override { - auto const other_a (boost::polymorphic_downcast const *> (&base_a)); + auto const other_a (boost::polymorphic_downcast const *> (&base_a)); auto result (current.first.data () == other_a->current.first.data ()); debug_assert (!result || (current.first.size () == other_a->current.first.size ())); debug_assert (!result || (current.second.data () == other_a->current.second.data ())); @@ -151,7 +151,7 @@ class iterator : public iterator_impl debug_assert (is_end_sentinal ()); } - nano::store::lmdb::iterator & operator= (nano::store::lmdb::iterator && other_a) + iterator & operator= (iterator && other_a) { if (cursor != nullptr) { @@ -164,7 +164,7 @@ class iterator : public iterator_impl return *this; } - store::iterator_impl & operator= (store::iterator_impl const &) = delete; + iterator_impl & operator= (iterator_impl const &) = delete; MDB_cursor * cursor{ nullptr }; std::pair, store::db_val> current; }; @@ -176,21 +176,21 @@ template class merge_iterator : public iterator_impl { public: - merge_iterator (store::transaction const & transaction_a, MDB_dbi db1_a, MDB_dbi db2_a) : - impl1 (std::make_unique> (transaction_a, db1_a)), - impl2 (std::make_unique> (transaction_a, db2_a)) + merge_iterator (transaction const & transaction_a, MDB_dbi db1_a, MDB_dbi db2_a) : + impl1 (std::make_unique> (transaction_a, db1_a)), + impl2 (std::make_unique> (transaction_a, db2_a)) { } merge_iterator () : - impl1 (std::make_unique> ()), - impl2 (std::make_unique> ()) + impl1 (std::make_unique> ()), + impl2 (std::make_unique> ()) { } - merge_iterator (store::transaction const & transaction_a, MDB_dbi db1_a, MDB_dbi db2_a, MDB_val const & val_a) : - impl1 (std::make_unique> (transaction_a, db1_a, val_a)), - impl2 (std::make_unique> (transaction_a, db2_a, val_a)) + merge_iterator (transaction const & transaction_a, MDB_dbi db1_a, MDB_dbi db2_a, MDB_val const & val_a) : + impl1 (std::make_unique> (transaction_a, db1_a, val_a)), + impl2 (std::make_unique> (transaction_a, db2_a, val_a)) { } @@ -202,13 +202,13 @@ class merge_iterator : public iterator_impl merge_iterator (merge_iterator const &) = delete; - store::iterator_impl & operator++ () override + iterator_impl & operator++ () override { ++least_iterator (); return *this; } - store::iterator_impl & operator-- () override + iterator_impl & operator-- () override { --least_iterator (); return *this; @@ -229,7 +229,7 @@ class merge_iterator : public iterator_impl return !(*this == base_a); } - bool operator== (store::iterator_impl const & base_a) const override + bool operator== (iterator_impl const & base_a) const override { debug_assert ((dynamic_cast const *> (&base_a) != nullptr) && "Incompatible iterator comparison"); auto & other (static_cast const &> (base_a)); @@ -267,9 +267,9 @@ class merge_iterator : public iterator_impl mutable bool from_first_database{ false }; private: - nano::store::lmdb::iterator & least_iterator () const + iterator & least_iterator () const { - nano::store::lmdb::iterator * result; + iterator * result; if (impl1->is_end_sentinal ()) { result = impl2.get (); @@ -304,7 +304,7 @@ class merge_iterator : public iterator_impl return *result; } - std::unique_ptr> impl1; - std::unique_ptr> impl2; + std::unique_ptr> impl1; + std::unique_ptr> impl2; }; } diff --git a/nano/store/rocksdb/iterator.hpp b/nano/store/rocksdb/iterator.hpp index b661c8af6e..99fc9a9c54 100644 --- a/nano/store/rocksdb/iterator.hpp +++ b/nano/store/rocksdb/iterator.hpp @@ -33,8 +33,8 @@ class iterator : public iterator_impl public: iterator () = default; - iterator (::rocksdb::DB * db, store::transaction const & transaction_a, ::rocksdb::ColumnFamilyHandle * handle_a, db_val const * val_a, bool const direction_asc) : - nano::store::iterator_impl (transaction_a) + iterator (::rocksdb::DB * db, transaction const & transaction_a, ::rocksdb::ColumnFamilyHandle * handle_a, db_val const * val_a, bool const direction_asc) : + iterator_impl (transaction_a) { // Don't fill the block cache for any blocks read as a result of an iterator if (is_read (transaction_a)) @@ -79,16 +79,16 @@ class iterator : public iterator_impl { } - iterator (nano::store::rocksdb::iterator && other_a) + iterator (iterator && other_a) { cursor = other_a.cursor; other_a.cursor = nullptr; current = other_a.current; } - iterator (nano::store::rocksdb::iterator const &) = delete; + iterator (iterator const &) = delete; - store::iterator_impl & operator++ () override + iterator_impl & operator++ () override { cursor->Next (); if (cursor->Valid ()) @@ -109,7 +109,7 @@ class iterator : public iterator_impl return *this; } - store::iterator_impl & operator-- () override + iterator_impl & operator-- () override { cursor->Prev (); if (cursor->Valid ()) @@ -135,9 +135,9 @@ class iterator : public iterator_impl return ¤t; } - bool operator== (store::iterator_impl const & base_a) const override + bool operator== (iterator_impl const & base_a) const override { - auto const other_a (boost::polymorphic_downcast const *> (&base_a)); + auto const other_a (boost::polymorphic_downcast const *> (&base_a)); if (!current.first.data () && !other_a->current.first.data ()) { @@ -187,13 +187,13 @@ class iterator : public iterator_impl current.second = nano::store::rocksdb::db_val{}; debug_assert (is_end_sentinal ()); } - nano::store::rocksdb::iterator & operator= (nano::store::rocksdb::iterator && other_a) + iterator & operator= (iterator && other_a) { cursor = std::move (other_a.cursor); current = other_a.current; return *this; } - store::iterator_impl & operator= (store::iterator_impl const &) = delete; + iterator_impl & operator= (iterator_impl const &) = delete; std::unique_ptr<::rocksdb::Iterator> cursor; std::pair current; From 635740a512bd066c5d6db9dc51b208051e6af031 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 10 Oct 2024 14:28:29 +0200 Subject: [PATCH 39/47] Adding type aliases to store classes. --- nano/node/wallet.cpp | 17 +++++++++-------- nano/node/wallet.hpp | 11 +++++++---- nano/store/CMakeLists.txt | 1 + nano/store/account.hpp | 13 ++++++++----- nano/store/block.hpp | 11 +++++++---- nano/store/confirmation_height.hpp | 11 +++++++---- nano/store/final.hpp | 11 +++++++---- nano/store/lmdb/account.cpp | 12 ++++++------ nano/store/lmdb/account.hpp | 10 +++++----- nano/store/lmdb/block.cpp | 11 ++++++----- nano/store/lmdb/block.hpp | 8 ++++---- nano/store/lmdb/confirmation_height.cpp | 10 +++++----- nano/store/lmdb/confirmation_height.hpp | 8 ++++---- nano/store/lmdb/final_vote.cpp | 10 +++++----- nano/store/lmdb/final_vote.hpp | 8 ++++---- nano/store/lmdb/online_weight.cpp | 8 ++++---- nano/store/lmdb/online_weight.hpp | 6 +++--- nano/store/lmdb/peer.cpp | 6 +++--- nano/store/lmdb/peer.hpp | 4 ++-- nano/store/lmdb/pending.cpp | 10 +++++----- nano/store/lmdb/pending.hpp | 8 ++++---- nano/store/lmdb/pruned.cpp | 10 +++++----- nano/store/lmdb/pruned.hpp | 8 ++++---- nano/store/lmdb/rep_weight.cpp | 10 +++++----- nano/store/lmdb/rep_weight.hpp | 8 ++++---- nano/store/online_weight.hpp | 9 ++++++--- nano/store/peer.hpp | 7 +++++-- nano/store/pending.hpp | 8 ++++---- nano/store/pruned.hpp | 11 +++++++---- nano/store/rep_weight.hpp | 11 +++++++---- nano/store/rocksdb/account.cpp | 12 ++++++------ nano/store/rocksdb/account.hpp | 10 +++++----- nano/store/rocksdb/block.cpp | 17 ++++++++++++----- nano/store/rocksdb/block.hpp | 8 ++++---- nano/store/rocksdb/confirmation_height.cpp | 10 +++++----- nano/store/rocksdb/confirmation_height.hpp | 8 ++++---- nano/store/rocksdb/final_vote.cpp | 10 +++++----- nano/store/rocksdb/final_vote.hpp | 8 ++++---- nano/store/rocksdb/online_weight.cpp | 8 ++++---- nano/store/rocksdb/online_weight.hpp | 6 +++--- nano/store/rocksdb/peer.cpp | 6 +++--- nano/store/rocksdb/peer.hpp | 4 ++-- nano/store/rocksdb/pending.cpp | 10 +++++----- nano/store/rocksdb/pending.hpp | 8 ++++---- nano/store/rocksdb/pruned.cpp | 10 +++++----- nano/store/rocksdb/pruned.hpp | 8 ++++---- nano/store/rocksdb/rep_weight.cpp | 12 ++++++------ nano/store/rocksdb/rep_weight.hpp | 8 ++++---- 48 files changed, 238 insertions(+), 201 deletions(-) diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 716f78ee2f..a1f46c78f3 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -1753,22 +1753,22 @@ std::unordered_map> nano::wallets nano::uint128_t const nano::wallets::generate_priority = std::numeric_limits::max (); nano::uint128_t const nano::wallets::high_priority = std::numeric_limits::max () - 1; -nano::store::iterator nano::wallet_store::begin (store::transaction const & transaction_a) +auto nano::wallet_store::begin (store::transaction const & transaction_a) -> iterator { - store::iterator result (std::make_unique> (transaction_a, env, handle, nano::store::lmdb::db_val (nano::account (special_count)))); + iterator result (std::make_unique> (transaction_a, env, handle, nano::store::lmdb::db_val (nano::account (special_count)))); return result; } -nano::store::iterator nano::wallet_store::begin (store::transaction const & transaction_a, nano::account const & key) +auto nano::wallet_store::begin (store::transaction const & transaction_a, nano::account const & key) -> iterator { - store::iterator result (std::make_unique> (transaction_a, env, handle, nano::store::lmdb::db_val (key))); + iterator result (std::make_unique> (transaction_a, env, handle, nano::store::lmdb::db_val (key))); return result; } -nano::store::iterator nano::wallet_store::find (store::transaction const & transaction_a, nano::account const & key) +auto nano::wallet_store::find (store::transaction const & transaction_a, nano::account const & key) -> iterator { auto result (begin (transaction_a, key)); - store::iterator end (nullptr); + iterator end{ nullptr }; if (result != end) { if (result->first == key) @@ -1787,10 +1787,11 @@ nano::store::iterator nano::wallet_store::fin return result; } -nano::store::iterator nano::wallet_store::end () +auto nano::wallet_store::end () -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } + nano::mdb_wallets_store::mdb_wallets_store (std::filesystem::path const & path_a, nano::lmdb_config const & lmdb_config_a) : environment (error, path_a, nano::store::lmdb::env::options::make ().set_config (lmdb_config_a).override_config_sync (nano::lmdb_config::sync_strategy::always).override_config_map_size (1ULL * 1024 * 1024 * 1024)) { diff --git a/nano/node/wallet.hpp b/nano/node/wallet.hpp index 7ef86efba8..ef26f4b0be 100644 --- a/nano/node/wallet.hpp +++ b/nano/node/wallet.hpp @@ -57,6 +57,9 @@ enum class key_type class wallet_store final { +public: + using iterator = store::iterator; + public: wallet_store (bool &, nano::kdf &, store::transaction &, store::lmdb::env &, nano::account, unsigned, std::string const &); wallet_store (bool &, nano::kdf &, store::transaction &, store::lmdb::env &, nano::account, unsigned, std::string const &, std::string const &); @@ -89,10 +92,10 @@ class wallet_store final bool fetch (store::transaction const &, nano::account const &, nano::raw_key &); bool exists (store::transaction const &, nano::account const &); void destroy (store::transaction const &); - store::iterator find (store::transaction const &, nano::account const &); - store::iterator begin (store::transaction const &, nano::account const &); - store::iterator begin (store::transaction const &); - store::iterator end (); + iterator find (store::transaction const &, nano::account const &); + iterator begin (store::transaction const &, nano::account const &); + iterator begin (store::transaction const &); + iterator end (); void derive_key (nano::raw_key &, store::transaction const &, std::string const &); void serialize_json (store::transaction const &, std::string &); void write_backup (store::transaction const &, std::filesystem::path const &); diff --git a/nano/store/CMakeLists.txt b/nano/store/CMakeLists.txt index 19ae4cf2ef..c44d7fc0de 100644 --- a/nano/store/CMakeLists.txt +++ b/nano/store/CMakeLists.txt @@ -32,6 +32,7 @@ add_library( peer.hpp pending.hpp pruned.hpp + rep_weight.hpp rocksdb/account.hpp rocksdb/block.hpp rocksdb/confirmation_height.hpp diff --git a/nano/store/account.hpp b/nano/store/account.hpp index 749cd9c842..ffa05de087 100644 --- a/nano/store/account.hpp +++ b/nano/store/account.hpp @@ -19,6 +19,9 @@ namespace nano::store */ class account { +public: + using iterator = store::iterator; + public: virtual void put (store::write_transaction const &, nano::account const &, nano::account_info const &) = 0; virtual bool get (store::transaction const &, nano::account const &, nano::account_info &) = 0; @@ -26,10 +29,10 @@ class account virtual void del (store::write_transaction const &, nano::account const &) = 0; virtual bool exists (store::transaction const &, nano::account const &) = 0; virtual size_t count (store::transaction const &) = 0; - virtual iterator begin (store::transaction const &, nano::account const &) const = 0; - virtual iterator begin (store::transaction const &) const = 0; - virtual iterator rbegin (store::transaction const &) const = 0; - virtual iterator end () const = 0; - virtual void for_each_par (std::function, iterator)> const &) const = 0; + virtual iterator begin (store::transaction const &, nano::account const &) const = 0; + virtual iterator begin (store::transaction const &) const = 0; + virtual iterator rbegin (store::transaction const &) const = 0; + virtual iterator end () const = 0; + virtual void for_each_par (std::function const &) const = 0; }; } // namespace nano::store diff --git a/nano/store/block.hpp b/nano/store/block.hpp index 17f92669d0..acd2ba72f3 100644 --- a/nano/store/block.hpp +++ b/nano/store/block.hpp @@ -21,6 +21,9 @@ namespace nano::store */ class block { +public: + using iterator = store::iterator; + public: virtual void put (store::write_transaction const &, nano::block_hash const &, nano::block const &) = 0; virtual void raw_put (store::write_transaction const &, std::vector const &, nano::block_hash const &) = 0; @@ -31,9 +34,9 @@ class block virtual void del (store::write_transaction const &, nano::block_hash const &) = 0; virtual bool exists (store::transaction const &, nano::block_hash const &) = 0; virtual uint64_t count (store::transaction const &) = 0; - virtual iterator begin (store::transaction const &, nano::block_hash const &) const = 0; - virtual iterator begin (store::transaction const &) const = 0; - virtual iterator end () const = 0; - virtual void for_each_par (std::function, iterator)> const & action_a) const = 0; + virtual iterator begin (store::transaction const &, nano::block_hash const &) const = 0; + virtual iterator begin (store::transaction const &) const = 0; + virtual iterator end () const = 0; + virtual void for_each_par (std::function const & action_a) const = 0; }; } // namespace nano::store diff --git a/nano/store/confirmation_height.hpp b/nano/store/confirmation_height.hpp index f0cb5ee73c..5569bec7ca 100644 --- a/nano/store/confirmation_height.hpp +++ b/nano/store/confirmation_height.hpp @@ -17,6 +17,9 @@ namespace nano::store */ class confirmation_height { +public: + using iterator = store::iterator; + public: virtual void put (store::write_transaction const & transaction_a, nano::account const & account_a, nano::confirmation_height_info const & confirmation_height_info_a) = 0; @@ -32,9 +35,9 @@ class confirmation_height virtual uint64_t count (store::transaction const & transaction_a) = 0; virtual void clear (store::write_transaction const &, nano::account const &) = 0; virtual void clear (store::write_transaction const &) = 0; - virtual iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const = 0; - virtual iterator begin (store::transaction const & transaction_a) const = 0; - virtual iterator end () const = 0; - virtual void for_each_par (std::function, iterator)> const &) const = 0; + virtual iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const = 0; + virtual iterator begin (store::transaction const & transaction_a) const = 0; + virtual iterator end () const = 0; + virtual void for_each_par (std::function const &) const = 0; }; } // namespace nano::store diff --git a/nano/store/final.hpp b/nano/store/final.hpp index 1b9f159951..677159dda5 100644 --- a/nano/store/final.hpp +++ b/nano/store/final.hpp @@ -17,6 +17,9 @@ namespace nano::store */ class final_vote { +public: + using iterator = store::iterator; + public: virtual bool put (store::write_transaction const & transaction_a, nano::qualified_root const & root_a, nano::block_hash const & hash_a) = 0; virtual std::vector get (store::transaction const & transaction_a, nano::root const & root_a) = 0; @@ -24,9 +27,9 @@ class final_vote virtual size_t count (store::transaction const & transaction_a) const = 0; virtual void clear (store::write_transaction const &, nano::root const &) = 0; virtual void clear (store::write_transaction const &) = 0; - virtual store::iterator begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const = 0; - virtual store::iterator begin (store::transaction const & transaction_a) const = 0; - virtual store::iterator end () const = 0; - virtual void for_each_par (std::function, store::iterator)> const & action_a) const = 0; + virtual iterator begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const = 0; + virtual iterator begin (store::transaction const & transaction_a) const = 0; + virtual iterator end () const = 0; + virtual void for_each_par (std::function const & action_a) const = 0; }; } // namespace nano::store diff --git a/nano/store/lmdb/account.cpp b/nano/store/lmdb/account.cpp index 19a35c8e44..e01ce6236d 100644 --- a/nano/store/lmdb/account.cpp +++ b/nano/store/lmdb/account.cpp @@ -43,27 +43,27 @@ size_t nano::store::lmdb::account::count (store::transaction const & transaction return store.count (transaction_a, tables::accounts); } -nano::store::iterator nano::store::lmdb::account::begin (store::transaction const & transaction, nano::account const & account) const +auto nano::store::lmdb::account::begin (store::transaction const & transaction, nano::account const & account) const -> iterator { return store.make_iterator (transaction, tables::accounts, account); } -nano::store::iterator nano::store::lmdb::account::begin (store::transaction const & transaction) const +auto nano::store::lmdb::account::begin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::accounts); } -nano::store::iterator nano::store::lmdb::account::rbegin (store::transaction const & transaction_a) const +auto nano::store::lmdb::account::rbegin (store::transaction const & transaction_a) const -> iterator { return store.make_iterator (transaction_a, tables::accounts, false); } -nano::store::iterator nano::store::lmdb::account::end () const +auto nano::store::lmdb::account::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } -void nano::store::lmdb::account::for_each_par (std::function, store::iterator)> const & action_a) const +void nano::store::lmdb::account::for_each_par (std::function const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/lmdb/account.hpp b/nano/store/lmdb/account.hpp index 6faaf3cfe8..6650f19fc6 100644 --- a/nano/store/lmdb/account.hpp +++ b/nano/store/lmdb/account.hpp @@ -22,11 +22,11 @@ class account : public nano::store::account void del (store::write_transaction const & transaction_a, nano::account const & account_a) override; bool exists (store::transaction const & transaction_a, nano::account const & account_a) override; size_t count (store::transaction const & transaction_a) override; - store::iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator rbegin (store::transaction const & transaction_a) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; + iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator rbegin (store::transaction const & transaction_a) const override; + iterator end () const override; + void for_each_par (std::function const & action_a) const override; /** * Maps account v1 to account information, head, rep, open, balance, timestamp and block count. (Removed) diff --git a/nano/store/lmdb/block.cpp b/nano/store/lmdb/block.cpp index 9d3e308abb..461e0b99f4 100644 --- a/nano/store/lmdb/block.cpp +++ b/nano/store/lmdb/block.cpp @@ -134,22 +134,23 @@ uint64_t nano::store::lmdb::block::count (store::transaction const & transaction { return store.count (transaction_a, tables::blocks); } -nano::store::iterator nano::store::lmdb::block::begin (store::transaction const & transaction) const + +auto nano::store::lmdb::block::begin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::blocks); } -nano::store::iterator nano::store::lmdb::block::begin (store::transaction const & transaction, nano::block_hash const & hash) const +auto nano::store::lmdb::block::begin (store::transaction const & transaction, nano::block_hash const & hash) const -> iterator { return store.make_iterator (transaction, tables::blocks, hash); } -nano::store::iterator nano::store::lmdb::block::end () const +auto nano::store::lmdb::block::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } -void nano::store::lmdb::block::for_each_par (std::function, store::iterator)> const & action_a) const +void nano::store::lmdb::block::for_each_par (std::function const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/lmdb/block.hpp b/nano/store/lmdb/block.hpp index 575803d831..2594945110 100644 --- a/nano/store/lmdb/block.hpp +++ b/nano/store/lmdb/block.hpp @@ -31,10 +31,10 @@ class block : public nano::store::block void del (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; bool exists (store::transaction const & transaction_a, nano::block_hash const & hash_a) override; uint64_t count (store::transaction const & transaction_a) override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + iterator end () const override; + void for_each_par (std::function const & action_a) const override; /** * Contains block_sideband and block for all block types (legacy send/change/open/receive & state blocks) diff --git a/nano/store/lmdb/confirmation_height.cpp b/nano/store/lmdb/confirmation_height.cpp index 1ce01edab4..234c56844b 100644 --- a/nano/store/lmdb/confirmation_height.cpp +++ b/nano/store/lmdb/confirmation_height.cpp @@ -59,22 +59,22 @@ void nano::store::lmdb::confirmation_height::clear (store::write_transaction con store.drop (transaction_a, nano::tables::confirmation_height); } -nano::store::iterator nano::store::lmdb::confirmation_height::begin (store::transaction const & transaction, nano::account const & account) const +auto nano::store::lmdb::confirmation_height::begin (store::transaction const & transaction, nano::account const & account) const -> iterator { return store.make_iterator (transaction, tables::confirmation_height, account); } -nano::store::iterator nano::store::lmdb::confirmation_height::begin (store::transaction const & transaction) const +auto nano::store::lmdb::confirmation_height::begin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::confirmation_height); } -nano::store::iterator nano::store::lmdb::confirmation_height::end () const +auto nano::store::lmdb::confirmation_height::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } -void nano::store::lmdb::confirmation_height::for_each_par (std::function, store::iterator)> const & action_a) const +void nano::store::lmdb::confirmation_height::for_each_par (std::function const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/lmdb/confirmation_height.hpp b/nano/store/lmdb/confirmation_height.hpp index 4674f81137..de35324595 100644 --- a/nano/store/lmdb/confirmation_height.hpp +++ b/nano/store/lmdb/confirmation_height.hpp @@ -23,10 +23,10 @@ class confirmation_height : public nano::store::confirmation_height uint64_t count (store::transaction const & transaction_a) override; void clear (store::write_transaction const & transaction_a, nano::account const & account_a) override; void clear (store::write_transaction const & transaction_a) override; - store::iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; + iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator end () const override; + void for_each_par (std::function const & action_a) const override; /* * Confirmation height of an account, and the hash for the block at that height diff --git a/nano/store/lmdb/final_vote.cpp b/nano/store/lmdb/final_vote.cpp index 2ae93bd5a9..a26153d1f7 100644 --- a/nano/store/lmdb/final_vote.cpp +++ b/nano/store/lmdb/final_vote.cpp @@ -64,22 +64,22 @@ void nano::store::lmdb::final_vote::clear (store::write_transaction const & tran store.drop (transaction_a, nano::tables::final_votes); } -nano::store::iterator nano::store::lmdb::final_vote::begin (store::transaction const & transaction, nano::qualified_root const & root) const +auto nano::store::lmdb::final_vote::begin (store::transaction const & transaction, nano::qualified_root const & root) const -> iterator { return store.make_iterator (transaction, tables::final_votes, root); } -nano::store::iterator nano::store::lmdb::final_vote::begin (store::transaction const & transaction) const +auto nano::store::lmdb::final_vote::begin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::final_votes); } -nano::store::iterator nano::store::lmdb::final_vote::end () const +auto nano::store::lmdb::final_vote::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } -void nano::store::lmdb::final_vote::for_each_par (std::function, store::iterator)> const & action_a) const +void nano::store::lmdb::final_vote::for_each_par (std::function const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint512_t const & start, nano::uint512_t const & end, bool const is_last) { diff --git a/nano/store/lmdb/final_vote.hpp b/nano/store/lmdb/final_vote.hpp index 92fc5253fd..896ab5d6a9 100644 --- a/nano/store/lmdb/final_vote.hpp +++ b/nano/store/lmdb/final_vote.hpp @@ -23,10 +23,10 @@ class final_vote : public nano::store::final_vote size_t count (store::transaction const & transaction_a) const override; void clear (store::write_transaction const & transaction_a, nano::root const & root_a) override; void clear (store::write_transaction const & transaction_a) override; - store::iterator begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; + iterator begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator end () const override; + void for_each_par (std::function const & action_a) const override; /** * Maps root to block hash for generated final votes. diff --git a/nano/store/lmdb/online_weight.cpp b/nano/store/lmdb/online_weight.cpp index 647aaf34da..c9e553a090 100644 --- a/nano/store/lmdb/online_weight.cpp +++ b/nano/store/lmdb/online_weight.cpp @@ -18,19 +18,19 @@ void nano::store::lmdb::online_weight::del (store::write_transaction const & tra store.release_assert_success (status); } -nano::store::iterator nano::store::lmdb::online_weight::begin (store::transaction const & transaction) const +auto nano::store::lmdb::online_weight::begin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::online_weight); } -nano::store::iterator nano::store::lmdb::online_weight::rbegin (store::transaction const & transaction) const +auto nano::store::lmdb::online_weight::rbegin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::online_weight, false); } -nano::store::iterator nano::store::lmdb::online_weight::end () const +auto nano::store::lmdb::online_weight::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } size_t nano::store::lmdb::online_weight::count (store::transaction const & transaction) const diff --git a/nano/store/lmdb/online_weight.hpp b/nano/store/lmdb/online_weight.hpp index 0567c63d9b..fe28103513 100644 --- a/nano/store/lmdb/online_weight.hpp +++ b/nano/store/lmdb/online_weight.hpp @@ -15,9 +15,9 @@ class online_weight : public nano::store::online_weight explicit online_weight (nano::store::lmdb::component & store_a); void put (store::write_transaction const & transaction_a, uint64_t time_a, nano::amount const & amount_a) override; void del (store::write_transaction const & transaction_a, uint64_t time_a) override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator rbegin (store::transaction const & transaction_a) const override; - store::iterator end () const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator rbegin (store::transaction const & transaction_a) const override; + iterator end () const override; size_t count (store::transaction const & transaction_a) const override; void clear (store::write_transaction const & transaction_a) override; diff --git a/nano/store/lmdb/peer.cpp b/nano/store/lmdb/peer.cpp index c43412d9df..a91cd3002b 100644 --- a/nano/store/lmdb/peer.cpp +++ b/nano/store/lmdb/peer.cpp @@ -45,12 +45,12 @@ void nano::store::lmdb::peer::clear (store::write_transaction const & transactio store.release_assert_success (status); } -nano::store::iterator nano::store::lmdb::peer::begin (store::transaction const & transaction) const +auto nano::store::lmdb::peer::begin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::peers); } -nano::store::iterator nano::store::lmdb::peer::end () const +auto nano::store::lmdb::peer::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } diff --git a/nano/store/lmdb/peer.hpp b/nano/store/lmdb/peer.hpp index 8197c00bee..db39eb5124 100644 --- a/nano/store/lmdb/peer.hpp +++ b/nano/store/lmdb/peer.hpp @@ -19,8 +19,8 @@ class peer : public nano::store::peer bool exists (store::transaction const &, nano::endpoint_key const & endpoint) const override; size_t count (store::transaction const &) const override; void clear (store::write_transaction const &) override; - store::iterator begin (store::transaction const &) const override; - store::iterator end () const override; + iterator begin (store::transaction const &) const override; + iterator end () const override; /* * Endpoints for peers diff --git a/nano/store/lmdb/pending.cpp b/nano/store/lmdb/pending.cpp index cabb70896b..925203d542 100644 --- a/nano/store/lmdb/pending.cpp +++ b/nano/store/lmdb/pending.cpp @@ -45,22 +45,22 @@ bool nano::store::lmdb::pending::any (store::transaction const & transaction_a, return iterator != end () && nano::pending_key (iterator->first).account == account_a; } -nano::store::iterator nano::store::lmdb::pending::begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const +auto nano::store::lmdb::pending::begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const -> iterator { return store.make_iterator (transaction_a, tables::pending, key_a); } -nano::store::iterator nano::store::lmdb::pending::begin (store::transaction const & transaction_a) const +auto nano::store::lmdb::pending::begin (store::transaction const & transaction_a) const -> iterator { return store.make_iterator (transaction_a, tables::pending); } -nano::store::iterator nano::store::lmdb::pending::end () const +auto nano::store::lmdb::pending::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } -void nano::store::lmdb::pending::for_each_par (std::function, store::iterator)> const & action_a) const +void nano::store::lmdb::pending::for_each_par (std::function const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint512_t const & start, nano::uint512_t const & end, bool const is_last) { diff --git a/nano/store/lmdb/pending.hpp b/nano/store/lmdb/pending.hpp index 13cd9172d2..46b5f7947c 100644 --- a/nano/store/lmdb/pending.hpp +++ b/nano/store/lmdb/pending.hpp @@ -22,10 +22,10 @@ class pending : public nano::store::pending std::optional get (store::transaction const & transaction_a, nano::pending_key const & key_a) override; bool exists (store::transaction const & transaction_a, nano::pending_key const & key_a) override; bool any (store::transaction const & transaction_a, nano::account const & account_a) override; - store::iterator begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; + iterator begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator end () const override; + void for_each_par (std::function const & action_a) const override; /** * Maps min_version 0 (destination account, pending block) to (source account, amount). (Removed) diff --git a/nano/store/lmdb/pruned.cpp b/nano/store/lmdb/pruned.cpp index 2be19c24f5..30bf1e0b99 100644 --- a/nano/store/lmdb/pruned.cpp +++ b/nano/store/lmdb/pruned.cpp @@ -45,22 +45,22 @@ void nano::store::lmdb::pruned::clear (store::write_transaction const & transact store.release_assert_success (status); } -nano::store::iterator nano::store::lmdb::pruned::begin (store::transaction const & transaction, nano::block_hash const & hash) const +auto nano::store::lmdb::pruned::begin (store::transaction const & transaction, nano::block_hash const & hash) const -> iterator { return store.make_iterator (transaction, tables::pruned, hash); } -nano::store::iterator nano::store::lmdb::pruned::begin (store::transaction const & transaction) const +auto nano::store::lmdb::pruned::begin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::pruned); } -nano::store::iterator nano::store::lmdb::pruned::end () const +auto nano::store::lmdb::pruned::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } -void nano::store::lmdb::pruned::for_each_par (std::function, store::iterator)> const & action_a) const +void nano::store::lmdb::pruned::for_each_par (std::function const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/lmdb/pruned.hpp b/nano/store/lmdb/pruned.hpp index 0aa2d7fc20..de1be14a1a 100644 --- a/nano/store/lmdb/pruned.hpp +++ b/nano/store/lmdb/pruned.hpp @@ -19,10 +19,10 @@ class pruned : public nano::store::pruned nano::block_hash random (store::transaction const & transaction_a) override; size_t count (store::transaction const & transaction_a) const override; void clear (store::write_transaction const & transaction_a) override; - store::iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; + iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator end () const override; + void for_each_par (std::function const & action_a) const override; /** * Pruned blocks hashes diff --git a/nano/store/lmdb/rep_weight.cpp b/nano/store/lmdb/rep_weight.cpp index 529efae68e..d01d204d5c 100644 --- a/nano/store/lmdb/rep_weight.cpp +++ b/nano/store/lmdb/rep_weight.cpp @@ -43,22 +43,22 @@ void nano::store::lmdb::rep_weight::del (store::write_transaction const & txn_a, store.release_assert_success (status); } -nano::store::iterator nano::store::lmdb::rep_weight::begin (store::transaction const & transaction_a, nano::account const & representative_a) const +auto nano::store::lmdb::rep_weight::begin (store::transaction const & transaction_a, nano::account const & representative_a) const -> iterator { return store.make_iterator (transaction_a, tables::rep_weights, representative_a); } -nano::store::iterator nano::store::lmdb::rep_weight::begin (store::transaction const & transaction_a) const +auto nano::store::lmdb::rep_weight::begin (store::transaction const & transaction_a) const -> iterator { return store.make_iterator (transaction_a, tables::rep_weights); } -nano::store::iterator nano::store::lmdb::rep_weight::end () const +auto nano::store::lmdb::rep_weight::end () const -> iterator { - return nano::store::iterator (nullptr); + return iterator{ nullptr }; } -void nano::store::lmdb::rep_weight::for_each_par (std::function, store::iterator)> const & action_a) const +void nano::store::lmdb::rep_weight::for_each_par (std::function const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/lmdb/rep_weight.hpp b/nano/store/lmdb/rep_weight.hpp index 2a6ef53c5c..809b23ae29 100644 --- a/nano/store/lmdb/rep_weight.hpp +++ b/nano/store/lmdb/rep_weight.hpp @@ -20,10 +20,10 @@ class rep_weight : public nano::store::rep_weight nano::uint128_t get (store::transaction const & txn_a, nano::account const & representative_a) override; void put (store::write_transaction const & txn_a, nano::account const & representative_a, nano::uint128_t const & weight_a) override; void del (store::write_transaction const &, nano::account const & representative_a) override; - store::iterator begin (store::transaction const & transaction_a, nano::account const & representative_a) const override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; + iterator begin (store::transaction const & transaction_a, nano::account const & representative_a) const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator end () const override; + void for_each_par (std::function const & action_a) const override; /** * Representative weights diff --git a/nano/store/online_weight.hpp b/nano/store/online_weight.hpp index aa17938e86..595a515108 100644 --- a/nano/store/online_weight.hpp +++ b/nano/store/online_weight.hpp @@ -17,12 +17,15 @@ namespace nano::store */ class online_weight { +public: + using iterator = store::iterator; + public: virtual void put (store::write_transaction const &, uint64_t, nano::amount const &) = 0; virtual void del (store::write_transaction const &, uint64_t) = 0; - virtual store::iterator begin (store::transaction const &) const = 0; - virtual store::iterator rbegin (store::transaction const &) const = 0; - virtual store::iterator end () const = 0; + virtual iterator begin (store::transaction const &) const = 0; + virtual iterator rbegin (store::transaction const &) const = 0; + virtual iterator end () const = 0; virtual size_t count (store::transaction const &) const = 0; virtual void clear (store::write_transaction const &) = 0; }; diff --git a/nano/store/peer.hpp b/nano/store/peer.hpp index 82f9a5381c..58e3c1d1e4 100644 --- a/nano/store/peer.hpp +++ b/nano/store/peer.hpp @@ -17,6 +17,9 @@ namespace nano::store */ class peer { +public: + using iterator = store::iterator; + public: /// Returns true if the peer was inserted, false if it was already in the container virtual void put (store::write_transaction const &, nano::endpoint_key const & endpoint, nano::millis_t timestamp) = 0; @@ -25,7 +28,7 @@ class peer virtual bool exists (store::transaction const &, nano::endpoint_key const & endpoint) const = 0; virtual size_t count (store::transaction const &) const = 0; virtual void clear (store::write_transaction const &) = 0; - virtual store::iterator begin (store::transaction const &) const = 0; - virtual store::iterator end () const = 0; + virtual iterator begin (store::transaction const &) const = 0; + virtual iterator end () const = 0; }; } // namespace nano::store diff --git a/nano/store/pending.hpp b/nano/store/pending.hpp index 23272cba73..771bfba5c7 100644 --- a/nano/store/pending.hpp +++ b/nano/store/pending.hpp @@ -29,9 +29,9 @@ class pending virtual std::optional get (store::transaction const &, nano::pending_key const &) = 0; virtual bool exists (store::transaction const &, nano::pending_key const &) = 0; virtual bool any (store::transaction const &, nano::account const &) = 0; - virtual store::iterator begin (store::transaction const &, nano::pending_key const &) const = 0; - virtual store::iterator begin (store::transaction const &) const = 0; - virtual store::iterator end () const = 0; - virtual void for_each_par (std::function, store::iterator)> const & action_a) const = 0; + virtual iterator begin (store::transaction const &, nano::pending_key const &) const = 0; + virtual iterator begin (store::transaction const &) const = 0; + virtual iterator end () const = 0; + virtual void for_each_par (std::function const & action_a) const = 0; }; } // namespace nano::store diff --git a/nano/store/pruned.hpp b/nano/store/pruned.hpp index cc40c812b8..5899c3d0cf 100644 --- a/nano/store/pruned.hpp +++ b/nano/store/pruned.hpp @@ -17,6 +17,9 @@ namespace nano::store */ class pruned { +public: + using iterator = store::iterator; + public: virtual void put (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) = 0; virtual void del (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) = 0; @@ -24,9 +27,9 @@ class pruned virtual nano::block_hash random (store::transaction const & transaction_a) = 0; virtual size_t count (store::transaction const & transaction_a) const = 0; virtual void clear (store::write_transaction const &) = 0; - virtual store::iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; - virtual store::iterator begin (store::transaction const & transaction_a) const = 0; - virtual store::iterator end () const = 0; - virtual void for_each_par (std::function, store::iterator)> const & action_a) const = 0; + virtual iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; + virtual iterator begin (store::transaction const & transaction_a) const = 0; + virtual iterator end () const = 0; + virtual void for_each_par (std::function const & action_a) const = 0; }; } // namespace nano::store diff --git a/nano/store/rep_weight.hpp b/nano/store/rep_weight.hpp index 72ac9f84aa..5d8fdb80a9 100644 --- a/nano/store/rep_weight.hpp +++ b/nano/store/rep_weight.hpp @@ -18,15 +18,18 @@ namespace nano::store */ class rep_weight { +public: + using iterator = store::iterator; + public: virtual ~rep_weight (){}; virtual uint64_t count (store::transaction const & txn_a) = 0; virtual nano::uint128_t get (store::transaction const & txn_a, nano::account const & representative_a) = 0; virtual void put (store::write_transaction const & txn_a, nano::account const & representative_a, nano::uint128_t const & weight_a) = 0; virtual void del (store::write_transaction const &, nano::account const & representative_a) = 0; - virtual store::iterator begin (store::transaction const & transaction_a, nano::account const & representative_a) const = 0; - virtual store::iterator begin (store::transaction const & transaction_a) const = 0; - virtual store::iterator end () const = 0; - virtual void for_each_par (std::function, store::iterator)> const & action_a) const = 0; + virtual iterator begin (store::transaction const & transaction_a, nano::account const & representative_a) const = 0; + virtual iterator begin (store::transaction const & transaction_a) const = 0; + virtual iterator end () const = 0; + virtual void for_each_par (std::function const & action_a) const = 0; }; } diff --git a/nano/store/rocksdb/account.cpp b/nano/store/rocksdb/account.cpp index 8ee01b98fe..9040f22e31 100644 --- a/nano/store/rocksdb/account.cpp +++ b/nano/store/rocksdb/account.cpp @@ -42,27 +42,27 @@ size_t nano::store::rocksdb::account::count (store::transaction const & transact return store.count (transaction_a, tables::accounts); } -nano::store::iterator nano::store::rocksdb::account::begin (store::transaction const & transaction, nano::account const & account) const +auto nano::store::rocksdb::account::begin (store::transaction const & transaction, nano::account const & account) const -> iterator { return store.make_iterator (transaction, tables::accounts, account); } -nano::store::iterator nano::store::rocksdb::account::begin (store::transaction const & transaction) const +auto nano::store::rocksdb::account::begin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::accounts); } -nano::store::iterator nano::store::rocksdb::account::rbegin (store::transaction const & transaction_a) const +auto nano::store::rocksdb::account::rbegin (store::transaction const & transaction_a) const -> iterator { return store.make_iterator (transaction_a, tables::accounts, false); } -nano::store::iterator nano::store::rocksdb::account::end () const +auto nano::store::rocksdb::account::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } -void nano::store::rocksdb::account::for_each_par (std::function, store::iterator)> const & action_a) const +void nano::store::rocksdb::account::for_each_par (std::function const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/rocksdb/account.hpp b/nano/store/rocksdb/account.hpp index df5752b4fc..1b2c068d00 100644 --- a/nano/store/rocksdb/account.hpp +++ b/nano/store/rocksdb/account.hpp @@ -20,10 +20,10 @@ class account : public nano::store::account void del (store::write_transaction const & transaction_a, nano::account const & account_a) override; bool exists (store::transaction const & transaction_a, nano::account const & account_a) override; size_t count (store::transaction const & transaction_a) override; - store::iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator rbegin (store::transaction const & transaction_a) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; + iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator rbegin (store::transaction const & transaction_a) const override; + iterator end () const override; + void for_each_par (std::function const & action_a) const override; }; } // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/block.cpp b/nano/store/rocksdb/block.cpp index 10ca4067eb..7532193ae7 100644 --- a/nano/store/rocksdb/block.cpp +++ b/nano/store/rocksdb/block.cpp @@ -133,22 +133,23 @@ uint64_t nano::store::rocksdb::block::count (store::transaction const & transact { return store.count (transaction_a, tables::blocks); } -nano::store::iterator nano::store::rocksdb::block::begin (store::transaction const & transaction) const + +auto nano::store::rocksdb::block::begin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::blocks); } -nano::store::iterator nano::store::rocksdb::block::begin (store::transaction const & transaction, nano::block_hash const & hash) const +auto nano::store::rocksdb::block::begin (store::transaction const & transaction, nano::block_hash const & hash) const -> iterator { return store.make_iterator (transaction, tables::blocks, hash); } -nano::store::iterator nano::store::rocksdb::block::end () const +auto nano::store::rocksdb::block::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } -void nano::store::rocksdb::block::for_each_par (std::function, store::iterator)> const & action_a) const +void nano::store::rocksdb::block::for_each_par (std::function const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { @@ -179,6 +180,7 @@ nano::block_predecessor_rocksdb_set::block_predecessor_rocksdb_set (store::write block_store{ block_store_a } { } + void nano::block_predecessor_rocksdb_set::fill_value (nano::block const & block_a) { auto hash = block_a.hash (); @@ -190,22 +192,27 @@ void nano::block_predecessor_rocksdb_set::fill_value (nano::block const & block_ std::copy (hash.bytes.begin (), hash.bytes.end (), data.begin () + block_store.block_successor_offset (transaction, value.size (), type)); block_store.raw_put (transaction, data, block_a.previous ()); } + void nano::block_predecessor_rocksdb_set::send_block (nano::send_block const & block_a) { fill_value (block_a); } + void nano::block_predecessor_rocksdb_set::receive_block (nano::receive_block const & block_a) { fill_value (block_a); } + void nano::block_predecessor_rocksdb_set::open_block (nano::open_block const & block_a) { // Open blocks don't have a predecessor } + void nano::block_predecessor_rocksdb_set::change_block (nano::change_block const & block_a) { fill_value (block_a); } + void nano::block_predecessor_rocksdb_set::state_block (nano::state_block const & block_a) { if (!block_a.previous ().is_zero ()) diff --git a/nano/store/rocksdb/block.hpp b/nano/store/rocksdb/block.hpp index 7df264a2fd..0a093f1c38 100644 --- a/nano/store/rocksdb/block.hpp +++ b/nano/store/rocksdb/block.hpp @@ -29,10 +29,10 @@ class block : public nano::store::block void del (store::write_transaction const & transaction_a, nano::block_hash const & hash_a) override; bool exists (store::transaction const & transaction_a, nano::block_hash const & hash_a) override; uint64_t count (store::transaction const & transaction_a) override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + iterator end () const override; + void for_each_par (std::function const & action_a) const override; protected: void block_raw_get (store::transaction const & transaction_a, nano::block_hash const & hash_a, nano::store::rocksdb::db_val & value) const; diff --git a/nano/store/rocksdb/confirmation_height.cpp b/nano/store/rocksdb/confirmation_height.cpp index 380cd80e32..eea420237c 100644 --- a/nano/store/rocksdb/confirmation_height.cpp +++ b/nano/store/rocksdb/confirmation_height.cpp @@ -59,22 +59,22 @@ void nano::store::rocksdb::confirmation_height::clear (store::write_transaction store.drop (transaction, nano::tables::confirmation_height); } -nano::store::iterator nano::store::rocksdb::confirmation_height::begin (store::transaction const & transaction, nano::account const & account) const +auto nano::store::rocksdb::confirmation_height::begin (store::transaction const & transaction, nano::account const & account) const -> iterator { return store.make_iterator (transaction, tables::confirmation_height, account); } -nano::store::iterator nano::store::rocksdb::confirmation_height::begin (store::transaction const & transaction) const +auto nano::store::rocksdb::confirmation_height::begin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::confirmation_height); } -nano::store::iterator nano::store::rocksdb::confirmation_height::end () const +auto nano::store::rocksdb::confirmation_height::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } -void nano::store::rocksdb::confirmation_height::for_each_par (std::function, store::iterator)> const & action_a) const +void nano::store::rocksdb::confirmation_height::for_each_par (std::function const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/rocksdb/confirmation_height.hpp b/nano/store/rocksdb/confirmation_height.hpp index 95d7300468..050ceef9b1 100644 --- a/nano/store/rocksdb/confirmation_height.hpp +++ b/nano/store/rocksdb/confirmation_height.hpp @@ -21,9 +21,9 @@ class confirmation_height : public nano::store::confirmation_height uint64_t count (store::transaction const & transaction_a) override; void clear (store::write_transaction const & transaction_a, nano::account const & account_a) override; void clear (store::write_transaction const & transaction_a) override; - store::iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; + iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator end () const override; + void for_each_par (std::function const & action_a) const override; }; } // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/final_vote.cpp b/nano/store/rocksdb/final_vote.cpp index 121da33360..3979b16cab 100644 --- a/nano/store/rocksdb/final_vote.cpp +++ b/nano/store/rocksdb/final_vote.cpp @@ -64,22 +64,22 @@ void nano::store::rocksdb::final_vote::clear (store::write_transaction const & t store.drop (transaction_a, nano::tables::final_votes); } -nano::store::iterator nano::store::rocksdb::final_vote::begin (store::transaction const & transaction, nano::qualified_root const & root) const +auto nano::store::rocksdb::final_vote::begin (store::transaction const & transaction, nano::qualified_root const & root) const -> iterator { return store.make_iterator (transaction, tables::final_votes, root); } -nano::store::iterator nano::store::rocksdb::final_vote::begin (store::transaction const & transaction) const +auto nano::store::rocksdb::final_vote::begin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::final_votes); } -nano::store::iterator nano::store::rocksdb::final_vote::end () const +auto nano::store::rocksdb::final_vote::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } -void nano::store::rocksdb::final_vote::for_each_par (std::function, store::iterator)> const & action_a) const +void nano::store::rocksdb::final_vote::for_each_par (std::function const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint512_t const & start, nano::uint512_t const & end, bool const is_last) { diff --git a/nano/store/rocksdb/final_vote.hpp b/nano/store/rocksdb/final_vote.hpp index d730ec08b8..0ffa549faf 100644 --- a/nano/store/rocksdb/final_vote.hpp +++ b/nano/store/rocksdb/final_vote.hpp @@ -21,9 +21,9 @@ class final_vote : public nano::store::final_vote size_t count (store::transaction const & transaction_a) const override; void clear (store::write_transaction const & transaction_a, nano::root const & root_a) override; void clear (store::write_transaction const & transaction_a) override; - store::iterator begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; + iterator begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator end () const override; + void for_each_par (std::function const & action_a) const override; }; } // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/online_weight.cpp b/nano/store/rocksdb/online_weight.cpp index c6f7e1dacf..42250c6897 100644 --- a/nano/store/rocksdb/online_weight.cpp +++ b/nano/store/rocksdb/online_weight.cpp @@ -18,19 +18,19 @@ void nano::store::rocksdb::online_weight::del (store::write_transaction const & store.release_assert_success (status); } -nano::store::iterator nano::store::rocksdb::online_weight::begin (store::transaction const & transaction) const +auto nano::store::rocksdb::online_weight::begin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::online_weight); } -nano::store::iterator nano::store::rocksdb::online_weight::rbegin (store::transaction const & transaction) const +auto nano::store::rocksdb::online_weight::rbegin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::online_weight, false); } -nano::store::iterator nano::store::rocksdb::online_weight::end () const +auto nano::store::rocksdb::online_weight::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } size_t nano::store::rocksdb::online_weight::count (store::transaction const & transaction) const diff --git a/nano/store/rocksdb/online_weight.hpp b/nano/store/rocksdb/online_weight.hpp index 68718f3e0b..4d940ffda3 100644 --- a/nano/store/rocksdb/online_weight.hpp +++ b/nano/store/rocksdb/online_weight.hpp @@ -17,9 +17,9 @@ class online_weight : public nano::store::online_weight explicit online_weight (nano::store::rocksdb::component & store_a); void put (store::write_transaction const & transaction_a, uint64_t time_a, nano::amount const & amount_a) override; void del (store::write_transaction const & transaction_a, uint64_t time_a) override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator rbegin (store::transaction const & transaction_a) const override; - store::iterator end () const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator rbegin (store::transaction const & transaction_a) const override; + iterator end () const override; size_t count (store::transaction const & transaction_a) const override; void clear (store::write_transaction const & transaction_a) override; }; diff --git a/nano/store/rocksdb/peer.cpp b/nano/store/rocksdb/peer.cpp index af226e8a83..71fa3ccc56 100644 --- a/nano/store/rocksdb/peer.cpp +++ b/nano/store/rocksdb/peer.cpp @@ -45,12 +45,12 @@ void nano::store::rocksdb::peer::clear (store::write_transaction const & transac store.release_assert_success (status); } -nano::store::iterator nano::store::rocksdb::peer::begin (store::transaction const & transaction) const +auto nano::store::rocksdb::peer::begin (store::transaction const & transaction) const -> iterator { return store.make_iterator (transaction, tables::peers); } -nano::store::iterator nano::store::rocksdb::peer::end () const +auto nano::store::rocksdb::peer::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } diff --git a/nano/store/rocksdb/peer.hpp b/nano/store/rocksdb/peer.hpp index a4ce7286c8..30e57644fd 100644 --- a/nano/store/rocksdb/peer.hpp +++ b/nano/store/rocksdb/peer.hpp @@ -21,7 +21,7 @@ class peer : public nano::store::peer bool exists (store::transaction const &, nano::endpoint_key const & endpoint) const override; size_t count (store::transaction const &) const override; void clear (store::write_transaction const &) override; - store::iterator begin (store::transaction const &) const override; - store::iterator end () const override; + iterator begin (store::transaction const &) const override; + iterator end () const override; }; } // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/pending.cpp b/nano/store/rocksdb/pending.cpp index 27efe5e637..3286cd8f94 100644 --- a/nano/store/rocksdb/pending.cpp +++ b/nano/store/rocksdb/pending.cpp @@ -45,22 +45,22 @@ bool nano::store::rocksdb::pending::any (store::transaction const & transaction_ return iterator != end () && nano::pending_key (iterator->first).account == account_a; } -nano::store::iterator nano::store::rocksdb::pending::begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const +auto nano::store::rocksdb::pending::begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const -> iterator { return store.template make_iterator (transaction_a, tables::pending, key_a); } -nano::store::iterator nano::store::rocksdb::pending::begin (store::transaction const & transaction_a) const +auto nano::store::rocksdb::pending::begin (store::transaction const & transaction_a) const -> iterator { return store.template make_iterator (transaction_a, tables::pending); } -nano::store::iterator nano::store::rocksdb::pending::end () const +auto nano::store::rocksdb::pending::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } -void nano::store::rocksdb::pending::for_each_par (std::function, store::iterator)> const & action_a) const +void nano::store::rocksdb::pending::for_each_par (std::function const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint512_t const & start, nano::uint512_t const & end, bool const is_last) { diff --git a/nano/store/rocksdb/pending.hpp b/nano/store/rocksdb/pending.hpp index 0ee4ced54a..4b98b0f079 100644 --- a/nano/store/rocksdb/pending.hpp +++ b/nano/store/rocksdb/pending.hpp @@ -16,9 +16,9 @@ class pending : public nano::store::pending std::optional get (store::transaction const & transaction_a, nano::pending_key const & key_a) override; bool exists (store::transaction const & transaction_a, nano::pending_key const & key_a) override; bool any (store::transaction const & transaction_a, nano::account const & account_a) override; - store::iterator begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; + iterator begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator end () const override; + void for_each_par (std::function const & action_a) const override; }; } // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/pruned.cpp b/nano/store/rocksdb/pruned.cpp index 41d7fbb586..572f17e348 100644 --- a/nano/store/rocksdb/pruned.cpp +++ b/nano/store/rocksdb/pruned.cpp @@ -45,22 +45,22 @@ void nano::store::rocksdb::pruned::clear (store::write_transaction const & trans store.release_assert_success (status); } -nano::store::iterator nano::store::rocksdb::pruned::begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const +auto nano::store::rocksdb::pruned::begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const -> iterator { return store.make_iterator (transaction_a, tables::pruned, hash_a); } -nano::store::iterator nano::store::rocksdb::pruned::begin (store::transaction const & transaction_a) const +auto nano::store::rocksdb::pruned::begin (store::transaction const & transaction_a) const -> iterator { return store.make_iterator (transaction_a, tables::pruned); } -nano::store::iterator nano::store::rocksdb::pruned::end () const +auto nano::store::rocksdb::pruned::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } -void nano::store::rocksdb::pruned::for_each_par (std::function, store::iterator)> const & action_a) const +void nano::store::rocksdb::pruned::for_each_par (std::function const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { diff --git a/nano/store/rocksdb/pruned.hpp b/nano/store/rocksdb/pruned.hpp index aa5db1fbab..0dc84b84ed 100644 --- a/nano/store/rocksdb/pruned.hpp +++ b/nano/store/rocksdb/pruned.hpp @@ -21,9 +21,9 @@ class pruned : public nano::store::pruned nano::block_hash random (store::transaction const & transaction_a) override; size_t count (store::transaction const & transaction_a) const override; void clear (store::write_transaction const & transaction_a) override; - store::iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - store::iterator begin (store::transaction const & transaction_a) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; + iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; + iterator begin (store::transaction const & transaction_a) const override; + iterator end () const override; + void for_each_par (std::function const & action_a) const override; }; } // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/rep_weight.cpp b/nano/store/rocksdb/rep_weight.cpp index 7f29e61e4b..68d4684ced 100644 --- a/nano/store/rocksdb/rep_weight.cpp +++ b/nano/store/rocksdb/rep_weight.cpp @@ -42,26 +42,26 @@ void nano::store::rocksdb::rep_weight::del (store::write_transaction const & txn store.release_assert_success (status); } -nano::store::iterator nano::store::rocksdb::rep_weight::begin (store::transaction const & txn_a, nano::account const & representative_a) const +auto nano::store::rocksdb::rep_weight::begin (store::transaction const & txn_a, nano::account const & representative_a) const -> iterator { return store.make_iterator (txn_a, tables::rep_weights, representative_a); } -nano::store::iterator nano::store::rocksdb::rep_weight::begin (store::transaction const & txn_a) const +auto nano::store::rocksdb::rep_weight::begin (store::transaction const & txn_a) const -> iterator { return store.make_iterator (txn_a, tables::rep_weights); } -nano::store::iterator nano::store::rocksdb::rep_weight::end () const +auto nano::store::rocksdb::rep_weight::end () const -> iterator { - return store::iterator (nullptr); + return iterator{ nullptr }; } -void nano::store::rocksdb::rep_weight::for_each_par (std::function, store::iterator)> const & action_a) const +void nano::store::rocksdb::rep_weight::for_each_par (std::function const & action_a) const { parallel_traversal ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { auto transaction (this->store.tx_begin_read ()); action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); }); -} \ No newline at end of file +} diff --git a/nano/store/rocksdb/rep_weight.hpp b/nano/store/rocksdb/rep_weight.hpp index c86f27150b..76e542264b 100644 --- a/nano/store/rocksdb/rep_weight.hpp +++ b/nano/store/rocksdb/rep_weight.hpp @@ -19,9 +19,9 @@ class rep_weight : public nano::store::rep_weight nano::uint128_t get (store::transaction const & txn_a, nano::account const & representative_a) override; void put (store::write_transaction const & txn_a, nano::account const & representative_a, nano::uint128_t const & weight_a) override; void del (store::write_transaction const &, nano::account const & representative_a) override; - store::iterator begin (store::transaction const & txn_a, nano::account const & representative_a) const override; - store::iterator begin (store::transaction const & txn_a) const override; - store::iterator end () const override; - void for_each_par (std::function, store::iterator)> const & action_a) const override; + iterator begin (store::transaction const & txn_a, nano::account const & representative_a) const override; + iterator begin (store::transaction const & txn_a) const override; + iterator end () const override; + void for_each_par (std::function const & action_a) const override; }; } From d54258102cca2f8876b636b5a49c3dbf3e9565d8 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 10 Oct 2024 14:37:08 +0200 Subject: [PATCH 40/47] Renaming file "final" to "final_vote". --- nano/secure/ledger.cpp | 4 ++-- nano/store/CMakeLists.txt | 4 ++-- nano/store/final.cpp | 1 - nano/store/final_vote.cpp | 1 + nano/store/{final.hpp => final_vote.hpp} | 0 nano/store/lmdb/final_vote.hpp | 2 +- nano/store/rocksdb/final_vote.hpp | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 nano/store/final.cpp create mode 100644 nano/store/final_vote.cpp rename nano/store/{final.hpp => final_vote.hpp} (100%) diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index cba173a6c8..bc9514a8b1 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -1523,4 +1523,4 @@ nano::container_info nano::ledger::container_info () const info.put ("bootstrap_weights", bootstrap_weights); info.add ("rep_weights", cache.rep_weights.container_info ()); return info; -} \ No newline at end of file +} diff --git a/nano/store/CMakeLists.txt b/nano/store/CMakeLists.txt index c44d7fc0de..e5e6a8c47c 100644 --- a/nano/store/CMakeLists.txt +++ b/nano/store/CMakeLists.txt @@ -9,7 +9,7 @@ add_library( db_val_impl.hpp iterator.hpp iterator_impl.hpp - final.hpp + final_vote.hpp lmdb/account.hpp lmdb/block.hpp lmdb/confirmation_height.hpp @@ -59,7 +59,7 @@ add_library( db_val.cpp iterator.cpp iterator_impl.cpp - final.cpp + final_vote.cpp lmdb/account.cpp lmdb/block.cpp lmdb/confirmation_height.cpp diff --git a/nano/store/final.cpp b/nano/store/final.cpp deleted file mode 100644 index 69d469dc76..0000000000 --- a/nano/store/final.cpp +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/nano/store/final_vote.cpp b/nano/store/final_vote.cpp new file mode 100644 index 0000000000..0b4565c1ab --- /dev/null +++ b/nano/store/final_vote.cpp @@ -0,0 +1 @@ +#include diff --git a/nano/store/final.hpp b/nano/store/final_vote.hpp similarity index 100% rename from nano/store/final.hpp rename to nano/store/final_vote.hpp diff --git a/nano/store/lmdb/final_vote.hpp b/nano/store/lmdb/final_vote.hpp index 896ab5d6a9..9b72b085a6 100644 --- a/nano/store/lmdb/final_vote.hpp +++ b/nano/store/lmdb/final_vote.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/nano/store/rocksdb/final_vote.hpp b/nano/store/rocksdb/final_vote.hpp index 0ffa549faf..a24093a576 100644 --- a/nano/store/rocksdb/final_vote.hpp +++ b/nano/store/rocksdb/final_vote.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace nano::store::rocksdb { From c659c8b1658b19ce858fabfb8e86568b0be76c84 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 10 Oct 2024 20:14:25 +0100 Subject: [PATCH 41/47] Using type inference in a few places for iterators. --- nano/nano_node/entry.cpp | 4 ++-- nano/secure/ledger.cpp | 6 +++--- nano/test_common/system.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index ae49f157a8..66b9a86fa6 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1942,7 +1942,7 @@ int main (int argc, char * const * argv) nano::locked>> opened_account_versions_shared (epoch_count); using opened_account_versions_t = decltype (opened_account_versions_shared)::value_type; node->store.account.for_each_par ( - [&opened_account_versions_shared, epoch_count] (nano::store::read_transaction const & /*unused*/, nano::store::iterator i, nano::store::iterator n) { + [&opened_account_versions_shared, epoch_count] (nano::store::read_transaction const & /*unused*/, auto i, auto n) { // First cache locally opened_account_versions_t opened_account_versions_l (epoch_count); for (; i != n; ++i) @@ -1979,7 +1979,7 @@ int main (int argc, char * const * argv) nano::locked>> unopened_highest_pending_shared; using unopened_highest_pending_t = decltype (unopened_highest_pending_shared)::value_type; node->store.pending.for_each_par ( - [&unopened_highest_pending_shared, &opened_accounts] (nano::store::read_transaction const & /*unused*/, nano::store::iterator i, nano::store::iterator n) { + [&unopened_highest_pending_shared, &opened_accounts] (nano::store::read_transaction const & /*unused*/, auto i, auto n) { // First cache locally unopened_highest_pending_t unopened_highest_pending_l; for (; i != n; ++i) diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index bc9514a8b1..93eb61ceac 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -749,7 +749,7 @@ void nano::ledger::initialize (nano::generate_cache_flags const & generate_cache if (generate_cache_flags_a.reps || generate_cache_flags_a.account_count || generate_cache_flags_a.block_count) { store.account.for_each_par ( - [this] (store::read_transaction const & /*unused*/, store::iterator i, store::iterator n) { + [this] (store::read_transaction const & /*unused*/, auto i, auto n) { uint64_t block_count_l{ 0 }; uint64_t account_count_l{ 0 }; for (; i != n; ++i) @@ -763,7 +763,7 @@ void nano::ledger::initialize (nano::generate_cache_flags const & generate_cache }); store.rep_weight.for_each_par ( - [this] (store::read_transaction const & /*unused*/, store::iterator i, store::iterator n) { + [this] (store::read_transaction const & /*unused*/, auto i, auto n) { nano::rep_weights rep_weights_l{ this->store.rep_weight }; for (; i != n; ++i) { @@ -776,7 +776,7 @@ void nano::ledger::initialize (nano::generate_cache_flags const & generate_cache if (generate_cache_flags_a.cemented_count) { store.confirmation_height.for_each_par ( - [this] (store::read_transaction const & /*unused*/, store::iterator i, store::iterator n) { + [this] (store::read_transaction const & /*unused*/, auto i, auto n) { uint64_t cemented_count_l (0); for (; i != n; ++i) { diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index c0a9831cf0..40f8be2203 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -532,7 +532,7 @@ void nano::test::system::generate_send_existing (nano::node & node_a, std::vecto nano::account account; random_pool::generate_block (account.bytes.data (), sizeof (account.bytes)); auto transaction = node_a.ledger.tx_begin_read (); - store::iterator entry (node_a.store.account.begin (transaction, account)); + auto entry = node_a.store.account.begin (transaction, account); if (entry == node_a.store.account.end ()) { entry = node_a.store.account.begin (transaction); From dd08220e2ccdc3092b4594bcc37aecda2007d1c1 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Fri, 18 Oct 2024 19:47:32 +0200 Subject: [PATCH 42/47] Only broadcast every 100ms or 255 votes --- nano/node/vote_generator.cpp | 18 ++++++++++++++++-- nano/node/vote_generator.hpp | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/nano/node/vote_generator.cpp b/nano/node/vote_generator.cpp index 00dccfd570..a54ec13694 100644 --- a/nano/node/vote_generator.cpp +++ b/nano/node/vote_generator.cpp @@ -289,11 +289,12 @@ void nano::vote_generator::run () nano::unique_lock lock{ mutex }; while (!stopped) { - condition.wait_for (lock, config.vote_generator_delay, [this] () { return this->candidates.size () >= nano::network::confirm_ack_hashes_max || !requests.empty (); }); + condition.wait_for (lock, config.vote_generator_delay, [this] () { return broadcast_predicate () || !requests.empty (); }); - if (!candidates.empty ()) + if (broadcast_predicate ()) { broadcast (lock); + next_broadcast = std::chrono::steady_clock::now () + std::chrono::milliseconds (config.vote_generator_delay); } if (!requests.empty ()) @@ -305,6 +306,19 @@ void nano::vote_generator::run () } } +bool nano::vote_generator::broadcast_predicate () const +{ + if (candidates.size () >= nano::network::confirm_ack_hashes_max) + { + return true; + } + if (candidates.size () > 0 && std::chrono::steady_clock::now () > next_broadcast) + { + return true; + } + return false; +} + nano::container_info nano::vote_generator::container_info () const { nano::lock_guard guard{ mutex }; diff --git a/nano/node/vote_generator.hpp b/nano/node/vote_generator.hpp index c93317bcc3..76fc0c583a 100644 --- a/nano/node/vote_generator.hpp +++ b/nano/node/vote_generator.hpp @@ -30,6 +30,7 @@ class vote_generator final using candidate_t = std::pair; using request_t = std::pair, std::shared_ptr>; using queue_entry_t = std::pair; + std::chrono::steady_clock::time_point next_broadcast = { std::chrono::steady_clock::now () }; public: vote_generator (nano::node_config const &, nano::node &, nano::ledger &, nano::wallets &, nano::vote_processor &, nano::local_vote_history &, nano::network &, nano::stats &, nano::logger &, bool is_final); @@ -56,6 +57,7 @@ class vote_generator final void broadcast_action (std::shared_ptr const &) const; void process_batch (std::deque & batch); bool should_vote (transaction_variant_t const &, nano::root const &, nano::block_hash const &) const; + bool broadcast_predicate () const; private: std::function const &, std::shared_ptr &)> reply_action; // must be set only during initialization by using set_reply_action From 483c6906e8fe556a2347f225c1af16fc04f702aa Mon Sep 17 00:00:00 2001 From: clemahieu Date: Mon, 21 Oct 2024 23:19:36 +0100 Subject: [PATCH 43/47] Pass transaction in to end iterator for future use. (#4761) --- nano/core_test/block_store.cpp | 26 ++++++------ nano/core_test/ledger.cpp | 2 +- nano/core_test/system.cpp | 8 ++-- nano/core_test/wallet.cpp | 16 +++---- nano/nano_node/entry.cpp | 12 +++--- nano/nano_wallet/entry.cpp | 2 +- nano/node/backlog_population.cpp | 2 +- nano/node/bootstrap/bootstrap_frontier.cpp | 6 +-- nano/node/bootstrap/bootstrap_server.cpp | 2 +- .../bootstrap_ascending/database_scan.cpp | 6 +-- nano/node/cli.cpp | 6 +-- nano/node/epoch_upgrader.cpp | 2 +- nano/node/json_handler.cpp | 42 +++++++++---------- nano/node/node.cpp | 10 ++--- nano/node/online_reps.cpp | 4 +- nano/node/peer_history.cpp | 4 +- nano/node/wallet.cpp | 22 +++++----- nano/node/wallet.hpp | 2 +- nano/qt/qt.cpp | 6 +-- nano/rpc_test/rpc.cpp | 14 +++---- nano/secure/ledger.cpp | 4 +- nano/secure/ledger_set_any.cpp | 4 +- nano/secure/ledger_set_confirmed.cpp | 4 +- nano/slow_test/node.cpp | 20 ++++----- nano/store/account.hpp | 2 +- nano/store/block.hpp | 2 +- nano/store/component.cpp | 2 +- nano/store/confirmation_height.hpp | 2 +- nano/store/final_vote.hpp | 2 +- nano/store/lmdb/account.cpp | 6 +-- nano/store/lmdb/account.hpp | 2 +- nano/store/lmdb/block.cpp | 8 ++-- nano/store/lmdb/block.hpp | 2 +- nano/store/lmdb/confirmation_height.cpp | 4 +- nano/store/lmdb/confirmation_height.hpp | 2 +- nano/store/lmdb/final_vote.cpp | 8 ++-- nano/store/lmdb/final_vote.hpp | 2 +- nano/store/lmdb/lmdb.cpp | 2 +- nano/store/lmdb/online_weight.cpp | 2 +- nano/store/lmdb/online_weight.hpp | 2 +- nano/store/lmdb/peer.cpp | 2 +- nano/store/lmdb/peer.hpp | 2 +- nano/store/lmdb/pending.cpp | 8 ++-- nano/store/lmdb/pending.hpp | 2 +- nano/store/lmdb/pruned.cpp | 8 ++-- nano/store/lmdb/pruned.hpp | 2 +- nano/store/lmdb/rep_weight.cpp | 4 +- nano/store/lmdb/rep_weight.hpp | 2 +- nano/store/online_weight.hpp | 2 +- nano/store/peer.hpp | 2 +- nano/store/pending.hpp | 2 +- nano/store/pruned.hpp | 2 +- nano/store/rep_weight.hpp | 2 +- nano/store/rocksdb/account.cpp | 6 +-- nano/store/rocksdb/account.hpp | 2 +- nano/store/rocksdb/block.cpp | 8 ++-- nano/store/rocksdb/block.hpp | 2 +- nano/store/rocksdb/confirmation_height.cpp | 4 +- nano/store/rocksdb/confirmation_height.hpp | 2 +- nano/store/rocksdb/final_vote.cpp | 8 ++-- nano/store/rocksdb/final_vote.hpp | 2 +- nano/store/rocksdb/online_weight.cpp | 2 +- nano/store/rocksdb/online_weight.hpp | 2 +- nano/store/rocksdb/peer.cpp | 2 +- nano/store/rocksdb/peer.hpp | 2 +- nano/store/rocksdb/pending.cpp | 8 ++-- nano/store/rocksdb/pending.hpp | 2 +- nano/store/rocksdb/pruned.cpp | 8 ++-- nano/store/rocksdb/pruned.hpp | 2 +- nano/store/rocksdb/rep_weight.cpp | 4 +- nano/store/rocksdb/rep_weight.hpp | 2 +- nano/store/rocksdb/rocksdb.cpp | 19 +++++---- nano/test_common/system.cpp | 8 ++-- nano/test_common/testutil.cpp | 8 ++-- 74 files changed, 211 insertions(+), 208 deletions(-) diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index fcf7a57144..84e98380c0 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -314,10 +314,10 @@ TEST (block_store, pending_iterator) auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants); ASSERT_TRUE (!store->init_error ()); auto transaction (store->tx_begin_write ()); - ASSERT_EQ (store->pending.end (), store->pending.begin (transaction)); + ASSERT_EQ (store->pending.end (transaction), store->pending.begin (transaction)); store->pending.put (transaction, nano::pending_key (1, 2), { 2, 3, nano::epoch::epoch_1 }); auto current (store->pending.begin (transaction)); - ASSERT_NE (store->pending.end (), current); + ASSERT_NE (store->pending.end (transaction), current); nano::pending_key key1 (current->first); ASSERT_EQ (nano::account (1), key1.account); ASSERT_EQ (nano::block_hash (2), key1.hash); @@ -411,7 +411,7 @@ TEST (block_store, empty_accounts) ASSERT_TRUE (!store->init_error ()); auto transaction (store->tx_begin_read ()); auto begin (store->account.begin (transaction)); - auto end (store->account.end ()); + auto end (store->account.end (transaction)); ASSERT_EQ (end, begin); } @@ -498,7 +498,7 @@ TEST (block_store, one_account) store->confirmation_height.put (transaction, account, { 20, nano::block_hash (15) }); store->account.put (transaction, account, { hash, account, hash, 42, 100, 200, nano::epoch::epoch_0 }); auto begin (store->account.begin (transaction)); - auto end (store->account.end ()); + auto end (store->account.end (transaction)); ASSERT_NE (end, begin); ASSERT_EQ (account, nano::account (begin->first)); nano::account_info info (begin->second); @@ -567,7 +567,7 @@ TEST (block_store, two_account) store->confirmation_height.put (transaction, account2, { 30, nano::block_hash (20) }); store->account.put (transaction, account2, { hash2, account2, hash2, 84, 200, 400, nano::epoch::epoch_0 }); auto begin (store->account.begin (transaction)); - auto end (store->account.end ()); + auto end (store->account.end (transaction)); ASSERT_NE (end, begin); ASSERT_EQ (account1, nano::account (begin->first)); nano::account_info info1 (begin->second); @@ -787,7 +787,7 @@ TEST (block_store, large_iteration) std::unordered_set accounts2; nano::account previous{}; auto transaction (store->tx_begin_read ()); - for (auto i (store->account.begin (transaction, 0)), n (store->account.end ()); i != n; ++i) + for (auto i (store->account.begin (transaction, 0)), n (store->account.end (transaction)); i != n; ++i) { nano::account current (i->first); ASSERT_GT (current.number (), previous.number ()); @@ -798,7 +798,7 @@ TEST (block_store, large_iteration) // Reverse iteration std::unordered_set accounts3; previous = std::numeric_limits::max (); - for (auto i (store->account.rbegin (transaction)), n (store->account.end ()); i != n; --i) + for (auto i (store->account.rbegin (transaction)), n (store->account.end (transaction)); i != n; --i) { nano::account current (i->first); ASSERT_LT (current.number (), previous.number ()); @@ -1253,8 +1253,8 @@ TEST (block_store, online_weight) { auto transaction (store->tx_begin_write ()); ASSERT_EQ (0, store->online_weight.count (transaction)); - ASSERT_EQ (store->online_weight.end (), store->online_weight.begin (transaction)); - ASSERT_EQ (store->online_weight.end (), store->online_weight.rbegin (transaction)); + ASSERT_EQ (store->online_weight.end (transaction), store->online_weight.begin (transaction)); + ASSERT_EQ (store->online_weight.end (transaction), store->online_weight.rbegin (transaction)); store->online_weight.put (transaction, 1, 2); store->online_weight.put (transaction, 3, 4); } @@ -1262,11 +1262,11 @@ TEST (block_store, online_weight) auto transaction (store->tx_begin_write ()); ASSERT_EQ (2, store->online_weight.count (transaction)); auto item (store->online_weight.begin (transaction)); - ASSERT_NE (store->online_weight.end (), item); + ASSERT_NE (store->online_weight.end (transaction), item); ASSERT_EQ (1, item->first); ASSERT_EQ (2, item->second.number ()); auto item_last (store->online_weight.rbegin (transaction)); - ASSERT_NE (store->online_weight.end (), item_last); + ASSERT_NE (store->online_weight.end (transaction), item_last); ASSERT_EQ (3, item_last->first); ASSERT_EQ (4, item_last->second.number ()); store->online_weight.del (transaction, 1); @@ -1276,8 +1276,8 @@ TEST (block_store, online_weight) } auto transaction (store->tx_begin_read ()); ASSERT_EQ (0, store->online_weight.count (transaction)); - ASSERT_EQ (store->online_weight.end (), store->online_weight.begin (transaction)); - ASSERT_EQ (store->online_weight.end (), store->online_weight.rbegin (transaction)); + ASSERT_EQ (store->online_weight.end (transaction), store->online_weight.begin (transaction)); + ASSERT_EQ (store->online_weight.end (transaction), store->online_weight.rbegin (transaction)); } TEST (block_store, pruned_blocks) diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index f30b895cfc..23d3d751b1 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -5464,7 +5464,7 @@ TEST (ledger, migrate_lmdb_to_rocksdb) ASSERT_TRUE (rocksdb_store.pending.get (rocksdb_transaction, nano::pending_key (nano::dev::genesis_key.pub, send->hash ()))); - for (auto i = rocksdb_store.online_weight.begin (rocksdb_transaction); i != rocksdb_store.online_weight.end (); ++i) + for (auto i = rocksdb_store.online_weight.begin (rocksdb_transaction); i != rocksdb_store.online_weight.end (rocksdb_transaction); ++i) { ASSERT_EQ (i->first, 100); ASSERT_EQ (i->second, 2); diff --git a/nano/core_test/system.cpp b/nano/core_test/system.cpp index 2072fe8cf9..7f9f1088a0 100644 --- a/nano/core_test/system.cpp +++ b/nano/core_test/system.cpp @@ -95,9 +95,9 @@ TEST (system, DISABLED_generate_send_new) { auto transaction (node1.store.tx_begin_read ()); auto iterator1 (node1.store.account.begin (transaction)); - ASSERT_NE (node1.store.account.end (), iterator1); + ASSERT_NE (node1.store.account.end (transaction), iterator1); ++iterator1; - ASSERT_EQ (node1.store.account.end (), iterator1); + ASSERT_EQ (node1.store.account.end (transaction), iterator1); } nano::keypair stake_preserver; auto send_block (system.wallet (0)->send_action (nano::dev::genesis_key.pub, stake_preserver.pub, nano::dev::constants.genesis_amount / 3 * 2, true)); @@ -130,13 +130,13 @@ TEST (system, DISABLED_generate_send_new) new_account = iterator2->first; } ++iterator2; - ASSERT_NE (system.wallet (0)->store.end (), iterator2); + ASSERT_NE (system.wallet (0)->store.end (transaction), iterator2); if (iterator2->first != nano::dev::genesis_key.pub) { new_account = iterator2->first; } ++iterator2; - ASSERT_EQ (system.wallet (0)->store.end (), iterator2); + ASSERT_EQ (system.wallet (0)->store.end (transaction), iterator2); ASSERT_FALSE (new_account.is_zero ()); } ASSERT_TIMELY (10s, node1.balance (new_account) != 0); diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index bd3b41325a..e9e170f6d5 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -104,7 +104,7 @@ TEST (wallet, empty_iteration) nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); auto i (wallet.begin (transaction)); - auto j (wallet.end ()); + auto j (wallet.end (transaction)); ASSERT_EQ (i, j); } @@ -119,7 +119,7 @@ TEST (wallet, one_item_iteration) ASSERT_FALSE (init); nano::keypair key1; wallet.insert_adhoc (transaction, key1.prv); - for (auto i (wallet.begin (transaction)), j (wallet.end ()); i != j; ++i) + for (auto i (wallet.begin (transaction)), j (wallet.end (transaction)); i != j; ++i) { ASSERT_EQ (key1.pub, nano::uint256_union (i->first)); nano::raw_key password; @@ -147,7 +147,7 @@ TEST (wallet, two_item_iteration) ASSERT_FALSE (init); wallet.insert_adhoc (transaction, key1.prv); wallet.insert_adhoc (transaction, key2.prv); - for (auto i (wallet.begin (transaction)), j (wallet.end ()); i != j; ++i) + for (auto i (wallet.begin (transaction)), j (wallet.end (transaction)); i != j; ++i) { pubs.insert (i->first); nano::raw_key password; @@ -266,7 +266,7 @@ TEST (wallet, find_none) nano::wallet_store wallet (init, kdf, transaction, env, nano::dev::genesis_key.pub, 1, "0"); ASSERT_FALSE (init); nano::account account (1000); - ASSERT_EQ (wallet.end (), wallet.find (transaction, account)); + ASSERT_EQ (wallet.end (transaction), wallet.find (transaction, account)); } TEST (wallet, find_existing) @@ -283,9 +283,9 @@ TEST (wallet, find_existing) wallet.insert_adhoc (transaction, key1.prv); ASSERT_TRUE (wallet.exists (transaction, key1.pub)); auto existing (wallet.find (transaction, key1.pub)); - ASSERT_NE (wallet.end (), existing); + ASSERT_NE (wallet.end (transaction), existing); ++existing; - ASSERT_EQ (wallet.end (), existing); + ASSERT_EQ (wallet.end (transaction), existing); } TEST (wallet, rekey) @@ -487,8 +487,8 @@ TEST (wallet, serialize_json_empty) ASSERT_EQ (wallet1.salt (transaction), wallet2.salt (transaction)); ASSERT_EQ (wallet1.check (transaction), wallet2.check (transaction)); ASSERT_EQ (wallet1.representative (transaction), wallet2.representative (transaction)); - ASSERT_EQ (wallet1.end (), wallet1.begin (transaction)); - ASSERT_EQ (wallet2.end (), wallet2.begin (transaction)); + ASSERT_EQ (wallet1.end (transaction), wallet1.begin (transaction)); + ASSERT_EQ (wallet2.end (transaction), wallet2.begin (transaction)); } TEST (wallet, serialize_json_one) diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 66b9a86fa6..37c2786bf2 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -353,7 +353,7 @@ int main (int argc, char * const * argv) auto inactive_node = nano::default_inactive_node (data_path, vm); auto transaction = inactive_node->node->store.tx_begin_read (); auto i = inactive_node->node->store.block.begin (transaction); - auto end = inactive_node->node->store.block.end (); + auto end = inactive_node->node->store.block.end (transaction); for (; i != end; ++i) { nano::block_hash hash = i->first; @@ -435,7 +435,7 @@ int main (int argc, char * const * argv) auto current (node->online_reps.trended ()); std::cout << boost::str (boost::format ("Trended Weight %1%\n") % current); auto transaction (node->store.tx_begin_read ()); - for (auto i (node->store.online_weight.begin (transaction)), n (node->store.online_weight.end ()); i != n; ++i) + for (auto i (node->store.online_weight.begin (transaction)), n (node->store.online_weight.end (transaction)); i != n; ++i) { using time_point = std::chrono::system_clock::time_point; time_point ts (std::chrono::duration_cast (std::chrono::nanoseconds (i->first))); @@ -471,7 +471,7 @@ int main (int argc, char * const * argv) // Cache the account heads to make searching quicker against unchecked keys. auto transaction (node->store.tx_begin_read ()); std::unordered_set frontier_hashes; - for (auto i (node->store.account.begin (transaction)), n (node->store.account.end ()); i != n; ++i) + for (auto i (node->store.account.begin (transaction)), n (node->store.account.end (transaction)); i != n; ++i) { frontier_hashes.insert (i->second.head); } @@ -1669,7 +1669,7 @@ int main (int argc, char * const * argv) } size_t const accounts_deque_overflow (32 * 1024); auto transaction = node->ledger.tx_begin_read (); - for (auto i (node->store.account.begin (transaction)), n (node->store.account.end ()); i != n; ++i) + for (auto i (node->store.account.begin (transaction)), n (node->store.account.end (transaction)); i != n; ++i) { { nano::unique_lock lock{ mutex }; @@ -1780,7 +1780,7 @@ int main (int argc, char * const * argv) start_threads (check_pending, pending); size_t const pending_deque_overflow (64 * 1024); - for (auto i (node->store.pending.begin (transaction)), n (node->store.pending.end ()); i != n; ++i) + for (auto i (node->store.pending.begin (transaction)), n (node->store.pending.end (transaction)); i != n; ++i) { { nano::unique_lock lock{ mutex }; @@ -1837,7 +1837,7 @@ int main (int argc, char * const * argv) auto transaction = source_node->ledger.tx_begin_read (); block_count = source_node->ledger.block_count (); std::cout << boost::str (boost::format ("Performing bootstrap emulation, %1% blocks in ledger...") % block_count) << std::endl; - for (auto i (source_node->store.account.begin (transaction)), n (source_node->store.account.end ()); i != n; ++i) + for (auto i (source_node->store.account.begin (transaction)), n (source_node->store.account.end (transaction)); i != n; ++i) { nano::account const & account (i->first); nano::account_info const & info (i->second); diff --git a/nano/nano_wallet/entry.cpp b/nano/nano_wallet/entry.cpp index 5d595c9c04..6a3eac399d 100644 --- a/nano/nano_wallet/entry.cpp +++ b/nano/nano_wallet/entry.cpp @@ -147,7 +147,7 @@ class wallet_daemon final { auto transaction (wallet->wallets.tx_begin_write ()); auto existing (wallet->store.begin (transaction)); - if (existing != wallet->store.end ()) + if (existing != wallet->store.end (transaction)) { wallet_config.account = existing->first; } diff --git a/nano/node/backlog_population.cpp b/nano/node/backlog_population.cpp index cb121dcb61..284b7c599e 100644 --- a/nano/node/backlog_population.cpp +++ b/nano/node/backlog_population.cpp @@ -96,7 +96,7 @@ void nano::backlog_population::populate_backlog (nano::unique_lock auto transaction = ledger.tx_begin_read (); auto it = ledger.store.account.begin (transaction, next); - auto const end = ledger.store.account.end (); + auto const end = ledger.store.account.end (transaction); auto should_refresh = [&transaction] () { auto cutoff = std::chrono::steady_clock::now () - 100ms; // TODO: Make this configurable diff --git a/nano/node/bootstrap/bootstrap_frontier.cpp b/nano/node/bootstrap/bootstrap_frontier.cpp index b0b951b55e..db696dbd61 100644 --- a/nano/node/bootstrap/bootstrap_frontier.cpp +++ b/nano/node/bootstrap/bootstrap_frontier.cpp @@ -239,7 +239,7 @@ void nano::frontier_req_client::next () { std::size_t max_size (128); auto transaction (node->store.tx_begin_read ()); - for (auto i (node->store.account.begin (transaction, current.number () + 1)), n (node->store.account.end ()); i != n && accounts.size () != max_size; ++i) + for (auto i (node->store.account.begin (transaction, current.number () + 1)), n (node->store.account.end (transaction)); i != n && accounts.size () != max_size; ++i) { nano::account_info const & info (i->second); nano::account const & account (i->first); @@ -381,7 +381,7 @@ void nano::frontier_req_server::next () auto transaction (node->store.tx_begin_read ()); if (!send_confirmed ()) { - for (auto i (node->store.account.begin (transaction, current.number () + 1)), n (node->store.account.end ()); i != n && accounts.size () != max_size; ++i) + for (auto i (node->store.account.begin (transaction, current.number () + 1)), n (node->store.account.end (transaction)); i != n && accounts.size () != max_size; ++i) { nano::account_info const & info (i->second); if (disable_age_filter || (now - info.modified) <= request->age) @@ -393,7 +393,7 @@ void nano::frontier_req_server::next () } else { - for (auto i (node->store.confirmation_height.begin (transaction, current.number () + 1)), n (node->store.confirmation_height.end ()); i != n && accounts.size () != max_size; ++i) + for (auto i (node->store.confirmation_height.begin (transaction, current.number () + 1)), n (node->store.confirmation_height.end (transaction)); i != n && accounts.size () != max_size; ++i) { nano::confirmation_height_info const & info (i->second); nano::block_hash const & confirmed_frontier (info.frontier); diff --git a/nano/node/bootstrap/bootstrap_server.cpp b/nano/node/bootstrap/bootstrap_server.cpp index fbe3b09f95..d8320164d5 100644 --- a/nano/node/bootstrap/bootstrap_server.cpp +++ b/nano/node/bootstrap/bootstrap_server.cpp @@ -395,7 +395,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (secure::transaction const & response.type = nano::asc_pull_type::frontiers; nano::asc_pull_ack::frontiers_payload response_payload{}; - for (auto it = store.account.begin (transaction, request.start), end = store.account.end (); it != end && response_payload.frontiers.size () < request.count; ++it) + for (auto it = store.account.begin (transaction, request.start), end = store.account.end (transaction); it != end && response_payload.frontiers.size () < request.count; ++it) { response_payload.frontiers.emplace_back (it->first, it->second.head); } diff --git a/nano/node/bootstrap_ascending/database_scan.cpp b/nano/node/bootstrap_ascending/database_scan.cpp index b2f5622c4f..acd2024315 100644 --- a/nano/node/bootstrap_ascending/database_scan.cpp +++ b/nano/node/bootstrap_ascending/database_scan.cpp @@ -77,7 +77,7 @@ std::deque nano::bootstrap_ascending::account_database_iterator:: std::deque result; auto it = ledger.store.account.begin (transaction, next); - auto const end = ledger.store.account.end (); + auto const end = ledger.store.account.end (transaction); for (size_t count = 0; it != end && count < batch_size; ++it, ++count) { @@ -115,7 +115,7 @@ std::deque nano::bootstrap_ascending::pending_database_iterator:: std::deque result; auto it = ledger.store.pending.begin (transaction, next); - auto const end = ledger.store.pending.end (); + auto const end = ledger.store.pending.end (transaction); // TODO: This pending iteration heuristic should be encapsulated in a pending_iterator class and reused across other components // The heuristic is to advance the iterator sequentially until we reach a new account or perform a fresh lookup if the account has too many pending blocks @@ -164,4 +164,4 @@ std::deque nano::bootstrap_ascending::pending_database_iterator:: bool nano::bootstrap_ascending::pending_database_iterator::warmed_up () const { return completed > 0; -} \ No newline at end of file +} diff --git a/nano/node/cli.cpp b/nano/node/cli.cpp index 75ec166243..5ebe67bbf1 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -1012,7 +1012,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map nano::raw_key seed; existing->second->store.seed (seed, transaction); std::cout << boost::str (boost::format ("Seed: %1%\n") % seed.to_string ()); - for (auto i (existing->second->store.begin (transaction)), m (existing->second->store.end ()); i != m; ++i) + for (auto i (existing->second->store.begin (transaction)), m (existing->second->store.end (transaction)); i != m; ++i) { nano::account const & account (i->first); nano::raw_key key; @@ -1201,7 +1201,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map { std::cout << boost::str (boost::format ("Wallet ID: %1%\n") % i->first.to_string ()); auto transaction (i->second->wallets.tx_begin_read ()); - for (auto j (i->second->store.begin (transaction)), m (i->second->store.end ()); j != m; ++j) + for (auto j (i->second->store.begin (transaction)), m (i->second->store.end (transaction)); j != m; ++j) { std::cout << nano::account (j->first).to_account () << '\n'; } @@ -1224,7 +1224,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map { auto transaction (wallet->second->wallets.tx_begin_write ()); auto account (wallet->second->store.find (transaction, account_id)); - if (account != wallet->second->store.end ()) + if (account != wallet->second->store.end (transaction)) { wallet->second->store.erase (transaction, account_id); } diff --git a/nano/node/epoch_upgrader.cpp b/nano/node/epoch_upgrader.cpp index a2fa389c52..6667e7e20d 100644 --- a/nano/node/epoch_upgrader.cpp +++ b/nano/node/epoch_upgrader.cpp @@ -116,7 +116,7 @@ void nano::epoch_upgrader::upgrade_impl (nano::raw_key const & prv_a, nano::epoc { auto transaction (store.tx_begin_read ()); // Collect accounts to upgrade - for (auto i (store.account.begin (transaction)), n (store.account.end ()); i != n && accounts_list.size () < count_limit; ++i) + for (auto i (store.account.begin (transaction)), n (store.account.end (transaction)); i != n && accounts_list.size () < count_limit; ++i) { nano::account const & account (i->first); nano::account_info const & info (i->second); diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 299acd94a5..591ce4b997 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -207,7 +207,7 @@ bool nano::json_handler::wallet_account_impl (store::transaction const & transac bool result (false); if (!ec) { - if (wallet_a->store.find (transaction_a, account_a) != wallet_a->store.end ()) + if (wallet_a->store.find (transaction_a, account_a) != wallet_a->store.end (transaction_a)) { result = true; } @@ -718,7 +718,7 @@ void nano::json_handler::account_list () { boost::property_tree::ptree accounts; auto transaction (node.wallets.tx_begin_read ()); - for (auto i (wallet->store.begin (transaction)), j (wallet->store.end ()); i != j; ++i) + for (auto i (wallet->store.begin (transaction)), j (wallet->store.end (transaction)); i != j; ++i) { boost::property_tree::ptree entry; entry.put ("", nano::account (i->first).to_account ()); @@ -1030,7 +1030,7 @@ void nano::json_handler::accounts_receivable () if (!ec) { boost::property_tree::ptree peers_l; - for (auto i (node.store.pending.begin (transaction, nano::pending_key (account, 0))), n (node.store.pending.end ()); i != n && nano::pending_key (i->first).account == account && peers_l.size () < count; ++i) + for (auto i (node.store.pending.begin (transaction, nano::pending_key (account, 0))), n (node.store.pending.end (transaction)); i != n && nano::pending_key (i->first).account == account && peers_l.size () < count; ++i) { nano::pending_key const & key (i->first); if (block_confirmed (node, transaction, key.hash, include_active, include_only_confirmed)) @@ -2240,7 +2240,7 @@ void nano::json_handler::delegators () { auto transaction (node.ledger.tx_begin_read ()); boost::property_tree::ptree delegators; - for (auto i (node.store.account.begin (transaction, start_account.number () + 1)), n (node.store.account.end ()); i != n && delegators.size () < count; ++i) + for (auto i (node.store.account.begin (transaction, start_account.number () + 1)), n (node.store.account.end (transaction)); i != n && delegators.size () < count; ++i) { nano::account_info const & info (i->second); if (info.representative == representative) @@ -2266,7 +2266,7 @@ void nano::json_handler::delegators_count () { uint64_t count (0); auto transaction (node.ledger.tx_begin_read ()); - for (auto i (node.store.account.begin (transaction)), n (node.store.account.end ()); i != n; ++i) + for (auto i (node.store.account.begin (transaction)), n (node.store.account.end (transaction)); i != n; ++i) { nano::account_info const & info (i->second); if (info.representative == account) @@ -2377,7 +2377,7 @@ void nano::json_handler::frontiers () { boost::property_tree::ptree frontiers; auto transaction (node.ledger.tx_begin_read ()); - for (auto i (node.store.account.begin (transaction, start)), n (node.store.account.end ()); i != n && frontiers.size () < count; ++i) + for (auto i (node.store.account.begin (transaction, start)), n (node.store.account.end (transaction)); i != n && frontiers.size () < count; ++i) { frontiers.put (i->first.to_account (), i->second.head.to_string ()); } @@ -2780,7 +2780,7 @@ void nano::json_handler::ledger () auto transaction = node.ledger.tx_begin_read (); if (!ec && !sorting) // Simple { - for (auto i (node.store.account.begin (transaction, start)), n (node.store.account.end ()); i != n && accounts.size () < count; ++i) + for (auto i (node.store.account.begin (transaction, start)), n (node.store.account.end (transaction)); i != n && accounts.size () < count; ++i) { nano::account_info const & info (i->second); if (info.modified >= modified_since && (receivable || info.balance.number () >= threshold.number ())) @@ -2821,7 +2821,7 @@ void nano::json_handler::ledger () else if (!ec) // Sorting { std::vector> ledger_l; - for (auto i (node.store.account.begin (transaction, start)), n (node.store.account.end ()); i != n; ++i) + for (auto i (node.store.account.begin (transaction, start)), n (node.store.account.end (transaction)); i != n; ++i) { nano::account_info const & info (i->second); nano::uint128_union balance (info.balance); @@ -3055,7 +3055,7 @@ void nano::json_handler::receivable () // The ptree container is used if there are any children nodes (e.g source/min_version) otherwise the amount container is used. std::vector> hash_ptree_pairs; std::vector> hash_amount_pairs; - for (auto i (node.store.pending.begin (transaction, nano::pending_key (account, 0))), n (node.store.pending.end ()); i != n && nano::pending_key (i->first).account == account && (should_sort || peers_l.size () < count); ++i) + for (auto i (node.store.pending.begin (transaction, nano::pending_key (account, 0))), n (node.store.pending.end (transaction)); i != n && nano::pending_key (i->first).account == account && (should_sort || peers_l.size () < count); ++i) { nano::pending_key const & key (i->first); if (block_confirmed (node, transaction, key.hash, include_active, include_only_confirmed)) @@ -4240,7 +4240,7 @@ void nano::json_handler::unopened () { auto transaction = node.store.tx_begin_read (); auto iterator = node.store.pending.begin (transaction, nano::pending_key (start, 0)); - auto end = node.store.pending.end (); + auto end = node.store.pending.end (transaction); nano::account current_account = start; nano::uint128_t current_account_sum{ 0 }; boost::property_tree::ptree accounts; @@ -4392,7 +4392,7 @@ void nano::json_handler::wallet_info () uint64_t adhoc_count (0); auto transaction (node.wallets.tx_begin_read ()); auto block_transaction = node.ledger.tx_begin_read (); - for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) + for (auto i (wallet->store.begin (transaction)), n (wallet->store.end (transaction)); i != n; ++i) { nano::account const & account (i->first); @@ -4448,7 +4448,7 @@ void nano::json_handler::wallet_balances () boost::property_tree::ptree balances; auto transaction (node.wallets.tx_begin_read ()); auto block_transaction = node.ledger.tx_begin_read (); - for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) + for (auto i (wallet->store.begin (transaction)), n (wallet->store.end (transaction)); i != n; ++i) { nano::account const & account (i->first); nano::uint128_t balance = node.ledger.any.account_balance (block_transaction, account).value_or (0).number (); @@ -4509,7 +4509,7 @@ void nano::json_handler::wallet_contains () if (!ec) { auto transaction (node.wallets.tx_begin_read ()); - auto exists (wallet->store.find (transaction, account) != wallet->store.end ()); + auto exists (wallet->store.find (transaction, account) != wallet->store.end (transaction)); response_l.put ("exists", exists ? "1" : "0"); } response_errors (); @@ -4599,7 +4599,7 @@ void nano::json_handler::wallet_frontiers () boost::property_tree::ptree frontiers; auto transaction (node.wallets.tx_begin_read ()); auto block_transaction = node.ledger.tx_begin_read (); - for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) + for (auto i (wallet->store.begin (transaction)), n (wallet->store.end (transaction)); i != n; ++i) { nano::account const & account (i->first); auto latest (node.ledger.any.account_head (block_transaction, account)); @@ -4630,7 +4630,7 @@ void nano::json_handler::wallet_history () std::multimap> entries; auto transaction (node.wallets.tx_begin_read ()); auto block_transaction = node.ledger.tx_begin_read (); - for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) + for (auto i (wallet->store.begin (transaction)), n (wallet->store.end (transaction)); i != n; ++i) { nano::account const & account (i->first); auto info = node.ledger.any.account_get (block_transaction, account); @@ -4704,7 +4704,7 @@ void nano::json_handler::wallet_ledger () boost::property_tree::ptree accounts; auto transaction (node.wallets.tx_begin_read ()); auto block_transaction = node.ledger.tx_begin_read (); - for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) + for (auto i (wallet->store.begin (transaction)), n (wallet->store.end (transaction)); i != n; ++i) { nano::account const & account (i->first); auto info = node.ledger.any.account_get (block_transaction, account); @@ -4780,11 +4780,11 @@ void nano::json_handler::wallet_receivable () boost::property_tree::ptree pending; auto transaction (node.wallets.tx_begin_read ()); auto block_transaction = node.ledger.tx_begin_read (); - for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) + for (auto i (wallet->store.begin (transaction)), n (wallet->store.end (transaction)); i != n; ++i) { nano::account const & account (i->first); boost::property_tree::ptree peers_l; - for (auto ii (node.store.pending.begin (block_transaction, nano::pending_key (account, 0))), nn (node.store.pending.end ()); ii != nn && nano::pending_key (ii->first).account == account && peers_l.size () < count; ++ii) + for (auto ii (node.store.pending.begin (block_transaction, nano::pending_key (account, 0))), nn (node.store.pending.end (block_transaction)); ii != nn && nano::pending_key (ii->first).account == account && peers_l.size () < count; ++ii) { nano::pending_key key (ii->first); if (block_confirmed (node, block_transaction, key.hash, include_active, include_only_confirmed)) @@ -4871,7 +4871,7 @@ void nano::json_handler::wallet_representative_set () { auto transaction (rpc_l->node.wallets.tx_begin_read ()); auto block_transaction = rpc_l->node.ledger.tx_begin_read (); - for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) + for (auto i (wallet->store.begin (transaction)), n (wallet->store.end (transaction)); i != n; ++i) { nano::account const & account (i->first); auto info = rpc_l->node.ledger.any.account_get (block_transaction, account); @@ -4905,7 +4905,7 @@ void nano::json_handler::wallet_republish () std::deque> republish_bundle; auto transaction (node.wallets.tx_begin_read ()); auto block_transaction = node.ledger.tx_begin_read (); - for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) + for (auto i (wallet->store.begin (transaction)), n (wallet->store.end (transaction)); i != n; ++i) { nano::account const & account (i->first); auto latest (node.ledger.any.account_head (block_transaction, account)); @@ -4967,7 +4967,7 @@ void nano::json_handler::wallet_work_get () { boost::property_tree::ptree works; auto transaction (node.wallets.tx_begin_read ()); - for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i) + for (auto i (wallet->store.begin (transaction)), n (wallet->store.end (transaction)); i != n; ++i) { nano::account const & account (i->first); uint64_t work (0); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 313a187685..229d17ce16 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -311,7 +311,7 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy auto is_initialized (false); { auto const transaction (store.tx_begin_read ()); - is_initialized = (store.account.begin (transaction) != store.account.end ()); + is_initialized = (store.account.begin (transaction) != store.account.end (transaction)); } if (!is_initialized && !flags.read_only) @@ -754,7 +754,7 @@ void nano::node::long_inactivity_cleanup () if (store.online_weight.count (transaction) > 0) { auto sample (store.online_weight.rbegin (transaction)); - auto n (store.online_weight.end ()); + auto n (store.online_weight.end (transaction)); debug_assert (sample != n); auto const one_week_ago = static_cast ((std::chrono::system_clock::now () - std::chrono::hours (7 * 24)).time_since_epoch ().count ()); perform_cleanup = sample->first < one_week_ago; @@ -803,7 +803,7 @@ void nano::node::ongoing_bootstrap () { auto transaction = store.tx_begin_read (); auto last_record = store.online_weight.rbegin (transaction); - if (last_record != store.online_weight.end ()) + if (last_record != store.online_weight.end (transaction)) { last_sample_time = last_record->first; } @@ -870,7 +870,7 @@ void nano::node::bootstrap_wallet () { auto & wallet (*i->second); nano::lock_guard wallet_lock{ wallet.store.mutex }; - for (auto j (wallet.store.begin (transaction)), m (wallet.store.end ()); j != m && accounts.size () < 128; ++j) + for (auto j (wallet.store.begin (transaction)), m (wallet.store.end (transaction)); j != m && accounts.size () < 128; ++j) { nano::account account (j->first); accounts.push_back (account); @@ -888,7 +888,7 @@ bool nano::node::collect_ledger_pruning_targets (std::deque & uint64_t read_operations (0); bool finish_transaction (false); auto transaction = ledger.tx_begin_read (); - for (auto i (store.confirmation_height.begin (transaction, last_account_a)), n (store.confirmation_height.end ()); i != n && !finish_transaction;) + for (auto i (store.confirmation_height.begin (transaction, last_account_a)), n (store.confirmation_height.end (transaction)); i != n && !finish_transaction;) { ++read_operations; auto const & account (i->first); diff --git a/nano/node/online_reps.cpp b/nano/node/online_reps.cpp index 72842ec2ee..b049128204 100644 --- a/nano/node/online_reps.cpp +++ b/nano/node/online_reps.cpp @@ -45,7 +45,7 @@ void nano::online_reps::sample () while (ledger.store.online_weight.count (transaction) >= config.network_params.node.max_weight_samples) { auto oldest (ledger.store.online_weight.begin (transaction)); - debug_assert (oldest != ledger.store.online_weight.end ()); + debug_assert (oldest != ledger.store.online_weight.end (transaction)); ledger.store.online_weight.del (transaction, oldest->first); } ledger.store.online_weight.put (transaction, std::chrono::system_clock::now ().time_since_epoch ().count (), online_l); @@ -70,7 +70,7 @@ nano::uint128_t nano::online_reps::calculate_trend (store::transaction & transac std::vector items; items.reserve (config.network_params.node.max_weight_samples + 1); items.push_back (config.online_weight_minimum.number ()); - for (auto i (ledger.store.online_weight.begin (transaction_a)), n (ledger.store.online_weight.end ()); i != n; ++i) + for (auto i (ledger.store.online_weight.begin (transaction_a)), n (ledger.store.online_weight.end (transaction_a)); i != n; ++i) { items.push_back (i->second.number ()); } diff --git a/nano/node/peer_history.cpp b/nano/node/peer_history.cpp index 1c605d9015..99b96ed1a8 100644 --- a/nano/node/peer_history.cpp +++ b/nano/node/peer_history.cpp @@ -104,7 +104,7 @@ void nano::peer_history::run_one () auto const now = std::chrono::system_clock::now (); auto const cutoff = now - config.erase_cutoff; - for (auto it = store.peer.begin (transaction); it != store.peer.end (); ++it) + for (auto it = store.peer.begin (transaction); it != store.peer.end (transaction); ++it) { auto const [endpoint, timestamp_millis] = *it; auto timestamp = nano::from_milliseconds_since_epoch (timestamp_millis); @@ -124,7 +124,7 @@ std::vector nano::peer_history::peers () const { auto transaction = store.tx_begin_read (); std::vector peers; - for (auto it = store.peer.begin (transaction); it != store.peer.end (); ++it) + for (auto it = store.peer.begin (transaction); it != store.peer.end (transaction); ++it) { auto const [endpoint, timestamp_millis] = *it; peers.push_back (endpoint.endpoint ()); diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index a1f46c78f3..5364416907 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -114,7 +114,7 @@ void nano::wallet_store::deterministic_index_set (store::transaction const & tra void nano::wallet_store::deterministic_clear (store::transaction const & transaction_a) { nano::uint256_union key (0); - for (auto i (begin (transaction_a)), n (end ()); i != n;) + for (auto i (begin (transaction_a)), n (end (transaction_a)); i != n;) { switch (key_type (nano::wallet_value (i->second))) { @@ -370,7 +370,7 @@ nano::wallet_store::wallet_store (bool & init_a, nano::kdf & kdf_a, store::trans std::vector nano::wallet_store::accounts (store::transaction const & transaction_a) { std::vector result; - for (auto i (begin (transaction_a)), n (end ()); i != n; ++i) + for (auto i (begin (transaction_a)), n (end (transaction_a)); i != n; ++i) { nano::account const & account (i->first); result.push_back (account); @@ -542,7 +542,7 @@ bool nano::wallet_store::valid_public_key (nano::public_key const & pub) bool nano::wallet_store::exists (store::transaction const & transaction_a, nano::public_key const & pub) { - return valid_public_key (pub) && find (transaction_a, pub) != end (); + return valid_public_key (pub) && find (transaction_a, pub) != end (transaction_a); } void nano::wallet_store::serialize_json (store::transaction const & transaction_a, std::string & string_a) @@ -597,7 +597,7 @@ bool nano::wallet_store::import (store::transaction const & transaction_a, nano: debug_assert (valid_password (transaction_a)); debug_assert (other_a.valid_password (transaction_a)); auto result (false); - for (auto i (other_a.begin (transaction_a)), n (end ()); i != n; ++i) + for (auto i (other_a.begin (transaction_a)), n (end (transaction_a)); i != n; ++i) { nano::raw_key prv; auto error (other_a.fetch (transaction_a, i->first, prv)); @@ -910,7 +910,7 @@ std::shared_ptr nano::wallet::change_action (nano::account const & if (store.valid_password (transaction)) { auto existing (store.find (transaction, source_a)); - if (existing != store.end () && !wallets.node.ledger.any.account_head (block_transaction, source_a).is_zero ()) + if (existing != store.end (transaction) && !wallets.node.ledger.any.account_head (block_transaction, source_a).is_zero ()) { auto info = wallets.node.ledger.any.account_get (block_transaction, source_a); debug_assert (info); @@ -977,7 +977,7 @@ std::shared_ptr nano::wallet::send_action (nano::account const & so if (store.valid_password (transaction)) { auto existing (store.find (transaction, source_a)); - if (existing != store.end ()) + if (existing != store.end (transaction)) { auto balance (wallets.node.ledger.any.account_balance (block_transaction, source_a)); if (balance && balance.value ().number () >= amount_a) @@ -1178,14 +1178,14 @@ bool nano::wallet::search_receivable (store::transaction const & wallet_transact { wallets.node.logger.info (nano::log::type::wallet, "Beginning receivable block search"); - for (auto i (store.begin (wallet_transaction_a)), n (store.end ()); i != n; ++i) + for (auto i (store.begin (wallet_transaction_a)), n (store.end (wallet_transaction_a)); i != n; ++i) { auto block_transaction = wallets.node.ledger.tx_begin_read (); nano::account const & account (i->first); // Don't search pending for watch-only accounts if (!nano::wallet_value (i->second).key.is_zero ()) { - for (auto j (wallets.node.store.pending.begin (block_transaction, nano::pending_key (account, 0))), k (wallets.node.store.pending.end ()); j != k && nano::pending_key (j->first).account == account; ++j) + for (auto j (wallets.node.store.pending.begin (block_transaction, nano::pending_key (account, 0))), k (wallets.node.store.pending.end (block_transaction)); j != k && nano::pending_key (j->first).account == account; ++j) { nano::pending_key key (j->first); auto hash (key.hash); @@ -1227,7 +1227,7 @@ bool nano::wallet::search_receivable (store::transaction const & wallet_transact void nano::wallet::init_free_accounts (store::transaction const & transaction_a) { free_accounts.clear (); - for (auto i (store.begin (transaction_a)), n (store.end ()); i != n; ++i) + for (auto i (store.begin (transaction_a)), n (store.end (transaction_a)); i != n; ++i) { free_accounts.insert (i->first); } @@ -1686,7 +1686,7 @@ void nano::wallets::compute_reps () { auto & wallet (*i->second); decltype (wallet.representatives) representatives_l; - for (auto ii (wallet.store.begin (transaction)), nn (wallet.store.end ()); ii != nn; ++ii) + for (auto ii (wallet.store.begin (transaction)), nn (wallet.store.end (transaction)); ii != nn; ++ii) { auto account (ii->first); if (check_rep (account, half_principal_weight, false)) @@ -1787,7 +1787,7 @@ auto nano::wallet_store::find (store::transaction const & transaction_a, nano::a return result; } -auto nano::wallet_store::end () -> iterator +auto nano::wallet_store::end (store::transaction const & transaction_a) -> iterator { return iterator{ nullptr }; } diff --git a/nano/node/wallet.hpp b/nano/node/wallet.hpp index ef26f4b0be..f3daef8170 100644 --- a/nano/node/wallet.hpp +++ b/nano/node/wallet.hpp @@ -95,7 +95,7 @@ class wallet_store final iterator find (store::transaction const &, nano::account const &); iterator begin (store::transaction const &, nano::account const &); iterator begin (store::transaction const &); - iterator end (); + iterator end (store::transaction const &); void derive_key (nano::raw_key &, store::transaction const &, std::string const &); void serialize_json (store::transaction const &, std::string &); void write_backup (store::transaction const &, std::filesystem::path const &); diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index aefd693bd0..48466d012a 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -268,7 +268,7 @@ void nano_qt::accounts::refresh_wallet_balance () auto block_transaction = this->wallet.node.ledger.tx_begin_read (); nano::uint128_t balance (0); nano::uint128_t pending (0); - for (auto i (this->wallet.wallet_m->store.begin (transaction)), j (this->wallet.wallet_m->store.end ()); i != j; ++i) + for (auto i (this->wallet.wallet_m->store.begin (transaction)), j (this->wallet.wallet_m->store.end (transaction)); i != j; ++i) { nano::public_key const & key (i->first); balance = balance + this->wallet.node.ledger.any.account_balance (block_transaction, key).value_or (0).number (); @@ -293,7 +293,7 @@ void nano_qt::accounts::refresh () auto transaction (wallet.wallet_m->wallets.tx_begin_read ()); auto block_transaction = this->wallet.node.ledger.tx_begin_read (); QBrush brush; - for (auto i (wallet.wallet_m->store.begin (transaction)), j (wallet.wallet_m->store.end ()); i != j; ++i) + for (auto i (wallet.wallet_m->store.begin (transaction)), j (wallet.wallet_m->store.end (transaction)); i != j; ++i) { nano::public_key key (i->first); auto balance_amount = wallet.node.ledger.any.account_balance (block_transaction, key).value_or (0).number (); @@ -1973,7 +1973,7 @@ void nano_qt::advanced_actions::refresh_ledger () { ledger_model->removeRows (0, ledger_model->rowCount ()); auto transaction (wallet.node.ledger.tx_begin_read ()); - for (auto i (wallet.node.ledger.store.account.begin (transaction)), j (wallet.node.ledger.store.account.end ()); i != j; ++i) + for (auto i (wallet.node.ledger.store.account.begin (transaction)), j (wallet.node.ledger.store.account.end (transaction)); i != j; ++i) { QList items; items.push_back (new QStandardItem (QString (i->first.to_account ().c_str ()))); diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 1efdeacaff..a13926989d 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -721,7 +721,7 @@ TEST (rpc, account_move) ASSERT_TRUE (destination->exists (key.pub)); ASSERT_TRUE (destination->exists (nano::dev::genesis_key.pub)); auto transaction (node->wallets.tx_begin_read ()); - ASSERT_EQ (source->store.end (), source->store.begin (transaction)); + ASSERT_EQ (source->store.end (transaction), source->store.begin (transaction)); } TEST (rpc, block) @@ -6212,7 +6212,7 @@ TEST (rpc, epoch_upgrade) { auto transaction (node->ledger.tx_begin_read ()); ASSERT_EQ (2, node->store.account.count (transaction)); - for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (); ++i) + for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (transaction); ++i) { nano::account_info info (i->second); ASSERT_EQ (info.epoch (), nano::epoch::epoch_0); @@ -6230,7 +6230,7 @@ TEST (rpc, epoch_upgrade) { auto transaction (node->ledger.tx_begin_read ()); ASSERT_EQ (4, node->store.account.count (transaction)); - for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (); ++i) + for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (transaction); ++i) { nano::account_info info (i->second); ASSERT_EQ (info.epoch (), nano::epoch::epoch_1); @@ -6293,7 +6293,7 @@ TEST (rpc, epoch_upgrade) { auto transaction (node->ledger.tx_begin_read ()); ASSERT_EQ (5, node->store.account.count (transaction)); - for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (); ++i) + for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (transaction); ++i) { nano::account_info info (i->second); ASSERT_EQ (info.epoch (), nano::epoch::epoch_2); @@ -6375,7 +6375,7 @@ TEST (rpc, epoch_upgrade_multithreaded) { auto transaction (node->ledger.tx_begin_read ()); ASSERT_EQ (2, node->store.account.count (transaction)); - for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (); ++i) + for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (transaction); ++i) { nano::account_info info (i->second); ASSERT_EQ (info.epoch (), nano::epoch::epoch_0); @@ -6394,7 +6394,7 @@ TEST (rpc, epoch_upgrade_multithreaded) { auto transaction (node->ledger.tx_begin_read ()); ASSERT_EQ (4, node->store.account.count (transaction)); - for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (); ++i) + for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (transaction); ++i) { nano::account_info info (i->second); ASSERT_EQ (info.epoch (), nano::epoch::epoch_1); @@ -6457,7 +6457,7 @@ TEST (rpc, epoch_upgrade_multithreaded) { auto transaction (node->ledger.tx_begin_read ()); ASSERT_EQ (5, node->store.account.count (transaction)); - for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (); ++i) + for (auto i (node->store.account.begin (transaction)); i != node->store.account.end (transaction); ++i) { nano::account_info info (i->second); ASSERT_EQ (info.epoch (), nano::epoch::epoch_2); diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 93eb61ceac..ec5aa666da 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -1429,12 +1429,12 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (std::filesystem::path const & data_p auto rocksdb_transaction (rocksdb_store->tx_begin_write ()); rocksdb_store->version.put (rocksdb_transaction, version); - for (auto i (store.online_weight.begin (lmdb_transaction)), n (store.online_weight.end ()); i != n; ++i) + for (auto i (store.online_weight.begin (lmdb_transaction)), n (store.online_weight.end (lmdb_transaction)); i != n; ++i) { rocksdb_store->online_weight.put (rocksdb_transaction, i->first, i->second); } - for (auto i (store.peer.begin (lmdb_transaction)), n (store.peer.end ()); i != n; ++i) + for (auto i (store.peer.begin (lmdb_transaction)), n (store.peer.end (lmdb_transaction)); i != n; ++i) { rocksdb_store->peer.put (rocksdb_transaction, i->first, i->second); } diff --git a/nano/secure/ledger_set_any.cpp b/nano/secure/ledger_set_any.cpp index 13e3b2c1fc..67b14fda19 100644 --- a/nano/secure/ledger_set_any.cpp +++ b/nano/secure/ledger_set_any.cpp @@ -60,7 +60,7 @@ uint64_t nano::ledger_set_any::account_height (secure::transaction const & trans auto nano::ledger_set_any::account_lower_bound (secure::transaction const & transaction, nano::account const & account) const -> account_iterator { auto disk = ledger.store.account.begin (transaction, account); - if (disk == ledger.store.account.end ()) + if (disk == ledger.store.account.end (transaction)) { return account_iterator{}; } @@ -153,7 +153,7 @@ uint64_t nano::ledger_set_any::block_height (secure::transaction const & transac std::optional> nano::ledger_set_any::receivable_lower_bound (secure::transaction const & transaction, nano::account const & account, nano::block_hash const & hash) const { auto result = ledger.store.pending.begin (transaction, { account, hash }); - if (result == ledger.store.pending.end ()) + if (result == ledger.store.pending.end (transaction)) { return std::nullopt; } diff --git a/nano/secure/ledger_set_confirmed.cpp b/nano/secure/ledger_set_confirmed.cpp index 9fe36d941a..8702d61b4f 100644 --- a/nano/secure/ledger_set_confirmed.cpp +++ b/nano/secure/ledger_set_confirmed.cpp @@ -108,11 +108,11 @@ auto nano::ledger_set_confirmed::receivable_upper_bound (secure::transaction con std::optional> nano::ledger_set_confirmed::receivable_lower_bound (secure::transaction const & transaction, nano::account const & account, nano::block_hash const & hash) const { auto result = ledger.store.pending.begin (transaction, { account, hash }); - while (result != ledger.store.pending.end () && !block_exists (transaction, result->first.hash)) + while (result != ledger.store.pending.end (transaction) && !block_exists (transaction, result->first.hash)) { ++result; } - if (result == ledger.store.pending.end ()) + if (result == ledger.store.pending.end (transaction)) { return std::nullopt; } diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index 5ffca07c61..c49f4d84de 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -37,7 +37,7 @@ size_t manually_count_pruned_blocks (nano::store::component & store) size_t count = 0; auto transaction = store.tx_begin_read (); auto i = store.pruned.begin (transaction); - for (; i != store.pruned.end (); ++i) + for (; i != store.pruned.end (transaction); ++i) { ++count; } @@ -54,7 +54,7 @@ TEST (system, generate_mass_activity) uint32_t count (20); system.generate_mass_activity (count, *system.nodes[0]); auto transaction (system.nodes[0]->store.tx_begin_read ()); - for (auto i (system.nodes[0]->store.account.begin (transaction)), n (system.nodes[0]->store.account.end ()); i != n; ++i) + for (auto i (system.nodes[0]->store.account.begin (transaction)), n (system.nodes[0]->store.account.end (transaction)); i != n; ++i) { } } @@ -76,7 +76,7 @@ TEST (system, generate_mass_activity_long) } system.generate_mass_activity (count, *system.nodes[0]); auto transaction (system.nodes[0]->store.tx_begin_read ()); - for (auto i (system.nodes[0]->store.account.begin (transaction)), n (system.nodes[0]->store.account.end ()); i != n; ++i) + for (auto i (system.nodes[0]->store.account.begin (transaction)), n (system.nodes[0]->store.account.end (transaction)); i != n; ++i) { } system.stop (); @@ -694,7 +694,7 @@ TEST (confirmation_height, many_accounts_single_confirmation) // All frontiers (except last) should have 2 blocks and both should be confirmed auto transaction = node->store.tx_begin_read (); - for (auto i (node->store.account.begin (transaction)), n (node->store.account.end ()); i != n; ++i) + for (auto i (node->store.account.begin (transaction)), n (node->store.account.end (transaction)); i != n; ++i) { auto & account = i->first; auto & account_info = i->second; @@ -706,7 +706,7 @@ TEST (confirmation_height, many_accounts_single_confirmation) } size_t cemented_count = 0; - for (auto i (node->ledger.store.confirmation_height.begin (transaction)), n (node->ledger.store.confirmation_height.end ()); i != n; ++i) + for (auto i (node->ledger.store.confirmation_height.begin (transaction)), n (node->ledger.store.confirmation_height.end (transaction)); i != n; ++i) { cemented_count += i->second.height; } @@ -782,7 +782,7 @@ TEST (confirmation_height, many_accounts_many_confirmations) auto transaction = node->store.tx_begin_read (); size_t cemented_count = 0; - for (auto i (node->ledger.store.confirmation_height.begin (transaction)), n (node->ledger.store.confirmation_height.end ()); i != n; ++i) + for (auto i (node->ledger.store.confirmation_height.begin (transaction)), n (node->ledger.store.confirmation_height.end (transaction)); i != n; ++i) { cemented_count += i->second.height; } @@ -925,7 +925,7 @@ TEST (confirmation_height, long_chains) ASSERT_EQ (num_blocks + 1, info->block_count); size_t cemented_count = 0; - for (auto i (node->ledger.store.confirmation_height.begin (transaction)), n (node->ledger.store.confirmation_height.end ()); i != n; ++i) + for (auto i (node->ledger.store.confirmation_height.begin (transaction)), n (node->ledger.store.confirmation_height.end (transaction)); i != n; ++i) { cemented_count += i->second.height; } @@ -1098,7 +1098,7 @@ TEST (confirmation_height, many_accounts_send_receive_self) auto transaction = node->store.tx_begin_read (); size_t cemented_count = 0; - for (auto i (node->ledger.store.confirmation_height.begin (transaction)), n (node->ledger.store.confirmation_height.end ()); i != n; ++i) + for (auto i (node->ledger.store.confirmation_height.begin (transaction)), n (node->ledger.store.confirmation_height.end (transaction)); i != n; ++i) { cemented_count += i->second.height; } @@ -1252,7 +1252,7 @@ TEST (confirmation_height, many_accounts_send_receive_self_no_elections) auto transaction = store->tx_begin_read (); size_t cemented_count = 0; - for (auto i (store->confirmation_height.begin (transaction)), n (store->confirmation_height.end ()); i != n; ++i) + for (auto i (store->confirmation_height.begin (transaction)), n (store->confirmation_height.end (transaction)); i != n; ++i) { cemented_count += i->second.height; } @@ -1746,7 +1746,7 @@ TEST (node, mass_epoch_upgrader) { auto transaction (node.store.tx_begin_read ()); size_t block_count_sum = 0; - for (auto i (node.store.account.begin (transaction)); i != node.store.account.end (); ++i) + for (auto i (node.store.account.begin (transaction)); i != node.store.account.end (transaction); ++i) { nano::account_info info (i->second); ASSERT_EQ (info.epoch (), nano::epoch::epoch_1); diff --git a/nano/store/account.hpp b/nano/store/account.hpp index ffa05de087..cc9b93f688 100644 --- a/nano/store/account.hpp +++ b/nano/store/account.hpp @@ -32,7 +32,7 @@ class account virtual iterator begin (store::transaction const &, nano::account const &) const = 0; virtual iterator begin (store::transaction const &) const = 0; virtual iterator rbegin (store::transaction const &) const = 0; - virtual iterator end () const = 0; + virtual iterator end (store::transaction const & transaction_a) const = 0; virtual void for_each_par (std::function const &) const = 0; }; } // namespace nano::store diff --git a/nano/store/block.hpp b/nano/store/block.hpp index acd2ba72f3..cf0464a527 100644 --- a/nano/store/block.hpp +++ b/nano/store/block.hpp @@ -36,7 +36,7 @@ class block virtual uint64_t count (store::transaction const &) = 0; virtual iterator begin (store::transaction const &, nano::block_hash const &) const = 0; virtual iterator begin (store::transaction const &) const = 0; - virtual iterator end () const = 0; + virtual iterator end (store::transaction const &) const = 0; virtual void for_each_par (std::function const & action_a) const = 0; }; } // namespace nano::store diff --git a/nano/store/component.cpp b/nano/store/component.cpp index 5d8c8bec20..ffe9c6e717 100644 --- a/nano/store/component.cpp +++ b/nano/store/component.cpp @@ -28,7 +28,7 @@ nano::store::component::component (nano::store::block & block_store_a, nano::sto void nano::store::component::initialize (store::write_transaction const & transaction_a, nano::ledger_cache & ledger_cache_a, nano::ledger_constants & constants) { debug_assert (constants.genesis->has_sideband ()); - debug_assert (account.begin (transaction_a) == account.end ()); + debug_assert (account.begin (transaction_a) == account.end (transaction_a)); auto hash_l (constants.genesis->hash ()); block.put (transaction_a, hash_l, *constants.genesis); ++ledger_cache_a.block_count; diff --git a/nano/store/confirmation_height.hpp b/nano/store/confirmation_height.hpp index 5569bec7ca..de3cc89e44 100644 --- a/nano/store/confirmation_height.hpp +++ b/nano/store/confirmation_height.hpp @@ -37,7 +37,7 @@ class confirmation_height virtual void clear (store::write_transaction const &) = 0; virtual iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const = 0; virtual iterator begin (store::transaction const & transaction_a) const = 0; - virtual iterator end () const = 0; + virtual iterator end (store::transaction const & transaction_a) const = 0; virtual void for_each_par (std::function const &) const = 0; }; } // namespace nano::store diff --git a/nano/store/final_vote.hpp b/nano/store/final_vote.hpp index 677159dda5..e9f9e34173 100644 --- a/nano/store/final_vote.hpp +++ b/nano/store/final_vote.hpp @@ -29,7 +29,7 @@ class final_vote virtual void clear (store::write_transaction const &) = 0; virtual iterator begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const = 0; virtual iterator begin (store::transaction const & transaction_a) const = 0; - virtual iterator end () const = 0; + virtual iterator end (store::transaction const & transaction_a) const = 0; virtual void for_each_par (std::function const & action_a) const = 0; }; } // namespace nano::store diff --git a/nano/store/lmdb/account.cpp b/nano/store/lmdb/account.cpp index e01ce6236d..766daaa81a 100644 --- a/nano/store/lmdb/account.cpp +++ b/nano/store/lmdb/account.cpp @@ -35,7 +35,7 @@ void nano::store::lmdb::account::del (store::write_transaction const & transacti bool nano::store::lmdb::account::exists (store::transaction const & transaction_a, nano::account const & account_a) { auto iterator (begin (transaction_a, account_a)); - return iterator != end () && nano::account (iterator->first) == account_a; + return iterator != end (transaction_a) && nano::account (iterator->first) == account_a; } size_t nano::store::lmdb::account::count (store::transaction const & transaction_a) @@ -58,7 +58,7 @@ auto nano::store::lmdb::account::rbegin (store::transaction const & transaction_ return store.make_iterator (transaction_a, tables::accounts, false); } -auto nano::store::lmdb::account::end () const -> iterator +auto nano::store::lmdb::account::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } @@ -68,6 +68,6 @@ void nano::store::lmdb::account::for_each_par (std::function ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { auto transaction (this->store.tx_begin_read ()); - action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); + action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end (transaction)); }); } diff --git a/nano/store/lmdb/account.hpp b/nano/store/lmdb/account.hpp index 6650f19fc6..283083d8d1 100644 --- a/nano/store/lmdb/account.hpp +++ b/nano/store/lmdb/account.hpp @@ -25,7 +25,7 @@ class account : public nano::store::account iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; iterator begin (store::transaction const & transaction_a) const override; iterator rbegin (store::transaction const & transaction_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; void for_each_par (std::function const & action_a) const override; /** diff --git a/nano/store/lmdb/block.cpp b/nano/store/lmdb/block.cpp index 461e0b99f4..72c4b05764 100644 --- a/nano/store/lmdb/block.cpp +++ b/nano/store/lmdb/block.cpp @@ -111,11 +111,11 @@ std::shared_ptr nano::store::lmdb::block::random (store::transactio nano::block_hash hash; nano::random_pool::generate_block (hash.bytes.data (), hash.bytes.size ()); auto existing = begin (transaction, hash); - if (existing == end ()) + if (existing == end (transaction)) { existing = begin (transaction); } - debug_assert (existing != end ()); + debug_assert (existing != end (transaction)); return existing->second.block; } @@ -145,7 +145,7 @@ auto nano::store::lmdb::block::begin (store::transaction const & transaction, na return store.make_iterator (transaction, tables::blocks, hash); } -auto nano::store::lmdb::block::end () const -> iterator +auto nano::store::lmdb::block::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } @@ -155,7 +155,7 @@ void nano::store::lmdb::block::for_each_par (std::function ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { auto transaction (this->store.tx_begin_read ()); - action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); + action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end (transaction)); }); } diff --git a/nano/store/lmdb/block.hpp b/nano/store/lmdb/block.hpp index 2594945110..f1130feaa3 100644 --- a/nano/store/lmdb/block.hpp +++ b/nano/store/lmdb/block.hpp @@ -33,7 +33,7 @@ class block : public nano::store::block uint64_t count (store::transaction const & transaction_a) override; iterator begin (store::transaction const & transaction_a) const override; iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; void for_each_par (std::function const & action_a) const override; /** diff --git a/nano/store/lmdb/confirmation_height.cpp b/nano/store/lmdb/confirmation_height.cpp index 234c56844b..c85e47547b 100644 --- a/nano/store/lmdb/confirmation_height.cpp +++ b/nano/store/lmdb/confirmation_height.cpp @@ -69,7 +69,7 @@ auto nano::store::lmdb::confirmation_height::begin (store::transaction const & t return store.make_iterator (transaction, tables::confirmation_height); } -auto nano::store::lmdb::confirmation_height::end () const -> iterator +auto nano::store::lmdb::confirmation_height::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } @@ -79,6 +79,6 @@ void nano::store::lmdb::confirmation_height::for_each_par (std::function ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { auto transaction (this->store.tx_begin_read ()); - action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); + action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end (transaction)); }); } diff --git a/nano/store/lmdb/confirmation_height.hpp b/nano/store/lmdb/confirmation_height.hpp index de35324595..36acd9fc94 100644 --- a/nano/store/lmdb/confirmation_height.hpp +++ b/nano/store/lmdb/confirmation_height.hpp @@ -25,7 +25,7 @@ class confirmation_height : public nano::store::confirmation_height void clear (store::write_transaction const & transaction_a) override; iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; iterator begin (store::transaction const & transaction_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; void for_each_par (std::function const & action_a) const override; /* diff --git a/nano/store/lmdb/final_vote.cpp b/nano/store/lmdb/final_vote.cpp index a26153d1f7..aed69f25bf 100644 --- a/nano/store/lmdb/final_vote.cpp +++ b/nano/store/lmdb/final_vote.cpp @@ -27,7 +27,7 @@ std::vector nano::store::lmdb::final_vote::get (store::transac { std::vector result; nano::qualified_root key_start{ root_a.raw, 0 }; - for (auto i = begin (transaction, key_start), n = end (); i != n && nano::qualified_root{ i->first }.root () == root_a; ++i) + for (auto i = begin (transaction, key_start), n = end (transaction); i != n && nano::qualified_root{ i->first }.root () == root_a; ++i) { result.push_back (i->second); } @@ -37,7 +37,7 @@ std::vector nano::store::lmdb::final_vote::get (store::transac void nano::store::lmdb::final_vote::del (store::write_transaction const & transaction, nano::root const & root) { std::vector final_vote_qualified_roots; - for (auto i = begin (transaction, nano::qualified_root{ root.raw, 0 }), n = end (); i != n && nano::qualified_root{ i->first }.root () == root; ++i) + for (auto i = begin (transaction, nano::qualified_root{ root.raw, 0 }), n = end (transaction); i != n && nano::qualified_root{ i->first }.root () == root; ++i) { final_vote_qualified_roots.push_back (i->first); } @@ -74,7 +74,7 @@ auto nano::store::lmdb::final_vote::begin (store::transaction const & transactio return store.make_iterator (transaction, tables::final_votes); } -auto nano::store::lmdb::final_vote::end () const -> iterator +auto nano::store::lmdb::final_vote::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } @@ -84,6 +84,6 @@ void nano::store::lmdb::final_vote::for_each_par (std::function ( [&action_a, this] (nano::uint512_t const & start, nano::uint512_t const & end, bool const is_last) { auto transaction (this->store.tx_begin_read ()); - action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); + action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end (transaction)); }); } diff --git a/nano/store/lmdb/final_vote.hpp b/nano/store/lmdb/final_vote.hpp index 9b72b085a6..c905edc9dd 100644 --- a/nano/store/lmdb/final_vote.hpp +++ b/nano/store/lmdb/final_vote.hpp @@ -25,7 +25,7 @@ class final_vote : public nano::store::final_vote void clear (store::write_transaction const & transaction_a) override; iterator begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const override; iterator begin (store::transaction const & transaction_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; void for_each_par (std::function const & action_a) const override; /** diff --git a/nano/store/lmdb/lmdb.cpp b/nano/store/lmdb/lmdb.cpp index a9d83eb483..ef467208b2 100644 --- a/nano/store/lmdb/lmdb.cpp +++ b/nano/store/lmdb/lmdb.cpp @@ -258,7 +258,7 @@ void nano::store::lmdb::component::upgrade_v22_to_v23 (store::write_transaction drop (transaction, tables::rep_weights); transaction.refresh (); - release_assert (rep_weight.begin (tx_begin_read ()) == rep_weight.end (), "rep weights table must be empty before upgrading to v23"); + release_assert (rep_weight.begin (tx_begin_read ()) == rep_weight.end (transaction), "rep weights table must be empty before upgrading to v23"); auto iterate_accounts = [this] (auto && func) { auto transaction = tx_begin_read (); diff --git a/nano/store/lmdb/online_weight.cpp b/nano/store/lmdb/online_weight.cpp index c9e553a090..a570b3ed8b 100644 --- a/nano/store/lmdb/online_weight.cpp +++ b/nano/store/lmdb/online_weight.cpp @@ -28,7 +28,7 @@ auto nano::store::lmdb::online_weight::rbegin (store::transaction const & transa return store.make_iterator (transaction, tables::online_weight, false); } -auto nano::store::lmdb::online_weight::end () const -> iterator +auto nano::store::lmdb::online_weight::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } diff --git a/nano/store/lmdb/online_weight.hpp b/nano/store/lmdb/online_weight.hpp index fe28103513..07668532c8 100644 --- a/nano/store/lmdb/online_weight.hpp +++ b/nano/store/lmdb/online_weight.hpp @@ -17,7 +17,7 @@ class online_weight : public nano::store::online_weight void del (store::write_transaction const & transaction_a, uint64_t time_a) override; iterator begin (store::transaction const & transaction_a) const override; iterator rbegin (store::transaction const & transaction_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; size_t count (store::transaction const & transaction_a) const override; void clear (store::write_transaction const & transaction_a) override; diff --git a/nano/store/lmdb/peer.cpp b/nano/store/lmdb/peer.cpp index a91cd3002b..e22b9c27a0 100644 --- a/nano/store/lmdb/peer.cpp +++ b/nano/store/lmdb/peer.cpp @@ -50,7 +50,7 @@ auto nano::store::lmdb::peer::begin (store::transaction const & transaction) con return store.make_iterator (transaction, tables::peers); } -auto nano::store::lmdb::peer::end () const -> iterator +auto nano::store::lmdb::peer::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } diff --git a/nano/store/lmdb/peer.hpp b/nano/store/lmdb/peer.hpp index db39eb5124..ba4eaf322e 100644 --- a/nano/store/lmdb/peer.hpp +++ b/nano/store/lmdb/peer.hpp @@ -20,7 +20,7 @@ class peer : public nano::store::peer size_t count (store::transaction const &) const override; void clear (store::write_transaction const &) override; iterator begin (store::transaction const &) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; /* * Endpoints for peers diff --git a/nano/store/lmdb/pending.cpp b/nano/store/lmdb/pending.cpp index 925203d542..fd2e573170 100644 --- a/nano/store/lmdb/pending.cpp +++ b/nano/store/lmdb/pending.cpp @@ -36,13 +36,13 @@ std::optional nano::store::lmdb::pending::get (store::transa bool nano::store::lmdb::pending::exists (store::transaction const & transaction_a, nano::pending_key const & key_a) { auto iterator (begin (transaction_a, key_a)); - return iterator != end () && nano::pending_key (iterator->first) == key_a; + return iterator != end (transaction_a) && nano::pending_key (iterator->first) == key_a; } bool nano::store::lmdb::pending::any (store::transaction const & transaction_a, nano::account const & account_a) { auto iterator (begin (transaction_a, nano::pending_key (account_a, 0))); - return iterator != end () && nano::pending_key (iterator->first).account == account_a; + return iterator != end (transaction_a) && nano::pending_key (iterator->first).account == account_a; } auto nano::store::lmdb::pending::begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const -> iterator @@ -55,7 +55,7 @@ auto nano::store::lmdb::pending::begin (store::transaction const & transaction_a return store.make_iterator (transaction_a, tables::pending); } -auto nano::store::lmdb::pending::end () const -> iterator +auto nano::store::lmdb::pending::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } @@ -69,6 +69,6 @@ void nano::store::lmdb::pending::for_each_par (std::functionstore.tx_begin_read ()); - action_a (transaction, this->begin (transaction, key_start), !is_last ? this->begin (transaction, key_end) : this->end ()); + action_a (transaction, this->begin (transaction, key_start), !is_last ? this->begin (transaction, key_end) : this->end (transaction)); }); } diff --git a/nano/store/lmdb/pending.hpp b/nano/store/lmdb/pending.hpp index 46b5f7947c..5012210947 100644 --- a/nano/store/lmdb/pending.hpp +++ b/nano/store/lmdb/pending.hpp @@ -24,7 +24,7 @@ class pending : public nano::store::pending bool any (store::transaction const & transaction_a, nano::account const & account_a) override; iterator begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const override; iterator begin (store::transaction const & transaction_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; void for_each_par (std::function const & action_a) const override; /** diff --git a/nano/store/lmdb/pruned.cpp b/nano/store/lmdb/pruned.cpp index 30bf1e0b99..960881acc8 100644 --- a/nano/store/lmdb/pruned.cpp +++ b/nano/store/lmdb/pruned.cpp @@ -27,11 +27,11 @@ nano::block_hash nano::store::lmdb::pruned::random (store::transaction const & t nano::block_hash random_hash; nano::random_pool::generate_block (random_hash.bytes.data (), random_hash.bytes.size ()); auto existing = begin (transaction, random_hash); - if (existing == end ()) + if (existing == end (transaction)) { existing = begin (transaction); } - return existing != end () ? existing->first : 0; + return existing != end (transaction) ? existing->first : 0; } size_t nano::store::lmdb::pruned::count (store::transaction const & transaction_a) const @@ -55,7 +55,7 @@ auto nano::store::lmdb::pruned::begin (store::transaction const & transaction) c return store.make_iterator (transaction, tables::pruned); } -auto nano::store::lmdb::pruned::end () const -> iterator +auto nano::store::lmdb::pruned::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } @@ -65,6 +65,6 @@ void nano::store::lmdb::pruned::for_each_par (std::function ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { auto transaction (this->store.tx_begin_read ()); - action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); + action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end (transaction)); }); } diff --git a/nano/store/lmdb/pruned.hpp b/nano/store/lmdb/pruned.hpp index de1be14a1a..a5d10ebf33 100644 --- a/nano/store/lmdb/pruned.hpp +++ b/nano/store/lmdb/pruned.hpp @@ -21,7 +21,7 @@ class pruned : public nano::store::pruned void clear (store::write_transaction const & transaction_a) override; iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; iterator begin (store::transaction const & transaction_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; void for_each_par (std::function const & action_a) const override; /** diff --git a/nano/store/lmdb/rep_weight.cpp b/nano/store/lmdb/rep_weight.cpp index d01d204d5c..02e97a9d85 100644 --- a/nano/store/lmdb/rep_weight.cpp +++ b/nano/store/lmdb/rep_weight.cpp @@ -53,7 +53,7 @@ auto nano::store::lmdb::rep_weight::begin (store::transaction const & transactio return store.make_iterator (transaction_a, tables::rep_weights); } -auto nano::store::lmdb::rep_weight::end () const -> iterator +auto nano::store::lmdb::rep_weight::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } @@ -63,6 +63,6 @@ void nano::store::lmdb::rep_weight::for_each_par (std::function ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { auto transaction (this->store.tx_begin_read ()); - action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); + action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end (transaction)); }); } diff --git a/nano/store/lmdb/rep_weight.hpp b/nano/store/lmdb/rep_weight.hpp index 809b23ae29..b0fa3aecbf 100644 --- a/nano/store/lmdb/rep_weight.hpp +++ b/nano/store/lmdb/rep_weight.hpp @@ -22,7 +22,7 @@ class rep_weight : public nano::store::rep_weight void del (store::write_transaction const &, nano::account const & representative_a) override; iterator begin (store::transaction const & transaction_a, nano::account const & representative_a) const override; iterator begin (store::transaction const & transaction_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; void for_each_par (std::function const & action_a) const override; /** diff --git a/nano/store/online_weight.hpp b/nano/store/online_weight.hpp index 595a515108..e6c90f8616 100644 --- a/nano/store/online_weight.hpp +++ b/nano/store/online_weight.hpp @@ -25,7 +25,7 @@ class online_weight virtual void del (store::write_transaction const &, uint64_t) = 0; virtual iterator begin (store::transaction const &) const = 0; virtual iterator rbegin (store::transaction const &) const = 0; - virtual iterator end () const = 0; + virtual iterator end (store::transaction const & transaction_a) const = 0; virtual size_t count (store::transaction const &) const = 0; virtual void clear (store::write_transaction const &) = 0; }; diff --git a/nano/store/peer.hpp b/nano/store/peer.hpp index 58e3c1d1e4..9a03721c9d 100644 --- a/nano/store/peer.hpp +++ b/nano/store/peer.hpp @@ -29,6 +29,6 @@ class peer virtual size_t count (store::transaction const &) const = 0; virtual void clear (store::write_transaction const &) = 0; virtual iterator begin (store::transaction const &) const = 0; - virtual iterator end () const = 0; + virtual iterator end (store::transaction const & transaction_a) const = 0; }; } // namespace nano::store diff --git a/nano/store/pending.hpp b/nano/store/pending.hpp index 771bfba5c7..c9d2fd6593 100644 --- a/nano/store/pending.hpp +++ b/nano/store/pending.hpp @@ -31,7 +31,7 @@ class pending virtual bool any (store::transaction const &, nano::account const &) = 0; virtual iterator begin (store::transaction const &, nano::pending_key const &) const = 0; virtual iterator begin (store::transaction const &) const = 0; - virtual iterator end () const = 0; + virtual iterator end (store::transaction const & transaction_a) const = 0; virtual void for_each_par (std::function const & action_a) const = 0; }; } // namespace nano::store diff --git a/nano/store/pruned.hpp b/nano/store/pruned.hpp index 5899c3d0cf..448020c230 100644 --- a/nano/store/pruned.hpp +++ b/nano/store/pruned.hpp @@ -29,7 +29,7 @@ class pruned virtual void clear (store::write_transaction const &) = 0; virtual iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const = 0; virtual iterator begin (store::transaction const & transaction_a) const = 0; - virtual iterator end () const = 0; + virtual iterator end (store::transaction const & transaction_a) const = 0; virtual void for_each_par (std::function const & action_a) const = 0; }; } // namespace nano::store diff --git a/nano/store/rep_weight.hpp b/nano/store/rep_weight.hpp index 5d8fdb80a9..b9fdc704ca 100644 --- a/nano/store/rep_weight.hpp +++ b/nano/store/rep_weight.hpp @@ -29,7 +29,7 @@ class rep_weight virtual void del (store::write_transaction const &, nano::account const & representative_a) = 0; virtual iterator begin (store::transaction const & transaction_a, nano::account const & representative_a) const = 0; virtual iterator begin (store::transaction const & transaction_a) const = 0; - virtual iterator end () const = 0; + virtual iterator end (store::transaction const & transaction_a) const = 0; virtual void for_each_par (std::function const & action_a) const = 0; }; } diff --git a/nano/store/rocksdb/account.cpp b/nano/store/rocksdb/account.cpp index 9040f22e31..d0ffa20d92 100644 --- a/nano/store/rocksdb/account.cpp +++ b/nano/store/rocksdb/account.cpp @@ -34,7 +34,7 @@ void nano::store::rocksdb::account::del (store::write_transaction const & transa bool nano::store::rocksdb::account::exists (store::transaction const & transaction_a, nano::account const & account_a) { auto iterator (begin (transaction_a, account_a)); - return iterator != end () && nano::account (iterator->first) == account_a; + return iterator != end (transaction_a) && nano::account (iterator->first) == account_a; } size_t nano::store::rocksdb::account::count (store::transaction const & transaction_a) @@ -57,7 +57,7 @@ auto nano::store::rocksdb::account::rbegin (store::transaction const & transacti return store.make_iterator (transaction_a, tables::accounts, false); } -auto nano::store::rocksdb::account::end () const -> iterator +auto nano::store::rocksdb::account::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } @@ -67,6 +67,6 @@ void nano::store::rocksdb::account::for_each_par (std::function ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { auto transaction (this->store.tx_begin_read ()); - action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); + action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end (transaction)); }); } diff --git a/nano/store/rocksdb/account.hpp b/nano/store/rocksdb/account.hpp index 1b2c068d00..c0b73bde43 100644 --- a/nano/store/rocksdb/account.hpp +++ b/nano/store/rocksdb/account.hpp @@ -23,7 +23,7 @@ class account : public nano::store::account iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; iterator begin (store::transaction const & transaction_a) const override; iterator rbegin (store::transaction const & transaction_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; void for_each_par (std::function const & action_a) const override; }; } // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/block.cpp b/nano/store/rocksdb/block.cpp index 7532193ae7..fcee0ffd36 100644 --- a/nano/store/rocksdb/block.cpp +++ b/nano/store/rocksdb/block.cpp @@ -110,11 +110,11 @@ std::shared_ptr nano::store::rocksdb::block::random (store::transac nano::block_hash hash; nano::random_pool::generate_block (hash.bytes.data (), hash.bytes.size ()); auto existing = begin (transaction, hash); - if (existing == end ()) + if (existing == end (transaction)) { existing = begin (transaction); } - debug_assert (existing != end ()); + debug_assert (existing != end (transaction)); return existing->second.block; } @@ -144,7 +144,7 @@ auto nano::store::rocksdb::block::begin (store::transaction const & transaction, return store.make_iterator (transaction, tables::blocks, hash); } -auto nano::store::rocksdb::block::end () const -> iterator +auto nano::store::rocksdb::block::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } @@ -154,7 +154,7 @@ void nano::store::rocksdb::block::for_each_par (std::function ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { auto transaction (this->store.tx_begin_read ()); - action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); + action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end (transaction)); }); } diff --git a/nano/store/rocksdb/block.hpp b/nano/store/rocksdb/block.hpp index 0a093f1c38..741c862f77 100644 --- a/nano/store/rocksdb/block.hpp +++ b/nano/store/rocksdb/block.hpp @@ -31,7 +31,7 @@ class block : public nano::store::block uint64_t count (store::transaction const & transaction_a) override; iterator begin (store::transaction const & transaction_a) const override; iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; void for_each_par (std::function const & action_a) const override; protected: diff --git a/nano/store/rocksdb/confirmation_height.cpp b/nano/store/rocksdb/confirmation_height.cpp index eea420237c..838a365208 100644 --- a/nano/store/rocksdb/confirmation_height.cpp +++ b/nano/store/rocksdb/confirmation_height.cpp @@ -69,7 +69,7 @@ auto nano::store::rocksdb::confirmation_height::begin (store::transaction const return store.make_iterator (transaction, tables::confirmation_height); } -auto nano::store::rocksdb::confirmation_height::end () const -> iterator +auto nano::store::rocksdb::confirmation_height::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } @@ -79,6 +79,6 @@ void nano::store::rocksdb::confirmation_height::for_each_par (std::function ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { auto transaction (this->store.tx_begin_read ()); - action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); + action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end (transaction)); }); } diff --git a/nano/store/rocksdb/confirmation_height.hpp b/nano/store/rocksdb/confirmation_height.hpp index 050ceef9b1..6819b69eba 100644 --- a/nano/store/rocksdb/confirmation_height.hpp +++ b/nano/store/rocksdb/confirmation_height.hpp @@ -23,7 +23,7 @@ class confirmation_height : public nano::store::confirmation_height void clear (store::write_transaction const & transaction_a) override; iterator begin (store::transaction const & transaction_a, nano::account const & account_a) const override; iterator begin (store::transaction const & transaction_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; void for_each_par (std::function const & action_a) const override; }; } // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/final_vote.cpp b/nano/store/rocksdb/final_vote.cpp index 3979b16cab..328027ae3b 100644 --- a/nano/store/rocksdb/final_vote.cpp +++ b/nano/store/rocksdb/final_vote.cpp @@ -27,7 +27,7 @@ std::vector nano::store::rocksdb::final_vote::get (store::tran { std::vector result; nano::qualified_root key_start{ root_a.raw, 0 }; - for (auto i = begin (transaction, key_start), n = end (); i != n && nano::qualified_root{ i->first }.root () == root_a; ++i) + for (auto i = begin (transaction, key_start), n = end (transaction); i != n && nano::qualified_root{ i->first }.root () == root_a; ++i) { result.push_back (i->second); } @@ -37,7 +37,7 @@ std::vector nano::store::rocksdb::final_vote::get (store::tran void nano::store::rocksdb::final_vote::del (store::write_transaction const & transaction, nano::root const & root) { std::vector final_vote_qualified_roots; - for (auto i = begin (transaction, nano::qualified_root{ root.raw, 0 }), n = end (); i != n && nano::qualified_root{ i->first }.root () == root; ++i) + for (auto i = begin (transaction, nano::qualified_root{ root.raw, 0 }), n = end (transaction); i != n && nano::qualified_root{ i->first }.root () == root; ++i) { final_vote_qualified_roots.push_back (i->first); } @@ -74,7 +74,7 @@ auto nano::store::rocksdb::final_vote::begin (store::transaction const & transac return store.make_iterator (transaction, tables::final_votes); } -auto nano::store::rocksdb::final_vote::end () const -> iterator +auto nano::store::rocksdb::final_vote::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } @@ -84,6 +84,6 @@ void nano::store::rocksdb::final_vote::for_each_par (std::function ( [&action_a, this] (nano::uint512_t const & start, nano::uint512_t const & end, bool const is_last) { auto transaction (this->store.tx_begin_read ()); - action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); + action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end (transaction)); }); } diff --git a/nano/store/rocksdb/final_vote.hpp b/nano/store/rocksdb/final_vote.hpp index a24093a576..67a1e0d52b 100644 --- a/nano/store/rocksdb/final_vote.hpp +++ b/nano/store/rocksdb/final_vote.hpp @@ -23,7 +23,7 @@ class final_vote : public nano::store::final_vote void clear (store::write_transaction const & transaction_a) override; iterator begin (store::transaction const & transaction_a, nano::qualified_root const & root_a) const override; iterator begin (store::transaction const & transaction_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; void for_each_par (std::function const & action_a) const override; }; } // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/online_weight.cpp b/nano/store/rocksdb/online_weight.cpp index 42250c6897..dafd0f51f1 100644 --- a/nano/store/rocksdb/online_weight.cpp +++ b/nano/store/rocksdb/online_weight.cpp @@ -28,7 +28,7 @@ auto nano::store::rocksdb::online_weight::rbegin (store::transaction const & tra return store.make_iterator (transaction, tables::online_weight, false); } -auto nano::store::rocksdb::online_weight::end () const -> iterator +auto nano::store::rocksdb::online_weight::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } diff --git a/nano/store/rocksdb/online_weight.hpp b/nano/store/rocksdb/online_weight.hpp index 4d940ffda3..1b88d329da 100644 --- a/nano/store/rocksdb/online_weight.hpp +++ b/nano/store/rocksdb/online_weight.hpp @@ -19,7 +19,7 @@ class online_weight : public nano::store::online_weight void del (store::write_transaction const & transaction_a, uint64_t time_a) override; iterator begin (store::transaction const & transaction_a) const override; iterator rbegin (store::transaction const & transaction_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; size_t count (store::transaction const & transaction_a) const override; void clear (store::write_transaction const & transaction_a) override; }; diff --git a/nano/store/rocksdb/peer.cpp b/nano/store/rocksdb/peer.cpp index 71fa3ccc56..0da5791028 100644 --- a/nano/store/rocksdb/peer.cpp +++ b/nano/store/rocksdb/peer.cpp @@ -50,7 +50,7 @@ auto nano::store::rocksdb::peer::begin (store::transaction const & transaction) return store.make_iterator (transaction, tables::peers); } -auto nano::store::rocksdb::peer::end () const -> iterator +auto nano::store::rocksdb::peer::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } diff --git a/nano/store/rocksdb/peer.hpp b/nano/store/rocksdb/peer.hpp index 30e57644fd..61f3b87c6f 100644 --- a/nano/store/rocksdb/peer.hpp +++ b/nano/store/rocksdb/peer.hpp @@ -22,6 +22,6 @@ class peer : public nano::store::peer size_t count (store::transaction const &) const override; void clear (store::write_transaction const &) override; iterator begin (store::transaction const &) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; }; } // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/pending.cpp b/nano/store/rocksdb/pending.cpp index 3286cd8f94..9fc4b1a2ef 100644 --- a/nano/store/rocksdb/pending.cpp +++ b/nano/store/rocksdb/pending.cpp @@ -36,13 +36,13 @@ std::optional nano::store::rocksdb::pending::get (store::tra bool nano::store::rocksdb::pending::exists (store::transaction const & transaction_a, nano::pending_key const & key_a) { auto iterator (begin (transaction_a, key_a)); - return iterator != end () && nano::pending_key (iterator->first) == key_a; + return iterator != end (transaction_a) && nano::pending_key (iterator->first) == key_a; } bool nano::store::rocksdb::pending::any (store::transaction const & transaction_a, nano::account const & account_a) { auto iterator (begin (transaction_a, nano::pending_key (account_a, 0))); - return iterator != end () && nano::pending_key (iterator->first).account == account_a; + return iterator != end (transaction_a) && nano::pending_key (iterator->first).account == account_a; } auto nano::store::rocksdb::pending::begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const -> iterator @@ -55,7 +55,7 @@ auto nano::store::rocksdb::pending::begin (store::transaction const & transactio return store.template make_iterator (transaction_a, tables::pending); } -auto nano::store::rocksdb::pending::end () const -> iterator +auto nano::store::rocksdb::pending::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } @@ -69,6 +69,6 @@ void nano::store::rocksdb::pending::for_each_par (std::functionstore.tx_begin_read ()); - action_a (transaction, this->begin (transaction, key_start), !is_last ? this->begin (transaction, key_end) : this->end ()); + action_a (transaction, this->begin (transaction, key_start), !is_last ? this->begin (transaction, key_end) : this->end (transaction)); }); } diff --git a/nano/store/rocksdb/pending.hpp b/nano/store/rocksdb/pending.hpp index 4b98b0f079..061d0031e0 100644 --- a/nano/store/rocksdb/pending.hpp +++ b/nano/store/rocksdb/pending.hpp @@ -18,7 +18,7 @@ class pending : public nano::store::pending bool any (store::transaction const & transaction_a, nano::account const & account_a) override; iterator begin (store::transaction const & transaction_a, nano::pending_key const & key_a) const override; iterator begin (store::transaction const & transaction_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; void for_each_par (std::function const & action_a) const override; }; } // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/pruned.cpp b/nano/store/rocksdb/pruned.cpp index 572f17e348..3cca201440 100644 --- a/nano/store/rocksdb/pruned.cpp +++ b/nano/store/rocksdb/pruned.cpp @@ -27,11 +27,11 @@ nano::block_hash nano::store::rocksdb::pruned::random (store::transaction const nano::block_hash random_hash; nano::random_pool::generate_block (random_hash.bytes.data (), random_hash.bytes.size ()); auto existing = begin (transaction, random_hash); - if (existing == end ()) + if (existing == end (transaction)) { existing = begin (transaction); } - return existing != end () ? existing->first : 0; + return existing != end (transaction) ? existing->first : 0; } size_t nano::store::rocksdb::pruned::count (store::transaction const & transaction_a) const @@ -55,7 +55,7 @@ auto nano::store::rocksdb::pruned::begin (store::transaction const & transaction return store.make_iterator (transaction_a, tables::pruned); } -auto nano::store::rocksdb::pruned::end () const -> iterator +auto nano::store::rocksdb::pruned::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } @@ -65,6 +65,6 @@ void nano::store::rocksdb::pruned::for_each_par (std::function ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { auto transaction (this->store.tx_begin_read ()); - action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); + action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end (transaction)); }); } diff --git a/nano/store/rocksdb/pruned.hpp b/nano/store/rocksdb/pruned.hpp index 0dc84b84ed..af10be5e8c 100644 --- a/nano/store/rocksdb/pruned.hpp +++ b/nano/store/rocksdb/pruned.hpp @@ -23,7 +23,7 @@ class pruned : public nano::store::pruned void clear (store::write_transaction const & transaction_a) override; iterator begin (store::transaction const & transaction_a, nano::block_hash const & hash_a) const override; iterator begin (store::transaction const & transaction_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; void for_each_par (std::function const & action_a) const override; }; } // namespace nano::store::rocksdb diff --git a/nano/store/rocksdb/rep_weight.cpp b/nano/store/rocksdb/rep_weight.cpp index 68d4684ced..e719ef9904 100644 --- a/nano/store/rocksdb/rep_weight.cpp +++ b/nano/store/rocksdb/rep_weight.cpp @@ -52,7 +52,7 @@ auto nano::store::rocksdb::rep_weight::begin (store::transaction const & txn_a) return store.make_iterator (txn_a, tables::rep_weights); } -auto nano::store::rocksdb::rep_weight::end () const -> iterator +auto nano::store::rocksdb::rep_weight::end (store::transaction const & transaction_a) const -> iterator { return iterator{ nullptr }; } @@ -62,6 +62,6 @@ void nano::store::rocksdb::rep_weight::for_each_par (std::function ( [&action_a, this] (nano::uint256_t const & start, nano::uint256_t const & end, bool const is_last) { auto transaction (this->store.tx_begin_read ()); - action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end ()); + action_a (transaction, this->begin (transaction, start), !is_last ? this->begin (transaction, end) : this->end (transaction)); }); } diff --git a/nano/store/rocksdb/rep_weight.hpp b/nano/store/rocksdb/rep_weight.hpp index 76e542264b..d27c23719f 100644 --- a/nano/store/rocksdb/rep_weight.hpp +++ b/nano/store/rocksdb/rep_weight.hpp @@ -21,7 +21,7 @@ class rep_weight : public nano::store::rep_weight void del (store::write_transaction const &, nano::account const & representative_a) override; iterator begin (store::transaction const & txn_a, nano::account const & representative_a) const override; iterator begin (store::transaction const & txn_a) const override; - iterator end () const override; + iterator end (store::transaction const & transaction_a) const override; void for_each_par (std::function const & action_a) const override; }; } diff --git a/nano/store/rocksdb/rocksdb.cpp b/nano/store/rocksdb/rocksdb.cpp index 85207da372..e62d1db09e 100644 --- a/nano/store/rocksdb/rocksdb.cpp +++ b/nano/store/rocksdb/rocksdb.cpp @@ -292,7 +292,10 @@ void nano::store::rocksdb::component::upgrade_v22_to_v23 (store::write_transacti transaction.refresh (); } - release_assert (rep_weight.begin (tx_begin_read ()) == rep_weight.end (), "rep weights table must be empty before upgrading to v23"); + { + auto tx = tx_begin_read (); + release_assert (rep_weight.begin (tx) == rep_weight.end (tx), "rep weights table must be empty before upgrading to v23"); + } auto iterate_accounts = [this] (auto && func) { auto transaction = tx_begin_read (); @@ -598,14 +601,14 @@ uint64_t nano::store::rocksdb::component::count (store::transaction const & tran // Peers/online weight are small enough that they can just be iterated to get accurate counts. if (table_a == tables::peers) { - for (auto i (peer.begin (transaction_a)), n (peer.end ()); i != n; ++i) + for (auto i (peer.begin (transaction_a)), n (peer.end (transaction_a)); i != n; ++i) { ++sum; } } else if (table_a == tables::online_weight) { - for (auto i (online_weight.begin (transaction_a)), n (online_weight.end ()); i != n; ++i) + for (auto i (online_weight.begin (transaction_a)), n (online_weight.end (transaction_a)); i != n; ++i) { ++sum; } @@ -624,7 +627,7 @@ uint64_t nano::store::rocksdb::component::count (store::transaction const & tran // otherwise there can be performance issues. else if (table_a == tables::accounts) { - for (auto i (account.begin (transaction_a)), n (account.end ()); i != n; ++i) + for (auto i (account.begin (transaction_a)), n (account.end (transaction_a)); i != n; ++i) { ++sum; } @@ -632,14 +635,14 @@ uint64_t nano::store::rocksdb::component::count (store::transaction const & tran else if (table_a == tables::blocks) { // This is also used in some CLI commands - for (auto i (block.begin (transaction_a)), n (block.end ()); i != n; ++i) + for (auto i (block.begin (transaction_a)), n (block.end (transaction_a)); i != n; ++i) { ++sum; } } else if (table_a == tables::confirmation_height) { - for (auto i (confirmation_height.begin (transaction_a)), n (confirmation_height.end ()); i != n; ++i) + for (auto i (confirmation_height.begin (transaction_a)), n (confirmation_height.end (transaction_a)); i != n; ++i) { ++sum; } @@ -647,7 +650,7 @@ uint64_t nano::store::rocksdb::component::count (store::transaction const & tran // rep_weights should only be used in tests otherwise there can be performance issues. else if (table_a == tables::rep_weights) { - for (auto i (rep_weight.begin (transaction_a)), n (rep_weight.end ()); i != n; ++i) + for (auto i (rep_weight.begin (transaction_a)), n (rep_weight.end (transaction_a)); i != n; ++i) { ++sum; } @@ -673,7 +676,7 @@ int nano::store::rocksdb::component::drop (store::write_transaction const & tran if (table_a == tables::peers) { int status = 0; - for (auto i = peer.begin (transaction_a), n = peer.end (); i != n; ++i) + for (auto i = peer.begin (transaction_a), n = peer.end (transaction_a); i != n; ++i) { status = del (transaction_a, tables::peers, nano::store::rocksdb::db_val (i->first)); release_assert (success (status)); diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index 40f8be2203..66af123ae8 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -257,9 +257,9 @@ nano::account nano::test::system::account (store::transaction const & transactio { auto wallet_l (wallet (index_a)); auto keys (wallet_l->store.begin (transaction_a)); - debug_assert (keys != wallet_l->store.end ()); + debug_assert (keys != wallet_l->store.end (transaction_a)); auto result (keys->first); - debug_assert (++keys == wallet_l->store.end ()); + debug_assert (++keys == wallet_l->store.end (transaction_a)); return nano::account (result); } @@ -533,11 +533,11 @@ void nano::test::system::generate_send_existing (nano::node & node_a, std::vecto random_pool::generate_block (account.bytes.data (), sizeof (account.bytes)); auto transaction = node_a.ledger.tx_begin_read (); auto entry = node_a.store.account.begin (transaction, account); - if (entry == node_a.store.account.end ()) + if (entry == node_a.store.account.end (transaction)) { entry = node_a.store.account.begin (transaction); } - debug_assert (entry != node_a.store.account.end ()); + debug_assert (entry != node_a.store.account.end (transaction)); destination = nano::account (entry->first); source = get_random_account (accounts_a); amount = get_random_amount (transaction, node_a, source); diff --git a/nano/test_common/testutil.cpp b/nano/test_common/testutil.cpp index 06e5ed505d..f2c3c77129 100644 --- a/nano/test_common/testutil.cpp +++ b/nano/test_common/testutil.cpp @@ -315,7 +315,7 @@ void nano::test::print_all_receivable_entries (const nano::store::component & st { std::cout << "Printing all receivable entries:\n"; auto const tx = store.tx_begin_read (); - auto const end = store.pending.end (); + auto const end = store.pending.end (tx); for (auto i = store.pending.begin (tx); i != end; ++i) { std::cout << "Key: " << i->first << std::endl; @@ -327,7 +327,7 @@ void nano::test::print_all_account_info (const nano::ledger & ledger) { std::cout << "Printing all account info:\n"; auto const tx = ledger.tx_begin_read (); - auto const end = ledger.store.account.end (); + auto const end = ledger.store.account.end (tx); for (auto i = ledger.store.account.begin (tx); i != end; ++i) { nano::account acc = i->first; @@ -349,7 +349,7 @@ void nano::test::print_all_blocks (const nano::store::component & store) { auto tx = store.tx_begin_read (); auto i = store.block.begin (tx); - auto end = store.block.end (); + auto end = store.block.end (tx); std::cout << "Listing all blocks" << std::endl; for (; i != end; ++i) { @@ -368,7 +368,7 @@ std::vector> nano::test::all_blocks (nano::node & n { auto transaction = node.store.tx_begin_read (); std::vector> result; - for (auto it = node.store.block.begin (transaction), end = node.store.block.end (); it != end; ++it) + for (auto it = node.store.block.begin (transaction), end = node.store.block.end (transaction); it != end; ++it) { result.push_back (it->second.block); } From 7e7f91ba06939cdd512c779fc1bff06bd063381b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 22 Oct 2024 21:12:53 +0200 Subject: [PATCH 44/47] Update boost to 1.86 (#4743) --- CMakeLists.txt | 2 ++ nano/core_test/websocket.cpp | 1 + nano/lib/config.cpp | 1 + nano/nano_wallet/entry.cpp | 1 + nano/node/distributed_work.cpp | 1 + nano/node/ipc/ipc_server.cpp | 1 + nano/node/node.cpp | 1 + nano/rpc_test/rpc.cpp | 1 + nano/test_common/system.cpp | 1 + submodules/boost | 2 +- 10 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0614d03be0..5b93fac654 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -466,6 +466,8 @@ set(BOOST_MODULE_LIBS ratio rational regex + scope + scope_exit serialization smart_ptr spirit diff --git a/nano/core_test/websocket.cpp b/nano/core_test/websocket.cpp index 6cf553d3e7..90991493d3 100644 --- a/nano/core_test/websocket.cpp +++ b/nano/core_test/websocket.cpp @@ -12,6 +12,7 @@ #include +#include #include #include diff --git a/nano/lib/config.cpp b/nano/lib/config.cpp index df922fcc07..4dda3dcf15 100644 --- a/nano/lib/config.cpp +++ b/nano/lib/config.cpp @@ -6,6 +6,7 @@ #include #include +#include #include diff --git a/nano/nano_wallet/entry.cpp b/nano/nano_wallet/entry.cpp index 6a3eac399d..4f149aa51d 100644 --- a/nano/nano_wallet/entry.cpp +++ b/nano/nano_wallet/entry.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include diff --git a/nano/node/distributed_work.cpp b/nano/node/distributed_work.cpp index 56312d7cc7..1404c06526 100644 --- a/nano/node/distributed_work.cpp +++ b/nano/node/distributed_work.cpp @@ -4,6 +4,7 @@ #include #include +#include std::shared_ptr nano::distributed_work::peer_request::get_prepared_json_request (std::string const & request_string_a) const { diff --git a/nano/node/ipc/ipc_server.cpp b/nano/node/ipc/ipc_server.cpp index bdd1eac708..ce711cb392 100644 --- a/nano/node/ipc/ipc_server.cpp +++ b/nano/node/ipc/ipc_server.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 229d17ce16..b3d5955511 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index a13926989d..309290dc1d 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -30,6 +30,7 @@ #include +#include #include #include diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index 66af123ae8..15aed96141 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include diff --git a/submodules/boost b/submodules/boost index b6928ae5c9..65c1319bb9 160000 --- a/submodules/boost +++ b/submodules/boost @@ -1 +1 @@ -Subproject commit b6928ae5c92e21a04bbe17a558e6e066dbe632f6 +Subproject commit 65c1319bb92fe7a9a4abd588eff5818d9c2bccf9 From 1d4e8363c2e46d2bfa4c1f490189764639f77519 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Tue, 22 Oct 2024 23:39:31 +0100 Subject: [PATCH 45/47] Disable backtrace in CI build until backtrace log linking is resolved. (#4764) --- ci/build-ci.sh | 2 +- ci/build.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/build-ci.sh b/ci/build-ci.sh index f03b00c9df..b2be2f7913 100755 --- a/ci/build-ci.sh +++ b/ci/build-ci.sh @@ -48,7 +48,7 @@ cmake \ -DNANO_WARN_TO_ERR=ON \ -DCMAKE_BUILD_TYPE=${BUILD_TYPE:-Debug} \ -DQt5_DIR=${qt_dir} \ -${BACKTRACE:-} \ +#${BACKTRACE:-} \ ${SANITIZERS:-} \ .. diff --git a/ci/build.sh b/ci/build.sh index 41d13cf265..f8610efa50 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -66,7 +66,7 @@ cmake \ -DCI_VERSION_PRE_RELEASE=${CI_VERSION_PRE_RELEASE:-OFF} \ ${CMAKE_SANITIZER:-} \ ${CMAKE_QT_DIR:-} \ -${CMAKE_BACKTRACE:-} \ +#${CMAKE_BACKTRACE:-} \ ${SRC} number_of_processors() { From 9efd84972ee89030f337964f4528041b9e716212 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Wed, 23 Oct 2024 06:42:09 +0100 Subject: [PATCH 46/47] Removing lines in build scripts because bash. (#4765) --- ci/build-ci.sh | 1 - ci/build.sh | 1 - 2 files changed, 2 deletions(-) diff --git a/ci/build-ci.sh b/ci/build-ci.sh index b2be2f7913..31a65eed7f 100755 --- a/ci/build-ci.sh +++ b/ci/build-ci.sh @@ -48,7 +48,6 @@ cmake \ -DNANO_WARN_TO_ERR=ON \ -DCMAKE_BUILD_TYPE=${BUILD_TYPE:-Debug} \ -DQt5_DIR=${qt_dir} \ -#${BACKTRACE:-} \ ${SANITIZERS:-} \ .. diff --git a/ci/build.sh b/ci/build.sh index f8610efa50..090aecbe86 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -66,7 +66,6 @@ cmake \ -DCI_VERSION_PRE_RELEASE=${CI_VERSION_PRE_RELEASE:-OFF} \ ${CMAKE_SANITIZER:-} \ ${CMAKE_QT_DIR:-} \ -#${CMAKE_BACKTRACE:-} \ ${SRC} number_of_processors() { From e1a4fcbec52448c92452d4fc5bb12fc6f8b36be3 Mon Sep 17 00:00:00 2001 From: gr0vity-dev <85646666+gr0vity-dev@users.noreply.github.com> Date: Fri, 25 Oct 2024 14:23:34 +0200 Subject: [PATCH 47/47] Optimize vote distribution between PRs and non-PRs (#4766) * Publish votes to all PRs and a subset of non PRs This avoids potential duplicate votes to PRs and better confirmation times for non PRs * small optimisation for list_non_pr --------- Co-authored-by: gr0vity-dev --- nano/node/network.cpp | 19 +++++++++++++++---- nano/node/network.hpp | 1 + nano/node/vote_generator.cpp | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/nano/node/network.cpp b/nano/node/network.cpp index 6a74df915d..269edcd87f 100644 --- a/nano/node/network.cpp +++ b/nano/node/network.cpp @@ -281,6 +281,15 @@ void nano::network::flood_vote (std::shared_ptr const & vote, float } } +void nano::network::flood_vote_non_pr (std::shared_ptr const & vote, float scale, bool rebroadcasted) +{ + nano::confirm_ack message{ node.network_params.network, vote, rebroadcasted }; + for (auto & i : list_non_pr (fanout (scale))) + { + i->send (message, nullptr); + } +} + void nano::network::flood_vote_pr (std::shared_ptr const & vote, bool rebroadcasted) { nano::confirm_ack message{ node.network_params.network, vote, rebroadcasted }; @@ -377,11 +386,13 @@ std::deque> nano::network::list_non_pr { std::deque> result; tcp_channels.list (result); + + auto partition_point = std::partition (result.begin (), result.end (), + [this] (std::shared_ptr const & channel) { + return !node.rep_crawler.is_pr (channel); + }); + result.resize (std::distance (result.begin (), partition_point)); nano::random_pool_shuffle (result.begin (), result.end ()); - result.erase (std::remove_if (result.begin (), result.end (), [this] (std::shared_ptr const & channel) { - return node.rep_crawler.is_pr (channel); - }), - result.end ()); if (result.size () > count_a) { result.resize (count_a, nullptr); diff --git a/nano/node/network.hpp b/nano/node/network.hpp index 5aa6ec8772..0ab498ed2b 100644 --- a/nano/node/network.hpp +++ b/nano/node/network.hpp @@ -95,6 +95,7 @@ class network final void flood_keepalive_self (float const scale_a = 0.5f); void flood_vote (std::shared_ptr const &, float scale, bool rebroadcasted = false); void flood_vote_pr (std::shared_ptr const &, bool rebroadcasted = false); + void flood_vote_non_pr (std::shared_ptr const &, float scale, bool rebroadcasted = false); // Flood block to all PRs and a random selection of non-PRs void flood_block_initial (std::shared_ptr const &); // Flood block to a random selection of peers diff --git a/nano/node/vote_generator.cpp b/nano/node/vote_generator.cpp index 68792d690d..e29c88cc97 100644 --- a/nano/node/vote_generator.cpp +++ b/nano/node/vote_generator.cpp @@ -277,7 +277,7 @@ void nano::vote_generator::vote (std::vector const & hashes_a, void nano::vote_generator::broadcast_action (std::shared_ptr const & vote_a) const { network.flood_vote_pr (vote_a); - network.flood_vote (vote_a, 2.0f); + network.flood_vote_non_pr (vote_a, 2.0f); vote_processor.vote (vote_a, inproc_channel); }