Repository navigation
Description
Follow-up spotted while reviewing #1462 (which closed #1457 for the From<&Resolved*> for RateLimitConfig impls). Same failure class, one layer up.
The gap
#1457 covered the Resolved* -> RateLimitConfig mapping. Those From call sites are themselves safe by construction — RateLimitConfig::from(&cfg.probe) and ::from(&cfg.dht) take distinct types, so the type system picks the impl and a swap there cannot compile.
The next step is not protected. In crates/node/src/runtime/mod.rs:
let probe_rate_limit_cfg = RateLimitConfig::from(&cfg.probe); // :857
let probe_rate_limiter = Arc::new(ProbeRateLimiter::new(&probe_rate_limit_cfg, ...)); // :858
...
let dht_rate_limit_cfg = RateLimitConfig::from(&cfg.dht); // :902
let dht_rate_limiter = Arc::new(DhtRateLimiter::new(&dht_rate_limit_cfg, ...)); // :903ProbeRateLimiter and DhtRateLimiter are distinct newtypes over ThreeLayerRateLimiter, but both constructors take &RateLimitConfig. The two locals are therefore interchangeable: passing dht_rate_limit_cfg to ProbeRateLimiter::new compiles clean, and nothing catches it. The declarations sit ~45 lines apart, so proximity does not help review either.
Why it matters
The two paths have deliberately different defaults, and the probe side is the tighter one (ADR 005 vs ADR 022):
| per-peer | per-IP | |
|---|---|---|
probe (ResolvedProbe::default) |
5.0 req/s, burst 5 | 50.0 req/s, burst 200 |
DHT (ResolvedDht::default) |
20.0 req/s, burst 40 | 100.0 req/s, burst 200 |
Feeding the probe limiter the DHT config silently loosens the per-peer probe cap 4x and the per-IP cap 2x on an unauthenticated path — the same category of quiet security regression #1457 was filed about, just at the wiring layer instead of the mapping layer.
Suggested fix
The From-impl approach does not transfer directly, since here the source type is the same on both sides. Options, roughly in increasing order of cost:
- Make the constructors take their own newtype (
ProbeRateLimitConfig/DhtRateLimitConfig) so the compiler picks the pairing — turns this into an arity/type problem, matching how theFromcall sites are already safe. - Have
ProbeRateLimiter::new/DhtRateLimiter::newtake the&Resolved*directly and do theFrominternally, removing the intermediate locals entirely. - A bring-up test that asserts each limiter reports its own ADR defaults — weaker, since it pins observable behavior rather than preventing the swap.
Option 1 or 2 would let the *_mapping_is_not_transposed tests stay as the transposition guard and hand this layer back to the compiler.
Notes
Not urgent — no known miswiring today; both locals are correct on main. Filed separately rather than folded into #1462 because it touches runtime wiring and possibly the limiter constructor signatures, neither of which is in that PR's diff.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
thiras commentedon Jul 26, 2026
Already resolved on
mainby #1462 (519fba2f), which took Option 2 from this issue:ProbeRateLimiter::new/DhtRateLimiter::newgainedfrom_resolvedconstructors that take&ResolvedProbe/&ResolvedDhtand do theFrominternally, and runtime bring-up now calls those.The two swappable locals this issue describes are gone:
Feeding the probe limiter the DHT config is now a type error rather than a silent 4x loosening of the per-peer probe cap. The only remaining
RateLimitConfig::from(...)call sites incrates/node/srcare inside the twofrom_resolvedbodies (where the source type picks the impl) and in tests. Both constructors carry doc comments describing exactly the swap this issue was filed about —crates/node/src/handlers/probe_rate_limit.rs:91-105andcrates/node/src/dht/rate_limit.rs:86-101— and the*_mapping_is_not_transposedtests remain the guard one layer down.Verified while batching #1466 / #1464 / #1459 in #1469.