Skip to content

fix(config): reject rate_per_mb = 0 at config resolution - #251

Merged
alpergundogdu merged 1 commit into
mainfrom
fix/234-rate-per-mb-zero
Apr 15, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
fix/234-rate-per-mb-zero

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Summary

Reject payment.rate_per_mb == 0 at 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_payment now returns anyhow::Result<ResolvedPayment> and calls anyhow::ensure!(rate_per_mb > 0, …) after the CLI / file / default merge.
  • resolve_config threads the ? through.
  • Doc comment on resolve_payment cites ADR 001 / ADR 014 so the constraint is discoverable.
  • Four new unit tests:
    • resolve_payment_rejects_zero_from_cli
    • resolve_payment_rejects_zero_from_file
    • resolve_payment_cli_overrides_file_and_passes_nonzero — regression guard for merge-order: a zero file value must not short-circuit a valid CLI override
    • resolve_payment_defaults_when_unset — locks DEFAULT_RATE_PER_MB pass-through

Scope

The receiver-side defense (client must also reject ProbeResponse / StreamResponse with rate_per_mb == 0) is out of scope. The cdn/client/v1 selection 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 -- --check
  • cargo clippy -p decdn-node --all-targets -- -D warnings
  • cargo clippy --workspace --all-targets -- -D warnings
  • RUSTDOCFLAGS="-D warnings" cargo doc -p decdn-node --no-deps --document-private-items
  • cargo test -p decdn-node — 46 tests pass (+4 new, all green)

Closes #234

🤖 Generated with Claude Code

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]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@alpergundogdu alpergundogdu self-assigned this Apr 15, 2026
@alpergundogdu
alpergundogdu merged commit 345494d into main Apr 15, 2026
15 of 19 checks passed
@alpergundogdu
alpergundogdu deleted the fix/234-rate-per-mb-zero branch April 15, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rate_per_mb value of 0 is accepted silently and would cause divide-by-zero in node selection formula

1 participant