From 08f86a4db8dc3c76782a8a852204a789ace6c4cb Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Fri, 2 Dec 2022 23:02:10 +0000 Subject: [PATCH] Revert "Headers-first fix" --- src/main.cpp | 38 +------------------------------------- src/main.h | 4 ---- 2 files changed, 1 insertion(+), 41 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 79dd69ec8..a4b8ffe81 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -332,8 +332,6 @@ struct CNodeState { CBlockIndex *pindexLastCommonBlock; //! Whether we've started headers synchronization with this peer. bool fSyncStarted; - //! When to potentially disconnect peer for stalling headers download - int64_t nHeadersSyncTimeout; //! Since when we're stalling block download progress (in microseconds), or 0. int64_t nStallingSince; list vBlocksInFlight; @@ -350,7 +348,6 @@ struct CNodeState { hashLastUnknownBlock.SetNull(); pindexLastCommonBlock = NULL; fSyncStarted = false; - nHeadersSyncTimeout = 0; nStallingSince = 0; nBlocksInFlight = 0; nBlocksInFlightValidHeaders = 0; @@ -517,7 +514,7 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vectorpindexBestKnownBlock == NULL || state->pindexBestKnownBlock->nChainWork < chainActive.Tip()->nChainWork || state->pindexBestKnownBlock->nChainWork < UintToArith256(Params().GetConsensus().nMinimumChainWork)) { + if (state->pindexBestKnownBlock == NULL || state->pindexBestKnownBlock->nChainWork < chainActive.Tip()->nChainWork) { // This peer has nothing interesting. return; } @@ -7651,7 +7648,6 @@ bool SendMessages(const Consensus::Params& params, CNode* pto) // Only actively request headers from a single peer, unless we're close to today. if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetTime() - 24 * 60 * 60) { state.fSyncStarted = true; - state.nHeadersSyncTimeout = GetTimeMicros() + HEADERS_DOWNLOAD_TIMEOUT_BASE + HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER * (EstimateNetHeight(params, pindexBestHeader->nHeight, pindexBestHeader->GetBlockTime()) - pindexBestHeader->nHeight); nSyncStarted++; const CBlockIndex *pindexStart = pindexBestHeader; /* If possible, start at the block preceding the currently @@ -7837,38 +7833,6 @@ bool SendMessages(const Consensus::Params& params, CNode* pto) pto->fDisconnect = true; } } - // Check for headers sync timeouts - if (state.fSyncStarted && state.nHeadersSyncTimeout < std::numeric_limits::max()) { - // Detect whether this is a stalling initial-headers-sync peer - if (pindexBestHeader->GetBlockTime() <= GetTime() - 24*60*60) { - if (nNow > state.nHeadersSyncTimeout && nSyncStarted == 1 && (nPreferredDownload - state.fPreferredDownload >= 1)) { - // Disconnect a (non-whitelisted) peer if it is our only sync peer, - // and we have others we could be using instead. - // Note: If all our peers are inbound, then we won't - // disconnect our sync peer for stalling; we have bigger - // problems if we can't get any outbound peers. - if (!pto->fWhitelisted) { - LogPrintf("Timeout downloading headers from peer=%d, disconnecting\n", pto->GetId()); - pto->fDisconnect = true; - return true; - } else { - LogPrintf("Timeout downloading headers from whitelisted peer=%d, not disconnecting\n", pto->GetId()); - // Reset the headers sync state so that we have a - // chance to try downloading from a different peer. - // Note: this will also result in at least one more - // getheaders message to be sent to - // this peer (eventually). - state.fSyncStarted = false; - nSyncStarted--; - state.nHeadersSyncTimeout = 0; - } - } - } else { - // After we've caught up once, reset the timeout so we can't trigger - // disconnect later. - state.nHeadersSyncTimeout = std::numeric_limits::max(); - } - } // // Message: getdata (blocks) diff --git a/src/main.h b/src/main.h index 5b57baad5..0034a4969 100644 --- a/src/main.h +++ b/src/main.h @@ -98,10 +98,6 @@ static const int DEFAULT_SCRIPTCHECK_THREADS = 0; static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16; /** Timeout in seconds during which a peer must stall block download progress before being disconnected. */ static const unsigned int BLOCK_STALLING_TIMEOUT = 2; -/** Headers download timeout expressed in microseconds - * Timeout = base + per_header * (expected number of headers) */ -static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_BASE = 30 * 60 * 1000000; // 30 minutes -static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER = 10000; // 10 ms/header /** Number of headers sent in one getheaders result. We rely on the assumption that if a peer sends * less than this number, we reached its tip. Changing this value is a protocol upgrade. */ static const unsigned int MAX_HEADERS_RESULTS = 160;