From 394670893546240b9c01987e075523ca3c33a300 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 9 Sep 2025 12:05:04 +0200 Subject: [PATCH] p2p/discover: fix two bugs in lookup iterator The lookup would add self into the replyBuffer if returned by another node. Avoid doing that by marking self as seen. With the changed initialization behavior of lookup, the lookupIterator needs to yield the buffer right after creation. This fixes the smallNetConvergence test, where all results are straight out of the local table. --- p2p/discover/lookup.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/p2p/discover/lookup.go b/p2p/discover/lookup.go index d15cdccc48..88c93a57cf 100644 --- a/p2p/discover/lookup.go +++ b/p2p/discover/lookup.go @@ -53,6 +53,7 @@ func newLookup(ctx context.Context, tab *Table, target enode.ID, q queryFunc) *l // Don't query further if we hit ourself. // Unlikely to happen often in practice. it.asked[tab.self().ID()] = true + it.seen[tab.self().ID()] = true // Initialize the lookup with nodes from table. closest := it.tab.findnodeByID(it.result.target, bucketSize, false) @@ -186,8 +187,12 @@ func (it *lookupIterator) Next() bool { // is in a degraded state, and we need to wait for it to fill again. it.lookupFailed(it.lookup.tab) } + // Otherwise, yield the initial nodes from the iterator before advancing + // the lookup. + it.buffer = it.lookup.replyBuffer continue } + newNodes := it.lookup.advance() it.buffer = it.lookup.replyBuffer if !newNodes {