Skip to content

Commit 4cc99df

Browse files
committed
Merge bitcoin#29569: Rename CalculateHeadersWork to CalculateClaimedHeadersWork
eb7cc9f Rename CalculateHeadersWork to CalculateClaimedHeadersWork (Greg Sanders) Pull request description: And clean up some comments. Confusion about what this is doing seems to be a running theme: bitcoin#29549 (comment) bitcoin#27278 (comment) ACKs for top commit: achow101: ACK eb7cc9f pablomartin4btc: ACK eb7cc9f 0xB10C: ACK eb7cc9f dergoegge: ACK eb7cc9f BrandonOdiwuor: ACK eb7cc9f Tree-SHA512: 6ccbc5e417155516487bb220753d189b5341dec05366db88a3fa5b1932eace21fbfaf23408c639bb54b36169a8d0a7536a1ee5e63b4ce5a3b70f2ff8407b6e07
2 parents a78ca70 + eb7cc9f commit 4cc99df

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/net_processing.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2690,8 +2690,8 @@ bool PeerManagerImpl::IsContinuationOfLowWorkHeadersSync(Peer& peer, CNode& pfro
26902690

26912691
bool PeerManagerImpl::TryLowWorkHeadersSync(Peer& peer, CNode& pfrom, const CBlockIndex* chain_start_header, std::vector<CBlockHeader>& headers)
26922692
{
2693-
// Calculate the total work on this chain.
2694-
arith_uint256 total_work = chain_start_header->nChainWork + CalculateHeadersWork(headers);
2693+
// Calculate the claimed total work on this chain.
2694+
arith_uint256 total_work = chain_start_header->nChainWork + CalculateClaimedHeadersWork(headers);
26952695

26962696
// Our dynamic anti-DoS threshold (minimum work required on a headers chain
26972697
// before we'll store it)
@@ -4424,7 +4424,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
44244424
MaybeSendGetHeaders(pfrom, GetLocator(m_chainman.m_best_header), *peer);
44254425
}
44264426
return;
4427-
} else if (prev_block->nChainWork + CalculateHeadersWork({cmpctblock.header}) < GetAntiDoSWorkThreshold()) {
4427+
} else if (prev_block->nChainWork + CalculateClaimedHeadersWork({cmpctblock.header}) < GetAntiDoSWorkThreshold()) {
44284428
// If we get a low-work header in a compact block, we can ignore it.
44294429
LogPrint(BCLog::NET, "Ignoring low-work compact block from peer %d\n", pfrom.GetId());
44304430
return;
@@ -4744,8 +4744,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
47444744
// cs_main in ProcessNewBlock is fine.
47454745
mapBlockSource.emplace(hash, std::make_pair(pfrom.GetId(), true));
47464746

4747-
// Check work on this block against our anti-dos thresholds.
4748-
if (prev_block && prev_block->nChainWork + CalculateHeadersWork({pblock->GetBlockHeader()}) >= GetAntiDoSWorkThreshold()) {
4747+
// Check claimed work on this block against our anti-dos thresholds.
4748+
if (prev_block && prev_block->nChainWork + CalculateClaimedHeadersWork({pblock->GetBlockHeader()}) >= GetAntiDoSWorkThreshold()) {
47494749
min_pow_checked = true;
47504750
}
47514751
}

src/test/fuzz/headerssync.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ FUZZ_TARGET(headers_sync_state, .init = initialize_headers_sync_state_fuzz)
108108

109109
// If we get to redownloading, the presynced headers need
110110
// to have the min amount of work on them.
111-
assert(CalculateHeadersWork(all_headers) >= min_work);
111+
assert(CalculateClaimedHeadersWork(all_headers) >= min_work);
112112
}
113113
}
114114

src/validation.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3895,7 +3895,7 @@ bool IsBlockMutated(const CBlock& block, bool check_witness_root)
38953895
return false;
38963896
}
38973897

3898-
arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader>& headers)
3898+
arith_uint256 CalculateClaimedHeadersWork(const std::vector<CBlockHeader>& headers)
38993899
{
39003900
arith_uint256 total_work{0};
39013901
for (const CBlockHeader& header : headers) {

src/validation.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ bool HasValidProofOfWork(const std::vector<CBlockHeader>& headers, const Consens
382382
/** Check if a block has been mutated (with respect to its merkle root and witness commitments). */
383383
bool IsBlockMutated(const CBlock& block, bool check_witness_root);
384384

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

388388
enum class VerifyDBResult {
389389
SUCCESS,

0 commit comments

Comments
 (0)