Skip to content

Commit

Permalink
server: Don't wait or try to send notfound data.
Browse files Browse the repository at this point in the history
This modifies the recent concurrent getdata serving logic to immediately
decrement the pending item count and move on to the next requested data
item when an item is not found.

Not only is it more efficient since it means there is no attempt to
acquire the semaphore, it also prevents an issue the new code introduced
where it could incorrectly queue up a nil message leading to a panic.
  • Loading branch information
davecgh committed Oct 31, 2023
1 parent 3aaaf3f commit c1e4cdd
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,22 @@ func (sp *serverPeer) handleServeGetData(invVects []*wire.InvVect,
continue
}
if dataMsg == nil {
// Keep track of all items that were not found in order to send a
// consolidated messsage once the entire batch is processed.
//
// The error when adding the inventory vector is ignored because the
// only way it could fail would be by exceeding the max allowed
// number of items which is impossible given the getdata message is
// enforced to not exceed that same maximum limit.
if notFoundMsg == nil {
notFoundMsg = wire.NewMsgNotFound()
}
notFoundMsg.AddInvVect(iv)

// There is no need to wait for the semaphore below when there is
// not any data to send.
sp.numPendingGetDataItemReqs.Add(^uint32(0))
continue
}

// Limit the number of items that can be queued to prevent wasting a
Expand Down

0 comments on commit c1e4cdd

Please sign in to comment.