mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-11 01:33:21 +01:00
refactor: Use reference for chain_start in HeadersSyncState
chain_start can never be null, so it's better to pass it as a reference rather than a raw pointer Also slightly reformat HeaderSyncState constructor to make clang-format happy Lastly, remove `const` from `chain_start` declaration in headers_sync_chainwork_tests, to work aroud a false-positive dangling-reference warning in gcc 13.0 Co-Authored-By: maflcko <6399679+maflcko@users.noreply.github.com>
This commit is contained in:
@@ -686,8 +686,8 @@ private:
|
||||
* calling); false otherwise.
|
||||
*/
|
||||
bool TryLowWorkHeadersSync(Peer& peer, CNode& pfrom,
|
||||
const CBlockIndex* chain_start_header,
|
||||
std::vector<CBlockHeader>& headers)
|
||||
const CBlockIndex& chain_start_header,
|
||||
std::vector<CBlockHeader>& headers)
|
||||
EXCLUSIVE_LOCKS_REQUIRED(!peer.m_headers_sync_mutex, !m_peer_mutex, !m_headers_presync_mutex, g_msgproc_mutex);
|
||||
|
||||
/** Return true if the given header is an ancestor of
|
||||
@@ -2633,10 +2633,10 @@ bool PeerManagerImpl::IsContinuationOfLowWorkHeadersSync(Peer& peer, CNode& pfro
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PeerManagerImpl::TryLowWorkHeadersSync(Peer& peer, CNode& pfrom, const CBlockIndex* chain_start_header, std::vector<CBlockHeader>& headers)
|
||||
bool PeerManagerImpl::TryLowWorkHeadersSync(Peer& peer, CNode& pfrom, const CBlockIndex& chain_start_header, std::vector<CBlockHeader>& headers)
|
||||
{
|
||||
// Calculate the claimed total work on this chain.
|
||||
arith_uint256 total_work = chain_start_header->nChainWork + CalculateClaimedHeadersWork(headers);
|
||||
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)
|
||||
@@ -2667,7 +2667,7 @@ bool PeerManagerImpl::TryLowWorkHeadersSync(Peer& peer, CNode& pfrom, const CBlo
|
||||
// handled inside of IsContinuationOfLowWorkHeadersSync.
|
||||
(void)IsContinuationOfLowWorkHeadersSync(peer, pfrom, headers);
|
||||
} else {
|
||||
LogDebug(BCLog::NET, "Ignoring low-work chain (height=%u) from peer=%d\n", chain_start_header->nHeight + headers.size(), pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "Ignoring low-work chain (height=%u) from peer=%d\n", chain_start_header.nHeight + headers.size(), pfrom.GetId());
|
||||
}
|
||||
|
||||
// The peer has not yet given us a chain that meets our work threshold,
|
||||
@@ -2933,7 +2933,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
|
||||
// Do anti-DoS checks to determine if we should process or store for later
|
||||
// processing.
|
||||
if (!already_validated_work && TryLowWorkHeadersSync(peer, pfrom,
|
||||
chain_start_header, headers)) {
|
||||
*chain_start_header, headers)) {
|
||||
// If we successfully started a low-work headers sync, then there
|
||||
// should be no headers to process any further.
|
||||
Assume(headers.empty());
|
||||
|
||||
Reference in New Issue
Block a user