refactor: Remove redundant parameter from CheckHeadersPoW
What changed, and why it matters
This is a minor code cleanup (refactor) in Bitcoin Core. It removes an unneeded input parameter from an internal function and makes that function fetch the same information from an existing member variable instead. The behavior of the program is unchanged.
No security action needed. This is a routine refactor with no security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors PeerManagerImpl::CheckHeadersPoW() in src/net_processing.cpp. Previously the caller passed m_chainparams.GetConsensus() as a Consensus::Params& argument; now the function retrieves m_chainparams.GetConsensus() internally. All call sites and the declaration are updated accordingly. There is no functional change: the same consensus parameters are used for the HasValidProofOfWork() check.
Changed components
src/net_processing.cppPeerManagerImpl::CheckHeadersPoW()Inspect captured patch +4 / −4
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 3a712f2f..7ab70cd6 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -644,7 +644,7 @@ private:
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_headers_presync_mutex, g_msgproc_mutex);
/** Various helpers for headers processing, invoked by ProcessHeadersMessage() */
/** Return true if headers are continuous and have valid proof-of-work (DoS points assigned on failure) */
- bool CheckHeadersPoW(const std::vector<CBlockHeader>& headers, const Consensus::Params& consensusParams, Peer& peer);
+ bool CheckHeadersPoW(const std::vector<CBlockHeader>& headers, Peer& peer);
/** Calculate an anti-DoS work threshold for headers chains */
arith_uint256 GetAntiDoSWorkThreshold();
/** Deal with state tracking and headers sync for peers that send
@@ -2485,10 +2485,10 @@ void PeerManagerImpl::SendBlockTransactions(CNode& pfrom, Peer& peer, const CBlo
MakeAndPushMessage(pfrom, NetMsgType::BLOCKTXN, resp);
}
-bool PeerManagerImpl::CheckHeadersPoW(const std::vector<CBlockHeader>& headers, const Consensus::Params& consensusParams, Peer& peer)
+bool PeerManagerImpl::CheckHeadersPoW(const std::vector<CBlockHeader>& headers, Peer& peer)
{
// Do these headers have proof-of-work matching what's claimed?
- if (!HasValidProofOfWork(headers, consensusParams)) {
+ if (!HasValidProofOfWork(headers, m_chainparams.GetConsensus())) {
Misbehaving(peer, "header with invalid proof of work");
return false;
}
@@ -2853,7 +2853,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
// We'll rely on headers having valid proof-of-work further down, as an
// anti-DoS criteria (note: this check is required before passing any
// headers into HeadersSyncState).
- if (!CheckHeadersPoW(headers, m_chainparams.GetConsensus(), peer)) {
+ if (!CheckHeadersPoW(headers, peer)) {
// Misbehaving() calls are handled within CheckHeadersPoW(), so we can
// just return. (Note that even if a header is announced via compact
// block, the header itself should be valid, so this type of error can
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.