Repository navigation
test(node): keep the voucher floor on live rate bounds, not the quote - #1388
Conversation
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.
|
Warning Review limit reached
Next review available in: 42 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (1)
WalkthroughThe change adds a regression test showing that voucher verification reads the live rate floor after governance updates, and updates ChangesLive voucher floor validation
Estimated code review effort: 2 (Simple) | ~10 minutes Note 🎁 Summarized by CodeRabbit FreeYour 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 |
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Coverage reportTotal: 81.56% (was 81.55%, ▲ +0.01%) — 53805/65972 lines
History
|
Review — quote-time rate-bounds snapshot for voucher validationThe diff is clean and faithfully implements the intent documented in That said, I think the fix is aimed at the wrong one of the two The two floors answer to different authorities
The chain enforces the live floor, with no per-channel snapshot
// PaymentChannel.sol:860-861
uint256 maxBytes = Math.mulDiv(amount, BYTES_PER_MB, deliveryFloor);
if (bytesDelivered > maxBytes) revert RateFloorViolation(amount, bytesDelivered, deliveryFloor);
Consequence (using this PR's own test scenario)Quote at floor
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: Suggested direction
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
🤖 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
Gas snapshotNo gas changes vs base. |
Contracts coverageLine coverage: 89.63% (2663/2971 lines) |
`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
…#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]>
…#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]>
…#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]>
Outcome
Keep the hard per-byte voucher floor reading the live rate bounds
(
self.rate_bounds.floor()incollect_voucher) — no change to servingbehaviour vs
main. This PR adds a regression test and a doc clarificationthat lock in why the live floor is correct, resolving the #1382 investigation.
Background
#1382 proposed pinning the floor snapshotted when the
StreamResponsewassigned 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_floorthreaded throughclamped_rate→deliver→window_forward_loop→collect_voucher).Why that approach is unsafe (and reverted)
The on-chain
PaymentChannel._advanceClaimWatermarkenforces the floor againstthe live
deliveryFloorat settlement:There is no per-channel floor snapshot (the
Channelstruct carries none) andsetRateBoundsoverwritesdeliveryFloorglobally. So a voucher priced belowthe 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
collect_voucher's hard floor onself.rate_bounds.floor()(reverts thequote_floorplumbing; the five handler files are back tomain).voucher_floor_tracks_live_bounds_not_the_quote: once the live floorrises above the quoted rate, a voucher paying that rate is rejected — it would
revert on-chain with
RateFloorViolation.rate_bounds.rsmodule doc that motivated the original change: thesnapshot-sharing guidance is for a single clamp decision; the hard voucher
floor must read the live value.
#1382 disposition
Refs #1382(notCloses) — the live-floor rejection is correct, so there is noacceptance-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-quotesignal via a new
VoucherRejectReason— is a separate protocol-crate follow-uptracked under #1382.
History
aabd774— the quote-time-snapshot approach.dd367ef— revert it to the live floor, add the regression test and the docclarification.
Verification
cargo fmt -- --checkcargo clippy -p decdn-node --tests -- -D warnings— cleancargo test -p decdn-node --lib voucher_floor_tracks_live_bounds_not_the_quote— passes🤖 Generated with Claude Code