Merge bitcoin/bitcoin#26387: p2p: TryLowWorkHeadersSync follow-ups

784b023191 [net processing] Simplify use of IsContinuationOfLowWorkHeadersSync in TryLowWorkHeaderSync (dergoegge)
e891aabf5a [net processing] Fixup TryLowWorkHeadersSync comment (dergoegge)

Pull request description:

  See https://github.com/bitcoin/bitcoin/pull/26355#discussion_r1003561481 and https://github.com/bitcoin/bitcoin/pull/26355#discussion_r1004554187

ACKs for top commit:
  hernanmarino:
    ACK 784b023191
  brunoerg:
    crACK 784b023191
  mzumsande:
    ACK 784b023191

Tree-SHA512: b47ac0d78a09ca3a1806e38c5d2e2fcf1e5f0668f202450b5079c5cb168e168ac6828c0948d23f3610696375134986d75ef3c6098858173023bcb743aec8004c
This commit is contained in:
fanquake 2022-10-31 15:28:43 +00:00
commit 43e813cab2
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -638,9 +638,8 @@ private:
* @param[in] chain_start_header Where these headers connect in our index.
* @param[in,out] headers The headers to be processed.
*
* @return True if chain was low work and a headers sync was
* initiated (and headers will be empty after calling); false
* otherwise.
* @return True if chain was low work (headers will be empty after
* calling); false otherwise.
*/
bool TryLowWorkHeadersSync(Peer& peer, CNode& pfrom,
const CBlockIndex* chain_start_header,
@ -2563,14 +2562,10 @@ bool PeerManagerImpl::TryLowWorkHeadersSync(Peer& peer, CNode& pfrom, const CBlo
peer.m_headers_sync.reset(new HeadersSyncState(peer.m_id, m_chainparams.GetConsensus(),
chain_start_header, minimum_chain_work));
// Now a HeadersSyncState object for tracking this synchronization is created,
// process the headers using it as normal.
if (!IsContinuationOfLowWorkHeadersSync(peer, pfrom, headers)) {
// Something went wrong, reset the headers sync.
peer.m_headers_sync.reset(nullptr);
LOCK(m_headers_presync_mutex);
m_headers_presync_stats.erase(peer.m_id);
}
// Now a HeadersSyncState object for tracking this synchronization
// is created, process the headers using it as normal. Failures are
// handled inside of IsContinuationOfLowWorkHeadersSync.
(void)IsContinuationOfLowWorkHeadersSync(peer, pfrom, headers);
} else {
LogPrint(BCLog::NET, "Ignoring low-work chain (height=%u) from peer=%d\n", chain_start_header->nHeight + headers.size(), pfrom.GetId());
}