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.
This commit is contained in:
1 file changed
+6
@@ -1451,6 +1451,7 @@ void PeerManagerImpl::FindNextBlocks(std::vector<const CBlockIndex*>& vBlocks, c
|
|||||||
{
|
{
|
||||||
std::vector<const CBlockIndex*> vToFetch;
|
std::vector<const CBlockIndex*> vToFetch;
|
||||||
int nMaxHeight = std::min<int>(state->pindexBestKnownBlock->nHeight, nWindowEnd + 1);
|
int nMaxHeight = std::min<int>(state->pindexBestKnownBlock->nHeight, nWindowEnd + 1);
|
||||||
|
bool is_limited_peer = IsLimitedPeer(peer);
|
||||||
NodeId waitingfor = -1;
|
NodeId waitingfor = -1;
|
||||||
while (pindexWalk->nHeight < nMaxHeight) {
|
while (pindexWalk->nHeight < nMaxHeight) {
|
||||||
// Read up to 128 (or more, if more blocks than that are needed) successors of pindexWalk (towards
|
// 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;
|
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);
|
vBlocks.push_back(pindex);
|
||||||
if (vBlocks.size() == count) {
|
if (vBlocks.size() == count) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in new issue
Block a user