@@ -18,6 +18,7 @@ import pkg/libp2p/[cid, switch, multihash, multicodec]
1818import pkg/ metrics
1919import pkg/ stint
2020import pkg/ questionable
21+ import pkg/ stew/ shims/ sets
2122
2223import ../../ rng
2324import ../../ stores/ blockstore
@@ -297,47 +298,31 @@ proc blockPresenceHandler*(
297298 trace " Received block presence from peer" , peer, len = blocks.len
298299 let
299300 peerCtx = self.peers.get (peer)
300- ourWantList = toSeq (self.pendingBlocks.wantList)
301+ ourWantList = toHashSet (self.pendingBlocks.wantList.toSeq )
301302
302303 if peerCtx.isNil:
303304 return
304305
305- trace " Build presence list"
306-
307306 for blk in blocks:
308307 if presence =? Presence .init (blk):
309308 peerCtx.setPresence (presence)
310309
311- trace " Built presence list"
312-
313- trace " Remove dont want cids"
314-
315310 let
316- peerHave = peerCtx.peerHave
317- dontWantCids = peerHave.filterIt (it notin ourWantList)
318-
319- trace " Removed dont want cids"
311+ peerHave = peerCtx.peerHave.toHashSet
312+ dontWantCids = peerHave - ourWantList
320313
321314 if dontWantCids.len > 0 :
322- peerCtx.cleanPresence (dontWantCids)
323-
324- trace " Remove want cids"
315+ peerCtx.cleanPresence (dontWantCids.toSeq)
325316
326317 let ourWantCids = ourWantList.filterIt (
327318 it in peerHave and not self.pendingBlocks.retriesExhausted (it) and
328319 not self.pendingBlocks.isInFlight (it)
329- )
330-
331- trace " Removed want cids"
332-
333- trace " Update pending blocks"
320+ ).toSeq
334321
335322 for address in ourWantCids:
336323 self.pendingBlocks.setInFlight (address, true )
337324 self.pendingBlocks.decRetries (address)
338325
339- trace " Updated pending blocks"
340-
341326 if ourWantCids.len > 0 :
342327 trace " Peer has blocks in our wantList" , peer, wants = ourWantCids
343328 # FIXME: this will result in duplicate requests for blocks
0 commit comments