Go-libp2p-kad-dht v0.43.0: routing tables now survive restarts

go-libp2p-kad-dht v0.43.0 saves the DHT routing table and uses it to rejoin the network after a restart.

Why

Until now, every restart started with an empty routing table and rejoined the Amino DHT through the same few bootstrap peers, even though a running node knows hundreds of DHT servers and most of them are still online when it comes back. Rejoining through those known peers makes restarts faster, takes load off the bootstrap peers, and lets nodes rejoin when the bootstrap peers are unreachable. It also makes it easier to hand bootstrap peer operation over to more operators in the future.

What changed

  • The DHT saves its routing table peers, with their addresses, to its datastore every hour and on shutdown.
  • On restart, it can dial the saved peers. They join the routing table through the usual checks, like any other peer.
  • BootstrapOrder picks what to dial first: BootstrapFirst (the default: bootstrap peers first, saved peers as a fallback), PersistedFirst or Concurrent.
  • RoutingTablePersistence(0) turns it off. The LAN DHT in dual doesn’t persist.

Kubo

Kubo integration is ready in ipfs/kubo#11481 as an opt-in flag, Routing.PersistDHTRoutingTable, together with two boxo changes (ipfs/boxo#1220, ipfs/boxo#1223). They are waiting for review and should land in an upcoming Kubo release. The plan is to ship it opt-in first and turn it on by default in a later release.

Measurements

From a week on the live Amino DHT:

  • A Kubo node reached 100 routing table peers in 2.1 s after a restart with persistence, against 11.5–22 s without, using fewer connections and file descriptors.
  • About 70% of saved peers still answered after 7 days, and a week-old snapshot still restored in under a second without contacting any bootstrap peer.
  • A node that had run for a day saved a more stable table: 83% of its peers were still reachable after 5 days.

Details are in libp2p/go-libp2p-kad-dht#1299 and ipfs/kubo#11481.

Feedback welcome, here or on GitHub, especially from projects that embed go-libp2p-kad-dht.

Always happy to see these improvements. But casually writing “should land in an upcoming Kubo release” at the end is literally what we used to call ‘burying the lead.’

Fair point, thanks! The post is mostly about go-libp2p-kad-dht: the feature is released in v0.43.0, so projects embedding the library already get it.

Kubo and boxo currently have no maintainers, so they are frozen for now. The integration is ready in ipfs/kubo#11481, and the feature will hopefully ship in Kubo once new maintainers are designated.