Repository navigation
perf(node,incentive,contracts): batch redeemer auth reads + drop per-top-up allowance read - #1727
Merged
alpergundogdu merged 10 commits intoAug 18, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Extend the seller-settlement anvil e2e with a second sweep on the same lane: the first redeem attaches a CapabilityReg and persists registered_until, and the second sweep advances the paid watermark without needing a fresh Authorization read. Asserted against the live chain (getAuthorization) and, via the harness's PersistentPoolStateStore, against the persisted registered_until. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The anvil e2e's second-sweep-attaches-no-CapabilityReg proof previously compared redeemMany gas usage between the two redeems, but a resent CapabilityReg is a near-gas-free no-op once PaymentPool._registerCapability observes cap != 0 (it returns before its SSTORE/signature check), so the gas-delta assertion could not actually detect a regression that re-attaches one. Replace it with a tracing_subscriber Layer that captures the redeemer's own cap_count field per landed redeem, keyed by tx hash, and assert on that directly for both sweeps. Also add a brief settle wait before the second delivery: firing it back-to-back with the first redeem's on-chain confirmation occasionally raced the redeemer's own bookkeeping closely enough to flake even though the store already showed registered_until persisted at that instant. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contracts coverageLine coverage: 89.68% (2545/2838 lines) |
Gas snapshotNo gas changes vs base. |
There was a problem hiding this comment.
Pull request overview
This PR is the first in an eth_call efficiency sweep of the paid path. It reduces redundant on-chain reads by (1) removing a per-top-up allowance() pre-check in the node daemon and (2) batching redeemer authorization reads while persisting a per-lane registered_until watermark to avoid future reads.
Changes:
- Node buyer top-up now attempts
topUpdirectly and only performs a just-in-timeapprove+ single retry on anERC20InsufficientAllowance-class revert. - Settlement redeemer batches
PaymentPool.getAuthorizationreads via a newgetAuthorizations(poolIds, signers)view and persistsregistered_untilso steady-state sweeps can skip reads. - Adds/updates unit tests, e2e assertions, and contract tests to pin the batching behavior and persistence semantics.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/tests/channel_state_store.rs | Adds persistence round-trip tests for registered_until and regression resistance. |
| crates/node/tests/anvil_settlement_e2e.rs | Extends e2e to assert second sweep attaches no CapabilityReg, capturing redeemer decision via tracing. |
| crates/node/src/payment_settlement.rs | Implements batched authorization reads, registered_until gating, and persistence writeback. |
| crates/node/src/channel_store.rs | Extends persisted lane record to include registered_until and adds monotone merge/write APIs. |
| crates/node/src/buyer_channel.rs | Adds allowance-recovery retry control-flow and switches funding to “try topUp first” posture. |
| crates/incentive/src/store.rs | Adds set_registered_until to PoolStateStore and monotone merge semantics in memory store. |
| crates/incentive/src/pool_open_error.rs | Adds selector matcher helper for allowance shortfall detection from revert data. |
| crates/incentive/src/payment_pool.rs | Updates alloy bindings/docs to include getAuthorizations and pins its selector. |
| crates/incentive/src/lib.rs | Re-exports is_erc20_allowance_shortfall. |
| crates/incentive/src/lane.rs | Adds registered_until to LaneState and clarifies hydration semantics/tests. |
| crates/client-pull/src/buyer_pool.rs | Tags top_up submit errors as allowance-shortfall for daemon retry logic. |
| contracts/test/PaymentPool.t.sol | Adds tests for getAuthorizations correctness and length-mismatch revert. |
| contracts/src/PaymentPool.sol | Adds getAuthorizations batch view and LengthMismatch error. |
| contracts/.gas-snapshot | Updates gas snapshot to reflect the additive contract/test changes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportTotal: 80.38% (was 80.35%, ▲ +0.03%) — 58144/72340 lines
History
|
…/allowance PR
- payment_settlement: make the `registered_until` writeback O(n) — walk the
already-built `read_keys` (each a unique `(pool_id, signer)` at
`provider == self`) and look each auth up in the map, instead of rescanning
every lane per auth.
- channel_store: reword the `registered_until` doc. The old text implied no
prior on-disk shape exists; state plainly that a record written before the
field fails to decode (`take_from_bytes` -> `DeserializeUnexpectedEnd`) and
that this break is the deliberate, unversioned pre-launch choice it is.
- buyer_pool: add a regression test proving `top_up`'s
`.context("submit topUp").context(AllowanceShortfall)` layering is still
recoverable via `downcast_ref::<AllowanceShortfall>()` (anyhow searches the
context chain), so the daemon approve-and-retry path is not dead code. The
existing tests injected the marker as a bare error and never exercised this.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
This was referenced Aug 18, 2026
Merged
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.
Summary
First of three PRs from an
eth_call-efficiency sweep of the paid path. This one bundles two independent, additive workstreams that both cut redundant on-chain reads. The remaining two (lazy origin directory, watcherget_logs/block-number consolidation) follow as separate PRs.1. Drop the per-top-up
allowance()read (node daemon)The node holds a standing unlimited USDC approval granted once at bootstrap, yet every
fund_pooltop-up still did anERC20.allowance()read beforetopUp— one redundanteth_callper top-up across thousands of pools. Nowfund_poolattemptstopUpdirectly and only reads allowance +approves + retries once whentopUpreverts with anERC20InsufficientAllowanceshortfall (the bad path: approval revoked/never granted). Detection is by revert selector match (is_erc20_allowance_shortfall), surfaced through the sharedtop_upvia anAllowanceShortfallmarker. The CLI open/top-up path (bounded deposit, no standing approval) keeps its pre-check and is untouched.2. Batch the redeemer's
getAuthorizationreadsThe settlement redeemer read
PaymentPool.getAuthorization(pool, signer)once per lane every sweep, purely to learn whether a signer's capability was already registered — thousands ofeth_calls per sweep at scale, and a thundering herd on every restart. This PR:PaymentPool.getAuthorizations(bytes32[], address[])batch view (+ alloy binding, selector-pinned);registered_until: u64watermark onLaneState/StoredLaneState(the observed capability expiry;0= unknown);registered_until > now, batches the remaining unknown/expired lanes into onegetAuthorizationscall per sweep, and persists observed expiry so restarts re-read nothing already known.Registration state is persisted with the lane (survives version-bump restarts), and
recordmergesregistered_untilmonotonically (max) so a concurrent voucher-path write carrying0can't clobber a known registration. The monotone merge is safe because on-chain_registerCapabilityis idempotent and expiry is immutable once set. The old per-laneplan_redeemis deleted.Net: steady-state redeemer auth reads ≈ zero; a fresh restart with thousands of lanes = one batched call, not thousands.
Testing
registered_untilround-trip; monotone/clobber-safe store merge in both memory + persistent stores;is_registered/plan_laneregister-decision cases; allowance-shortfall selector + bad-path retry control-flow with zero-read/one-read counters).CapabilityReg(asserted via the redeemer's capturedcap_count, verified to fail under a deliberately-injected regression).cargo build && clippy,nextest(workspace),fmt,cargo deny,anvil-e2ecompile + live run; contractsforge fmt/build --deny warnings/test(820/820), gas snapshot committed,aderyn/slitherno new findings.Notes
🤖 Generated with Claude Code