Skip to content

Commit 2f6a055

Browse files
committed
p2p: sync from limited peer, only request blocks below threshold
Requesting historical blocks from network limited peers is a direct disconnection cause. The node must only request the blocks who know for sure the limited peer can provide.
1 parent 7312772 commit 2f6a055

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/net_processing.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,7 @@ void PeerManagerImpl::FindNextBlocks(std::vector<const CBlockIndex*>& vBlocks, c
14511451
{
14521452
std::vector<const CBlockIndex*> vToFetch;
14531453
int nMaxHeight = std::min<int>(state->pindexBestKnownBlock->nHeight, nWindowEnd + 1);
1454+
bool is_limited_peer = IsLimitedPeer(peer);
14541455
NodeId waitingfor = -1;
14551456
while (pindexWalk->nHeight < nMaxHeight) {
14561457
// Read up to 128 (or more, if more blocks than that are needed) successors of pindexWalk (towards
@@ -1505,6 +1506,11 @@ void PeerManagerImpl::FindNextBlocks(std::vector<const CBlockIndex*>& vBlocks, c
15051506
return;
15061507
}
15071508

1509+
// Don't request blocks that go further than what limited peers can provide
1510+
if (is_limited_peer && (state->pindexBestKnownBlock->nHeight - pindex->nHeight >= static_cast<int>(NODE_NETWORK_LIMITED_MIN_BLOCKS) - 2 /* two blocks buffer for possible races */)) {
1511+
continue;
1512+
}
1513+
15081514
vBlocks.push_back(pindex);
15091515
if (vBlocks.size() == count) {
15101516
return;

0 commit comments

Comments
 (0)