Skip to content

Commit

Permalink
Merge bitcoin#29569: Rename CalculateHeadersWork to CalculateClaimedH…
Browse files Browse the repository at this point in the history
…eadersWork

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
  • Loading branch information
achow101 committed Mar 9, 2024
2 parents a78ca70 + eb7cc9f commit 4cc99df
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2690,8 +2690,8 @@ bool PeerManagerImpl::IsContinuationOfLowWorkHeadersSync(Peer& peer, CNode& pfro

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

// Our dynamic anti-DoS threshold (minimum work required on a headers chain
// before we'll store it)
Expand Down Expand Up @@ -4424,7 +4424,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
MaybeSendGetHeaders(pfrom, GetLocator(m_chainman.m_best_header), *peer);
}
return;
} else if (prev_block->nChainWork + CalculateHeadersWork({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.
LogPrint(BCLog::NET, "Ignoring low-work compact block from peer %d\n", pfrom.GetId());
return;
Expand Down Expand Up @@ -4744,8 +4744,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
// cs_main in ProcessNewBlock is fine.
mapBlockSource.emplace(hash, std::make_pair(pfrom.GetId(), true));

// Check work on this block against our anti-dos thresholds.
if (prev_block && prev_block->nChainWork + CalculateHeadersWork({pblock->GetBlockHeader()}) >= GetAntiDoSWorkThreshold()) {
// Check claimed work on this block against our anti-dos thresholds.
if (prev_block && prev_block->nChainWork + CalculateClaimedHeadersWork({pblock->GetBlockHeader()}) >= GetAntiDoSWorkThreshold()) {
min_pow_checked = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/headerssync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ FUZZ_TARGET(headers_sync_state, .init = initialize_headers_sync_state_fuzz)

// If we get to redownloading, the presynced headers need
// to have the min amount of work on them.
assert(CalculateHeadersWork(all_headers) >= min_work);
assert(CalculateClaimedHeadersWork(all_headers) >= min_work);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3895,7 +3895,7 @@ bool IsBlockMutated(const CBlock& block, bool check_witness_root)
return false;
}

arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader>& headers)
arith_uint256 CalculateClaimedHeadersWork(const std::vector<CBlockHeader>& headers)
{
arith_uint256 total_work{0};
for (const CBlockHeader& header : headers) {
Expand Down
4 changes: 2 additions & 2 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ bool HasValidProofOfWork(const std::vector<CBlockHeader>& headers, const Consens
/** Check if a block has been mutated (with respect to its merkle root and witness commitments). */
bool IsBlockMutated(const CBlock& block, bool check_witness_root);

/** Return the sum of the work on a given set of headers */
arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader>& headers);
/** 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);

enum class VerifyDBResult {
SUCCESS,
Expand Down

0 comments on commit 4cc99df

Please sign in to comment.