You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// If a peer gives us as many headers as possible, this is implicitly a signal that the
2091
+
// peer has more headers to send us. In Bitcoin Core, the node always asks for more
2092
+
// headers at this point. Our logic is slightly more complex, because:
2093
+
// (1) There is an apparent bug in the Bitcoin Core state machine here, where we can
2094
+
// end up downloading headers from lots of peers at the same time by accident, which we
2095
+
// work around rather than truly fix;
2096
+
// (2) For various reasons we may want to avoid letting the header downloads get "too
2097
+
// far ahead" of block downloads, so we may pause syncing for that reasons.
2098
+
if (nCount == MAX_HEADERS_RESULTS) {
2099
+
if (all_duplicate && !nodestate->fSyncStarted) {
2100
+
// In this case two things are true:
2101
+
// 1) This node's most recent batch of headers only included ones we already had.
2102
+
// 2) We don't have this node marked as a peer to header-sync from.
2103
+
// This happens when some exogenous event, like an INV of a new block, causes us
2104
+
// to ask a peer for an unbounded number of headers, when we're already in the
2105
+
// process of downloading the headers from a different peer.
2106
+
// In this case the right thing to do is simply stop syncing headers from this
2107
+
// peer; it's redundant. Here we do nothing; since we don't ask the peer for
2108
+
// more headers, it will stop sending them.
2109
+
} elseif (got_enough_headers) {
2110
+
// If we're trying to save memory on headers, and we've already got plenty of headers,
2111
+
// pause until we're ready for more.
2112
+
LogPrint(BCLog::NET, "Pausing header sync from peer=%d, because the last one was too far ahead of block sync (%d >> %d)\n", pfrom.GetId(), pindexLast->nHeight, m_chainman.ActiveHeight());
2113
+
if (nodestate->fSyncStarted) {
2114
+
// Cancel sync from this node, so we don't penalize it later.
2115
+
// This will cause us to automatically start syncing from a different node (or restart syncing from the same node) later,
2116
+
// if we still need to sync headers.
2117
+
nSyncStarted--;
2118
+
nodestate->fSyncStarted = false;
2119
+
nodestate->m_headers_sync_timeout = 0us;
2120
+
}
2121
+
} else {
2122
+
// TODO: optimize: if pindexLast is an ancestor of m_chainman.ActiveChain().Tip or pindexBestHeader, continue
2123
+
// from there instead.
2124
+
LogPrint(BCLog::NET, "more getheaders (%d) to end to peer=%d (startheight:%d)\n",
boolfFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->IsAddrFetchConn()); // Download if this is a nice peer, or we have no nice peers and this one might do.
4479
-
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) {
0 commit comments