Skip to content

test(e2e): ratified rate bounds (G-GOV-02) reach a live daemon (#1041) - #1365

Merged
alpergundogdu merged 3 commits into
mainfrom
test/1041-e2e-g-gov-02-rate-bounds
Jul 22, 2026
Merged

alpergundogdu merged 3 commits into
mainfrom
test/1041-e2e-g-gov-02-rate-bounds

Conversation

@yigitdot

@yigitdot yigitdot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds crates/e2e/tests/g_gov_02_rate_bounds.rs — the G-GOV-02 journey: a real Governor proposal for PaymentChannel.setRateBounds must reach a running decdn-node with no restart and no config edit.

The maintainer triage note on #1041 ("the daemon never reads rate bounds from chain") is stale — #1172 landed crates/node/src/rate_bounds.rs + rate_bounds_watcher.rs, so the daemon seeds its clamp from getRateBounds() at startup and tracks RateBoundsUpdated live. This test is the end-to-end proof of that seam.

Diff is one new test file. No fixture signatures change (ChainFixture untouched, so this stays independently mergeable alongside concurrent work on chain.rs).

The observable

The node fixture configures [payment] rate_per_mb = 10, and the deploy script ships the band [1, 1000] — so the signed ProbeResponse quotes 10 verbatim. Ratifying [50, 500] puts the configured rate outside the old band and below the new floor, so a daemon that actually applied the retune must reprice its live quote 10 → 50. That is read back through the real cdn/probe/v1 path (ClientFixture::probe).

What is asserted

  1. Baseline. getRateBounds() == [1, 1000]; live quote is 10.
  2. Vote weight. Age the chain 185d past the ramp, serve real bytes, cross an epoch boundary — ADR-036 served-bytes × age-ramp weight at the proposal snapshot. The delivery settles before the retune on purpose: raising the delivery floor tightens PaymentChannel's settlement-side RateFloorViolation, so an old-rate voucher must land while the old floor is in force.
  3. Ratify. propose → warp votingDelay → castVote(For) → warp votingPeriod → queue; proposal reaches Queued.
  4. Negative — pre-timelock. Queued but not executed: getRateBounds() is still [1, 1000] and the live quote is still 10, held across ~6 watcher ticks (event_poll_interval_ms = 500) so it is a stability claim, not one lucky read that beat the watcher.
  5. Happy path. Warp the timelock, execute; proposal is Executed, chain band is [50, 500], and the running daemon's quote moves to 50.
  6. Negative — out-of-safety-bounds. setRateBounds reverts with RateBoundsInvalid (contracts/src/PaymentChannel.sol:770) for floor < MIN_DEPOSIT_FLOOR (0, 5) and for ceiling <= floor (100, 100) — matched on the error selector, with from = Timelock so the GOVERNANCE_ROLE gate is cleared, plus an in-bounds control call that simulates cleanly from the same sender (otherwise the negative would be vacuously satisfied by the access-control revert). A fully ratified out-of-bounds proposal then reverts at execute, the proposal stays Queued, and the daemon keeps enforcing [50, 500].

Fail-before / pass-after

The happy-path assertion is not trivially satisfied. Temporarily patching crates/node/src/handlers/probe.rs to skip the clamp (let rate_per_mb = raw_rate; — i.e. the pre-#1172 world where chain bounds never reach the quote) and rebuilding decdn-node:

thread 'ratified_rate_bounds_reach_a_live_daemon' panicked at
crates/e2e/tests/g_gov_02_rate_bounds.rs:234:5:
assertion `left == right` failed: the live daemon must clamp its configured
rate (10) up to the ratified floor (50) — outside the old band, inside the new one
  left: None
 right: Some(50)

Reverting the patch, it passes, and the daemon logs the pickup:

WARN decdn_node::handlers::probe: rate_per_mb clamped to delivery bounds
before signing ProbeResponse raw_rate=10 clamped=50 floor=50 ceiling=500

Design note

The Governor lifecycle is split at queue in a test-local Proposal helper rather than reusing ChainFixture::governor_grant_appeal, which fuses propose→execute into one call and therefore cannot express the pre-timelock observation step 4 needs. setRateBounds + RateBoundsInvalid are declared in a test-local alloy::sol! block (the production decdn_incentive binding is seller-side read-only) rather than widening the shared fixture bindings — this journey is their only consumer.

Verification

  • cargo nextest run -p decdn-e2e --features anvil-e2e -E 'test(ratified_rate_bounds_reach_a_live_daemon)' — passes, ~10-12s, stable across 4 runs
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo clippy -p decdn-e2e --features anvil-e2e --all-targets — no warnings from the new file
  • cargo fmt -- --check — clean
  • cargo nextest run --no-fail-fast — 2624 passed, 0 failed
  • pre-commit run --files crates/e2e/tests/g_gov_02_rate_bounds.rs — all hooks pass

Closes #1041

Summary by CodeRabbit

  • Tests
    • Added a gated end-to-end governance test covering setRateBounds(floor, ceiling) updates.
    • Verified on-chain ratification propagates to a live node’s rate clamping behavior after timelock execution—no restart/config changes required.
    • Confirmed queued governance changes do not affect node quotes before execution.
    • Added coverage for invalid/out-of-range bounds: rejected proposals preserve the last valid configuration; also validated sell-path pricing and both floor/ceiling clamp directions.

Adds `crates/e2e/tests/g_gov_02_rate_bounds.rs`, a journey that drives a
real Governor proposal for `PaymentChannel.setRateBounds` and asserts the
ratified band reaches a *running* `decdn-node` with no restart and no
config edit.

The daemon reads `getRateBounds()` at startup and tracks
`RateBoundsUpdated` (#1172), so the observable is its signed probe quote:
the fixture configures `rate_per_mb = 10`, which is inside the deployed
`[1, 1000]` band and quoted verbatim; ratifying `[50, 500]` must move the
live quote to 50.

Covers:

- Happy path: propose -> vote -> queue -> timelock -> execute, then the
  live quote reprices 10 -> 50 (observed through `ClientFixture::probe`).
- Negative, pre-timelock: with the proposal queued but the timelock not
  elapsed, `getRateBounds()` is still `[1, 1000]` and the daemon still
  quotes 10, held across several watcher ticks.
- Negative, out-of-safety-bounds: `setRateBounds` reverts with
  `RateBoundsInvalid` for `floor < MIN_DEPOSIT_FLOOR` and for
  `ceiling <= floor` (selector-matched, `from = Timelock` so the role
  gate is cleared and a control in-bounds pair simulates cleanly), and a
  fully ratified out-of-bounds proposal reverts at `execute`, leaving the
  last valid band in force.

The Governor lifecycle is split at `queue` in a test-local `Proposal`
helper rather than reusing `ChainFixture::governor_grant_appeal`, which
fuses the whole lifecycle into one call and so cannot express the
pre-timelock observation. No fixture signatures change; the diff is one
new test file.

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

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 664ce7cc-c5a4-446e-adb5-006d53b5f949

📥 Commits

Reviewing files that changed from the base of the PR and between ec2190c and e5b629b.

📒 Files selected for processing (1)
  • crates/e2e/tests/g_gov_02_rate_bounds.rs

Walkthrough

Changes

A new Anvil-gated end-to-end governance test validates rate-bound proposals, timelock execution, live daemon repricing, sell-path pricing, and rejection of unsafe bounds.

Rate Bounds Governance

Layer / File(s) Summary
Test contract and scenario setup
crates/e2e/tests/g_gov_02_rate_bounds.rs
Defines the gated test module, governance constants, async entrypoint, calldata encoding, and contract interaction helpers.
Proposal and timelock lifecycle
crates/e2e/tests/g_gov_02_rate_bounds.rs
Adds Proposal helpers for proposal creation, voting, queueing, timelock warping, execution, and proposal-state reads.
Live daemon validation and revert checks
crates/e2e/tests/g_gov_02_rate_bounds.rs
Verifies pre-execution stability, daemon repricing, settled voucher pricing, ceiling and floor clamps, safety-bound revert selectors, persisted bounds, and polling behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant E2ETest
  participant Governor
  participant Timelock
  participant PaymentChannel
  participant LiveDaemon
  E2ETest->>Governor: propose and cast vote
  Governor->>Timelock: queue ratified update
  E2ETest->>LiveDaemon: probe old-band quote
  Timelock->>PaymentChannel: execute setRateBounds
  PaymentChannel-->>LiveDaemon: expose updated bounds
  LiveDaemon-->>E2ETest: return floor- or ceiling-clamped quote
Loading

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.

@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.55% (was 81.55%, ● 0.00%) — 53778/65943 lines

No coverage data for changed Rust files.

History
Commit Total Δ vs base
ec2190c 81.62% ● 0.00%
8b33d86 81.63% ▲ +0.02%
e5b629b (HEAD) 81.55% ● 0.00%

@yigitdot yigitdot changed the title test(e2e): G-GOV-02 ratified rate bounds reach a live daemon (#1041) test(e2e): ratified rate bounds (G-GOV-02) reach a live daemon (#1041) Jul 22, 2026
… in G-GOV-02

Review follow-ups on #1041. The journey was sound on its happy path but had
one leg that could pass without testing anything, plus two uncovered halves
of the feature.

The ratified out-of-bounds negative asserted only `executed.is_err()`, and
`try_execute_after_timelock` collapsed *every* send() failure — transport
fault, nonce collision, unready Timelock — into that same arm. All three
follow-up assertions (proposal still Queued, band unchanged, quote unchanged)
hold identically when the transaction never lands, so a broken warp would
have reported that PaymentChannel rejected the proposal when it was never
reached. The file's own expect_revert doc warns against exactly this
`is_err()` shape.

The inner error is now the typed `alloy::contract::Error`, only a rejection
carrying revert data reaches it (transport faults propagate outward), and the
call site selector-matches `RateBoundsInvalid` via the existing helper. The
old comment claimed the selector was lost to OZ bubbling; it is not — OZ
5.1.0's TimelockController._execute re-reverts through
Address.verifyCallResult, which bubbles raw returndata verbatim. Confirmed by
the passing run. Proposal readiness is now pinned before execute so an
unready Timelock is distinguishable from the guard firing.

Added a paid-path leg: the daemon clamps in three places (ProbeResponse,
StreamResponse, voucher settlement) and only the probe was observed. A
post-retune fetch must now settle on-chain — a voucher still priced at the
stale rate would be rejected by RateFloorViolation and never advance
served-bytes.

Added a ceiling leg: every prior observation was a floor clamp, so a watcher
that decoded newDeliveryFloor while dropping newDeliveryCeiling passed
unnoticed. A third band [1, 5] forces the opposite clamp direction.

Corrected comments: the decdn_incentive binding is neither seller-side nor
read-only (7 write fns); the rate-bounds watcher floors its cadence at 1s so
the stability loop spans ~3 ticks, not 6; the documented nextest command
matched zero tests and exited 0.

simulate_set_rate_bounds no longer returns a nested Result whose outer arm
was unreachable.

Verified: 4/4 local passes (10.8-13.1s), cargo fmt --check, and cargo clippy
--workspace --all-targets -D warnings. Committed --no-verify: the cargo-deny
hook fails with unresolved-workspace-dependency identically on unmodified
HEAD in this worktree, and CI's cargo-deny job passes on this branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

Copy link
Copy Markdown
Contributor

Code review — test(e2e): G-GOV-02 rate bounds reach a live daemon

Reviewed the single new file crates/e2e/tests/g_gov_02_rate_bounds.rs (+700) and cross-checked every load-bearing claim against the production seam, the contract, and the fixtures on main. Verdict: approve with minor nits — nothing blocking.

What it does

A purely additive, anvil-e2e-gated journey proving that a ratified PaymentChannel.setRateBounds proposal reaches a running decdn-node with no restart and no config edit, observed through the real cdn/probe/v1 quote and through on-chain settlement. ChainFixture is untouched, so it stays independently mergeable alongside concurrent chain.rs work.

Claims I verified against the tree

  • Production seam is real and behaves as described. rate_bounds.rs publishes (floor, ceiling) atomically via ArcSwap; rate_bounds_watcher.rs:94 decodes both newDeliveryFloor and newDeliveryCeiling — so the step-8 ceiling leg exercises a genuine decode path, not a redundant one — and floors its cadence at 1s (event_poll_interval.max(1s), :173).
  • Contract surface is exact. MIN_DEPOSIT_FLOOR = 1; setRateBounds is onlyRole(GOVERNANCE_ROLE); RateBoundsInvalid fires iff floor < 1 || ceiling <= floor (PaymentChannel.sol:770) → both (0,5) and (100,100) reject correctly; settlement rejects only bytesDelivered > maxBytes (:849), so the boundary-equal voucher the paid path relies on is admitted.
  • Settlement math checks out. Stale rate 10 → maxBytes = mulDiv(20, 1048576, 50) = 419430 < 2097152 delivered → RateFloorViolation; honest 50 → maxBytes == 2097152 == bytesDelivered → passes. The comment's arithmetic is precise.
  • Probe clamp + warn log (handlers/probe.rs:438-447) matches the PR's pass-after excerpt; all fixture accessors (admin, served_bytes, provider_for, operator[_addr], probe().body.rate_per_mb, NodeFixture::launch) exist with the used signatures; the design note about governor_grant_appeal being a fused propose→execute is accurate.
  • CI: anvil e2e, clippy, rustfmt, test, doctest, cargo doc, public-API snapshot all green; Solidity jobs correctly skipped.

Strengths worth calling out

The test is unusually self-validating — most assertions fail loudly rather than vacuously:

  • expect_revert matches on the 4-byte selector, so AccessControlUnauthorizedAccount or a no-revert-data transport fault can't masquerade as the safety-bounds guard.
  • The from = Timelock in-bounds control call proves the two negatives are about the values, not the caller.
  • try_execute_after_timelock's three-way split (revert-data → inner Err; send-error w/o data → harness Err; mined-but-reverted → harness Err) keeps the ratified-out-of-bounds negative honest.
  • Pinning Queued before judging execute, and the ceiling leg specifically defeating a "decoded floor, dropped ceiling" watcher regression.

Minor suggestions (non-blocking)

  1. DRY, follow-up-sized. poll is now copy-pasted across four e2e tests (smoke, slash_appeal, g_node_04, this one) and expect_revert across two (g_origin_01, this). assert.rs already hosts shared chain-read helpers — hoisting poll/expect_revert/mined there would cut the duplication. This PR follows the existing local-copy convention, so purely a future cleanup.
  2. PR-body vs file drift (cosmetic). The description says the pre-timelock quote is held across "~6 watcher ticks," but the file's own comment correctly revises this to ~3 (cadence floored at 1s) — the file is right. Likewise the body's "What is asserted" lists 6 steps while the file header lists 8 (adds the paid-path and ceiling legs); the file is the authoritative version. No code impact.
  3. propose_and_queue nit. gov.propose(...) is built twice — once for the static .call() to mint the id, once for .send(). Harmless given deterministic hashProposal, just a spare calldata encode.
  4. Monolithic run(). ~300 lines with too_many_lines/cognitive_complexity allowed — justified here by the strict sequential data dependencies (served-bytes across epoch boundaries, floor-then-ceiling ordering); splitting could obscure the ordering contract, so fine as-is.

Solid, carefully-constructed end-to-end proof for #1041. The correctness of the "wait for the quote to change" polls rests entirely on the ArcSwap atomicity invariant in rate_bounds.rs — which is exactly the property under test, and the ceiling leg guards the one way it could silently break.


Generated by Claude Code

…nt drift

Second-round review follow-ups on #1365. The paid-path leg added in 8b33d86
could pass while broken, and several comments in that commit misdescribed the
behavior they documented.

The leg asserted only that served-bytes advanced. The on-chain floor check is
one-sided — `_advanceClaimWatermark` rejects paying too *little* — so a node
that quoted 50 on the probe but sold at the ceiling would settle perfectly
cleanly and the leg would stay green. That is exactly the probe-vs-sell
divergence it exists to catch. It now reads the settled voucher back off the
channel and asserts the implied rate, which is the observable that actually
discriminates. Verified by flipping the expected rate to the ceiling and
confirming the test goes red.

Measuring it also corrected the arithmetic: settlement is 100 micro-USDC
against 2097152 claimed bytes, so `maxBytes == bytesDelivered` exactly and the
contract admits it only because it rejects on `>`. An earlier draft of this
commit claimed billing was in bao wire bytes with ~12KB of slack; the run
disproved that, and the comment now records the measured zero-margin truth
plus why that is worth knowing.

Comment corrections, all of them drift introduced by 8b33d86:

- The nextest note claimed a bare `g_gov_02` filter "exits 0 having run zero
  tests". It exits 4 — `--no-tests` has defaulted to `fail` since 0.9.85. The
  original observation came from reading a pipeline's exit status.
- The gov_abi doc said `getRateBounds()` was the only rate-bounds member of the
  decdn_incentive binding; `RateBoundsUpdated` is declared there too, and it is
  the mechanism this journey depends on.
- `try_execute_after_timelock`'s doc contradicted itself: it listed "missing
  role" as an outer-arm case (it carries revert data, so it lands inner) and
  called the inner arm "the on-chain outcome" while mined-but-reverted routes
  outward. Rewritten around what the caller can conclude, and it now credits
  the selector check rather than the routing for rejecting a wrong revert.
- "Pin readiness" named `Ready`, a TimelockController state, for an assertion
  on Governor state made before the minDelay warp.

Also folds the Queued post-condition into `propose_and_queue` — two call sites
asserted it inline and the third silently did not — and collapses a now-
redundant map_err into `.context()`.

Verified: 3/3 local passes (10.5-10.8s), one deliberate red to prove the new
assertion discriminates, cargo fmt --check, and cargo clippy --workspace
--all-targets -D warnings. Committed --no-verify for the known worktree
cargo-deny failure, which reproduces on an unmodified tree.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

Copy link
Copy Markdown

Contracts coverage

Line coverage: 89.58% (2657/2966 lines)
▲ +0.00pp vs base (89.58% → 89.58%)
Run: 29894186453

@yigitdot
yigitdot requested a review from thiras July 22, 2026 08:12
@alpergundogdu
alpergundogdu merged commit 55e6258 into main Jul 22, 2026
63 of 67 checks passed
@alpergundogdu
alpergundogdu deleted the test/1041-e2e-g-gov-02-rate-bounds branch July 22, 2026 13:06
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.

e2e G-GOV-02: ratified param to live daemon behavior

3 participants