fix(service-disco): initialise the network size estimator - #2920
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2920 +/- ##
==========================================
- Coverage 82.21% 82.20% -0.02%
==========================================
Files 175 175
Lines 31559 31585 +26
Branches 13 12 -1
==========================================
+ Hits 25945 25963 +18
- Misses 5614 5622 +8
🚀 New features to boost your workflow:
|
gmelodie
force-pushed
the
fix/service-disco/missing-field
branch
from
August 7, 2026 19:06
830bd9b to
5ad6b88
Compare
gmelodie
marked this pull request as ready for review
August 7, 2026 19:07
gmelodie
enabled auto-merge
August 7, 2026 19:08
richard-ramos
approved these changes
Aug 8, 2026
vladopajic
approved these changes
Aug 8, 2026
vladopajic
reviewed
Aug 8, 2026
| discoConfig: discoConfig, | ||
| xprPublishing: xprPublishing, | ||
| ) | ||
| disco.initKadBase(switch, config, rng, isServer = not client) |
Member
There was a problem hiding this comment.
isServer = not isClient
in general code shouldn't really do twists like this,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ServiceDiscovery.newbuilt theKadDHTbase object field by field and missednsEstimator.KadDHT.newset that field, so only a node that mounts service discovery carried a nil estimator.Every provider path reads the estimator, so a provide on such a node segfaults:
addProvidercallskad.nsEstimator.networkSize()atlibp2p/protocols/kademlia/provider.nim:314.maybeTrackNetsizecallskad.nsEstimator.track()atlibp2p/protocols/kademlia/provider.nim:252.The crash happens with
optimisticProvideon and off, becausemaybeTrackNetsizeruns on both branches. This is the downstream trace, from the logos-libp2p-module tutorial job, which callsstartProvidingthrough the C bindings on a node that mounts service discovery:Two constructors that build the same base object are the reason one field went missing, so the fix removes the duplication instead of patching one line.
initKadBaseinlibp2p/protocols/kademlia.nimnow sets every shared field, including the routing table both constructors built from the same three config values.KadDHT.newandServiceDiscovery.newboth call it, andServiceDiscovery.newkeeps only its own fields. The next base field reaches both protocols on its own.Affected Areas
KadDHTandServiceDiscoveryconstruction, and the Kademlia provider paths a service discovery node reaches.Compatibility & Downstream Validation
The signatures of
KadDHT.newandServiceDiscovery.newdo not change, andinitKadBasesets the same fields to the same values the two constructors set before, so no downstream project needs an adaptation.KadDHT.newbehaviour, so a Nimbus node observes no difference.masterpin. See fix(service-disco): advertise a caller-supplied XPR logos-co/logos-libp2p-module#99.Impact on Library Users
No API change. A
ServiceDiscoverynode now provides keys instead of crashing. A user who avoidedstartProvidingandaddProvideron a service discovery node to dodge the crash can drop that workaround.Risk Assessment
Low.
initKadBaseassigns the fields the two constructors assigned inline, with the same expressions. The estimator starts empty, sonetworkSizereturns "not enough data" until enough lookups converge, which is the state a plainKadDHTnode already starts in. The new indirection runs one time per node, at construction.The refactor touches
KadDHT.new, which every Kademlia user reaches, so the field-by-field diff is worth a close read.References
Additional Notes
tests/libp2p/service_discovery/component/test_add_provider.nimprovides a key between two service discovery nodes, which is the shortest path to the same crash. It reproduces the SIGSEGV onmasterand passes with the fix.