From e24fb0d7a7acfcd7030ee39e83c51d0f0c3a1291 Mon Sep 17 00:00:00 2001 From: Eric Voskuil Date: Sat, 19 Sep 2026 18:37:56 -0400 Subject: [PATCH] Use const iterator accessors for read-only traversal. Co-Authored-By: Claude Sonnet 5 --- include/bitcoin/node/impl/chasers/chaser_organize.ipp | 6 +++--- src/chasers/chaser_check.cpp | 4 ++-- src/protocols/protocol_block_in_31800.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/bitcoin/node/impl/chasers/chaser_organize.ipp b/include/bitcoin/node/impl/chasers/chaser_organize.ipp index 6175b99e..31df6e5d 100644 --- a/include/bitcoin/node/impl/chasers/chaser_organize.ipp +++ b/include/bitcoin/node/impl/chasers/chaser_organize.ipp @@ -142,7 +142,7 @@ void CLASS::do_organize(typename Block::cptr block, bool prioritized, } const auto it = tree_.find(hash); - if (it != tree_.end()) + if (it != tree_.cend()) { handler(error_duplicate(), it->second->get_state()->height()); return; @@ -354,7 +354,7 @@ void CLASS::do_prioritize(const system::hash_digest& hash, return; // Only the top of a cached branch can tie the candidate top. - if (std::any_of(tree_.begin(), tree_.end(), [&](const auto& item) NOEXCEPT + if (std::any_of(tree_.cbegin(), tree_.cend(), [&](const auto& item) NOEXCEPT { return get_header(*item.second).previous_block_hash() == hash; })) @@ -661,7 +661,7 @@ void CLASS::shrink_tree(bool current) NOEXCEPT return; shrunk_ = true; - tree_ = { tree_.begin(), tree_.end() }; + tree_ = { tree_.cbegin(), tree_.cend() }; LOGV("Tree buckets reduced to (" << tree_.bucket_count() << ")."); } diff --git a/src/chasers/chaser_check.cpp b/src/chasers/chaser_check.cpp index eedd6e1d..bb27cc7c 100644 --- a/src/chasers/chaser_check.cpp +++ b/src/chasers/chaser_check.cpp @@ -221,7 +221,7 @@ void chaser_check::do_starved(object_t self) NOEXCEPT BC_ASSERT(stranded()); // Remove the starved channel to prevent self-selection. - if (speeds_.find(self) != speeds_.end()) + if (speeds_.find(self) != speeds_.cend()) speeds_.erase(self); // Find the slowest reporting channel. @@ -232,7 +232,7 @@ void chaser_check::do_starved(object_t self) NOEXCEPT }); // Direct the slowest channel to split work and stop. - if (slowest != speeds_.end()) + if (slowest != speeds_.cend()) { // Erase entry so less likely to be claimed again before stopping. const auto slow = slowest->first; diff --git a/src/protocols/protocol_block_in_31800.cpp b/src/protocols/protocol_block_in_31800.cpp index 35e6cda4..803efa29 100644 --- a/src/protocols/protocol_block_in_31800.cpp +++ b/src/protocols/protocol_block_in_31800.cpp @@ -276,7 +276,7 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec, const auto& block = message->block; const auto hash = block.hash(); const auto it = map_->find(hash); - if (it == map_->end()) + if (it == map_->cend()) { // Allow unrequested block, not counted toward performance. LOGR("Unrequested block [" << encode_hash(hash) << "] from ["