feat(mix): add coverRateFraction config to cover traffic#2322
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a configurable coverRateFraction to Mix ConstantRateCoverTraffic to scale cover emission/precompute rates below the maximum safe rate defined by the spec, with accompanying unit tests.
Changes:
- Introduces
coverRateFraction: float = 0.7(validated to(0.0, 1.0]) and exposes it via an accessor. - Updates emission interval and precomputation sizing logic to incorporate the fraction and precomputes
precomputeTarget. - Adds unit tests covering the new formula, batch sizing impact, range validation, and a small-
fedge case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
libp2p/protocols/mix/cover_traffic.nim |
Adds coverRateFraction, adjusts emission/precompute computations, stores precomputeTarget, and exposes an accessor. |
tests/libp2p/mix/test_cover_traffic.nim |
Adds a new suite validating interval math, batch sizing behavior, parameter validation, and a small-fraction edge case. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2322 +/- ##
==========================================
+ Coverage 73.42% 73.46% +0.03%
==========================================
Files 168 168
Lines 22221 22229 +8
Branches 20 20
==========================================
+ Hits 16316 16330 +14
+ Misses 5905 5899 -6
🚀 New features to boost your workflow:
|
bb78813 to
aa797e0
Compare
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
aa797e0 to
a4b306b
Compare
jm-clius
left a comment
There was a problem hiding this comment.
As far as I can see, this matches the new spec and design intention. :)
| # Effective cover budget after `cover_rate_fraction` scaling: floor(f * R). | ||
| # Clamped to at least 1 so very small f values don't produce a zero divisor. | ||
| let scaledSlots = max(1, (totalSlots.float * coverRateFraction).int) |
There was a problem hiding this comment.
scaledSlots is derived via (totalSlots.float * coverRateFraction).int, which makes the effective slot count sensitive to floating-point representation/truncation (as the test comment notes). Common decimal fractions (e.g. 0.7) can produce values like 69.999… for R=100 and truncate to 69, leading to an off-by-one emission rate and platform-dependent behavior. Consider making the conversion deterministic (e.g., apply an explicit floor with a small epsilon, or use a fixed-point/rational conversion) so coverRateFraction=0.7 reliably maps to 70% of R.
Summary
Adds the
cover_rate_fractionparameter (f ∈ (0.0, 1.0], default 0.7) toConstantRateCoverTraffic, per Mix Cover Traffic spec §7.fscales cover emission rate relative to the max safe rateR / ((1 + L) * P), reserving budget headroom for forwarding spikes.((1 + L) * P) / (f * R)(f * R) / (1 + L)(stored as field, not recomputed)This helps reduce amount of cover traffic to plan and inturn gives more room for other traffic and also reduces proof generation overhead on the node.
Affected Areas
Compatibility & Downstream Validation
API is backward-compatible; new param has a default. Cover traffic is not yet integrated in Nimbus/Waku/Codex.
Impact on Library Users
coverRateFraction: float = 0.7onConstantRateCoverTraffic.new().Risk Assessment
Backward-compatible API; default behavior change is intentional per spec.
References