Repository navigation
Description
Split out of the review on #1456 (rather than widening a deletion PR).
What
crates/node/src/rate_limit.rs has two From impls mapping ResolvedDht / ResolvedProbe (in decdn-common) onto the engine-local RateLimitConfig. They are the single mapping point the runtime uses (crates/node/src/runtime/mod.rs:857 and :902), and the comment above them used to claim centralizing there "lets the compiler catch a field transposition between the two parallel representations."
That claim is false. After #1440 removed trusted_ips: HashSet<IpAddr>, all eight remaining fields are f64 / u32 / usize, so every one can be swapped with a same-typed sibling and still compile:
| Swap | Compiles? |
|---|---|
per_peer_rate_per_sec ↔ per_ip_rate_per_sec ↔ global_rate_per_sec |
yes |
per_peer_burst ↔ per_ip_burst ↔ global_burst |
yes |
max_tracked_per_ip ↔ max_tracked_per_peer |
yes |
The exhaustive struct literals do catch an added or dropped field, which is worth having — but that is arity, not transposition, and any struct literal without ..Default::default() gets it for free. The comment has been corrected in #1456 to say what it actually buys; this issue is about closing the gap.
Why it matters
grep finds no test covering either impl — every rate-limiter test builds RateLimitConfig by hand rather than going through the From. Two aggravating factors:
- The two impl bodies are now byte-identical, so a transposition introduced in one and not the other is invisible to review-by-diff.
- The defaults differ meaningfully. DHT is
per_peer 20/40, per_ip 100/200; probe isper_peer 5/5, per_ip 50/200(ADR 005 deliberately tighter, since probes are unauthenticated and cheap to flood). Aper_peer↔per_iptransposition in the probe impl would loosen the per-peer probe cap from 5 req/s to 50 req/s — a security-relevant misconfiguration on an unauthenticated path, silently.
Proposed fix
One test per impl, ~20 lines total: build a ResolvedDht / ResolvedProbe with eight pairwise-distinct sentinel values and assert each lands in its matching RateLimitConfig slot. That makes the centralization argument load-bearing and costs less than the comment defending it did.
Then restore the stronger wording in the comment at crates/node/src/rate_limit.rs:101-108.
Related
- Remove the trusted-IP rate-limit exemption (ADR 005/022) #1440 / refactor: drop two dead knobs — min-reputation floor and trusted-IP rate-limit exemption #1456 — removed the one type-distinguished field, which is what took this from ~90% false to 100% false.
- A larger follow-up worth considering separately: there are now five structurally identical eight-field rate-limit structs across two crates (
Dht/ProbeRateLimitConfig,ResolvedDht/ResolvedProbe,RateLimitConfig), differing only inDefaultvalues and doc prose. A sharedRateLimitTuningin theconfig-typesleaf crate is newly unblocked now thattrusted_ips(the field that would have draggedstd::netin) is gone. The cost is losing the per-ADR default doc prose ("Absent => 20 req/s" vs "Absent => 5 req/s"), which is a genuine feature — judgement call, not a must.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
fix: address review findings on the #1438/#1440 removal
refactor: drop two dead knobs — min-reputation floor and trusted-IP r…
test(rate-limit): put the sentinel assertions under the arity guard too
fix(rate-limit): correct the mapping-guard comments and close the wir…
fix(rate-limit): pin the From<&Resolved*> mappings and make limiter w…