From 45686522224598bed9923e60daad109094d7bc29 Mon Sep 17 00:00:00 2001 From: Daniela Brozzoni Date: Fri, 8 Aug 2025 12:01:45 +0200 Subject: [PATCH] refactor: Use std::span in HasValidProofOfWork Co-Authored-By: Pieter Wuille --- src/validation.cpp | 6 +++--- src/validation.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index ecc517451bc..99f516ccf96 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4130,10 +4130,10 @@ std::vector ChainstateManager::GenerateCoinbaseCommitment(CBlock& return commitment; } -bool HasValidProofOfWork(const std::vector& headers, const Consensus::Params& consensusParams) +bool HasValidProofOfWork(std::span headers, const Consensus::Params& consensusParams) { - return std::all_of(headers.cbegin(), headers.cend(), - [&](const auto& header) { return CheckProofOfWork(header.GetHash(), header.nBits, consensusParams);}); + return std::ranges::all_of(headers, + [&](const auto& header) { return CheckProofOfWork(header.GetHash(), header.nBits, consensusParams); }); } bool IsBlockMutated(const CBlock& block, bool check_witness_root) diff --git a/src/validation.h b/src/validation.h index 291c1021dc9..daf954c820e 100644 --- a/src/validation.h +++ b/src/validation.h @@ -410,8 +410,8 @@ BlockValidationState TestBlockValidity( bool check_pow, bool check_merkle_root) EXCLUSIVE_LOCKS_REQUIRED(cs_main); -/** Check with the proof of work on each blockheader matches the value in nBits */ -bool HasValidProofOfWork(const std::vector& headers, const Consensus::Params& consensusParams); +/** Check that the proof of work on each blockheader matches the value in nBits */ +bool HasValidProofOfWork(std::span headers, const Consensus::Params& consensusParams); /** Check if a block has been mutated (with respect to its merkle root and witness commitments). */ bool IsBlockMutated(const CBlock& block, bool check_witness_root);