feat(dht)!: add trust quarantine thresholds#119
Open
mickvandijke wants to merge 8 commits into
Open
Conversation
Add close-group quarantine below 0.20 with natural readmission at 0.45. Keep 0.35 as lazy swap eligibility, avoid quarantined peers in automatic lookups, and keep explicit sends unblocked. BREAKING CHANGE: AdaptiveDhtConfig now includes quarantine_threshold and quarantine_readmit_threshold fields.
c5f7387 to
8721feb
Compare
Implement stricter trust gating for K-closest set admission and readmission, adding support for filtering newly promoted peers below the readmission threshold. Update routing table logic and wire compatibility to stabilize behavior across nodes. Extend related tests and documentation. BREAKING CHANGE: Adjusts close-group thresholds affecting trust-based peer routing and admission policies.
Gate all new routing-table admissions at quarantine_readmit_threshold while allowing existing routing-table peers above the quarantine threshold to stay and move into the close group. BREAKING CHANGE: new peers below quarantine_readmit_threshold are no longer admitted to the routing table, even for non-close routing slots.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a trust-based quarantine policy for DHT routing, adding separate thresholds for (1) swap eligibility, (2) quarantine/automatic-avoidance, and (3) new-peer admission/readmission, and propagates that policy through routing-table admission, lookup candidate selection, and DHT maintenance flows.
Changes:
- Extend
AdaptiveDhtConfig/DhtNetworkConfigto include quarantine thresholds and validate/enforce them throughout DHT operations. - Add close-group quarantine enforcement (evict low-trust close peers when RT has surplus above K) and filter quarantined/below-threshold peers from local lookup results and automatic maintenance paths.
- Update integration tests and documentation to reflect the new trust threshold semantics and breaking config changes.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/trust_flow.rs | Updates tests to build AdaptiveDhtConfig with new fields via ..Default::default(). |
| tests/sybil_protection.rs | Updates docs/comments and config construction to align with quarantine + swap semantics. |
| src/network.rs | Updates node config docs and builder toggle to enable/disable all adaptive thresholds coherently. |
| src/dht/core_engine.rs | Adds quarantine thresholds/state and enforcement logic + extensive unit tests for threshold behavior. |
| src/dht_network_manager.rs | Applies quarantine filtering to lookup/bootstrap/refresh/self-lookup paths and re-runs quarantine after admissions. |
| src/adaptive/dht.rs | Adds new config fields, validation, propagation into the manager config, and triggers quarantine enforcement after trust updates. |
| README.md | Updates high-level trust system description to reflect quarantine model. |
| docs/trust-signals-api.md | Re-documents API semantics around the new thresholds and behavior. |
| docs/SECURITY_MODEL.md | Updates security model docs to match quarantine-based routing enforcement. |
| docs/ROUTING_TABLE_DESIGN.md | Updates routing-table design invariants/threshold descriptions to reflect quarantine + admission gating. |
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
[0.20, 0.45): they may remain in the table and can move into the close group, while peers below 0.20 are avoided by automatic lookup/dial paths.Breaking Changes
AdaptiveDhtConfignow includesquarantine_thresholdandquarantine_readmit_threshold.quarantine_readmit_thresholdbefore admission when trust quarantine is enabled.quarantine_thresholdare no longer handed out through DHT lookup results or used by automatic lookup/dial maintenance paths.Tests
Greptile Summary
This PR adds a three-tiered trust quarantine policy to the DHT routing layer: a 0.20 eviction/avoidance threshold, a 0.45 new-peer admission threshold, and the existing 0.35 lazy-swap threshold. The implementation gates new routing-table admissions, close-group evictions, local lookup results, automatic lookup/dial paths, bootstrap, and bucket refresh.
quarantine_thresholdandquarantine_readmit_thresholdfields toAdaptiveDhtConfig,DhtNetworkConfig, andDhtCoreEngine, wired end-to-end fromAdaptiveDHTthroughDhtNetworkManagerto the core routing engine.enforce_close_group_trust_gate,check_new_peer_admission,should_avoid_for_lookup, andshould_avoid_automatic_candidateas new trust-gating primitives guarded byquarantine_enabled().broadcast_routing_events_with_quarantineto run deferred close-group evictions after any routing-table admission and emit a single mergedKClosestPeersChangedevent.Confidence Score: 4/5
The new quarantine logic is well-tested, correctly gated behind quarantine_enabled(), and does not block explicit sends. All automatic lookup paths consistently apply the new filters.
The three-threshold eviction and lookup-filtering paths are covered by purpose-built unit tests exercising boundary conditions, deferred eviction, and readmission. The _previous_close_group dead parameter and quarantined_peers growth under adversarial churn are notable open questions but neither breaks current behaviour.
src/dht/core_engine.rs — the enforce_close_group_trust_gate dead parameter and quarantined_peers unbounded growth warrant a second look before long-running node deployments.
Important Files Changed
_previous_close_groupparameter inenforce_close_group_trust_gateis accepted at every call site but unused.quarantined_peersHashSet has no upper-bound or expiry mechanism.broadcast_routing_events_with_quarantinecorrectly merges admission and quarantine-eviction events into a singleKClosestPeersChanged.AdaptiveDhtConfigwith validation, defaults, and propagation. Tests cover defaults, validation, and threshold ordering.trust_enforcement(false)zeroes all three thresholds;trust_enforcement(true)uses fullAdaptiveDhtConfig::default()...Default::default()for the two new fields; test intent unchanged.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Trust event reported] --> B[Update TrustEngine score] B --> C[enforce_trust_quarantine] C --> D{trust_engine present?} D -- No --> Z[return false] D -- Yes --> E[enforce_close_group_trust_gate] E --> F{quarantine enabled?} F -- No --> G[return empty events] F -- Yes --> H{node_count > K AND K-closest peer below quarantine_threshold?} H -- No --> I[return empty events] H -- Yes --> J[evict peer, add to quarantined_peers] J --> H J --> K[emit PeerRemoved + KClosestPeersChanged] K --> L[broadcast_routing_events] M[New peer admission] --> N{peer already known?} N -- No --> O[check_new_peer_admission] O --> P{quarantine enabled?} P -- No --> Q[admit peer] P -- Yes --> R{trust >= readmit_threshold?} R -- No --> S[Reject] R -- Yes --> T[remove from quarantined_peers, admit] T --> U[broadcast_routing_events_with_quarantine] U --> V{PeerAdded or KClosestPeersChanged?} V -- No --> W[broadcast directly] V -- Yes --> X[enforce_close_group_trust_gate deferred pass] X --> Y[merge KClosestPeersChanged, broadcast] AA[Automatic lookup / bootstrap / bucket refresh] --> AB[should_avoid_automatic_peer] AB --> AC{quarantine enabled?} AC -- No --> AD[include peer] AC -- Yes --> AE{trust below quarantine_threshold OR quarantined and below readmit?} AE -- Yes --> AF[skip peer] AE -- No --> AG{unknown peer below readmit_threshold?} AG -- Yes --> AF AG -- No --> ADPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(docs): document adaptive trust enfor..." | Re-trigger Greptile