feat(kad): add provider rejection and spillover#2394
Open
feat(kad): add provider rejection and spillover#2394
Conversation
f09c683 to
2a828c5
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2394 +/- ##
==========================================
- Coverage 73.54% 73.54% -0.01%
==========================================
Files 168 168
Lines 22349 22522 +173
Branches 20 20
==========================================
+ Hits 16436 16563 +127
- Misses 5913 5959 +46
🚀 New features to boost your workflow:
|
2a828c5 to
a72e2dc
Compare
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
7dba6f5 to
57cb483
Compare
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in Kademlia overload-protection path for provider records: receivers can reject ADD_PROVIDER requests when a per-key limit is reached, and advertisers can attempt spillover to farther peers. It extends the Kademlia message/config surface and updates tests/metrics around the new behavior.
Changes:
- Added provider rejection status to Kademlia protobuf messages and a new
maxProvidersPerKeyconfig option. - Changed
ADD_PROVIDERhandling/sending logic to support rejection responses, spillover, and shared batch-waiting behavior. - Enabled and expanded Kademlia tests for the new feature, plus added related metrics.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
tests/libp2p/kademlia/utils.nim |
Adds a test helper to send ADD_PROVIDER and inspect the returned status. |
tests/libp2p/kademlia/test_encoding.nim |
Adds protobuf round-trip coverage for AddProviderStatus. |
tests/libp2p/kademlia/test_add_provider.nim |
Adds rejection/spillover behavioral tests and test-only setup changes. |
tests/config.nims |
Enables the new Kademlia provider-rejection compile flag in test builds. |
libp2p/protocols/kademlia/types.nim |
Adds config for per-key provider limits and a shared async batch helper. |
libp2p/protocols/kademlia/put.nim |
Refactors put batching to use the new shared wait helper. |
libp2p/protocols/kademlia/provider.nim |
Implements response-aware ADD_PROVIDER, rejection handling, and spillover. |
libp2p/protocols/kademlia/protobuf.nim |
Adds protobuf enum/field support for provider acceptance/rejection status. |
libp2p/protocols/kademlia/kademlia_metrics.nim |
Adds counters for provider rejections and spillover rounds. |
libp2p/protocols/kademlia/get.nim |
Refactors get-path batch waiting to use the shared helper. |
libp2p/protocols/kademlia/find.nim |
Exposes the full lookup shortlist in sorted order for spillover candidate selection. |
libp2p/protocols/kademlia.nim |
Adds constructor-time handling for the new config in flagged vs. unflagged builds. |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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
Adds overload protection for Kademlia provider records behind the
-d:kadProviderRejectioncompilation flag.ADD_PROVIDERrequests when a configurable per-key provider limit (maxProvidersPerKey) is reached.Changes by File
libp2p/protocols/kademlia/protobuf.nimAddProviderStatusenum:accepted = 0rejected = 1Messagetype.providerStatus: Opt[AddProviderStatus]libp2p/protocols/kademlia/types.nimDefaultMaxProvidersPerKey = 0(0 = unlimited)maxProvidersPerKey: intinKadDHTConfiglibp2p/protocols/kademlia/find.nimallSortedPeers*(state: LookupState): seq[PeerId]libp2p/protocols/kademlia/provider.nimdispatchAddProviderreturn type:Result[void, string]Result[AddProviderStatus, string]acceptedfor backward compatibility.addProvider:iterativeLookup.ADD_PROVIDERin XOR-distance order.handleAddProvider:maxProvidersPerKey.sendAddProviderResponseto centralize response writing.libp2p/protocols/kademlia/kademlia_metrics.nimkad_provider_rejections_sentkad_provider_spillover_roundstests/libp2p/kademlia/test_add_provider.nim{.define: kadProviderRejection.}to enable flag during tests.AddProviderStatusAffected Areas
ADD_PROVIDERhandling now supports optional rejection responses and spillover logicCompatibility & Downstream Validation
dispatchAddProviderchange:acceptedDownstream Consumers
maxProvidersPerKeyImpact on Library Users
AddProviderStatus:Message.providerStatus:none()unless flag is active and message is a replyKadDHTConfig.maxProvidersPerKey:0(unlimited)KadDHTConfig.new:LookupState.allSortedPeers():kad_provider_rejections_sentkad_provider_spillover_roundsdispatchAddProvider:Risk Assessment
Iterative Lookup Overhead
addProviderusesiterativeLookupunder the flag.getProvidersResponse Handling
ADD_PROVIDER.acceptedTest Flag Scope
{.define: kadProviderRejection.}applies to entire compilation unit.Re-advertisement Exemption
References
https://github.com/vacp2p/roadmap/pull/445/changes#diff-40a4fb71e95fc9a8144b7c1f1e8ac53f49cb50ddf996d67c960b23d362b68bb1