Skip to content

Commit 20515ea

Browse files
committed
validation: Use span for CalculateClaimedHeadersWork
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 52575e9 commit 20515ea

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4751,7 +4751,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
47514751
MaybeSendGetHeaders(pfrom, GetLocator(m_chainman.m_best_header), *peer);
47524752
}
47534753
return;
4754-
} else if (prev_block->nChainWork + CalculateClaimedHeadersWork({cmpctblock.header}) < GetAntiDoSWorkThreshold()) {
4754+
} else if (prev_block->nChainWork + CalculateClaimedHeadersWork({{cmpctblock.header}}) < GetAntiDoSWorkThreshold()) {
47554755
// If we get a low-work header in a compact block, we can ignore it.
47564756
LogPrint(BCLog::NET, "Ignoring low-work compact block from peer %d\n", pfrom.GetId());
47574757
return;
@@ -5068,7 +5068,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
50685068
mapBlockSource.emplace(hash, std::make_pair(pfrom.GetId(), true));
50695069

50705070
// Check claimed work on this block against our anti-dos thresholds.
5071-
if (prev_block && prev_block->nChainWork + CalculateClaimedHeadersWork({pblock->GetBlockHeader()}) >= GetAntiDoSWorkThreshold()) {
5071+
if (prev_block && prev_block->nChainWork + CalculateClaimedHeadersWork({{pblock->GetBlockHeader()}}) >= GetAntiDoSWorkThreshold()) {
50725072
min_pow_checked = true;
50735073
}
50745074
}

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4137,7 +4137,7 @@ bool IsBlockMutated(const CBlock& block, bool check_witness_root)
41374137
return false;
41384138
}
41394139

4140-
arith_uint256 CalculateClaimedHeadersWork(const std::vector<CBlockHeader>& headers)
4140+
arith_uint256 CalculateClaimedHeadersWork(std::span<const CBlockHeader> headers)
41414141
{
41424142
arith_uint256 total_work{0};
41434143
for (const CBlockHeader& header : headers) {

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ bool HasValidProofOfWork(const std::vector<CBlockHeader>& headers, const Consens
408408
bool IsBlockMutated(const CBlock& block, bool check_witness_root);
409409

410410
/** Return the sum of the claimed work on a given set of headers. No verification of PoW is done. */
411-
arith_uint256 CalculateClaimedHeadersWork(const std::vector<CBlockHeader>& headers);
411+
arith_uint256 CalculateClaimedHeadersWork(std::span<const CBlockHeader> headers);
412412

413413
enum class VerifyDBResult {
414414
SUCCESS,

0 commit comments

Comments
 (0)