Skip to content

Commit 7ad15d1

Browse files
committed
[net processing] Handle IsContinuationOfLowWorkHeadersSync return value correctly when new headers sync is started
1 parent fabc031 commit 7ad15d1

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/net_processing.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,14 +2565,22 @@ bool PeerManagerImpl::TryLowWorkHeadersSync(Peer& peer, CNode& pfrom, const CBlo
25652565

25662566
// Now a HeadersSyncState object for tracking this synchronization is created,
25672567
// process the headers using it as normal.
2568-
return IsContinuationOfLowWorkHeadersSync(peer, pfrom, headers);
2568+
if (!IsContinuationOfLowWorkHeadersSync(peer, pfrom, headers)) {
2569+
// Something went wrong, reset the headers sync.
2570+
peer.m_headers_sync.reset(nullptr);
2571+
LOCK(m_headers_presync_mutex);
2572+
m_headers_presync_stats.erase(peer.m_id);
2573+
}
25692574
} else {
25702575
LogPrint(BCLog::NET, "Ignoring low-work chain (height=%u) from peer=%d\n", chain_start_header->nHeight + headers.size(), pfrom.GetId());
2571-
// Since this is a low-work headers chain, no further processing is required.
2572-
headers = {};
2573-
return true;
25742576
}
2577+
2578+
// The peer has not yet given us a chain that meets our work threshold,
2579+
// so we want to prevent further processing of the headers in any case.
2580+
headers = {};
2581+
return true;
25752582
}
2583+
25762584
return false;
25772585
}
25782586

0 commit comments

Comments
 (0)