From c1e4cdd9e7a26092648ef3ff15ca291297d49634 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 31 Oct 2023 12:48:14 -0500 Subject: [PATCH] server: Don't wait or try to send notfound data. 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. --- server.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server.go b/server.go index 8d5442056c..af8c05079f 100644 --- a/server.go +++ b/server.go @@ -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