You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
node: thread Bytes through leech-governor accumulators + client.rs window math (full-arithmetic newtype, follow-up to #894) #910
kind:featureNew capability or a change to current behaviorprio:lowWhen convenientrustDependabot: a Cargo update; use area: labels for Rust code otherwise
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.
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
Dependency order:#894 must merge first — Bytes and Percent are defined there. This issue is blocked until that PR lands.
Files to touch (exact):
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.
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.
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
kind:featureNew capability or a change to current behaviorprio:lowWhen convenientrustDependabot: a Cargo update; use area: labels for Rust code otherwise
Activity
github-actions commentedon Jun 15, 2026
🎯 Triage report
Follow-up to #894, which landed
Bytes/Percentnewtypes at the config→LeechCapsboundary but left internal accumulators and hot-path arithmetic as bareu64. This issue extends type safety end-to-end intoleech_governor.rsandclient.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
enhancement,technical,rust,low(unchanged)saturating_add/saturating_subonBytes) are all specified; success criteria is compile-clean with existing tests passing; self-contained scope with no design decisions open🔗 Similar issues
Bytes/Percentnewtypes at the boundary; this issue is the explicitly deferred second steppull_ahead_bytesseam now targeted here💡 Notes and suggestions
Dependency order: #894 must merge first —
BytesandPercentare defined there. This issue is blocked until that PR lands.Files to touch (exact):
crates/config-types/src/bytes.rs— addimpl Bytes { pub fn saturating_add(self, rhs: Self) -> Selfandsaturating_sub.Ordis already derived. Check whetherAdd/Subtrait impls are also worth adding for ergonomics in the arithmetic-heavy callers.crates/node/src/leech_governor.rs— changeLeechState.{global_pulled, global_served}andPeerLeech.{pulled, served}fromu64toBytes; updaterecord_pulled/record_served/poll_admission.crates/node/src/handlers/client.rs— changepull_ahead_bytes: OnceLock<u64>toOnceLock<Bytes>; update the window-paced serve-loop arithmetic.Anti-panic policy reminder: All arithmetic on
Bytesaccumulators must remainsaturating_*— no direct+/-operator impls that could panic under the workspace-wideclippy::integer_arithmeticdeny, or simply avoid overloadingAdd/Subif that triggers the lint.Suggested subtask checklist:
saturating_add/saturating_subtoBytesinconfig-typesLeechStateandPeerLeechaccumulator fields toBytesrecord_pulled/record_served/poll_admissionarithmeticpull_ahead_bytes: OnceLockinclient.rsand surrounding window mathcargo clippyclean,cargo nextest run -p decdn-nodegreenAdd this agentic workflows to your repo
To install this agentic workflow, run
refactor(node): type-encode seed-leech cap units with Bytes/Percent n…