Merge bitcoin/bitcoin#30742: kernel: Use spans instead of vectors for passing block headers to validation functions

a2955f0979 validation: Use span for ImportBlocks paths (TheCharlatan)
20515ea3f5 validation: Use span for CalculateClaimedHeadersWork (TheCharlatan)
52575e96e7 validation: Use span for ProcessNewBlockHeaders (TheCharlatan)

Pull request description:

  Makes it friendlier for potential future users of the kernel library if they do not store the headers in a std::vector, but can guarantee contiguous memory.

  Take this opportunity to also change the argument of ImportBlocks previously taking a `std::vector` to a `std::span`.

ACKs for top commit:
  stickies-v:
    re-ACK a2955f0979 - no changes except further walking the ~file~ path of modernizing variable names.
  maflcko:
    ACK a2955f0979 🕑
  achow101:
    ACK a2955f0979
  danielabrozzoni:
    ACK a2955f0979

Tree-SHA512: 8b07f4ad26e270b65600d1968cd78847b85caca5bfbb83fd9860389f26656b1d9a40b85e0990339f50403d18cedcd2456990054f3b8b0bedce943e50222d2709
This commit is contained in:
Ava Chow
2024-09-03 15:40:40 -04:00
9 changed files with 19 additions and 16 deletions

View File

@@ -70,6 +70,7 @@
#include <numeric>
#include <optional>
#include <ranges>
#include <span>
#include <string>
#include <tuple>
#include <utility>
@@ -4136,7 +4137,7 @@ bool IsBlockMutated(const CBlock& block, bool check_witness_root)
return false;
}
arith_uint256 CalculateClaimedHeadersWork(const std::vector<CBlockHeader>& headers)
arith_uint256 CalculateClaimedHeadersWork(std::span<const CBlockHeader> headers)
{
arith_uint256 total_work{0};
for (const CBlockHeader& header : headers) {
@@ -4384,7 +4385,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
}
// Exposed wrapper for AcceptBlockHeader
bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>& headers, bool min_pow_checked, BlockValidationState& state, const CBlockIndex** ppindex)
bool ChainstateManager::ProcessNewBlockHeaders(std::span<const CBlockHeader> headers, bool min_pow_checked, BlockValidationState& state, const CBlockIndex** ppindex)
{
AssertLockNotHeld(cs_main);
{