Skip to content

feat(mix): add coverRateFraction config to cover traffic#2322

Merged
chaitanyaprem merged 4 commits into
masterfrom
feat/cover-rate-fraction
Apr 27, 2026
Merged

feat(mix): add coverRateFraction config to cover traffic#2322
chaitanyaprem merged 4 commits into
masterfrom
feat/cover-rate-fraction

Conversation

@chaitanyaprem
Copy link
Copy Markdown
Contributor

@chaitanyaprem chaitanyaprem commented Apr 23, 2026

Summary

Adds the cover_rate_fraction parameter (f ∈ (0.0, 1.0], default 0.7) to ConstantRateCoverTraffic, per Mix Cover Traffic spec §7. f scales cover emission rate relative to the max safe rate R / ((1 + L) * P), reserving budget headroom for forwarding spikes.

  • Emission interval: ((1 + L) * P) / (f * R)
  • Precompute target: (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

  • Gossipsub
  • Transports
  • Peer Management / Discovery
  • Protocol Logic — mix cover traffic
  • Build / Tooling
  • Other

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

  • New optional coverRateFraction: float = 0.7 on ConstantRateCoverTraffic.new().

Risk Assessment

Backward-compatible API; default behavior change is intentional per spec.

References

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-f edge 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.

Comment thread libp2p/protocols/mix/cover_traffic.nim Outdated
Comment thread libp2p/protocols/mix/cover_traffic.nim Outdated
Comment thread libp2p/protocols/mix/cover_traffic.nim
Comment thread libp2p/protocols/mix/cover_traffic.nim Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 73.46%. Comparing base (adb2743) to head (4242c5c).

Files with missing lines Patch % Lines
libp2p/protocols/mix/cover_traffic.nim 90.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Files with missing lines Coverage Δ
libp2p/protocols/mix/cover_traffic.nim 73.38% <90.00%> (+1.72%) ⬆️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread libp2p/protocols/mix/cover_traffic.nim
Comment thread libp2p/protocols/mix/cover_traffic.nim Outdated
chaitanyaprem and others added 2 commits April 24, 2026 10:46
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@chaitanyaprem chaitanyaprem force-pushed the feat/cover-rate-fraction branch from aa797e0 to a4b306b Compare April 24, 2026 05:16
Copy link
Copy Markdown
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see, this matches the new spec and design intention. :)

@gmelodie gmelodie changed the title feat(mix): add cover_rate_fraction config to cover traffic feat(mix): add coverRateFraction config to cover traffic Apr 24, 2026
@github-project-automation github-project-automation Bot moved this from new to In Progress in nim-libp2p Apr 24, 2026
@chaitanyaprem chaitanyaprem enabled auto-merge (squash) April 24, 2026 15:40
Copilot AI review requested due to automatic review settings April 24, 2026 15:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +197 to +199
# 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)
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@chaitanyaprem chaitanyaprem merged commit 02bb4cf into master Apr 27, 2026
24 checks passed
@chaitanyaprem chaitanyaprem deleted the feat/cover-rate-fraction branch April 27, 2026 17:08
@github-project-automation github-project-automation Bot moved this from In Progress to done in nim-libp2p Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants