Repository navigation
docs(adr): operator early withdrawal (withdraw-while-open) in ADR 003 - #710
Conversation
… 003 Lets a provider redeem the accrued delta of a client-signed voucher while the channel stays Open, via a new provider-only `withdraw` that routes the delta through FeeRouter same-tx with no dispute window. Safe by construction: withdrawal redeems a client-signed, cumulative, monotonic voucher (operator can only under-claim itself; client cannot be harmed), and FeeRouter's additive accounting means incremental routing double-counts nothing. - Channel struct: add withdrawnAmount/withdrawnBytes payout watermark; reuse claimed* as the best-voucher watermark, now advanced during Open. - withdraw(): provider-only, Open-only, nonReentrant; disputeChannel-grade monotonicity against claimed*; routes amount-withdrawnAmount + byte delta. - settleChannel routes the un-withdrawn remainder; reclaimExpired refunds deposit-withdrawnAmount; closeChannel cannot regress below the withdrawn point. New invariant 4; rewrote the stale "settles once per channel" text. - ChannelWithdrawn event, "Operator early withdrawal" security subsection, and overview / FeeRouter-integration / slashing-interaction updates. - Note per-call rounding (operator leg absorbs truncation), close-before- expiry residual, and per-withdraw CapacityBond.recordSettlement. - Drive-by: fix stale slash split in Slashing and Channel Interactions to ADR 026's escrow-on-slash 50% challenger / 50% burn. Contract + off-chain implementation tracked in #327. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request updates the payment channel design in adr/003-payments.md to introduce an early withdrawal mechanism (withdraw) for operators while a channel remains open, allowing incremental redemption of client-signed vouchers. The review feedback identifies a critical protocol deadlock issue where requiring a strictly greater nonce (nonce > claimedNonce) for closeChannel after a withdrawal prevents providers from closing the channel using the same voucher they last withdrew with. It is recommended to allow nonce >= claimedNonce for closing when claimedNonce > 0.
There was a problem hiding this comment.
Pull request overview
This PR updates ADR 003 (Payment Model) to specify operator/provider early withdrawals from payment channels while the channel remains Open, by introducing a provider-only withdraw(channelId, amount, nonce, bytesDelivered, signature) flow that routes voucher deltas through FeeRouter without requiring a dispute window.
Changes:
- Adds an Open-state
withdrawmechanism withwithdrawnAmount/withdrawnByteswatermarks and delta-based routing intoFeeRouter. - Updates the close/settle/expiry accounting model so final settlement routes only the un-withdrawn remainder and expiry refunds
deposit - withdrawnAmount. - Expands the ADR’s security + FeeRouter integration documentation, including rounding notes and a slashing-split doc correction.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…a wording - Fix close deadlock: post-withdraw closeChannel now requires nonce >= claimedNonce (non-regression) instead of strict nonce >, so a party can close at the current watermark voucher instead of being stuck until expiresAt when no newer voucher exists. withdraw/disputeChannel keep strict nonce >. Updated both the Fee Routing and lifecycle descriptions. - ChannelSettled event: routedAmount/bytesDelivered now documented as the un-withdrawn remainder (claimedAmount-withdrawnAmount), not claimedAmount. - FeeRouter intro: "all three legs" now per routing call (each withdraw and the final settleChannel), not settle-only. - Clarify the withdraw delta (amount - withdrawnAmount) is against the pre-call withdrawnAmount, captured before the watermark advances. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
What
Amends ADR 003 to let an operator (provider) withdraw accrued funds while the channel stays
Open, instead of only atcloseChannel→ dispute window →settleChannel. Adds a provider-onlywithdraw(channelId, amount, nonce, bytesDelivered, signature)that redeems the accrued delta of a client-signed voucher and routes it throughFeeRoutersame-tx — no dispute window.There is no
PaymentChannel.solyet (the channel lifecycle lives only in ADR 003; implementation is tracked in #327), so this is an in-place spec amendment — single file.Why it's safe (the crux)
FeeRouter.routeSettlementis purely additive (+= bytesDelivered, fresh split per call, no per-channel guard —contracts/src/FeeRouter.sol:213) → incremental routing double-counts nothing; per-call deltas telescope to the lifetime claim.Changes (all in
adr/003-payments.md)withdrawnAmount/withdrawnBytespayout watermark;claimed*reused as the best-voucher watermark, now advanced duringOpen.withdraw: provider-only,Open-only,nonReentrant;disputeChannel-grade monotonicity againstclaimed*; routesamount - withdrawnAmount+ byte delta.settleChannelroutes the un-withdrawn remainder;reclaimExpiredrefundsdeposit - withdrawnAmount;closeChannelcannot regress below the withdrawn point. New invariant 4; rewrote the now-false "settles once per channel" text.ChannelWithdrawn, an "Operator early withdrawal" security subsection, plus overview / FeeRouter-integration / slashing-interaction updates.CapacityBond.recordSettlementside effect.Verification
Spec-only change — verified by documentation-consistency checks:
make -C adr check-refs(links/anchors/spacing),markdownlint,adr-book-list— all pass viapre-commit run --files adr/003-payments.md.contracts/src/FeeRouter.sol:213.withdrawnAmount ≤ claimedAmount ≤ deposit) and withdraw+settle telescoping checked across all lifecycle paths.Out of scope (#327)
PaymentChannel.solimplementation ofwithdraw, off-chain node withdrawal-submission logic, and anycrates/incentiveChannelStatefield additions. When #327 lands, ADR 016's PaymentChannel function-mutation list should gain awithdraw()row.🤖 Generated with Claude Code