diff --git a/src/chainparams.cpp b/src/chainparams.cpp index a1f7168245279..dd4aa25e57a26 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -191,7 +191,6 @@ class CMainParams : public CChainParams { pchMessageStart[3] = 0xbd; vAlertPubKey = ParseHex("048240a8748a80a286b270ba126705ced4f2ce5a7847b3610ea3c06513150dade2a8512ed5ea86320824683fc0818f0ac019214973e677acd1244f6d0571fc5103"); nDefaultPort = 9999; - nDelayGetHeadersTime = 24 * 60 * 60; nPruneAfterHeight = 100000; genesis = CreateGenesisBlock(1390095618, 28917698, 0x1e0ffff0, 1, 50 * COIN); @@ -339,7 +338,6 @@ class CTestNetParams : public CChainParams { pchMessageStart[3] = 0xff; vAlertPubKey = ParseHex("04517d8a699cb43d3938d7b24faaff7cda448ca4ea267723ba614784de661949bf632d6304316b244646dea079735b9a6fc4af804efb4752075b9fe2245e14e412"); nDefaultPort = 19999; - nDelayGetHeadersTime = 24 * 60 * 60; nPruneAfterHeight = 1000; genesis = CreateGenesisBlock(1390666206UL, 3861367235UL, 0x1e0ffff0, 1, 50 * COIN); @@ -469,7 +467,6 @@ class CDevNetParams : public CChainParams { pchMessageStart[3] = 0xff; vAlertPubKey = ParseHex("04517d8a699cb43d3938d7b24faaff7cda448ca4ea267723ba614784de661949bf632d6304316b244646dea079735b9a6fc4af804efb4752075b9fe2245e14e412"); nDefaultPort = 19999; - nDelayGetHeadersTime = 24 * 60 * 60; nPruneAfterHeight = 1000; genesis = CreateGenesisBlock(1417713337, 1096447, 0x207fffff, 1, 50 * COIN); @@ -585,7 +582,6 @@ class CRegTestParams : public CChainParams { pchMessageStart[1] = 0xc1; pchMessageStart[2] = 0xb7; pchMessageStart[3] = 0xdc; - nDelayGetHeadersTime = std::numeric_limits::max(); // never delay GETHEADERS in regtests nDefaultPort = 19994; nPruneAfterHeight = 1000; diff --git a/src/chainparams.h b/src/chainparams.h index a4ebe40e3c71d..034e186bc73d3 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -69,7 +69,6 @@ class CChainParams bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; } /** Policy: Filter transactions that do not match well-defined patterns */ bool RequireStandard() const { return fRequireStandard; } - int64_t DelayGetHeadersTime() const { return nDelayGetHeadersTime; } uint64_t PruneAfterHeight() const { return nPruneAfterHeight; } /** Make miner stop after a block is found. In RPC, don't return until nGenProcLimit blocks are generated */ bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; } @@ -96,7 +95,6 @@ class CChainParams //! Raw pub key bytes for the broadcast alert signing key. std::vector vAlertPubKey; int nDefaultPort; - int64_t nDelayGetHeadersTime; uint64_t nPruneAfterHeight; std::vector vSeeds; std::vector base58Prefixes[MAX_BASE58_TYPES]; diff --git a/src/net.h b/src/net.h index 5741926989339..9408429e795a2 100644 --- a/src/net.h +++ b/src/net.h @@ -775,9 +775,6 @@ class CNode // Used for headers announcements - unfiltered blocks to relay // Also protected by cs_inventory std::vector vBlockHashesToAnnounce; - // Blocks received by INV while headers chain was too far behind. These are used to delay GETHEADERS messages - // Also protected by cs_inventory - std::vector vDelayedGetHeaders; // Used for BIP35 mempool sending, also protected by cs_inventory bool fSendMempool; @@ -927,12 +924,6 @@ class CNode vBlockHashesToAnnounce.push_back(hash); } - void PushDelayedGetHeaders(const uint256 &hash) - { - LOCK(cs_inventory); - vDelayedGetHeaders.push_back(hash); - } - void AskFor(const CInv& inv); void CloseSocketDisconnect(); diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 770e27b733ff7..14db0334402e8 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1476,30 +1476,13 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr if (inv.type == MSG_BLOCK) { UpdateBlockAvailability(pfrom->GetId(), inv.hash); if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) { - // Always send GETHEADERS when we are still on the devnet genesis block. Otherwise we'll never sync. - // This is because after startup of the node, we are in IBD mode, which will only be left when recent - // blocks arrive. At the same time, we won't get any blocks from peers because we keep delaying - // GETHEADERS - bool fDevNetGenesis = !chainparams.GetConsensus().hashDevnetGenesisBlock.IsNull() && pindexBestHeader->GetBlockHash() == chainparams.GetConsensus().hashDevnetGenesisBlock; - - if (!fDevNetGenesis && (GetAdjustedTime() - pindexBestHeader->GetBlockTime() > chainparams.DelayGetHeadersTime())) { - // We are pretty far from being completely synced at the moment. If we would initiate a new - // chain of GETHEADERS/HEADERS now, we may end up downnloading the full chain from multiple - // peers at the same time, slowing down the initial sync. At the same time, we don't know - // if the peer we got this INV from may have a chain we don't know about yet, so we HAVE TO - // send a GETHEADERS message at some point in time. This is delayed to later in SendMessages - // when the headers chain has catched up enough. - LogPrint("net", "delaying getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id); - pfrom->PushDelayedGetHeaders(inv.hash); - } else { - // We used to request the full block here, but since headers-announcements are now the - // primary method of announcement on the network, and since, in the case that a node - // fell back to inv we probably have a reorg which we should get the headers for first, - // we now only provide a getheaders response here. When we receive the headers, we will - // then ask for the blocks we need. - connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::GETHEADERS, chainActive.GetLocator(pindexBestHeader), inv.hash)); - LogPrint("net", "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id); - } + // We used to request the full block here, but since headers-announcements are now the + // primary method of announcement on the network, and since, in the case that a node + // fell back to inv we probably have a reorg which we should get the headers for first, + // we now only provide a getheaders response here. When we receive the headers, we will + // then ask for the blocks we need. + connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::GETHEADERS, chainActive.GetLocator(pindexBestHeader), inv.hash)); + LogPrint("net", "getheaders (%d) %s to peer=%d\n", pindexBestHeader->nHeight, inv.hash.ToString(), pfrom->id); } } else @@ -1893,6 +1876,11 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr ReadCompactSize(vRecv); // ignore tx count; assume it is 0. } + if (nCount == 0) { + // Nothing interesting. Stop asking this peers for more headers. + return true; + } + const CBlockIndex *pindexLast = NULL; { LOCK(cs_main); @@ -1964,20 +1952,6 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr // from there instead. LogPrint("net", "more getheaders (%d) to end to peer=%d (startheight:%d)\n", pindexLast->nHeight, pfrom->id, pfrom->nStartingHeight); connman.PushMessage(pfrom, msgMaker.Make(NetMsgType::GETHEADERS, chainActive.GetLocator(pindexLast), uint256())); - } else { - if (GetAdjustedTime() - pindexBestHeader->GetBlockTime() > chainparams.DelayGetHeadersTime()) { - // peer has sent us a HEADERS message below maximum size and we are still quite far from being fully - // synced, this means we probably got a bad peer for initial sync and need to continue with another one. - // By disconnecting we force to start a new iteration of initial headers sync in SendMessages - // TODO should we handle whitelisted peers here as we do in headers sync timeout handling? - pfrom->fDisconnect = true; - return error("detected bad peer for initial headers sync, disconnecting %d", pfrom->id); - } - - if (nCount == 0) { - // Nothing interesting. Stop asking this peers for more headers. - return true; - } } bool fCanDirectFetch = CanDirectFetch(chainparams.GetConsensus()); @@ -2493,8 +2467,7 @@ class CompareInvMempoolOrder bool SendMessages(CNode* pto, CConnman& connman, const std::atomic& interruptMsgProc) { - const CChainParams chainParams = Params(); - const Consensus::Params& consensusParams = chainParams.GetConsensus(); + const Consensus::Params& consensusParams = Params().GetConsensus(); { // Don't send anything until the version handshake is complete if (!pto->fSuccessfullyConnected || pto->fDisconnect) @@ -2601,17 +2574,6 @@ bool SendMessages(CNode* pto, CConnman& connman, const std::atomic& interr } } - if (GetAdjustedTime() - pindexBestHeader->GetBlockTime() <= chainParams.DelayGetHeadersTime()) { - // Headers chain has catched up enough so we can send out GETHEADER messages which were initially meant to - // be sent directly after INV was received - LOCK(pto->cs_inventory); - BOOST_FOREACH(const uint256 &hash, pto->vDelayedGetHeaders) { - LogPrint("net", "process delayed getheaders (%d) to peer=%d\n", pindexBestHeader->nHeight, pto->id); - connman.PushMessage(pto, msgMaker.Make(NetMsgType::GETHEADERS, chainActive.GetLocator(pindexBestHeader), hash)); - } - pto->vDelayedGetHeaders.clear(); - } - // Resend wallet transactions that haven't gotten in a block yet // Except during reindex, importing and IBD, when old wallet // transactions become unconfirmed and spams other nodes.