Skip to content

feat(service-disco): add registrar - #2275

Merged
gmelodie merged 26 commits into
masterfrom
feat/service-disco/registrar
Apr 17, 2026
Merged

gmelodie merged 26 commits into
masterfrom
feat/service-disco/registrar

Conversation

@gmelodie

@gmelodie gmelodie commented Apr 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Implements the REGISTER flow for the Logos service-discovery protocol on top of per-service routing tables.
Adds the Registrar with anti-Sybil logic, retry-ticket validation, advertisement cache (LRU), and wires everything through ServiceDiscovery.new. Also consolidates types and expands ServiceDiscoveryConfig into a full configuration with defaults.

Changes

  • libp2p/protocols/service_discovery/types.nim:

    • Expands ServiceDiscoveryConfig with full protocol parameters and constructor.
    • Moves ServiceStatus and ServiceRoutingTableManager here.
    • Adds AdvertisementKey, Advertisement, Registrar, AdvertiseTask, Advertiser.
    • Adds registrar and rtManager to ServiceDiscovery; renames discoveryConfig → discoConfig.
    • Adds helpers: Registrar.new, Advertiser.new, toAdvertisementKey, hashServiceId, advertisesService.
  • libp2p/protocols/service_discovery/registrar.nim (new):

    • adScore, insertAd, removeAd
    • pruneExpiredAds, waitingTime, updateLowerBounds
    • validateRegisterMessage, processRetryTicket
    • sendRegisterResponse, acceptAdvertisement (full admission + LRU + metrics)
  • libp2p/protocols/service_discovery/routing_table_manager.nim:

    • Removes moved types; simplifies imports.
  • libp2p/protocols/service_discovery.nim:

    • Adds/exports routing manager.
    • Implements ServiceDiscovery.new and protocol handler loop (stubs for getAds, register).
  • Tests:

    • Coverage for registrar logic and helpers (test_registrar.nim, utils.nim).

Affected Areas

  • Peer Management / Discovery

    • REGISTER flow, anti-Sybil logic, routing table integration.
  • Protocol Logic

    • Full config, handler loop, advertisement cache with LRU and IP tree.

Compatibility & Downstream Validation

  • ServiceDiscovery.discoveryConfig → discoConfig (breaking rename).
  • ServiceDiscovery.new added; object-literal construction may need updates.
  • Moved types may require import path fixes.

Impact on Library Users

  • Breaking: discoveryConfig → discoConfig.
  • Additive:
    • New fields: registrar, rtManager.
    • New types: Registrar, Advertisement*, Advertiser.
    • New procs: registrar logic + ServiceDiscovery.new.
  • ServiceDiscoveryConfig now fully defined (constructor + defaults).
  • Moved types from routing_table_manager.nim to types.nim.

Risk Assessment

  • IPv6 handling in adScore: now safely skipped (fix).
  • Global LRU eviction: low risk, possible service imbalance.
  • Wall-clock expiry: low risk (clock skew/sleep effects).

References

@gmelodie gmelodie self-assigned this Apr 14, 2026
@gmelodie
gmelodie changed the base branch from master to feat/service-disco/service-routing-tables April 14, 2026 15:14
@gmelodie gmelodie changed the title Feat/service disco/registrar feat(service-disco): registrar Apr 14, 2026
@gmelodie gmelodie changed the title feat(service-disco): registrar feat(service-disco): add registrar Apr 14, 2026
@gmelodie
gmelodie force-pushed the feat/service-disco/registrar branch from c82c531 to 0a3fb63 Compare April 14, 2026 20:05
@gmelodie
gmelodie marked this pull request as ready for review April 14, 2026 20:10
@gmelodie
gmelodie requested a review from a team as a code owner April 14, 2026 20:10
@gmelodie
gmelodie requested review from richard-ramos and vladopajic and removed request for a team April 14, 2026 20:10
@codecov-commenter

codecov-commenter commented Apr 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.90604% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.73%. Comparing base (c65ab1b) to head (14a5c71).

Files with missing lines Patch % Lines
libp2p/protocols/service_discovery/registrar.nim 89.59% 23 Missing ⚠️
libp2p/protocols/service_discovery.nim 74.07% 14 Missing ⚠️
libp2p/protocols/service_discovery/types.nim 78.26% 5 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2275      +/-   ##
==========================================
+ Coverage   72.56%   72.73%   +0.17%     
==========================================
  Files         164      165       +1     
  Lines       20886    21266     +380     
  Branches       20       20              
==========================================
+ Hits        15155    15468     +313     
- Misses       5731     5798      +67     
Files with missing lines Coverage Δ
...tocols/service_discovery/routing_table_manager.nim 97.56% <ø> (+0.03%) ⬆️
libp2p/protocols/service_discovery/types.nim 64.81% <78.26%> (+47.03%) ⬆️
libp2p/protocols/service_discovery.nim 67.58% <74.07%> (-26.76%) ⬇️
libp2p/protocols/service_discovery/registrar.nim 89.73% <89.59%> (ø)

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vladopajic vladopajic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general lgtm, needs more tidying up before merge

if serviceLowerBound > w:
w = serviceLowerBound

for addressInfo in ad.data.addresses:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ad.data.addresses.filterIPv4()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just want filtering IPv4's for iptree related stuff, service discovery supports ipv6. IPTree is a sybil attack mitigation for ipv4 advertisements

doAssert res.isOk(), "sign failed in test helper"
t

proc createTestMultiAddress*(ip: string): MultiAddress =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crate or make stick to one

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aslo Test in name is unecessery

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since these are utilities that will be used everywhere better stick to same convention

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sticking with createSwitch for simplicity (other tests use that name) and changing everything else to makeFoo

@github-project-automation github-project-automation Bot moved this from new to In Progress in nim-libp2p Apr 15, 2026
@gmelodie
gmelodie force-pushed the feat/service-disco/registrar branch 2 times, most recently from 0fee4b6 to 1eeba32 Compare April 15, 2026 17:31
@gmelodie
gmelodie force-pushed the feat/service-disco/service-routing-tables branch from be64b83 to 423c403 Compare April 15, 2026 18:47
@gmelodie
gmelodie force-pushed the feat/service-disco/registrar branch from e4a3701 to 6700ef4 Compare April 15, 2026 18:53
@richard-ramos
richard-ramos requested a review from Copilot April 15, 2026 18:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements the REGISTER side of the Logos service-discovery protocol by introducing a Registrar (admission control + retry ticket handling + ad cache/LRU + IP-tree scoring) and wiring it into ServiceDiscovery alongside consolidated protocol types/config.

Changes:

  • Expanded ServiceDiscoveryConfig with defaults and moved/added core service-discovery types (registrar/cache-related types, routing-table manager types).
  • Added registrar.nim with cache management, waiting-time computation, retry-ticket validation, and advertisement acceptance logic.
  • Added comprehensive unit tests for registrar logic plus shared test helpers.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
libp2p/protocols/service_discovery/types.nim Adds config defaults/constructor and consolidates service-discovery types (registrar + routing-table manager types).
libp2p/protocols/service_discovery/registrar.nim New registrar implementation (waiting-time scoring, pruning/eviction, retry ticket processing, cache + metrics).
libp2p/protocols/service_discovery/routing_table_manager.nim Removes moved type definitions and simplifies imports.
libp2p/protocols/service_discovery.nim Adds ServiceDiscovery.new and wires in registrar + per-service routing manager; adds handler loop scaffolding.
tests/libp2p/service_discovery/utils.nim Adds registrar/discovery construction helpers and advertisement/ticket builders for tests.
tests/libp2p/service_discovery/test_registrar.nim Adds unit test coverage for registrar waiting-time, bounds, pruning, and retry-ticket processing.

Comment thread libp2p/protocols/service_discovery.nim Resolved
Comment thread libp2p/protocols/service_discovery.nim Resolved
Comment thread libp2p/protocols/service_discovery.nim Resolved
@gmelodie
gmelodie force-pushed the feat/service-disco/registrar branch from 09bf42d to dccfe2a Compare April 15, 2026 20:01
Base automatically changed from feat/service-disco/service-routing-tables to master April 15, 2026 21:22
@gmelodie
gmelodie requested review from a team and richard-ramos April 15, 2026 21:22
@gmelodie
gmelodie force-pushed the feat/service-disco/registrar branch from dccfe2a to 17e220a Compare April 16, 2026 13:46
@gmelodie
gmelodie force-pushed the feat/service-disco/registrar branch from 1614eae to 5c12571 Compare April 16, 2026 14:31
@gmelodie
gmelodie enabled auto-merge April 16, 2026 14:55
@gmelodie
gmelodie added this pull request to the merge queue Apr 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 17, 2026
@gmelodie
gmelodie added this pull request to the merge queue Apr 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 17, 2026
@gmelodie
gmelodie enabled auto-merge April 17, 2026 19:13
@gmelodie
gmelodie added this pull request to the merge queue Apr 17, 2026
Merged via the queue into master with commit 1d35075 Apr 17, 2026
35 of 36 checks passed
@gmelodie
gmelodie deleted the feat/service-disco/registrar branch April 17, 2026 21:03
@github-project-automation github-project-automation Bot moved this from In Progress to done in nim-libp2p Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants