diff --git a/internal/netsync/manager.go b/internal/netsync/manager.go index 3d081b655..8602ff462 100644 --- a/internal/netsync/manager.go +++ b/internal/netsync/manager.go @@ -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) { @@ -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++ @@ -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++