Skip to content

Commit 8b57013

Browse files
committed
[net processing] Remove nStartingHeight check from block relay
nStartingHeight was introduced in commit 7a47324 (Bitcoin version 0.2.9, P2P version 209) with the comment "better prevention of inventory relaying during initial download". At that time, there was no function to determine whether the node was still in Initial Block Download, so to prevent syncing nodes from relaying old blocks to their peers, a check was added to never relay a block to a peer where the height was lower than 2000 less than the peer's best block. That check was updated several times in later commits to ensure that we weren't relaying blocks before the latest checkpoint if the peer didn't provide a startingheight. The checkpoint comparison was changed to compare with an estimate of the highest block in commit eae82d8. In commit 202e019, all block relay was gated on being out of Initial Block Download. In commit 0278fb5, the comparison to nBlockEstimate was removed since "we already checked IsIBD()". We can remove the check against nStartingHeight entirely. If the node is out of Initial Block Download, then its tip height must have been within 24 hours of current time, so should not be more than ~144 blocks behind the most work tip.
1 parent 6a48063 commit 8b57013

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/net_processing.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,8 +1295,9 @@ void PeerManager::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_
12951295
void PeerManager::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
12961296
const int nNewHeight = pindexNew->nHeight;
12971297
m_connman.SetBestHeight(nNewHeight);
1298-
12991298
SetServiceFlagsIBDCache(!fInitialDownload);
1299+
1300+
// Relay inventory, but don't relay old inventory during initial block download.
13001301
if (!fInitialDownload) {
13011302
// Find the hashes of all blocks that weren't previously in the best chain.
13021303
std::vector<uint256> vHashes;
@@ -1310,13 +1311,10 @@ void PeerManager::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockInde
13101311
break;
13111312
}
13121313
}
1313-
// Relay inventory, but don't relay old inventory during initial block download.
13141314
m_connman.ForEachNode([nNewHeight, &vHashes](CNode* pnode) {
13151315
LOCK(pnode->cs_inventory);
1316-
if (nNewHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 0)) {
1317-
for (const uint256& hash : reverse_iterate(vHashes)) {
1318-
pnode->vBlockHashesToAnnounce.push_back(hash);
1319-
}
1316+
for (const uint256& hash : reverse_iterate(vHashes)) {
1317+
pnode->vBlockHashesToAnnounce.push_back(hash);
13201318
}
13211319
});
13221320
m_connman.WakeMessageHandler();

0 commit comments

Comments
 (0)