Skip to content

PaymentChannel: cooperative close (fast settle, no dispute window) #947

Closed

Description

@alpergundogdu

Problem

A client's unused deposit (`deposit − claimedAmount`) is only returned via `closeChannel` → 48h dispute window → `settleChannel`. The window exists to let an offline party counter a stale-low close with a higher voucher. When both parties are online and agree on the final state, that 48h is pure latency on the client's refund.

The provider already has a window-free path to its own earnings (`withdraw`); the client has no equivalent. Asymmetry, not a deep design constraint.

Proposal

Add `cooperativeClose(channelId, amount, nonce, bytesDelivered, clientVoucherSig, providerCloseSig)` — settles in one tx, no dispute window, callable by either party. Requires two signatures over the same final tuple:

  • client voucher sig — caps the amount the provider may claim.
  • provider `CooperativeClose` waiver (new EIP-712 typehash) — provider attests it holds no higher voucher and waives the window.

With both sigs over one tuple there is nothing to dispute → settle immediately (route provider's `amount − withdrawnAmount`, refund client `deposit − amount`).

Safety

  • No locked funds. Purely additive; if the node is offline/declines, client falls back to the existing `closeChannel` path. No enforcement/timeout/escrow.
  • Finality. Terminal `Closed` set atomically; the on-chain `claimed*` watermark (not the off-chain sig) is the anchor — a stale waiver below it reverts (`AmountRegression`/`NonMonotonicNonce`) and can never under-settle. `Open`-only.
  • Paused router. Mirrors `settleChannel`'s defer branch so a paused `FeeRouter` never freezes the client refund.

Off-chain exchange

Two new `cdn/client/v1` `ClientMessage` variants: `CooperativeCloseRequest { channel_id }` → `CooperativeCloseAuth { amount, nonce, bytes_delivered, signature }`. Standalone request/response. Node-side discipline: don't sign while a delivery is in flight, and stop accepting payment on the channel after signing.

Scope

  • ADR 003 § Cooperative close
  • `PaymentChannel.cooperativeClose` + `COOPERATIVE_CLOSE_TYPEHASH` + tests (Solidity)
  • Rust wire variants + `crates/incentive` waiver signing + node handler/guard (follow-up)

ADR + Solidity land together; the Rust off-chain implementation follows the ADR.

Activity

  1. added
    design:adr
    design:economics
    kind:feature
    prio:medium
    on Jun 18, 2026
  2. github-actions commented on Jun 18, 2026

    @github-actions

    🎯 Triage report

    A well-specified feature that eliminates the 48h dispute window when both parties are online and cooperating. The proposal uses dual EIP-712 signatures (client voucher sig + provider CooperativeClose waiver) over the same final tuple, which is the standard safe pattern for off-chain payment channel optimistic settlement. The Solidity scope (ADR 003 update + contract + tests) is self-contained; the Rust off-chain implementation is correctly deferred as a follow-up.

    📊 Assessment

    Dimension Value Reasoning
    Type Feature Adds a new settlement path with no prior equivalent
    Labels enhancement, technical, ADR, economics, medium New contract entrypoint; touches ADR 003; payment-channel economics; important UX improvement but graceful fallback exists
    Coding agent Suitable Requirements are precise, success criteria are on-chain verifiable, scope is bounded to Solidity + ADR; no cross-team coordination needed

    🔗 Similar issues

    💡 Notes and suggestions

    Implementation checklist (Solidity)

    • Define COOPERATIVE_CLOSE_TYPEHASH — include channelId, amount, nonce, bytesDelivered in the type hash to prevent cross-channel and cross-field replay.
    • Verify provider has not already withdrawn more than amount — the amount − withdrawnAmount routing requires amount >= withdrawnAmount, otherwise revert (similar to AmountRegression).
    • State guard: Open-only (per spec). Must not be callable in Closing state (would bypass the dispute window the uncooperative-close path relies on).
    • Confirm claimedAmount watermark is updated atomically when writing the terminal Closed state, not just on the FeeRouter call, so a replay attempt always reverts.
    • Mirror settleChannel's paused-router defer branch exactly — test with a mock paused router to confirm the client refund is never frozen.
    • Test: stale waiver (amount below withdrawnAmount) reverts with AmountRegression.
    • Test: nonce regression reverts with NonMonotonicNonce.
    • Test: valid cooperative close emits same events as settleChannel so indexers don't need a separate code path.
    • Test: cooperative close called on a Closing-state channel reverts.

    EIP-712 note: The provider waiver is a new typehash distinct from the client voucher typehash — ensure the domain separator binds to the contract address and chain ID so testnet waivers can't be replayed on mainnet.

    Node-side (Rust, follow-up): The guard "don't sign while a delivery is in flight" should be a mutex/state flag in crates/incentive, not just a convention. The node must also stop accepting new vouchers on a channel after emitting CooperativeCloseAuth — otherwise a race between the off-chain ack and an in-flight voucher could leave a higher voucher unclaimed.

    Generated by Agentic Triage for issue #947 · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

design:adrdesign:economicskind:featureprio:medium

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions