Repository navigation
feat(reputation): local EWMA scoring (ADR 008 §3, §14a) (#321) - #468
Conversation
Implements per-peer EWMA reputation scoring in the previously-stub
`decdn-reputation` crate. Scope is ADR 008 §14a (PoC):
- `LocalReputation` store keyed by `iroh::PublicKey`, RwLock-shared
- `Outcome::{Unreachable, Corruption, Delivered{bytes, elapsed}}` enum
forecloses nonsensical states (e.g. unreachable-but-delivered)
- `LocalReputationConfig` with ADR §3 defaults (α=0.1, initial=0.5,
weights 40/40/20) validated at `LocalReputation::new`; rejects
non-finite values, weights not summing to 1.0, zero `expected_bps`
- §8 per-report ±0.05 clamp wired but defaults to no-op (1.0) per
§14a's "no clamping" PoC scope; production opts in via config
- 17 unit tests including default-config pinning, zero-elapsed safety,
multi-thread concurrency, and config-validation rejects
In-memory only — persistence is intentionally not implemented per ADR
008 §14a.3, superseding the `data_dir` line in the issue body. Network
gossip aggregation deferred to #326; outcome producer wiring waits on
#317 (paid delivery handler); selection consumer waits on #380.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Implements ADR 008 PoC-scope local reputation scoring in decdn-reputation by replacing the prior stub/gossip-oriented surface with an in-memory per-peer EWMA model keyed by iroh::PublicKey. This provides the leaf-level API that future node-side outcome producers and selection consumers can integrate without bringing in persistence or gossip aggregation yet.
Changes:
- Added
LocalReputationin-memory store with per-peer EWMA folding and thread-safe access (RwLock<HashMap<...>>). - Introduced
Outcome(typed delivery outcome signals) andLocalReputationConfigwith construction-time validation viaLocalReputation::new. - Updated the crate root to expose the new local-scoring API and clarify PoC scope in docs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/reputation/src/local.rs | Adds the full local EWMA reputation model (config, outcome type, scoring, validation) plus comprehensive unit tests. |
| crates/reputation/src/lib.rs | Updates crate-level docs to reflect PoC scope and re-exports the new local reputation API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Code Review
This pull request implements a local reputation scoring system for deCDN nodes according to ADR 008, using an in-memory EWMA model to evaluate peer performance based on reachability, correctness, and delivery speed. The implementation provides thread-safe score management and extensive unit tests. Feedback identifies a potential memory exhaustion issue due to the unbounded growth of the peer score map and recommends implementing an eviction strategy for inactive peers.
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
Summary
Implements PoC-scope local reputation scoring in
crates/reputation/, which was a stub. Closes #321.LocalReputation— per-peer EWMA store keyed byiroh::PublicKey,Arc-shareable,RwLock-protectedOutcome::{Unreachable, Corruption, Delivered{bytes, elapsed}}— sum type forecloses nonsensical signal combinations at the type levelLocalReputationConfig— ADR §3 defaults validated at construction (LocalReputation::new -> Result<Self, ConfigError>); rejects NaN/inf, out-of-[0,1], weights not summing to 1.0, andexpected_bps == 0so a single bad config can't NaN-poison every future score#[non_exhaustive]onOutcomeandLocalReputationConfigfor forward-compat with Implement network reputation gossip aggregation (ReputationReport) #326 / paid deliverySpec mapping (ADR 008)
local_score = ewma(prev, sample, α=0.1)LocalReputation::foldinteraction = 0.4·speed + 0.4·correctness + 0.2·reachabilityLocalReputation::interaction_scorespeed_score = min(1, actual_bps / expected_bps)(default 10 MiB/s)speed_scorefree fnmax_delta_per_updatefield — wired but defaults to1.0(no-op) per §14adata_dirlineOut of scope (deferred)
crates/node/— needs paid-delivery handler (Implement cdn/client/v1 paid delivery protocol (StreamRequest, StreamResponse, ChunkData, vouchers) #317)crates/node/src/selection.rs)cdn/reputation/v1— issue Implement network reputation gossip aggregation (ReputationReport) #326Test plan
cargo nextest run -p decdn-reputation— 17/17 passcargo nextest run --workspace— 509/509 pass, no regressionscargo clippy --workspace --all-targets -- -D warnings— clean (anti-panic compliant:PoisonError::into_innerfor lock recovery,clampfor f64 bounds, zero-elapsed guard inspeed_score)cargo fmt --all -- --check— cleanconcurrent_record_and_score_does_not_lose_updates— 8 threads × 1000 ops, snapshot consistency + score-in-rangeinvalid_config_rejected— NaN α, zeroexpected_bps, weight-sum mismatch, out-of-rangeinitial_scoredefault_config_matches_adr_008_section_3speed_score_function_is_correctNotes for reviewers
node/src/lib.rsedits.crates/reputation/.🤖 Generated with Claude Code