diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2023-07-20 20:53:08 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2024-02-01 16:23:59 -0300 |
commit | 2f6a05512fa86d086b2b976c401394571d88bd93 (patch) | |
tree | 777b2f2d063f6fb66254a1004f3cb52325af9ac8 /src/net_processing.cpp | |
parent | 73127722a2d2b5c8da4102284f9d0cf504a2e72d (diff) |
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.
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r-- | src/net_processing.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp index e211ee3b2c..48d2ce280a 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1451,6 +1451,7 @@ void PeerManagerImpl::FindNextBlocks(std::vector<const CBlockIndex*>& vBlocks, c { std::vector<const CBlockIndex*> vToFetch; int nMaxHeight = std::min<int>(state->pindexBestKnownBlock->nHeight, nWindowEnd + 1); + bool is_limited_peer = IsLimitedPeer(peer); NodeId waitingfor = -1; while (pindexWalk->nHeight < nMaxHeight) { // 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 return; } + // Don't request blocks that go further than what limited peers can provide + if (is_limited_peer && (state->pindexBestKnownBlock->nHeight - pindex->nHeight >= static_cast<int>(NODE_NETWORK_LIMITED_MIN_BLOCKS) - 2 /* two blocks buffer for possible races */)) { + continue; + } + vBlocks.push_back(pindex); if (vBlocks.size() == count) { return; |