Repository navigation
feat(payments): chunk voucher redemption into gas-bounded redeemMany transactions - #1704
Merged
Merged
Conversation
… per-chunk floor Rework plan_redeem to return Result<Option<PlannedLane>> (dropping the threshold param and RedeemPlan enum), and wire the chunked submit path: redeem_one/redeem_sweep/redeem_pool_on_close now collect PlannedLanes, chunk_redemptions under the per-chunk floor + voucher-count cap, and submit each chunk via submit_chunk with an oversize halve-and-retry. Thread redeem_max_vouchers_per_tx through the redeemer loop, the service struct, bootstrap, and final_redeem_sweep; the close path forces floor 0 so a high-lane closing pool settles in chunks before its dispute deadline. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ize default Adds a two-test N/N+1 gas benchmark (each in its own EVM state, avoiding a warm-access-list artifact that showed up when both calls shared one test function) that measures redeemMany's marginal per-voucher cost at ~34.5k gas. Against Arbitrum One's ~32M block gas limit (external reference), that puts a safe chunk size around 458 vouchers, so the existing default of 300 holds with ~1.5x headroom — left unchanged, doc comment updated to cite the measurement instead of an unverified assumption.
Capture the measured redeemMany gas from _redeemFreshLanesAndSnapshotGas and assert it against pinned values (N: 507,093, N+1: 541,614; ±5,000 tolerance) so the figures cited by DEFAULT_REDEEM_MAX_VOUCHERS_PER_TX's doc comment are checkable from tracked code, not only from the gitignored snapshots/PaymentPool.json. Also logs the measured gas under -vv and reconciles the doc comment's safe_max to 458 (was inconsistently "roughly 460" against the worked 458 figure).
Reframe redeem_interval_secs docstrings from per-lane 'above-threshold claim' to the per-chunk floor model, and import std::cmp::Reverse rather than fully qualifying it in chunk_redemptions. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Note
This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.
Copilot stopped reviewing on behalf of
alpergundogdu due to an error
August 17, 2026 14:45
Add a first-time-signer variant of the redeemMany N-vs-(N+1) gas benchmark: each lane's CapabilityReg rides in the same measured call as its voucher, instead of being pre-registered in a separate unmeasured call. This isolates the realistic per-lane cost for the target workload of one-time payers whose capability is registered on their single redemption. Measured: first-time marginal 63,404 gas/lane (vs 34,521 for an already-registered signer), so registration itself costs ~28,883 gas. A 300-lane all-first-time chunk runs ~19.0M gas — over a 16M half-block budget but comfortably under a 32M full block. Measurement only; DEFAULT_REDEEM_MAX_VOUCHERS_PER_TX is unchanged.
…fault The pinned redeemMany benchmark measures both an already-registered-signer marginal (~34.5k) and a first-time-signer marginal (~63.4k, redeem + one-time capability registration). The one-time-payer workload hits the first-time case per lane, so 300 lanes cost ~19M gas — under a 32M block, over a half-block budget — with submit_chunk's halve-retry as the backstop. Keep the default 300. Co-Authored-By: Claude Opus 4.8 <[email protected]>
alpergundogdu
added a commit
that referenced
this pull request
Aug 17, 2026
Re-applies the per-pool floor-credit accounting onto main's reworked voucher path (#1672 in-memory vouchers + periodic flush, #1699 self-describing vouchers, #1704 redeemMany chunking): - Serve loops (delivery.rs, serve_leg.rs): keep the FloorReservation note_unpaid/ release_live_repaid/mid-stream-PoolExhausted hooks, now attached to main's per-voucher commit_one_voucher/VoucherStop recoup (dropping the removed batch-recoup + commit_interval). - VoucherRejectReason: apply the three-way split (SpendingCapExhausted / CapabilityExpired / PoolExhausted) on top of main's removal of the RetryLater wire variant; a PoolError::Store fault now aborts the stream with no wire reason. - node_origin voucher_verdict, ADR 003/005, public-api snapshot updated to match. Verified: workspace build + clippy --all-targets + fmt clean; decdn-node 886/886, protocol/incentive merge-sensitive tests, and public-api snapshot all pass. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
A node's redeemer submitted one
redeemManyfor an entire sweep, which does not scale: a 100 Gbps node serving thousands-to-millions of distinct payers accumulates one lane per(pool, signer), and a single transaction carrying that many vouchers cannot fit in a block. Economics were never the blocker (~34.5k gas/voucher ≈ fractions of a cent on Arbitrum) — per-transaction size is.This splits redemption into gas-bounded chunks (many cheap
redeemManytransactions) and replaces the per-lane dust skip with a per-chunk aggregate value floor, so dust settles by riding alongside real value instead of being skipped or attacked lane-by-lane. Node-side only — no contract, wire, ABI, or storage change (redeemManyalready takes an array).How
plan_redeemno longer skips below-threshold lanes; a chunk (one transaction) is submitted only when its lanes' aggregate unredeemed value clears F, and every lane in a submitted chunk settles. High-value lanes are spread across chunks (descending sort + round-robin deal) so dust rides along rather than segregating into a below-floor chunk.chunk_redemptionspartitions planned lanes into chunks of at mostredeem_max_vouchers_per_tx(new config, default 300), splitting a pool across chunks when needed;group_by_poolrebuilds per-poolPoolBatches per chunk (each(pool, signer)lane is distinct, so no duplicate capability).is_oversize_send_err) is halved and retried, bounded by depth (MAX_SPLIT_DEPTH) and shrinking length — loss-freesplit_off, no swallowed errors on other arms.PoolRedeemedevents, so a deferred/failed/halved chunk simply leaves its lanes for the next sweep — cumulative, monotone, retry-safe, per chunk.Design decisions
redeem_threshold_micro_usdc, default 1 USDC); against ~$0.0001 of gas per chunk it is ~100× margin. No gas→USDC conversion.Mis explicitly out of scope. The over-subscription / double-spend surface (a tiny pool with many self-capped capabilities across distinct lanes) is a separate serve-time concern; ADR 003'sM ≥ N·tsizing is left untouched, with a one-line forward note.assertApproxEqAbs, single-pool measurement); the high-fan-out (one-pool-per-client) case adds per-pool overhead, and the halve-retry mechanic is the designed answer to any chunk that still exceeds the limit.Testing
chunk_redemptions(floor / count-cap / value-spread / force / empty),group_by_pool,is_oversize_send_err, config resolution (default + reject-zero).redeemManygas micro-benchmark pins the marginal in tracked assertions (isolated in independent EVM state to avoid a warm-access-list artifact).forge test: 816 passed / 0 failed; CI build--deny warnings+fmtclean.--all-targetsclean; node+common suite 1288 passed; anvil-e2e compile gate green.ADR 003 reframes the redemption threshold as the per-chunk floor (present-tense canon,
M ≥ N·tuntouched).🤖 Generated with Claude Code