Repository navigation
feat(payments): soft delivery-rate floor — clamp credited bytes instead of reverting - #1753
Conversation
…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]>
Contracts coverageLine coverage: 89.67% (2544/2837 lines) |
Gas snapshotNo gas changes vs base. |
There was a problem hiding this comment.
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
RateFloorViolationrevert with soft-floor byte clamping during redemption; update and extend tests to cover clamping + batch behavior. - Rust/protocol + node: remove the now-unproducible
RateFloorRaisedrejection 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_voucheras 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]>
Coverage reportTotal: 80.85% (was 80.84%, ▲ +0.01%) — 58641/72528 lines
History
|
What
Turn the
PaymentPooldelivery-rate floor into a soft floor. A sub-floor voucher no longer reverts — it settles its fullcumulativeUSDC and credits only the floor-justified byte ceiling: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
RateFloorViolationrevert had a real failure mode: because_applyVoucherruns inside theredeemManybatch 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 namedRateFloorRaised).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;
cumulativeneeds no extra bound because credit is already paid-proportional (bytesPaid = mulDiv(bytesDelta, paid, desired)).Changes
Contract
PaymentPool._applyVoucher: clamp instead of revert; deleteerror RateFloorViolation. TheredeemManyskip-vs-revert taxonomy now reverts only on a structural error (bad signature / closed pool).redeemMany_softFloor_subFloorLaneDoesNotPoisonBatch,after-floor-raise, and a fuzz test. Gas snapshot regenerated.Off-chain (the seller no longer hard-rejects either)
rate_boundsnow only clamps the node's own quote up to the floor before signing.RateFloorRaisedwire reason end to end: theVoucherRejectReasonvariant, its buyer-side cache-miss retry classifier (collapses toPoolExhausted), the metric, the public-API snapshot, and its ADR 005 definition.ADRs
Reviewer notes
uint64(Math.min(bytesDelivered, mulDiv(...)))cast is overflow-safe: theminruns inuint256and is bounded above by theuint64bytesDelivered.g_gov_02sells at the floor, so its runtime assertions are unchanged; only its stale comments were updated. Verified it still compiles underanvil-e2e.RateFloorRaisedshifts postcard discriminants of laterVoucherRejectReasonvariants — a wire break, fine pre-launch (every side updates in this PR).Verification
forge build --sizes --deny warningsclean;forge test823 pass / 0 fail; slither exit 0 (no medium+); aderyn 0 new findings vs baseline.cargo clippy --workspace --all-targetsclean;cargo nextest -p decdn-node891 pass;-p decdn-protocol133 pass;cargo test --no-run -p decdn-e2e --features anvil-e2ecompiles; fmt clean (Rust + Sol).Contract-side follow-up to the ADR-only PR #1751.
🤖 Generated with Claude Code