Skip to content

test(node): keep the voucher floor on live rate bounds, not the quote - #1388

Merged
alpergundogdu merged 3 commits into
mainfrom
fix/quote-time-rate-bounds-voucher
Jul 22, 2026
Merged

alpergundogdu merged 3 commits into
mainfrom
fix/quote-time-rate-bounds-voucher

Conversation

@altanoruc

@altanoruc altanoruc commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Outcome

Keep the hard per-byte voucher floor reading the live rate bounds
(self.rate_bounds.floor() in collect_voucher) — no change to serving
behaviour vs main
. This PR adds a regression test and a doc clarification
that lock in why the live floor is correct, resolving the #1382 investigation.

Background

#1382 proposed pinning the floor snapshotted when the StreamResponse was
signed and reusing it to accept that stream's later vouchers, so a mid-stream
governance floor raise wouldn't reject a voucher paying the quoted rate. The
first commit here implemented that (quote_floor threaded through
clamped_rate → deliver → window_forward_loop → collect_voucher).

Why that approach is unsafe (and reverted)

The on-chain PaymentChannel._advanceClaimWatermark enforces the floor against
the live deliveryFloor at settlement:

// PaymentChannel.sol
uint256 maxBytes = Math.mulDiv(amount, BYTES_PER_MB, deliveryFloor);
if (bytesDelivered > maxBytes) revert RateFloorViolation(amount, bytesDelivered, deliveryFloor);

There is no per-channel floor snapshot (the Channel struct carries none) and
setRateBounds overwrites deliveryFloor globally. So a voucher priced below
the live floor is unredeemable. Pinning the quote-time floor at acceptance would
make the node countersign — and keep serving — vouchers it can never claim
on-chain after a floor raise, the exact hazard the floor check exists to
prevent. The node rejecting such a voucher is correct self-protection, not a
bug
.

The advertised-rate check was already correctly quote-pinned via rate_per_mb;
only the hard, on-chain-mirrored floor was in question, and it must track the
chain.

Changes

  • Keep collect_voucher's hard floor on self.rate_bounds.floor() (reverts the
    quote_floor plumbing; the five handler files are back to main).
  • Add voucher_floor_tracks_live_bounds_not_the_quote: once the live floor
    rises above the quoted rate, a voucher paying that rate is rejected — it would
    revert on-chain with RateFloorViolation.
  • Clarify the rate_bounds.rs module doc that motivated the original change: the
    snapshot-sharing guidance is for a single clamp decision; the hard voucher
    floor must read the live value.

#1382 disposition

Refs #1382 (not Closes) — the live-floor rejection is correct, so there is no
acceptance-side bug to fix. The real UX improvement — don't hit an honest buyer
with an opaque anyhow::bail! reset on a floor raise; emit a graceful re-quote
signal via a new VoucherRejectReason — is a separate protocol-crate follow-up
tracked under #1382.

History

  • aabd774 — the quote-time-snapshot approach.
  • dd367ef — revert it to the live floor, add the regression test and the doc
    clarification.

Verification

  • cargo fmt -- --check
  • cargo clippy -p decdn-node --tests -- -D warnings — clean
  • cargo test -p decdn-node --lib voucher_floor_tracks_live_bounds_not_the_quote — passes

🤖 Generated with Claude Code

The seller clamps `rate_per_mb` against a `RateBounds` snapshot when signing
a `StreamResponse`, but `collect_voucher` re-read the live floor via
`self.rate_bounds.floor()` when enforcing the hard per-byte floor. A
governance floor raise (applied by the `RateBoundsUpdated` watcher on a ~1s
cadence) landing between the signed quote and a voucher for that stream would
reject a voucher paying exactly the rate the node itself quoted, failing an
in-flight paid stream the buyer paid correctly.

`clamped_rate` now returns `(clamped_rate, quote_floor)` from a single
snapshot, and the floor is threaded through `deliver` / `window_forward_loop`
into `collect_voucher`, which enforces `verify_rate(.., quote_floor, 0)`
instead of a live re-read. Quote and acceptance now agree by construction for
the lifetime of a stream, as the `rate_bounds.rs` quote-then-verify note
intends. The clamp/ceiling behaviour at quote time is unchanged.
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@altanoruc, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 42 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 74d1b9ba-6d77-4072-b4f1-c8b71209bcd2

📥 Commits

Reviewing files that changed from the base of the PR and between dd367ef and 4219e45.

📒 Files selected for processing (1)
  • crates/node/src/rate_bounds.rs

Walkthrough

The change adds a regression test showing that voucher verification reads the live rate floor after governance updates, and updates RateBounds::snapshot() documentation to describe appropriate snapshot usage.

Changes

Live voucher floor validation

Layer / File(s) Summary
Live floor verification and snapshot guidance
crates/node/src/rate_bounds.rs, crates/node/src/handlers/client/mod.rs
Documentation clarifies per-decision snapshots and live-floor checks, while a Tokio test verifies that a previously quoted voucher is rejected after the live floor increases.

Estimated code review effort: 2 (Simple) | ~10 minutes


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.56% (was 81.55%, ▲ +0.01%) — 53805/65972 lines

File Coverage Lines Δ
crates/node/src/handlers/client/mod.rs 88.17% 596/676 ▲ +0.38%
crates/node/src/rate_bounds.rs 100.00% 73/73 ● 0.00%
History
Commit Total Δ vs base
aabd774 81.56% ▲ +0.01%
dd367ef 81.56% ▲ +0.01%
4219e45 (HEAD) 81.56% ▲ +0.01%

Copy link
Copy Markdown
Contributor Author

Review — quote-time rate-bounds snapshot for voucher validation

The diff is clean and faithfully implements the intent documented in rate_bounds.rs (§quote-then-verify) and requested in #1382. clamped_rate returning (rate, floor) from a single snapshot() is the right shape, the respond_error discard is correctly commented, and the threading through delivery/window/dispatch is mechanical and consistent. CI is green.

That said, I think the fix is aimed at the wrong one of the two verify_rate calls, and in the floor-raise case it trades a safe failure for a silent, unredeemable-voucher loss. Worth reconciling before merge.

The two floors answer to different authorities

collect_voucher makes two rate checks:

  1. Advertised-rate check — verify_rate(amount_delta, delta_bytes, rate_per_mb, DEFAULT_TOLERANCE_BPS). "Did the buyer pay what I quoted?" Should be pinned to the quote — and it already was: rate_per_mb has always been the clamped quote threaded from clamped_rate. ✅
  2. Hard per-byte floor — the one this PR moves from self.rate_bounds.floor() to quote_floor. Its own comment states the purpose: "so a synced node never countersigns a voucher it then cannot redeem." That's not a question about the quote — it's "what will the chain accept at settlement?" And the chain uses the live floor.

The chain enforces the live floor, with no per-channel snapshot

PaymentChannel._advanceClaimWatermark reads the global deliveryFloor at settlement:

// PaymentChannel.sol:860-861
uint256 maxBytes = Math.mulDiv(amount, BYTES_PER_MB, deliveryFloor);
if (bytesDelivered > maxBytes) revert RateFloorViolation(amount, bytesDelivered, deliveryFloor);

setRateBounds overwrites that var globally (PaymentChannel.sol:783), and the Channel struct carries no floor field — so a governance raise applies immediately to every open channel's settlement. No grandfathering.

Consequence (using this PR's own test scenario)

Quote at floor F, buyer pays exactly F/MB. Governance raises the floor to 2F on-chain; the watcher applies it (~1s). Buyer sends the voucher paying F.

So the fix removes the node's circuit-breaker: "lose the in-flight interval, stop" becomes "serve the whole remaining stream unredeemably, and churn the redeemer" — the wrong direction on a fund-custody path.

The new comment "so the quoted floor is always live" papers over exactly this: quote_floor is a real chain-sourced value (never the stale 0 seed), but the whole point of the change is that it is no longer the live floor at settlement — which is the value that governs redeemability.

Suggested direction

  • Keep the advertised-rate check pinned to the quote (already is), but leave the hard per-byte floor tracking the live floor — that check exists to mirror the chain.
  • If the real goal is "don't punish a correctly-paying buyer with an opaque reset on a floor raise," the redeemability-preserving fix is to fail gracefully — finish the stream cleanly with an actionable reason (as the existing VoucherRejectReason clean-finish paths do) so the buyer re-quotes at the new floor — rather than pinning a floor the chain won't honor. The anyhow::bail! reset is the UX wart worth fixing.
  • If the intended policy is genuinely "a governance floor raise must not strand in-flight channels," that's a contract change (snapshot the floor per channel at open, or grandfather open channels), not a node-only one — a node-side pin hands the buyer an "accepted" the chain later repudiates.

Could you confirm which semantics you're after? If I'm missing an operational assumption (e.g. the floor only ever moves at channel boundaries), say so and I'll withdraw the concern.

Minor — test doesn't guard the wiring

voucher_floor_uses_quote_snapshot_not_live_bounds re-derives both verify_rate(...) calls inline; it never drives collect_voucher. It proves clamped_rate returns the snapshot floor and that verify_rate's math differs between the two floors — but reverting the one-line voucher.rs change (quote_floor → self.rate_bounds.floor()) would still pass it. A test that exercises the real acceptance path (floor raise mid-stream, then a quoted-rate voucher through deliver/collect_voucher, asserting VoucherOutcome::Accepted) would actually lock the fix in.

🤖 Automated review via Claude Code


Generated by Claude Code

…snapshot

PR #1388 pinned the hard per-byte voucher floor to the rate-bounds snapshot
taken when the StreamResponse was signed (`quote_floor`), so a mid-stream
governance floor raise would no longer reject a voucher paying the quoted
rate. That is unsafe: the on-chain `PaymentChannel._advanceClaimWatermark`
enforces the floor against the LIVE `deliveryFloor` at settlement, with no
per-channel snapshot (the `Channel` struct carries none) and `setRateBounds`
overwriting it globally. A voucher priced below the live floor is unredeemable
(`RateFloorViolation`), so pinning the quote-time floor makes the node
countersign — and keep serving — vouchers it can never claim on-chain, the
exact hazard the floor check exists to prevent.

Restore the acceptance check to the live floor (`self.rate_bounds.floor()`),
reverting the `quote_floor` plumbing threaded through
clamped_rate/deliver/window_forward_loop/collect_voucher. The advertised-rate
check was already correctly quote-pinned via `rate_per_mb`; only the hard
on-chain-mirrored floor was in question, and it must track the chain.

- Replace the #1388 unit test with `voucher_floor_tracks_live_bounds_not_the_quote`,
  which asserts the correct invariant: once the live floor rises above the
  quoted rate, a voucher paying that rate is rejected (it would revert on-chain).
- Clarify the `rate_bounds.rs` module doc that misled the change: the
  snapshot-sharing guidance is for a single clamp decision; the hard voucher
  floor must read the live value. Honouring the buyer across a floor raise is a
  separate concern needing a graceful re-quote signal, not a stale floor.

Refs #1382, #1388

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01E7YvMUv2JZcZudSKaL4KmG
@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 89.63% (2663/2971 lines)
▲ +0.00pp vs base (89.63% → 89.63%)
Run: 29921173658

@altanoruc altanoruc changed the title fix(node): use quote-time rate-bounds snapshot for voucher validation test(node): keep the voucher floor on live rate bounds, not the quote Jul 22, 2026
`cargo doc` runs with `-D rustdoc::broken-intra-doc-links`, and `Self::floor` /
`Self::ceiling` don't resolve inside a module-level (`//!`) doc comment — there
is no `Self` there, only the `rate_bounds` module. Use `RateBounds::floor` /
`RateBounds::ceiling`, matching the existing `RateBounds::snapshot` link in the
same paragraph. Fixes the `cargo doc` CI job.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01E7YvMUv2JZcZudSKaL4KmG
@alpergundogdu
alpergundogdu merged commit c0046d7 into main Jul 22, 2026
23 checks passed
@alpergundogdu
alpergundogdu deleted the fix/quote-time-rate-bounds-voucher branch July 22, 2026 12:59
thiras added a commit that referenced this pull request Jul 23, 2026
…#1375, #1377, #1382)

Batch of three tightly-coupled fixes on the paid-pull buyer path, all
surfaced in the G-GOV e2e review series.

#1377 — express UpstreamRefused's evidence invariants in the type.
Convert the two-pub-field struct to a newtype over a private inner enum
(Open{error,response} / MidStream{error}). Enum variant fields cannot be
private in Rust, so the newtype is what makes "present response ⇒
open-stage, verified" unforgeable. Crate-private open() derives error from
the response (and now also rejects ok==true); pub mid_stream() is provably
evidence-free; error()/evidence() accessors; slash_sig-eliding Debug. All
consumers migrated (.error→.error(), .response→.evidence()), incl. the e2e
on-chain-challenge feeder which can no longer receive an unverified response.

#1375 — buyer-side rate ceiling + retained slash evidence.
Refuse a stream quote above effective_rate_ceiling(candidate probe rate,
config max_rate_per_mb) BEFORE paying, via a typed RateAboveCeiling that
carries the operator's own signed over-quote as replayable evidence (single
crate-private constructor derives the quoted rate from the response).
Classified as reputation-neutral PullVerdict::RateCeiling: metered
(node_pull_rate_above_ceiling) and suppressed, never tarring the peer. New
cache.max_rate_per_mb knob wired through all surfacing sites and both the
node-to-node and CLI buyer paths.

#1382 — graceful re-quote signal on a live-floor voucher rejection.
Emit the new VoucherRejectReason::RateFloorRaised (appended wire variant)
instead of an opaque anyhow::bail! when a governance floor raise strands an
honest buyer's quote; the buyer classifies it retry-with-re-quote (channel
kept). Scope per merged #1388, which correctly kept the live-floor read.

ADR 005 updated (SoT) with the new reason plus the two handler-direct
variants its listing had drifted from. Adds unit, loopback, and node-origin
integration coverage (probe-relative bound, exact-ceiling accept, evidence
signature recovery, RateCeiling verdict) and extends the wire-order freeze
test. Verified: fmt, clippy --all-targets, protocol/client-pull/node
suites, public-api snapshot, and e2e (anvil-e2e) build.

Closes #1375
Closes #1377
Closes #1382

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
thiras added a commit that referenced this pull request Jul 23, 2026
…#1375, #1377, #1382)

Batch of three tightly-coupled fixes on the paid-pull buyer path, all
surfaced in the G-GOV e2e review series.

#1377 — express UpstreamRefused's evidence invariants in the type.
Convert the two-pub-field struct to a newtype over a private inner enum
(Open{error,response} / MidStream{error}). Enum variant fields cannot be
private in Rust, so the newtype is what makes "present response ⇒
open-stage, verified" unforgeable. Crate-private open() derives error from
the response (and now also rejects ok==true); pub mid_stream() is provably
evidence-free; error()/evidence() accessors; slash_sig-eliding Debug. All
consumers migrated (.error→.error(), .response→.evidence()), incl. the e2e
on-chain-challenge feeder which can no longer receive an unverified response.

#1375 — buyer-side rate ceiling + retained slash evidence.
Refuse a stream quote above effective_rate_ceiling(candidate probe rate,
config max_rate_per_mb) BEFORE paying, via a typed RateAboveCeiling that
carries the operator's own signed over-quote as replayable evidence (single
crate-private constructor derives the quoted rate from the response).
Classified as reputation-neutral PullVerdict::RateCeiling: metered
(node_pull_rate_above_ceiling) and suppressed, never tarring the peer. New
cache.max_rate_per_mb knob wired through all surfacing sites and both the
node-to-node and CLI buyer paths.

#1382 — graceful re-quote signal on a live-floor voucher rejection.
Emit the new VoucherRejectReason::RateFloorRaised (appended wire variant)
instead of an opaque anyhow::bail! when a governance floor raise strands an
honest buyer's quote; the buyer classifies it retry-with-re-quote (channel
kept). Scope per merged #1388, which correctly kept the live-floor read.

ADR 005 updated (SoT) with the new reason plus the two handler-direct
variants its listing had drifted from. Adds unit, loopback, and node-origin
integration coverage (probe-relative bound, exact-ceiling accept, evidence
signature recovery, RateCeiling verdict) and extends the wire-order freeze
test. Verified: fmt, clippy --all-targets, protocol/client-pull/node
suites, public-api snapshot, and e2e (anvil-e2e) build.

Closes #1375
Closes #1377
Closes #1382

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
thiras added a commit that referenced this pull request Jul 23, 2026
…#1375, #1377, #1382) (#1420)

Batch of three tightly-coupled fixes on the paid-pull buyer path, all
surfaced in the G-GOV e2e review series.

#1377 — express UpstreamRefused's evidence invariants in the type.
Convert the two-pub-field struct to a newtype over a private inner enum
(Open{error,response} / MidStream{error}). Enum variant fields cannot be
private in Rust, so the newtype is what makes "present response ⇒
open-stage, verified" unforgeable. Crate-private open() derives error from
the response (and now also rejects ok==true); pub mid_stream() is provably
evidence-free; error()/evidence() accessors; slash_sig-eliding Debug. All
consumers migrated (.error→.error(), .response→.evidence()), incl. the e2e
on-chain-challenge feeder which can no longer receive an unverified response.

#1375 — buyer-side rate ceiling + retained slash evidence.
Refuse a stream quote above effective_rate_ceiling(candidate probe rate,
config max_rate_per_mb) BEFORE paying, via a typed RateAboveCeiling that
carries the operator's own signed over-quote as replayable evidence (single
crate-private constructor derives the quoted rate from the response).
Classified as reputation-neutral PullVerdict::RateCeiling: metered
(node_pull_rate_above_ceiling) and suppressed, never tarring the peer. New
cache.max_rate_per_mb knob wired through all surfacing sites and both the
node-to-node and CLI buyer paths.

#1382 — graceful re-quote signal on a live-floor voucher rejection.
Emit the new VoucherRejectReason::RateFloorRaised (appended wire variant)
instead of an opaque anyhow::bail! when a governance floor raise strands an
honest buyer's quote; the buyer classifies it retry-with-re-quote (channel
kept). Scope per merged #1388, which correctly kept the live-floor read.

ADR 005 updated (SoT) with the new reason plus the two handler-direct
variants its listing had drifted from. Adds unit, loopback, and node-origin
integration coverage (probe-relative bound, exact-ceiling accept, evidence
signature recovery, RateCeiling verdict) and extends the wire-order freeze
test. Verified: fmt, clippy --all-targets, protocol/client-pull/node
suites, public-api snapshot, and e2e (anvil-e2e) build.

Closes #1375
Closes #1377
Closes #1382

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.

3 participants