Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions internal/netsync/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2070,9 +2070,10 @@ func (m *SyncManager) SyncPeerID() int32 {
return 0
}

// RequestFromPeer requests any combination of blocks, votes, and treasury
// spends from the given peer. It ensures all of the requests are tracked so
// the peer is not banned for sending unrequested data when it responds.
// RequestFromPeer makes a best effort to request any combination of blocks,
// votes, and treasury spends from the given peer. It ensures all of the
// requests are tracked so the peer is not banned for sending unrequested data
// when it responds.
//
// This function is safe for concurrent access.
func (m *SyncManager) RequestFromPeer(peer *Peer, blocks, voteHashes, tSpendHashes []chainhash.Hash) {
Expand All @@ -2094,6 +2095,12 @@ func (m *SyncManager) RequestFromPeer(peer *Peer, blocks, voteHashes, tSpendHash
continue
}

// Stop requesting when the request would exceed the max size of the map
// used to track requests.
if len(m.requestedBlocks)+1 > maxRequestedBlocks {
break
}

gdMsg.AddInvVect(wire.NewInvVect(wire.InvTypeBlock, blockHash))
m.requestedBlocks[*blockHash] = peer
numRequested++
Expand All @@ -2117,6 +2124,12 @@ func (m *SyncManager) RequestFromPeer(peer *Peer, blocks, voteHashes, tSpendHash
continue
}

// Stop requesting when the request would exceed the max size of the
// map used to track requests.
if len(m.requestedTxns)+1 > maxRequestedTxns {
break
}

gdMsg.AddInvVect(wire.NewInvVect(wire.InvTypeTx, txHash))
m.requestedTxns[*txHash] = peer
numRequested++
Expand Down