Skip to content

docs(adr): operator early withdrawal (withdraw-while-open) in ADR 003 - #710

Merged
alpergundogdu merged 2 commits into
mainfrom
adr/003-operator-early-withdrawal
May 29, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
adr/003-operator-early-withdrawal

Conversation

@thiras

@thiras thiras commented May 29, 2026

Copy link
Copy Markdown
Contributor

What

Amends ADR 003 to let an operator (provider) withdraw accrued funds while the channel stays Open, instead of only at closeChannel → dispute window → settleChannel. Adds a provider-only withdraw(channelId, amount, nonce, bytesDelivered, signature) that redeems the accrued delta of a client-signed voucher and routes it through FeeRouter same-tx — no dispute window.

There is no PaymentChannel.sol yet (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)

  • Vouchers are client-signed, cumulative, and monotonic → an operator can only ever withdraw an amount the client already authorized, and can only under-claim itself; the client cannot be harmed.
  • FeeRouter.routeSettlement is 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.
  • The un-withdrawn remainder still passes through the full dispute window at close.

Changes (all in adr/003-payments.md)

  • Struct: withdrawnAmount / withdrawnBytes payout watermark; claimed* reused 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.
  • Accounting: settleChannel routes the un-withdrawn remainder; reclaimExpired refunds deposit - withdrawnAmount; closeChannel cannot regress below the withdrawn point. New invariant 4; rewrote the now-false "settles once per channel" text.
  • Event ChannelWithdrawn, an "Operator early withdrawal" security subsection, plus overview / FeeRouter-integration / slashing-interaction updates.
  • Notes per-call rounding (operator leg absorbs truncation, gas-bounded), the close-before-expiry residual, and the per-withdraw CapacityBond.recordSettlement side effect.
  • Drive-by fix: corrected a stale slash split in Slashing and Channel Interactions ("50/30/20" SafetyReserve model) to ADR 026's canonical escrow-on-slash 50% challenger / 50% burn.

Verification

Spec-only change — verified by documentation-consistency checks:

  • make -C adr check-refs (links/anchors/spacing), markdownlint, adr-book-list — all pass via pre-commit run --files adr/003-payments.md.
  • FeeRouter additive-accounting claim confirmed against contracts/src/FeeRouter.sol:213.
  • Watermark invariants (withdrawnAmount ≤ claimedAmount ≤ deposit) and withdraw+settle telescoping checked across all lifecycle paths.

Out of scope (#327)

PaymentChannel.sol implementation of withdraw, off-chain node withdrawal-submission logic, and any crates/incentive ChannelState field additions. When #327 lands, ADR 016's PaymentChannel function-mutation list should gain a withdraw() row.

🤖 Generated with Claude Code

… 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]>
Copilot AI review requested due to automatic review settings May 29, 2026 20:05

@gemini-code-assist gemini-code-assist Bot 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.

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.

Comment thread adr/003-payments.md Resolved
Comment thread adr/003-payments.md Resolved

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 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 withdraw mechanism with withdrawnAmount/withdrawnBytes watermarks and delta-based routing into FeeRouter.
  • 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.

Comment thread adr/003-payments.md Resolved
Comment thread adr/003-payments.md Resolved
Comment thread adr/003-payments.md Resolved
Comment thread adr/003-payments.md Resolved
Comment thread adr/003-payments.md Resolved
Comment thread adr/003-payments.md Resolved
Comment thread adr/003-payments.md Resolved
Comment thread adr/003-payments.md Resolved
Comment thread adr/003-payments.md Resolved
Comment thread adr/003-payments.md Resolved
…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]>
@alpergundogdu
alpergundogdu merged commit 0a6a49b into main May 29, 2026
19 checks passed
@alpergundogdu
alpergundogdu deleted the adr/003-operator-early-withdrawal branch May 29, 2026 20:29
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.

3 participants