Skip to content

Commit ef6dbe6

Browse files
committed
Respond to getheaders if we have sufficient chainwork
Previously, we would check to see if we were in IBD and ignore getheaders requests accordingly. However, the IBD criteria -- an optimization mostly targeted at behavior when we have peers serving us many blocks we need to download -- is difficult to reason about in edge-case scenarios, such as if the network were to go a long time without any blocks found and nodes getting restarted during that time. To make things simpler to reason about, just use nMinimumChainWork as our anti-DoS threshold; as long as our chain has that much work, it should be fine to respond to a peer asking for our headers (and this should allow such a peer to request blocks from us if needed).
1 parent d0bf9bb commit ef6dbe6

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/net_processing.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,9 +3189,23 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
31893189
return;
31903190
}
31913191

3192+
if (fImporting || fReindex) {
3193+
LogPrint(BCLog::NET, "Ignoring getheaders from peer=%d while importing/reindexing\n", pfrom.GetId());
3194+
return;
3195+
}
3196+
31923197
LOCK(cs_main);
3193-
if (m_chainman.ActiveChainstate().IsInitialBlockDownload() && !pfrom.HasPermission(NetPermissionFlags::Download)) {
3194-
LogPrint(BCLog::NET, "Ignoring getheaders from peer=%d because node is in initial block download\n", pfrom.GetId());
3198+
3199+
// Note that if we were to be on a chain that forks from the checkpointed
3200+
// chain, then serving those headers to a peer that has seen the
3201+
// checkpointed chain would cause that peer to disconnect us. Requiring
3202+
// that our chainwork exceed nMinimumChainWork is a protection against
3203+
// being fed a bogus chain when we started up for the first time and
3204+
// getting partitioned off the honest network for serving that chain to
3205+
// others.
3206+
if (m_chainman.ActiveTip() == nullptr ||
3207+
(m_chainman.ActiveTip()->nChainWork < nMinimumChainWork && !pfrom.HasPermission(NetPermissionFlags::Download))) {
3208+
LogPrint(BCLog::NET, "Ignoring getheaders from peer=%d because active chain has too little work\n", pfrom.GetId());
31953209
return;
31963210
}
31973211

0 commit comments

Comments
 (0)