revert: Fix duplicate initial headers sync

commits reverted:
- 753ed61fb3
This commit is contained in:
Kittywhiskers Van Gogh 2024-08-01 20:31:06 +00:00 committed by pasta
parent abccb2dd03
commit 26d477b6ae
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
3 changed files with 4 additions and 29 deletions

View File

@ -3806,30 +3806,7 @@ void PeerManagerImpl::ProcessMessage(
statsClient.inc(strprintf("message.received.inv_%s", inv.GetCommand()), 1.0f);
UpdateBlockAvailability(pfrom.GetId(), inv.hash);
if (fAlreadyHave || fImporting || fReindex || mapBlocksInFlight.count(inv.hash)) {
continue;
}
CNodeState *state = State(pfrom.GetId());
if (!state) {
continue;
}
// Download if this is a nice peer, or we have no nice peers and this one might do.
bool fFetch = state->fPreferredDownload || (nPreferredDownload == 0 && !pfrom.IsAddrFetchConn());
// Only actively request headers from a single peer, unless we're close to end of initial download.
if ((nSyncStarted == 0 && fFetch) || m_chainman.m_best_header->GetBlockTime() > GetAdjustedTime() - nMaxTipAge) {
// Make sure to mark this peer as the one we are currently syncing with etc.
state->fSyncStarted = true;
state->m_headers_sync_timeout = current_time + HEADERS_DOWNLOAD_TIMEOUT_BASE +
(
// Convert HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER to microseconds before scaling
// to maintain precision
std::chrono::microseconds{HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER} *
(GetAdjustedTime() - m_chainman.m_best_header->GetBlockTime()) / m_chainparams.GetConsensus().nPowTargetSpacing
);
nSyncStarted++;
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) {
// Headers-first is the primary method of announcement on
// the network. If a node fell back to sending blocks by inv,
// it's probably for a re-org. The final block hash

View File

@ -91,11 +91,10 @@ class BIP68_112_113Test(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = True
# Must also set '-maxtipage=600100' to allow syncing from very old blocks
# and '-dip3params=2000:2000' to create pre-dip3 blocks only
# Must set '-dip3params=2000:2000' to create pre-dip3 blocks only
self.extra_args = [[
'-whitelist=noban@127.0.0.1',
'-maxtipage=600100', '-dip3params=2000:2000',
'-dip3params=2000:2000',
'-par=1', # Use only one script thread to get the exact reject reason for testing
]]
self.supports_cli = False

View File

@ -38,7 +38,6 @@ class MaxUploadTest(BitcoinTestFramework):
self.extra_args = [[
"-maxuploadtarget=200",
"-blockmaxsize=999000",
"-maxtipage="+str(2*60*60*24*7),
"-acceptnonstdtxn=1"
]]
self.supports_cli = False
@ -149,7 +148,7 @@ class MaxUploadTest(BitcoinTestFramework):
self.nodes[0].disconnect_p2ps()
self.log.info("Restarting node 0 with download permission and 1MB maxuploadtarget")
self.restart_node(0, ["-whitelist=download@127.0.0.1", "-maxuploadtarget=1", "-blockmaxsize=999000", "-maxtipage="+str(2*60*60*24*7), "-mocktime="+str(current_mocktime)])
self.restart_node(0, ["-whitelist=download@127.0.0.1", "-maxuploadtarget=1", "-blockmaxsize=999000", "-mocktime="+str(current_mocktime)])
# Reconnect to self.nodes[0]
peer = self.nodes[0].add_p2p_connection(TestP2PConn())