Question: In the test node is it expected that a “simple” await disco.bootstrap(forceRefresh = not cfg.client) takes between 30 seconds or minutes (depending on forceRefresh boolean) in a network of 7 nodes?
Answer: Yes.
Underneath it does:
proc bootstrap*(kad: KadDHT, forceRefresh = false) =
await kad.refreshTable(kad.rtable, forceRefresh)
And refreshTable does:
discard await kad.findNode(rtable.selfId, rtable)
for each bucket in routing table:
if bucket is empty:
skip
if not (forceRefresh or bucket.isStale()):
skip
randomKey = randomKeyInBucket(...)
discard await kad.findNode(randomKey, rtable)
Each findNode is an iterative Kademlia lookup, that will do:
pick closest known peers from routing table
send FIND_NODE RPCs to them
receive closerPeers
add those peers to shortlist/routing table
repeat until enough closest peers responded or no more candidates
So basically in this setup what is happening is:
- First temporary node completes this operation fast because the network does not yet know old temporary peer IDs.
- After we kill it and we deploy a new one, bootstrap/permanent nodes may still have the dead temporary peer in their routing tables.
- The new temporary node connects to whatever bootstrap is selected, asks for peers, and receives stale old temporary peers in closerPeers.
- `findNode` tries them and waits for dial/RPC timeouts.
- With `forceRefresh = false`, this may cost around one or a few timeout rounds, e.g. 30 seconds.
- With `forceRefresh = true`, it repeats lookup work for every non-empty bucket, so the same stale entries can cost minutes.
Even more, we can see in kademlia DefaultTimeout = 5.seconds and DefaultRetries = 5 so the 30 seconds when forceRefresh=false makes total sense.
In the case of forceRefresh = true, the behavior would be:
findNode(self)
then findNode(random key) for every non-empty bucket
each lookup can encounter stale peers
each stale peer can cost ~30s
total can become minutes