Repository navigation
fix(config): reject rate_per_mb = 0 at config resolution - #251
Merged
Merged
Conversation
The payment rate participates in the node selection score defined in ADR 001 (`rate_per_mb × rtt_ms × (1 / max(reputation, 0.1)²)`) and in the rate-mismatch evidence path in ADR 014. A zero rate would let a node trivially win every client selection while earning no payable revenue — a misconfiguration that should fail startup loudly, not silently degrade the network later. Change `resolve_payment` to return `anyhow::Result<ResolvedPayment>` and ensure `rate_per_mb > 0` after CLI / file / default merge. Cover both sources with unit tests, pin CLI-overrides-file precedence so a zero file value doesn't short-circuit a valid override, and lock the default pass-through. The receiver-side defense (clients must also reject `ProbeResponse` / `StreamResponse` with `rate_per_mb == 0`) is out of scope here; the client selection code does not exist yet. Tracked as a follow-up. Closes #234 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request updates the configuration resolution logic to ensure that the rate_per_mb payment setting is greater than zero, preventing potential misconfigurations in the node selection algorithm. The resolve_payment function now returns an anyhow::Result, and corresponding error handling has been added to resolve_config. Additionally, several unit tests were introduced to verify the validation logic and the priority of CLI arguments over configuration files. I have no feedback to provide.
3 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reject
payment.rate_per_mb == 0at config resolution time instead of letting the node start with a silently-broken rate.The value participates in the node selection score defined in ADR 001 (
rate_per_mb × rtt_ms × (1 / max(reputation, 0.1)²)) and in the rate-mismatch evidence path in ADR 014. A zero rate would let a node trivially win every client selection while earning no payable revenue — an obvious misconfiguration that should fail startup loudly, not silently degrade the network later.Changes
resolve_paymentnow returnsanyhow::Result<ResolvedPayment>and callsanyhow::ensure!(rate_per_mb > 0, …)after the CLI / file / default merge.resolve_configthreads the?through.resolve_paymentcites ADR 001 / ADR 014 so the constraint is discoverable.resolve_payment_rejects_zero_from_cliresolve_payment_rejects_zero_from_fileresolve_payment_cli_overrides_file_and_passes_nonzero— regression guard for merge-order: a zero file value must not short-circuit a valid CLI overrideresolve_payment_defaults_when_unset— locksDEFAULT_RATE_PER_MBpass-throughScope
The receiver-side defense (client must also reject
ProbeResponse/StreamResponsewithrate_per_mb == 0) is out of scope. Thecdn/client/v1selection code doesn't exist yet; when it lands, it will need its own check on the receive path. Will file a follow-up issue.Test plan
cargo fmt -- --checkcargo clippy -p decdn-node --all-targets -- -D warningscargo clippy --workspace --all-targets -- -D warningsRUSTDOCFLAGS="-D warnings" cargo doc -p decdn-node --no-deps --document-private-itemscargo test -p decdn-node— 46 tests pass (+4 new, all green)Closes #234
🤖 Generated with Claude Code