Skip to content

Commit 52575e9

Browse files
committed
validation: Use span for ProcessNewBlockHeaders
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.
1 parent 338bc2c commit 52575e9

File tree

7 files changed

+11
-9
lines changed

7 files changed

+11
-9
lines changed

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4764,7 +4764,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
47644764

47654765
const CBlockIndex *pindex = nullptr;
47664766
BlockValidationState state;
4767-
if (!m_chainman.ProcessNewBlockHeaders({cmpctblock.header}, /*min_pow_checked=*/true, state, &pindex)) {
4767+
if (!m_chainman.ProcessNewBlockHeaders({{cmpctblock.header}}, /*min_pow_checked=*/true, state, &pindex)) {
47684768
if (state.IsInvalid()) {
47694769
MaybePunishNodeForBlock(pfrom.GetId(), state, /*via_compact_block=*/true, "invalid header via cmpctblock");
47704770
return;

src/rpc/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ static RPCHelpMan submitheader()
10951095
}
10961096

10971097
BlockValidationState state;
1098-
chainman.ProcessNewBlockHeaders({h}, /*min_pow_checked=*/true, state);
1098+
chainman.ProcessNewBlockHeaders({{h}}, /*min_pow_checked=*/true, state);
10991099
if (state.IsValid()) return UniValue::VNULL;
11001100
if (state.IsError()) {
11011101
throw JSONRPCError(RPC_VERIFY_ERROR, state.ToString());

src/test/blockfilter_index_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ bool BuildChainTestingSetup::BuildChain(const CBlockIndex* pindex,
103103
CBlockHeader header = block->GetBlockHeader();
104104

105105
BlockValidationState state;
106-
if (!Assert(m_node.chainman)->ProcessNewBlockHeaders({header}, true, state, &pindex)) {
106+
if (!Assert(m_node.chainman)->ProcessNewBlockHeaders({{header}}, true, state, &pindex)) {
107107
return false;
108108
}
109109
}

src/test/fuzz/utxo_snapshot.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void initialize_chain()
5858
auto& chainman{*setup->m_node.chainman};
5959
for (const auto& block : chain) {
6060
BlockValidationState dummy;
61-
bool processed{chainman.ProcessNewBlockHeaders({*block}, true, dummy)};
61+
bool processed{chainman.ProcessNewBlockHeaders({{block->GetBlockHeader()}}, true, dummy)};
6262
Assert(processed);
6363
const auto* index{WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(block->GetHash()))};
6464
Assert(index);
@@ -137,7 +137,7 @@ void utxo_snapshot_fuzz(FuzzBufferType buffer)
137137
if constexpr (!INVALID) {
138138
for (const auto& block : *g_chain) {
139139
BlockValidationState dummy;
140-
bool processed{chainman.ProcessNewBlockHeaders({*block}, true, dummy)};
140+
bool processed{chainman.ProcessNewBlockHeaders({{block->GetBlockHeader()}}, true, dummy)};
141141
Assert(processed);
142142
const auto* index{WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(block->GetHash()))};
143143
Assert(index);

src/test/validation_block_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ std::shared_ptr<CBlock> MinerTestingSetup::FinalizeBlock(std::shared_ptr<CBlock>
101101
// submit block header, so that miner can get the block height from the
102102
// global state and the node has the topology of the chain
103103
BlockValidationState ignored;
104-
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlockHeaders({pblock->GetBlockHeader()}, true, ignored));
104+
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlockHeaders({{pblock->GetBlockHeader()}}, true, ignored));
105105

106106
return pblock;
107107
}

src/validation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include <numeric>
7171
#include <optional>
7272
#include <ranges>
73+
#include <span>
7374
#include <string>
7475
#include <tuple>
7576
#include <utility>
@@ -4384,7 +4385,7 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
43844385
}
43854386

43864387
// Exposed wrapper for AcceptBlockHeader
4387-
bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>& headers, bool min_pow_checked, BlockValidationState& state, const CBlockIndex** ppindex)
4388+
bool ChainstateManager::ProcessNewBlockHeaders(std::span<const CBlockHeader> headers, bool min_pow_checked, BlockValidationState& state, const CBlockIndex** ppindex)
43884389
{
43894390
AssertLockNotHeld(cs_main);
43904391
{

src/validation.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <memory>
4040
#include <optional>
4141
#include <set>
42+
#include <span>
4243
#include <stdint.h>
4344
#include <string>
4445
#include <thread>
@@ -1217,12 +1218,12 @@ class ChainstateManager
12171218
* May not be called in a
12181219
* validationinterface callback.
12191220
*
1220-
* @param[in] block The block headers themselves
1221+
* @param[in] headers The block headers themselves
12211222
* @param[in] min_pow_checked True if proof-of-work anti-DoS checks have been done by caller for headers chain
12221223
* @param[out] state This may be set to an Error state if any error occurred processing them
12231224
* @param[out] ppindex If set, the pointer will be set to point to the last new block index object for the given headers
12241225
*/
1225-
bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, bool min_pow_checked, BlockValidationState& state, const CBlockIndex** ppindex = nullptr) LOCKS_EXCLUDED(cs_main);
1226+
bool ProcessNewBlockHeaders(std::span<const CBlockHeader> headers, bool min_pow_checked, BlockValidationState& state, const CBlockIndex** ppindex = nullptr) LOCKS_EXCLUDED(cs_main);
12261227

12271228
/**
12281229
* Sufficiently validate a block for disk storage (and store on disk).

0 commit comments

Comments
 (0)