Skip to content

feat(payments): soft delivery-rate floor — clamp credited bytes instead of reverting - #1753

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/stoic-mahavira-cb734b
Aug 19, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/stoic-mahavira-cb734b

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

What

Turn the PaymentPool delivery-rate floor into a soft floor. A sub-floor voucher no longer reverts — it settles its full cumulative USDC and credits only the floor-justified byte ceiling:

creditedBytes = min(bytesDelivered, cumulative * BYTES_PER_MB / deliveryFloor)

Why

The floor's purpose is to stop cheap bytes from inflating the served-bytes metric — which is the only byte-weighted metric anywhere: FeeRouter.bytesPerEpoch → DecdnGovernor._getVotes (ADR 036). Reputation is local-only throughput; buyback is USDC-amount-weighted. Policing payment was never the point.

The hard RateFloorViolation revert had a real failure mode: because _applyVoucher runs inside the redeemMany batch loop, one sub-floor voucher reverted the entire batch (every pool and lane), stranding honest lanes. The realistic trigger is a governance floor-raise landing on a voucher a node already served and accepted in good faith (the off-chain reason was literally named RateFloorRaised).

Clamping neutralises the inflation attack at the place it matters (vote weight) while the payment still clears. Credit stays bounded by real, floor-priced routed USDC, so cheap bytes still cannot buy vote weight; cumulative needs no extra bound because credit is already paid-proportional (bytesPaid = mulDiv(bytesDelta, paid, desired)).

Changes

Contract

  • PaymentPool._applyVoucher: clamp instead of revert; delete error RateFloorViolation. The redeemMany skip-vs-revert taxonomy now reverts only on a structural error (bad signature / closed pool).
  • Tests rewritten to soft-floor semantics, including redeemMany_softFloor_subFloorLaneDoesNotPoisonBatch, after-floor-raise, and a fuzz test. Gas snapshot regenerated.

Off-chain (the seller no longer hard-rejects either)

  • Removed the acceptance-time floor check in the client voucher handler; the advertised-rate check still protects per-delta revenue. rate_bounds now only clamps the node's own quote up to the floor before signing.
  • Removed the now-unproducible RateFloorRaised wire reason end to end: the VoucherRejectReason variant, its buyer-side cache-miss retry classifier (collapses to PoolExhausted), the metric, the public-API snapshot, and its ADR 005 definition.

ADRs

  • 003 (§Rate-floor enforcement rewrite + call sites), 036 (threat-model dependency), 005 (VoucherRejectReason). ADR 016 unchanged — the contract surface (routeSettlement pipe, constructor args) is unchanged and it never enumerated the error.

Reviewer notes

  • The uint64(Math.min(bytesDelivered, mulDiv(...))) cast is overflow-safe: the min runs in uint256 and is bounded above by the uint64 bytesDelivered.
  • g_gov_02 sells at the floor, so its runtime assertions are unchanged; only its stale comments were updated. Verified it still compiles under anvil-e2e.
  • Removing RateFloorRaised shifts postcard discriminants of later VoucherRejectReason variants — a wire break, fine pre-launch (every side updates in this PR).

Verification

  • forge build --sizes --deny warnings clean; forge test 823 pass / 0 fail; slither exit 0 (no medium+); aderyn 0 new findings vs baseline.
  • cargo clippy --workspace --all-targets clean; cargo nextest -p decdn-node 891 pass; -p decdn-protocol 133 pass; cargo test --no-run -p decdn-e2e --features anvil-e2e compiles; fmt clean (Rust + Sol).

Contract-side follow-up to the ADR-only PR #1751.

🤖 Generated with Claude Code

…ad of reverting

The deliveryFloor's purpose is to stop cheap bytes from inflating the served-bytes
metric (the ADR 036 governance vote weight), not to police payment. Replace the hard
`RateFloorViolation` revert in `PaymentPool` redemption with a clamp: a sub-floor
voucher settles its full `cumulative` USDC and credits only
`min(bytesDelivered, cumulative * BYTES_PER_MB / deliveryFloor)` bytes toward the
served-bytes counter that feeds `DecdnGovernor` vote weight.

This removes the batch-poisoning failure mode where one sub-floor voucher reverted a
whole `redeemMany` (every pool and lane). The realistic trigger is a governance
floor-raise landing on a voucher a node already served and accepted in good faith.
Credit stays bounded by real, floor-priced routed USDC, so cheap bytes still cannot
buy vote weight; `cumulative` needs no extra bound because credit is paid-proportional.

Contract:
- PaymentPool: clamp in `_applyVoucher`; delete `RateFloorViolation`; the redeemMany
  skip-vs-revert taxonomy now reverts only on a structural error (bad signature /
  closed pool). Tests rewritten to soft-floor semantics (+ batch-no-poison,
  after-floor-raise, fuzz). Gas snapshot regenerated.

Off-chain (the seller no longer hard-rejects either):
- Remove the acceptance-time floor check in the client voucher handler; the
  advertised-rate check still protects per-delta revenue. `rate_bounds` now only
  clamps the node's own quote up to the floor before signing.
- Remove the now-unproducible `RateFloorRaised` wire reason end to end: the enum
  variant, its buyer-side cache-miss retry classifier (collapses to `PoolExhausted`),
  the metric, the public-API snapshot, and its ADR 005 definition.

ADRs: 003 (§Rate-floor enforcement rewrite + call sites), 036 (threat-model
dependency), 005 (VoucherRejectReason). ADR 016 unchanged — the contract surface
(routeSettlement pipe, constructor args) is unchanged and it never enumerated the error.

Contract-side follow-up to the ADR-only PR #1751.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 19, 2026 13:15
@github-actions

github-actions Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

Contracts coverage

Line coverage: 89.67% (2544/2837 lines)
▼ -0.00pp vs base (89.68% → 89.67%)
Run: 32257783611

@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

Copilot AI 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.

Pull request overview

This PR changes deCDN’s payment semantics so the on-chain PaymentPool delivery-rate floor is enforced as a soft floor: redemption no longer reverts on sub-floor vouchers, but instead settles the full cumulative USDC while clamping the credited (vote-weight) bytes to the floor-justified ceiling. This aligns the floor with its intended role (protect served-bytes governance weight) and removes a batch-redemption failure mode where a single sub-floor lane could revert redeemMany.

Changes:

  • Solidity: replace the hard RateFloorViolation revert with soft-floor byte clamping during redemption; update and extend tests to cover clamping + batch behavior.
  • Rust/protocol + node: remove the now-unproducible RateFloorRaised rejection reason end-to-end and delete the node-side acceptance-time cumulative floor check; keep quote-time clamping + per-span advertised-rate protection.
  • ADRs/e2e: update documentation and e2e assertions to match “soft floor clamps credited bytes” semantics.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/protocol/tests/snapshots/public_api__public_api.snap Updates public API snapshot to remove RateFloorRaised.
crates/protocol/src/client.rs Removes RateFloorRaised from VoucherRejectReason and updates related documentation/tests.
crates/node/src/rate_bounds.rs Updates module docs to reflect quote-time-only floor usage and soft-floor settlement behavior.
crates/node/src/node_origin/mod.rs Updates pull-failure classification and tests after removing RateFloorRaised; treats PoolExhausted as retryable (top-up) without suppressing peers.
crates/node/src/metrics.rs Removes the voucher rate-floor rejection metric and its recorder hook.
crates/node/src/handlers/client/voucher.rs Removes acceptance-time cumulative floor rejection; keeps advertised-rate check; adjusts tests to call verify_voucher without self.
crates/node/src/handlers/client/mod.rs Removes tests specific to “live-floor hard rejection” behavior, now obsolete under soft-floor settlement.
crates/e2e/tests/g_gov_02_rate_bounds.rs Updates commentary/assertion framing for soft-floor clamping semantics.
contracts/test/PaymentPool.t.sol Rewrites and expands rate-floor tests for soft-floor semantics, adds redeemMany non-poisoning coverage and fuzzing.
contracts/src/PaymentPool.sol Implements credited-bytes clamping (creditedBytes = min(bytesDelivered, mulDiv(...))) and removes RateFloorViolation.
contracts/.gas-snapshot Updates gas snapshot for the modified tests/paths.
adr/036-served-bytes-voting-weight.md Updates threat-model dependency language from “revert” to “clamp credited bytes.”
adr/005-protocol.md Removes RateFloorRaised from protocol definitions and updates retry semantics text.
adr/003-payments.md Updates redemption/rate-floor sections to document soft-floor credited-bytes clamping and related operational implications.
Suppressed comments (1)

crates/node/src/handlers/client/voucher.rs:600

  • These setup lines create a handler/store/metrics but the test never uses them (it now calls ClientHandler::verify_voucher as a pure helper). Removing this avoids unnecessary async setup work and makes the test’s intent clearer.
        let metrics = Arc::new(Metrics::new());
        let store = Arc::new(decdn_incentive::store::MemoryPoolStateStore::new())
            as Arc<dyn PoolStateStore>;
        let (_handler, _dir) = handler_over_store(&metrics, store).await;


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

`verify_voucher` is now an associated fn, so `stale_voucher_is_benign_*` and
`divergent_voucher_at_equal_amount_*` no longer need the `handler_over_store`
fixture (they sign with a local EIP-712 domain and `verify_voucher` skips the
signature). Remove the unused handler/store/metrics setup and downgrade both to
sync `#[test]` — no `.await` remains.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

Copy link
Copy Markdown

Coverage report

Total: 80.85% (was 80.84%, ▲ +0.01%) — 58641/72528 lines

File Coverage Lines Δ
crates/node/src/handlers/client/mod.rs 91.81% 1144/1246 ▼ 0.11%
crates/node/src/handlers/client/voucher.rs 92.08% 372/404 ▲ +2.10%
crates/node/src/metrics.rs 95.09% 968/1018 ● 0.00%
crates/node/src/node_origin/mod.rs 91.01% 1043/1146 ● 0.00%
crates/node/src/rate_bounds.rs 97.50% 78/80 ● 0.00%
crates/protocol/src/client.rs 99.04% 722/729 ● 0.00%
History
Commit Total Δ vs base
49be43a (HEAD) 80.85% ▲ +0.01%

@alpergundogdu
alpergundogdu merged commit c5a8626 into main Aug 19, 2026
26 checks passed
@alpergundogdu
alpergundogdu deleted the claude/stoic-mahavira-cb734b branch August 19, 2026 14:04
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.

2 participants