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.
This commit is contained in:
TheCharlatan committed 2024-08-30 10:17:26 +02:00
1 parent 52575e96e7
commit 20515ea3f5
3 files changed
+4 -4

No files matched your search

+2 -2
View File
@@ -4751,7 +4751,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
MaybeSendGetHeaders(pfrom, GetLocator(m_chainman.m_best_header), *peer); MaybeSendGetHeaders(pfrom, GetLocator(m_chainman.m_best_header), *peer);
} }
return; return;
} else if (prev_block->nChainWork + CalculateClaimedHeadersWork({cmpctblock.header}) < GetAntiDoSWorkThreshold()) { } else if (prev_block->nChainWork + CalculateClaimedHeadersWork({{cmpctblock.header}}) < GetAntiDoSWorkThreshold()) {
// If we get a low-work header in a compact block, we can ignore it. // If we get a low-work header in a compact block, we can ignore it.
LogPrint(BCLog::NET, "Ignoring low-work compact block from peer %d\n", pfrom.GetId()); LogPrint(BCLog::NET, "Ignoring low-work compact block from peer %d\n", pfrom.GetId());
return; return;
@@ -5068,7 +5068,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
mapBlockSource.emplace(hash, std::make_pair(pfrom.GetId(), true)); mapBlockSource.emplace(hash, std::make_pair(pfrom.GetId(), true));
// Check claimed work on this block against our anti-dos thresholds. // Check claimed work on this block against our anti-dos thresholds.
if (prev_block && prev_block->nChainWork + CalculateClaimedHeadersWork({pblock->GetBlockHeader()}) >= GetAntiDoSWorkThreshold()) { if (prev_block && prev_block->nChainWork + CalculateClaimedHeadersWork({{pblock->GetBlockHeader()}}) >= GetAntiDoSWorkThreshold()) {
min_pow_checked = true; min_pow_checked = true;
} }
} }
+1 -1
View File
@@ -4137,7 +4137,7 @@ bool IsBlockMutated(const CBlock& block, bool check_witness_root)
return false; return false;
} }
arith_uint256 CalculateClaimedHeadersWork(const std::vector<CBlockHeader>& headers) arith_uint256 CalculateClaimedHeadersWork(std::span<const CBlockHeader> headers)
{ {
arith_uint256 total_work{0}; arith_uint256 total_work{0};
for (const CBlockHeader& header : headers) { for (const CBlockHeader& header : headers) {
+1 -1
View File
@@ -408,7 +408,7 @@ bool HasValidProofOfWork(const std::vector<CBlockHeader>& headers, const Consens
bool IsBlockMutated(const CBlock& block, bool check_witness_root); bool IsBlockMutated(const CBlock& block, bool check_witness_root);
/** Return the sum of the claimed work on a given set of headers. No verification of PoW is done. */ /** Return the sum of the claimed work on a given set of headers. No verification of PoW is done. */
arith_uint256 CalculateClaimedHeadersWork(const std::vector<CBlockHeader>& headers); arith_uint256 CalculateClaimedHeadersWork(std::span<const CBlockHeader> headers);
enum class VerifyDBResult { enum class VerifyDBResult {
SUCCESS, SUCCESS,