Skip to content

Commit 394e59d

Browse files
committed
Politely and safely refuse getheaders requests for headers we have trimmed.
1 parent 763d298 commit 394e59d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/net_processing.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,10 +3166,17 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
31663166
LogPrint(BCLog::NET, "getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.IsNull() ? "end" : hashStop.ToString(), pfrom.GetId());
31673167
for (; pindex; pindex = m_chainman.ActiveChain().Next(pindex))
31683168
{
3169+
if (pindex->trimmed()) {
3170+
// For simplicity, if any of the headers they're asking for are trimmed,
3171+
// just drop the request.
3172+
LogPrint(BCLog::NET, "%s: ignoring getheaders from peer=%i which would return at least one trimmed header\n", __func__, pfrom.GetId());
3173+
return;
3174+
}
31693175
vHeaders.push_back(pindex->GetBlockHeader());
31703176
if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop)
31713177
break;
31723178
}
3179+
31733180
// pindex can be nullptr either if we sent m_chainman.ActiveChain().Tip() OR
31743181
// if our peer has m_chainman.ActiveChain().Tip() (and thus we are sending an empty
31753182
// headers message). In both cases it's safe to update

0 commit comments

Comments
 (0)