Repository navigation
feat(service-disco): routing table manager - #2274
Conversation
83e1db0 to
0b74e2c
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2274 +/- ##
==========================================
+ Coverage 72.31% 72.41% +0.09%
==========================================
Files 163 164 +1
Lines 20577 20689 +112
Branches 18 20 +2
==========================================
+ Hits 14881 14982 +101
- Misses 5696 5707 +11
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds per-service Kademlia routing tables for the service-discovery protocol via a new ServiceRoutingTableManager, along with service-specific metrics and unit tests. This also refactors Kademlia’s bucket refresh logic into a reusable refreshTable() proc so non-main routing tables can be refreshed.
Changes:
- Introduces
ServiceRoutingTableManager+ServiceStatusto manage per-serviceRoutingTables seeded from the main table. - Adds
service_discovery_metrics.nimmetrics for service-discovery messaging, registrar cache, and service routing tables. - Refactors
KadDHT.bootstrap()to delegate to a newKadDHT.refreshTable(rtable, ...)and adds unit tests for both routing tables and the manager.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
libp2p/protocols/service_discovery/routing_table_manager.nim |
New manager for per-service routing tables + refresh integration + metrics updates. |
libp2p/protocols/service_discovery/service_discovery_metrics.nim |
New service-discovery metrics declarations (includes routing table gauges/counters). |
libp2p/protocols/service_discovery/types.nim |
Adds ServiceId = Key alias for service routing table identification. |
libp2p/protocols/kademlia.nim |
Adds refreshTable(kad, rtable, ...) and updates bootstrap() to use it. |
tests/libp2p/service_discovery/test_routing_table_manager.nim |
New unit tests for service routing table manager + refreshAllTables behavior. |
tests/libp2p/kademlia/test_routing_table.nim |
New unit tests for routing table insertion/eviction/selection helpers. |
|
|
||
| discard table.insert(peerKey) | ||
| cd_service_table_insertions.inc() |
There was a problem hiding this comment.
table.insert(peerKey) updates the global Kademlia routing-table gauges (kad_routing_table_peers, etc.) as a side effect. Inserting into per-service routing tables will therefore corrupt the Kademlia routing-table metrics. This likely needs a metrics-isolation mechanism (separate metrics for service tables, or a way to disable Kademlia metric updates for these inserts).
There was a problem hiding this comment.
I think this is ok. service tables inserts/deletes/whatever are still kademlia inserts/deletes/whatevers
| for bucket in mainRoutingTable.buckets: | ||
| for peer in bucket.peers: | ||
| discard serviceTable.insert(peer.nodeId) | ||
|
|
There was a problem hiding this comment.
serviceTable.insert(...) calls into kademlia/routing_table.insert, which updates the global kad_routing_table_* gauges/counters. Seeding service routing tables from the main table will therefore overwrite the Kademlia routing table metrics and make them incorrect operationally. Consider adding a “no-metrics” insert path for service tables or moving routing-table metrics updates out of the core RoutingTable.insert API.
There was a problem hiding this comment.
I think this is ok. service tables inserts/deletes/whatever are still kademlia inserts/deletes/whatevers
2051b62 to
c6a8deb
Compare
89138c9 to
a495405
Compare
a495405 to
b4d439b
Compare
f8c40a6 to
a9fa626
Compare
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
be64b83 to
423c403
Compare
Summary
Adds
ServiceRoutingTableManager, enabling per-service Kademlia routing tables seeded from the main DHT, with service status tracking and metrics.Changes
service_routing_tables.nimServiceStatus:Interest,Provided,BothServiceRoutingTableManager:tables: per-serviceRoutingTableserviceStatus: tracks participationnew()— init manageraddService(...)removeService(...)getTable(...)→Opt[RoutingTable]insertPeer(...)— inserts peer, increments metrichasService(...)refreshAllTables(...)— refresh viakad.refreshTablecount(),serviceIds(),clear()Metrics:
Affected Areas
Peer Discovery
Protocol Logic
Compatibility & Downstream Validation
Fully additive
No changes to existing APIs or wire formats
Nimbus / Waku / Codex: no impact
Impact on Library Users
New:
ServiceStatus,ServiceRoutingTableManagerNew APIs:
addService,removeService,getTable,insertPeer,refreshAllTablesRisk Assessment
Extra memory (per-service tables)
Risk: low
Sequential refresh may be slow
Risk: low
Silent no-op on missing service in
insertPeerRisk: low
References