Simplify TryLowWorkHeadersSync invocation

Make use of the fact that now TryLowWorkHeadersSync is (like
IsContinuationOfLowWorkHeadersSync) an operation that partially processes headers, so
it can be invoked in a similar way, only bailing out when there is nothing left to do.
This commit is contained in:
Pieter Wuille
2022-08-23 17:57:42 -04:00
parent ab52fb4e95
commit 7f1cf440ca

View File

@@ -2807,14 +2807,14 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
// At this point, the headers connect to something in our block index.
// 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)) {
// If we successfully started a low-work headers sync, then there
// should be no headers to process any further.
Assume(headers.empty());
return;
if (!already_validated_work) {
already_validated_work = TryLowWorkHeadersSync(peer, pfrom, chain_start_header, headers);
have_headers_sync = already_validated_work;
}
// If there is nothing left to process, stop.
if (headers.empty()) return;
// At this point, we have a set of headers with sufficient work on them
// which can be processed.