Skip to content

node: thread Bytes through leech-governor accumulators + client.rs window math (full-arithmetic newtype, follow-up to #894) #910

Closed

Description

@yigitdot

Follow-up to #894, which introduced Bytes/Percent newtypes at the boundary only (CacheConfig → ResolvedCache → LeechCaps fields/constructor), unwrapping to u64 at the edge. The internal byte arithmetic is still bare u64.

Scope

Push Bytes deeper so byte arithmetic is type-checked end-to-end, not just at the config/caps boundary:

  • crates/node/src/leech_governor.rs: change the accumulators — LeechState.{global_pulled, global_served} and PeerLeech.{pulled, served} — from u64 to Bytes, and the record_pulled/record_served/poll_admission math along with them.
  • crates/node/src/handlers/client.rs: the window-paced serve loop's window/pulled/served_paid arithmetic (currently u64, fed by pull_ahead_bytes: OnceLock<u64>).
  • Add the needed ops to Bytes in crates/config-types/src/bytes.rs: saturating_add/saturating_sub, a Percent::scale_saturating-style multiply already exists, plus Ord (already derived).

Why deferred

#894 review chose boundary-only as the small PR. This variant ripples into hot-path arithmetic across two files and is a larger review/audit surface for a latent-only safety gain, so it was split out.

Refs

Activity

  1. added
    kind:feature
    rust
    prio:low
    on Jun 15, 2026
  2. github-actions commented on Jun 15, 2026

    @github-actions

    🎯 Triage report

    Follow-up to #894, which landed Bytes/Percent newtypes at the config→LeechCaps boundary but left internal accumulators and hot-path arithmetic as bare u64. This issue extends type safety end-to-end into leech_governor.rs and client.rs. The scope is latent-only (no runtime behavior change), and the file targets and required API additions are precisely enumerated — a mechanical type-threading refactor.

    📊 Assessment

    Dimension Value Reasoning
    Type Task Refactoring/type-safety improvement with no observable behavior change
    Labels enhancement, technical, rust, low (unchanged) Already correct: internal type hygiene, Rust-specific, low urgency
    Coding agent Suitable Exact file paths, field names, and required ops (saturating_add/saturating_sub on Bytes) are all specified; success criteria is compile-clean with existing tests passing; self-contained scope with no design decisions open

    🔗 Similar issues

    💡 Notes and suggestions

    Dependency order: #894 must merge first — Bytes and Percent are defined there. This issue is blocked until that PR lands.

    Files to touch (exact):

    1. crates/config-types/src/bytes.rs — add impl Bytes { pub fn saturating_add(self, rhs: Self) -> Self and saturating_sub. Ord is already derived. Check whether Add/Sub trait impls are also worth adding for ergonomics in the arithmetic-heavy callers.
    2. crates/node/src/leech_governor.rs — change LeechState.{global_pulled, global_served} and PeerLeech.{pulled, served} from u64 to Bytes; update record_pulled/record_served/poll_admission.
    3. crates/node/src/handlers/client.rs — change pull_ahead_bytes: OnceLock<u64> to OnceLock<Bytes>; update the window-paced serve-loop arithmetic.

    Anti-panic policy reminder: All arithmetic on Bytes accumulators must remain saturating_* — no direct +/- operator impls that could panic under the workspace-wide clippy::integer_arithmetic deny, or simply avoid overloading Add/Sub if that triggers the lint.

    Suggested subtask checklist:

    • Add saturating_add / saturating_sub to Bytes in config-types
    • Update LeechState and PeerLeech accumulator fields to Bytes
    • Update record_pulled / record_served / poll_admission arithmetic
    • Update pull_ahead_bytes: OnceLock in client.rs and surrounding window math
    • cargo clippy clean, cargo nextest run -p decdn-node green

    Generated by Agentic Triage for issue #910 · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  3. self-assigned this
    on Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:featureprio:lowrust

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions