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: type-encode the seed-leech cap units (Bytes/Percent newtypes) to close the config→LeechCaps confusion seam #894
kind:featureNew capability or a change to current behaviorprio:lowWhen convenientrustDependabot: a Cargo update; use area: labels for Rust code otherwise
Follow-up from the #893 review (implements #856). Non-blocking; latent-only today.
Problem
The three seed-leech cap knobs are bare u64s carrying two different units, distinguished only by field name, and they are threaded through a second three-u64 struct and wired name-by-name:
Two are byte quantities, one is a percent (scale 100, SHARE_RATIO_SCALE). A transposition (bytes↔percent) compiles, runs, and does not panic (the governor's saturating arithmetic absorbs it), silently mis-pricing the abuse caps. The allowance formula mixes a bytes field and a percent field in one expression (leech_governor.rs:138-143).
Proposal
Introduce Bytes(u64) / Percent(u64) newtypes (ideally in config-types, matching the existing OriginUrl/Hash/PinnedHashes instinct), with Percent owning SHARE_RATIO_SCALE. Thread them through CacheConfig (serde transparent), ResolvedCache, and LeechCaps so a unit transposition becomes a compile error end-to-end.
Scope / why deferred
Touches the serde config surface broadly; a Bytes wrapper ripples into byte arithmetic across leech_governor.rs and client.rs. The type-design review explicitly recommended it as its own small PR rather than bloating #893.
A type-safety refactoring filed from the #893 review: the three seed-leech cap fields are bare u64s with mixed units (bytes and percent-×100), allowing a silent bytes↔percent transposition that compiles, runs without panic, and mis-prices abuse caps. The fix is to introduce Bytes(u64) / Percent(u64) newtypes in config-types and thread them through CacheConfig → ResolvedCache → LeechCaps so a transposition becomes a compile error. Scope is well-scoped to ~5 files; explicitly extracted from #893 to stay focused.
📊 Assessment
Dimension
Value
Reasoning
Type
Task
Pure refactoring for type-safety; no new user-visible behaviour
Labels
unchanged (enhancement, technical, rust, low)
Already accurately set; no additions warranted
Coding agent
Suitable
Requirements, affected files, arithmetic formula locations, and the implementation pattern (mirror OriginUrl/Hash/PinnedHashes in config-types) are all specified. Success criterion is clear: cargo build rejects a bytes↔percent transposition.
💡 Notes and suggestions
Ordering note: this issue was filed against code in the open PR #893. Implement after #893 merges to avoid a rebase conflict on the same three struct fields.
Implementation checklist:
Add Bytes(u64) to crates/config-types/src/lib.rs — serde transparent, derive Copy/Clone/Debug/PartialEq/Eq/PartialOrd/Ord; expose .0 or impl From/Into<u64> for arithmetic sites
Add Percent(u64) to same crate — same derives; move SHARE_RATIO_SCALE: u64 = 100 constant into it (e.g., Percent::SCALE) so callers can't construct a raw-scale value without importing the type
Update CacheConfig (wherever it lives in common) to use Bytes / Percent for the three fields; verify serde(transparent) round-trips against existing TOML fixtures
Update ResolvedCache fields at crates/common/src/config/resolved.rs:218-228
Update LeechCaps fields at crates/node/src/leech_governor.rs:43-57
Fix the wiring at crates/node/src/runtime/mod.rs:960-964 (the name-by-name assignment will now type-check instead of relying on field naming)
Fix the allowance formula at leech_governor.rs:138-143 — likely needs .0 unwraps or arithmetic impl on the newtypes; keep the saturation properties intact
Audit crates/node/src/client.rs for any u64 byte arithmetic on these values
Run cargo clippy --workspace --all-targets and cargo nextest run to confirm no regressions
Design tip: if arithmetic across the two types is needed (e.g., comparing a Bytes field to a Percent-scaled value), make that an explicit named function on Percent (e.g., fn apply_to(self, bytes: Bytes) -> Bytes) rather than impl'ing Mul, to preserve the "this is a deliberate unit cross" intent at the call site in leech_governor.rs:138-143.
kind:featureNew capability or a change to current behaviorprio:lowWhen convenientrustDependabot: a Cargo update; use area: labels for Rust code otherwise
Activity
fix(node): address PR #893 review round 2 (deposit-guard doc, error s…
github-actions commentedon Jun 13, 2026
🎯 Triage report
A type-safety refactoring filed from the #893 review: the three seed-leech cap fields are bare
u64s with mixed units (bytes and percent-×100), allowing a silent bytes↔percent transposition that compiles, runs without panic, and mis-prices abuse caps. The fix is to introduceBytes(u64)/Percent(u64)newtypes inconfig-typesand thread them throughCacheConfig→ResolvedCache→LeechCapsso a transposition becomes a compile error. Scope is well-scoped to ~5 files; explicitly extracted from #893 to stay focused.📊 Assessment
enhancement,technical,rust,low)OriginUrl/Hash/PinnedHashesinconfig-types) are all specified. Success criterion is clear:cargo buildrejects a bytes↔percent transposition.💡 Notes and suggestions
Ordering note: this issue was filed against code in the open PR #893. Implement after #893 merges to avoid a rebase conflict on the same three struct fields.
Implementation checklist:
Bytes(u64)tocrates/config-types/src/lib.rs— serdetransparent, deriveCopy/Clone/Debug/PartialEq/Eq/PartialOrd/Ord; expose.0or implFrom/Into<u64>for arithmetic sitesPercent(u64)to same crate — same derives; moveSHARE_RATIO_SCALE: u64 = 100constant into it (e.g.,Percent::SCALE) so callers can't construct a raw-scale value without importing the typeCacheConfig(wherever it lives incommon) to useBytes/Percentfor the three fields; verifyserde(transparent)round-trips against existing TOML fixturesResolvedCachefields atcrates/common/src/config/resolved.rs:218-228LeechCapsfields atcrates/node/src/leech_governor.rs:43-57crates/node/src/runtime/mod.rs:960-964(the name-by-name assignment will now type-check instead of relying on field naming)leech_governor.rs:138-143— likely needs.0unwraps or arithmetic impl on the newtypes; keep the saturation properties intactcrates/node/src/client.rsfor anyu64byte arithmetic on these valuescargo clippy --workspace --all-targetsandcargo nextest runto confirm no regressionsDesign tip: if arithmetic across the two types is needed (e.g., comparing a
Bytesfield to aPercent-scaled value), make that an explicit named function onPercent(e.g.,fn apply_to(self, bytes: Bytes) -> Bytes) rather than impl'ingMul, to preserve the "this is a deliberate unit cross" intent at the call site inleech_governor.rs:138-143.Add this agentic workflows to your repo
To install this agentic workflow, run
feat(node): window-paced pull-through for regional proxy warming (#856)…
refactor(node): type-encode seed-leech cap units with Bytes/Percent n…
refactor(node): thread Bytes through leech-governor + window math (#910…
refactor(workspace,contracts)!: delete dead code found by the mechani…