diff --git a/src/headerssync.cpp b/src/headerssync.cpp index cdd50ca0f80..8811c1fa073 100644 --- a/src/headerssync.cpp +++ b/src/headerssync.cpp @@ -70,9 +70,6 @@ HeadersSyncState::ProcessingResult HeadersSyncState::ProcessNextHeaders( { ProcessingResult ret; - Assume(!headers.empty()); - if (headers.empty()) return ret; - Assume(m_download_state != State::FINAL); if (m_download_state == State::FINAL) return ret; @@ -139,13 +136,11 @@ HeadersSyncState::ProcessingResult HeadersSyncState::ProcessNextHeaders( bool HeadersSyncState::ValidateAndStoreHeadersCommitments(const std::vector& headers) { - // The caller should not give us an empty set of headers. - Assume(headers.size() > 0); - if (headers.size() == 0) return true; - Assume(m_download_state == State::PRESYNC); if (m_download_state != State::PRESYNC) return false; + if (headers.size() == 0) return true; + if (headers[0].hashPrevBlock != m_last_header_received.GetHash()) { // Somehow our peer gave us a header that doesn't connect. // This might be benign -- perhaps our peer reorged away from the chain diff --git a/src/net_processing.cpp b/src/net_processing.cpp index d2336c05d02..137ada81f32 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2726,20 +2726,6 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer, { size_t nCount = headers.size(); - if (nCount == 0) { - // Nothing interesting. Stop asking this peers for more headers. - // If we were in the middle of headers sync, receiving an empty headers - // message suggests that the peer suddenly has nothing to give us - // (perhaps it reorged to our chain). Clear download state for this peer. - LOCK(peer.m_headers_sync_mutex); - if (peer.m_headers_sync) { - peer.m_headers_sync.reset(nullptr); - LOCK(m_headers_presync_mutex); - m_headers_presync_stats.erase(pfrom.GetId()); - } - return; - } - // Before we do any processing, make sure these pass basic sanity checks. // 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 @@ -2776,15 +2762,12 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer, // are still in PRESYNC) // - replaced with headers that are now ready for validation, such as // during the REDOWNLOAD phase of a low-work headers sync. - // So just check whether we still have headers that we need to process, - // or not. - if (headers.empty()) { - return; - } - have_headers_sync = !!peer.m_headers_sync; } + // If there is nothing left to process, stop. + if (headers.empty()) return; + // Do these headers connect to something in our block index? const CBlockIndex *chain_start_header{WITH_LOCK(::cs_main, return m_chainman.m_blockman.LookupBlockIndex(headers[0].hashPrevBlock))}; bool headers_connect_blockindex{chain_start_header != nullptr};