go-ethereum/p2p/discover
Csaba Kiraly 33785aab21
p2p/discover: document BFS choice, add RandomWorkers split
Two related changes to CrawlIterator:

(1) Add a file-level commentary block explaining why the iterator uses a
FIFO queue (BFS over the FINDNODE-response graph) and what it is *not*
suitable for (target-directed lookup -- use RandomNodes() / the alpha=3
lookup iterator for that). The choice was inherited from dcrawl.nim
without explicit reasoning; making it visible avoids future readers
re-deriving the survey-vs-lookup distinction.

The BFS rationale is two-fold:

 - Coverage: BFS reaches every peer within N hops of the seeds in
   order, so a time-bounded run produces a representative sample of the
   reachable graph rather than a deep tendril through one sub-region.
 - Adversarial resilience: a peer returning malicious "neighbour"
   claims, dead-end peers, or eclipse-style sub-graphs cannot
   monopolise the worker pool, because pending work from other branches
   sits ahead of the attacker's responses in the queue. DFS would
   amplify each of these attacks.

(2) Add a RandomWorkers field to CrawlOptions. Of the Workers-sized
worker pool, the first (Workers - RandomWorkers) workers pop the FIFO
front (BFS), while RandomWorkers workers pop a uniform-random queue
index via swap-and-pop (O(1)). Total worker count is unchanged.

Default RandomWorkers = Workers / 4 (4 of 16 with the default
parallelism). At this ratio:

 - Cold-start cost is negligible: 12 of 16 workers still drain FIFO,
   so the first ~1s of a fresh crawl behaves like pure BFS.
 - 25% of pops break strict FIFO ordering, providing a mild
   anti-fingerprint defence against an attacker who could otherwise
   predict our processing order from the contents of their own
   FINDNODE responses.

Operators can override per-run via the new --random-workers CLI flag
on `devp2p discv4 crawl` and `discv5 crawl`. Negative value forces
pure BFS; positive value selects an explicit count.

The new TestCrawlIteratorRandomWorkers covers four pop-policy
configurations (all-fifo, all-random, half-half, default) and
asserts the iterator still terminates and emits each node exactly
once in each.
2026-05-07 14:41:58 +02:00
..
v4wire p2p/discover: refactor node and endpoint representation (#29844) 2024-05-29 15:02:26 +02:00
v5wire p2p/discover/v5wire: use Whoareyou.ChallengeData instead of storing encoded packet (#31547) 2026-02-22 21:58:47 +01:00
common.go p2p/discover: fix timeout loop early exit when removing expired matchers (#34743) 2026-04-28 10:57:58 +02:00
crawliter.go p2p/discover: document BFS choice, add RandomWorkers split 2026-05-07 14:41:58 +02:00
crawliter_test.go p2p/discover: document BFS choice, add RandomWorkers split 2026-05-07 14:41:58 +02:00
lookup.go p2p/discover: remove hot-spin in table refresh trigger (#32912) 2025-10-15 11:51:33 +02:00
metrics.go metrics, cmd/geth: change init-process of metrics (#30814) 2024-12-10 13:27:29 +01:00
node.go p2p/discover: remove type encPubkey (#30172) 2024-07-18 11:09:02 +02:00
ntp.go all: remove dependency on golang.org/exp (#29314) 2024-03-25 07:50:18 +01:00
table.go p2p/discover: resolve DNS hostnames for bootstrap nodes (#34101) 2026-03-28 11:37:39 +01:00
table_reval.go p2p/discover: remove unused parameter in revalidationList.get (#31155) 2025-02-11 13:45:44 +01:00
table_reval_test.go p2p/discover: refactor node and endpoint representation (#29844) 2024-05-29 15:02:26 +02:00
table_test.go p2p/discover: resolve DNS hostnames for bootstrap nodes (#34101) 2026-03-28 11:37:39 +01:00
table_util_test.go p2p/discover: remove type encPubkey (#30172) 2024-07-18 11:09:02 +02:00
v4_lookup_test.go Revert "p2p/discover: add test for lookup returning immediately" 2025-09-12 11:29:43 +02:00
v4_udp.go p2p/discover: restore nextTimeout update in UDPv4 resetTimeout loop (#34878) 2026-05-05 15:28:28 +02:00
v4_udp_test.go p2p/discover: wait for bootstrap to be done (#32881) 2025-10-13 19:58:50 +02:00
v5_talk.go p2p/discover: pass node instead of node ID to TALKREQ handler (#31075) 2025-04-02 14:56:21 +02:00
v5_udp.go p2p/discover: remove delay from discv5 RandomNodes (#32517) 2025-09-10 19:51:04 +02:00
v5_udp_test.go p2p/discover: fix flaky TestUDPv5_findnodeHandling (#34109) 2026-04-14 09:43:44 +02:00