From c12aae541dd0a3da23897c58dbe54416e381542f Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Sat, 19 Sep 2026 18:33:24 -0400 Subject: [PATCH] Use const iterator accessors for read-only traversal. Co-Authored-By: Claude Sonnet 5 --- .../impl/query/consensus/consensus_prevouts.ipp | 2 +- .../database/impl/unspent/unspent_scanner.ipp | 8 ++++---- .../database/impl/unspent/unspent_serial.ipp | 8 ++++---- .../database/impl/unspent/unspent_spans.ipp | 2 +- test/query/address/address_outpoints.cpp | 14 +++++++------- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/bitcoin/database/impl/query/consensus/consensus_prevouts.ipp b/include/bitcoin/database/impl/query/consensus/consensus_prevouts.ipp index 44ded9019..65dec426d 100644 --- a/include/bitcoin/database/impl/query/consensus/consensus_prevouts.ipp +++ b/include/bitcoin/database/impl/query/consensus/consensus_prevouts.ipp @@ -59,7 +59,7 @@ code CLASS::get_prevouts(point_sets& sets, size_t points, return system::error::confirmed_double_spend; // Augment spend.points with metadata. - auto it = cache.spends.begin(); + auto it = cache.spends.cbegin(); for (auto& set: sets) { for (auto& point: set.points) diff --git a/include/bitcoin/database/impl/unspent/unspent_scanner.ipp b/include/bitcoin/database/impl/unspent/unspent_scanner.ipp index 51708f736..67210dd8f 100644 --- a/include/bitcoin/database/impl/unspent/unspent_scanner.ipp +++ b/include/bitcoin/database/impl/unspent/unspent_scanner.ipp @@ -59,7 +59,7 @@ code CLASS::scan(difference_set& set, unspent_totals& out, index.push_back(at); const auto parallel = poolstl::execution::par_if(turbo_); - std::for_each(parallel, index.begin(), index.end(), + std::for_each(parallel, index.cbegin(), index.cend(), [&](size_t at) NOEXCEPT { if (fail) @@ -94,7 +94,7 @@ code CLASS::bounds(std_vector& out, std::iota(blocks.begin(), blocks.end(), zero); const auto parallel = poolstl::execution::par_if(turbo_); - std::for_each(parallel, blocks.begin(), blocks.end(), + std::for_each(parallel, blocks.cbegin(), blocks.cend(), [&](size_t block) NOEXCEPT { counts.at(block) = query_.get_tx_count(branch.at(block)); @@ -222,10 +222,10 @@ code CLASS::toggle_creates(difference_set& set, output_links& exclusions, if (!store_.outs.puts.get(ptr, tx.outs_fk, outs)) return error::integrity; - auto excluded = outs.excluded.begin(); + auto excluded = outs.excluded.cbegin(); for (uint32_t index{}; index < outs.number; ++index) { - if (excluded != outs.excluded.end() && excluded->first == index) + if (excluded != outs.excluded.cend() && excluded->first == index) exclusions.push_back((excluded++)->second); else set.toggle(tx.outs_fk + index); diff --git a/include/bitcoin/database/impl/unspent/unspent_serial.ipp b/include/bitcoin/database/impl/unspent/unspent_serial.ipp index 6a3de225b..fed3b4dcc 100644 --- a/include/bitcoin/database/impl/unspent/unspent_serial.ipp +++ b/include/bitcoin/database/impl/unspent/unspent_serial.ipp @@ -118,7 +118,7 @@ code CLASS::partition(unspent_elements& out, sizes& offsets, const auto parallel = poolstl::execution::par_if(turbo_); std::atomic_bool fail{}; - std::for_each(parallel, index.begin(), index.end(), + std::for_each(parallel, index.cbegin(), index.cend(), [&](size_t chunk) NOEXCEPT { if (fail) @@ -139,7 +139,7 @@ code CLASS::partition(unspent_elements& out, sizes& offsets, starts(counts, offsets, chunks); out.resize(offsets.back()); - std::for_each(parallel, index.begin(), index.end(), + std::for_each(parallel, index.cbegin(), index.cend(), [&](size_t chunk) NOEXCEPT { if (fail) @@ -261,7 +261,7 @@ code CLASS::fill(unspent_coins& out, output_links& puts, std::iota(index.begin(), index.end(), zero); std::atomic_bool fail{}; - std::for_each(parallel, index.begin(), index.end(), + std::for_each(parallel, index.cbegin(), index.cend(), [&](size_t chunk) NOEXCEPT { if (fail) @@ -310,7 +310,7 @@ void CLASS::gather(unspent_coins& out, output_links& links, std::iota(index.begin(), index.end(), zero); const auto parallel = poolstl::execution::par_if(turbo_); - std::for_each(parallel, index.begin(), index.end(), + std::for_each(parallel, index.cbegin(), index.cend(), [&](size_t at) NOEXCEPT { out.at(at) = std::move(coins.at(order.at(at))); diff --git a/include/bitcoin/database/impl/unspent/unspent_spans.ipp b/include/bitcoin/database/impl/unspent/unspent_spans.ipp index de2ec2ed9..9b73ee908 100644 --- a/include/bitcoin/database/impl/unspent/unspent_spans.ipp +++ b/include/bitcoin/database/impl/unspent/unspent_spans.ipp @@ -62,7 +62,7 @@ code CLASS::for_each(const difference_set& set, const Span& span) const NOEXCEPT std::atomic_bool fail{}; const auto parallel = poolstl::execution::par_if(turbo_); - std::for_each(parallel, index.begin(), index.end(), + std::for_each(parallel, index.cbegin(), index.cend(), [&](size_t chunk) NOEXCEPT { if (fail) diff --git a/test/query/address/address_outpoints.cpp b/test/query/address/address_outpoints.cpp index 90c721939..0ee3daaaf 100644 --- a/test/query/address/address_outpoints.cpp +++ b/test/query/address/address_outpoints.cpp @@ -37,7 +37,7 @@ BOOST_AUTO_TEST_CASE(query_address__get_confirmed_unspent_outpoints__turbo_genes const std::atomic_bool cancel{}; BOOST_REQUIRE(!query.get_confirmed_unspent_outpoints(cancel, out, test::genesis_address0, true)); BOOST_REQUIRE_EQUAL(out.size(), 1u); - BOOST_REQUIRE(*out.begin() == query.get_outpoint(query.to_output(0, 0))); + BOOST_REQUIRE(*out.cbegin() == query.get_outpoint(query.to_output(0, 0))); } BOOST_AUTO_TEST_CASE(query_address__get_confirmed_unspent_outpoints__genesis__expected) @@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE(query_address__get_confirmed_unspent_outpoints__genesis__ex const std::atomic_bool cancel{}; BOOST_REQUIRE(!query.get_confirmed_unspent_outpoints(cancel, out, test::genesis_address0)); BOOST_REQUIRE_EQUAL(out.size(), 1u); - BOOST_REQUIRE(*out.begin() == query.get_outpoint(query.to_output(0, 0))); + BOOST_REQUIRE(*out.cbegin() == query.get_outpoint(query.to_output(0, 0))); } // get_minimum_unspent_outpoints @@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(query_address__get_minimum_unspent_outpoints__at__included) const std::atomic_bool cancel{}; BOOST_REQUIRE(!query.get_minimum_unspent_outpoints(cancel, out, test::genesis_address0, 5000000000)); BOOST_REQUIRE_EQUAL(out.size(), 1u); - BOOST_REQUIRE(*out.begin() == query.get_outpoint(query.to_output(0, 0))); + BOOST_REQUIRE(*out.cbegin() == query.get_outpoint(query.to_output(0, 0))); } BOOST_AUTO_TEST_CASE(query_address__get_minimum_unspent_outpoints__below__included) @@ -117,11 +117,11 @@ BOOST_AUTO_TEST_CASE(query_address__get_minimum_unspent_outpoints__below__includ const std::atomic_bool cancel{}; BOOST_REQUIRE(!query.get_minimum_unspent_outpoints(cancel, out, test::genesis_address0, 0)); BOOST_REQUIRE_EQUAL(out.size(), 1u); - BOOST_REQUIRE(*out.begin() == query.get_outpoint(query.to_output(0, 0))); + BOOST_REQUIRE(*out.cbegin() == query.get_outpoint(query.to_output(0, 0))); BOOST_REQUIRE(!query.get_minimum_unspent_outpoints(cancel, out, test::genesis_address0, 4999999999)); BOOST_REQUIRE_EQUAL(out.size(), 1u); - BOOST_REQUIRE(*out.begin() == query.get_outpoint(query.to_output(0, 0))); + BOOST_REQUIRE(*out.cbegin() == query.get_outpoint(query.to_output(0, 0))); } // get_address_outpoints1 @@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(query_address__get_address_outpoints1__turbo_genesis__expec const std::atomic_bool cancel{}; BOOST_REQUIRE(!query.get_address_outpoints(cancel, out, test::genesis_address0, true)); BOOST_REQUIRE_EQUAL(out.size(), 1u); - BOOST_REQUIRE(*out.begin() == query.get_outpoint(query.to_output(0, 0))); + BOOST_REQUIRE(*out.cbegin() == query.get_outpoint(query.to_output(0, 0))); } BOOST_AUTO_TEST_CASE(query_address__get_address_outpoints1__genesis__expected) @@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(query_address__get_address_outpoints1__genesis__expected) const std::atomic_bool cancel{}; BOOST_REQUIRE(!query.get_address_outpoints(cancel, out, test::genesis_address0)); BOOST_REQUIRE_EQUAL(out.size(), 1u); - BOOST_REQUIRE(*out.begin() == query.get_outpoint(query.to_output(0, 0))); + BOOST_REQUIRE(*out.cbegin() == query.get_outpoint(query.to_output(0, 0))); } BOOST_AUTO_TEST_CASE(query_address__get_address_outpoints1__cancel__query_canceled_false)