Repository navigation
feat(protocol,incentive): cooperative-close wire + EIP-712 foundation - #949
Conversation
…#947) Foundation for the off-chain cooperative-close exchange (ADR 003 §Cooperative close). On its own it changes no behavior — the node handler (PR B) and CLI reconcile (PR C) build on it. protocol (cdn/client/v1): - Append two ClientMessage variants (discriminants 7, 8, ADR-013 append-only): CooperativeCloseRequest { channel_id } and CooperativeCloseAuth { channel_id, amount, nonce, bytes_delivered, signature }. - COOPERATIVE_CLOSE_SIG_LEN (65) + CooperativeCloseAuth::validate length check; InvalidCooperativeCloseSigLen error; discriminant test pins 7/8. - decdn-client-pull variant_name match extended for the two new variants. incentive: - cooperative_close module: the provider's EIP-712 CooperativeClose waiver (sign/recover/verify), sharing the voucher PaymentChannel domain; distinct typehash so a voucher sig can't stand in for a waiver and vice versa. - cooperativeClose fn + ChannelCooperativelyClosed event added to the PaymentChannel alloy sol! binding. Tests: round-trip, wrong-signer, high-s rejection, typehash lock to the contract wording, waiver != voucher digest. Workspace clippy clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request implements EIP-712 cooperative-close waivers for the PaymentChannel contract, allowing cooperative channel settlement in a single transaction without a dispute window. It introduces the cooperative_close module in crates/incentive with signing and verification logic, updates the PaymentChannel Solidity bindings with the cooperativeClose function and ChannelCooperativelyClosed event, and adds the CooperativeCloseRequest and CooperativeCloseAuth protocol messages to the client protocol. There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
Adds the first (non-behavior-changing) building blocks for off-chain cooperative close: new cdn/client/v1 wire messages for requesting/returning a cooperative-close waiver, and a new decdn-incentive EIP-712 helper for signing/verifying the provider waiver that matches the PaymentChannel contract’s cooperative close typed data.
Changes:
- Extended
ClientMessagewith appended cooperative-close request/auth variants (discriminants 7/8) and added wire-level signature length validation. - Introduced
decdn-incentivecooperative_closemodule to sign/recover/verify provider waivers under the existing PaymentChannel EIP-712 domain with a distinct typehash. - Updated the
PaymentChannelalloy ABI binding withcooperativeClose+ChannelCooperativelyClosed, and extendedclient-pulldebug naming for the new protocol variants.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/protocol/src/message.rs | Adds a new MessageValidationError variant for cooperative-close signature length validation. |
| crates/protocol/src/client.rs | Appends new ClientMessage variants + adds CooperativeClose* wire structs and validation; updates discriminant test. |
| crates/incentive/src/payment_channel.rs | Extends the alloy PaymentChannel ABI binding with cooperative-close function + event. |
| crates/incentive/src/lib.rs | Exposes the new cooperative_close module and re-exports its public types. |
| crates/incentive/src/cooperative_close.rs | Implements EIP-712 cooperative-close waiver signing and verification with tests (typehash lock, digest separation, high-s rejection). |
| crates/client-pull/src/lib.rs | Extends variant_name for the new protocol variants. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// Settle in one tx with NO dispute window, given a client voucher | ||
| /// and a matching provider `CooperativeClose` waiver over the same | ||
| /// final tuple (ADR 003 §Cooperative close). Callable by client or | ||
| /// provider. Open-only. | ||
| function cooperativeClose( |
| /// Channel cooperatively closed and settled in one tx (no dispute | ||
| /// window). The watcher drops the persisted `ChannelState` exactly | ||
| /// as it does for `ChannelSettled` — `Closed` is terminal either way. | ||
| event ChannelCooperativelyClosed( |
Coverage reportTotal: 84.23% (was 84.21%, ▲ +0.02%) — 38540/45754 lines
History
|
…947) Address PR review: the cooperativeClose function + ChannelCooperativelyClosed event in the alloy binding ship ahead of the on-chain change, so flag that calling against an older deployment reverts and the event is emitted only by deployments carrying the companion contract change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…types The cooperative-close wire types (CooperativeCloseRequest/Auth, the COOPERATIVE_CLOSE_SIG_LEN const, and InvalidCooperativeCloseSigLen) were added to the public surface but the insta snapshot wasn't refreshed, failing the public-API gate. Additive-only regeneration. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ing (#947) Implements the node (provider) half of cooperative close (ADR 003 §Cooperative close), on top of the wire + EIP-712 foundation (#949). - Handler answers a CooperativeCloseRequest on cdn/client/v1 by signing a CooperativeClose waiver over the channel's current voucher watermark (last_amount/nonce/bytes) with the node's eth key and replying with a CooperativeCloseAuth. Best-effort: unknown channel or no-voucher-yet (nonce 0) finishes with no auth and the client falls back to closeChannel. - Self-protection (the "refuse payment after signing" guard): a persisted cooperative_close_signed flag on ChannelState. Once set, the node refuses new StreamRequests (ServeRejectReason::CooperativeCloseSigned -> NotFound, wire-indistinguishable) and rejects in-flight vouchers (VoucherRejectReason::CooperativeCloseSigned). Checking the flag at both the request gate and the voucher gate bounds any signed-mid-delivery loss to one voucher interval, so no separate "don't sign while delivering" interlock is needed. - Persistence: the flag rides as an additive trailing postcard segment after the v2 trailer in channels.redb — no schema bump, defaults false for records written before it existed (forward/backward compatible). - mark_cooperative_close_signed uses the same clone-record-swap durability discipline as apply_voucher (#527): persist before the waiver is returned. Tests: redb round-trip across reopen, no-segment-decodes-false, and an end-to-end loopback (waiver recovers to the node key over the on-chain typed data, flag persists, subsequent delivery refused). 951 crate tests pass; workspace clippy + fmt clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ing (#947) Implements the node (provider) half of cooperative close (ADR 003 §Cooperative close), on top of the wire + EIP-712 foundation (#949). - Handler answers a CooperativeCloseRequest on cdn/client/v1 by signing a CooperativeClose waiver over the channel's current voucher watermark (last_amount/nonce/bytes) with the node's eth key and replying with a CooperativeCloseAuth. Best-effort: unknown channel or no-voucher-yet (nonce 0) finishes with no auth and the client falls back to closeChannel. - Self-protection (the "refuse payment after signing" guard): a persisted cooperative_close_signed flag on ChannelState. Once set, the node refuses new StreamRequests (ServeRejectReason::CooperativeCloseSigned -> NotFound, wire-indistinguishable) and rejects in-flight vouchers (VoucherRejectReason::CooperativeCloseSigned). Checking the flag at both the request gate and the voucher gate bounds any signed-mid-delivery loss to one voucher interval, so no separate "don't sign while delivering" interlock is needed. - Persistence: the flag rides as an additive trailing postcard segment after the v2 trailer in channels.redb — no schema bump, defaults false for records written before it existed (forward/backward compatible). - mark_cooperative_close_signed uses the same clone-record-swap durability discipline as apply_voucher (#527): persist before the waiver is returned. Tests: redb round-trip across reopen, no-segment-decodes-false, and an end-to-end loopback (waiver recovers to the node key over the on-chain typed data, flag persists, subsequent delivery refused). 951 crate tests pass; workspace clippy + fmt clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ing (#957) * feat(node): cooperative-close provider side — sign waiver + stop serving (#947) Implements the node (provider) half of cooperative close (ADR 003 §Cooperative close), on top of the wire + EIP-712 foundation (#949). - Handler answers a CooperativeCloseRequest on cdn/client/v1 by signing a CooperativeClose waiver over the channel's current voucher watermark (last_amount/nonce/bytes) with the node's eth key and replying with a CooperativeCloseAuth. Best-effort: unknown channel or no-voucher-yet (nonce 0) finishes with no auth and the client falls back to closeChannel. - Self-protection (the "refuse payment after signing" guard): a persisted cooperative_close_signed flag on ChannelState. Once set, the node refuses new StreamRequests (ServeRejectReason::CooperativeCloseSigned -> NotFound, wire-indistinguishable) and rejects in-flight vouchers (VoucherRejectReason::CooperativeCloseSigned). Checking the flag at both the request gate and the voucher gate bounds any signed-mid-delivery loss to one voucher interval, so no separate "don't sign while delivering" interlock is needed. - Persistence: the flag rides as an additive trailing postcard segment after the v2 trailer in channels.redb — no schema bump, defaults false for records written before it existed (forward/backward compatible). - mark_cooperative_close_signed uses the same clone-record-swap durability discipline as apply_voucher (#527): persist before the waiver is returned. Tests: redb round-trip across reopen, no-segment-decodes-false, and an end-to-end loopback (waiver recovers to the node key over the on-chain typed data, flag persists, subsequent delivery refused). 951 crate tests pass; workspace clippy + fmt clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(node,incentive): coop-close review fixes — v1 flag decode, off-thread fsync, idempotent retry - channel_store: gate the coop-close bool decode on schema_version >= 2 so v1 records' trailing bytes are never mis-decoded as the flag - client handler: run mark_cooperative_close_signed on spawn_blocking, matching apply_voucher / update_channel_deposit (no fsync on a runtime worker) - incentive: early-return Ok(()) when already flagged, avoiding a redundant fsync on retried CooperativeCloseRequest Co-Authored-By: Claude Opus 4.8 <[email protected]> * test(protocol): regenerate public-API snapshot for CooperativeCloseSigned #952 adds VoucherRejectReason::CooperativeCloseSigned to the public surface; the snapshot wasn't refreshed against main (it passed only vs the old stacked base). Additive-only regeneration. Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
* feat(client-pull,cli): client-initiated cooperative close (#971) The buyer/initiator half of cooperative close, on top of the provider waiver (#957) and the wire+EIP-712 foundation (#949). One settle, no 48h dispute window (ADR 003 §Cooperative close). Shared core — `decdn_client_pull::cooperative_close`: - `request_cooperative_close_auth` does the `cdn/client/v1` exchange: send `CooperativeCloseRequest { channel_id }`, await `CooperativeCloseAuth`. A clean stream-end with no frame (the provider's decline for an unknown / zero-voucher channel, handlers/client.rs) maps to `Ok(None)`. - `prepare_close` is the network-free, security-critical step: the provider dictates the final tuple, so the client (a) refuses if it exceeds the authorized watermark — a provider can't hold a higher client voucher, so a larger tuple is a payout-inflation attempt up to the deposit — and (b) verifies the waiver recovers to the provider before spending gas, then signs its own voucher over the agreed tuple. - `cooperative_close` ties request -> prepare -> on-chain `cooperativeClose` submit. The contract enforces the deposit ceiling and monotonic claimed* floor, so a revert is non-fatal (Reverted) — caller falls back to closeChannel. Generic over `Provider`, so the node->node buyer reconcile (#972) drives the same core. Thin CLI — `decdn channel coop-close`: - Chain coords resolve flag > [blockchain] config > default (pure `resolve_chain`, unit-tested). The channel + authorized watermark come from the buyer store (`get_by_provider`), so no manual amount/nonce/bytes tuple is passed — the store IS the record of what this client paid. On Settled the channel is forgotten; Declined/Reverted tell the user to fall back. Tests: prepare_close accept-at-watermark / accept-below / refuse-over-claim / refuse-wrong-signer; CLI resolve precedence. 622 crate tests pass (one pre-existing non-hermetic setup test, which reads the dev's real ~/.decdn config, excluded); workspace clippy + fmt clean. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(client-pull): address coop-close review feedback - Map a deterministic estimation-time revert (caught by gas estimation in `.send()`) to `CooperativeCloseOutcome::Reverted` via typed `as_revert_data()`, so the CLI prints the closeChannel fallback guidance instead of a hard error. A send error without revert data stays a transport/RPC error the caller should retry. - Submit the re-serialized parsed `provider_sig.as_bytes()` rather than the raw wire bytes, so a non-canonical `v` (0/1) that parses and verifies still lands on-chain in the 27/28 form `ECDSA.recover` requires — both sigs now go through the same normalizer. - Reject a waiver whose echoed `channel_id` does not match the requested channel with an actionable error (signature verification already failed closed; this just makes the diagnostic clear). Add a covering test. Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…y vector (#1009) (#1010) * test(incentive,contracts): pin cooperative-close EIP-712 waiver parity vector (#1009) The cooperative-close waiver (PRs #948/#949/#957/#973) is signed off-chain in Rust and verified on-chain by PaymentChannel, with the EIP-712 type and domain hand-duplicated on each side. Nothing pinned the full typed-data digest across both, so a drift in the domain (name/version) or struct encoding would produce unsettleable waivers with no test failure — the existing coverage only pinned the typehash string (Rust) and round-tripped sign/recover within each language. Commit one canonical parity vector and assert it from both sides: - Rust: EXPECTED_COOP_CLOSE_DIGEST + cooperative_close_digest_matches_committed_vector asserting sample_close().signing_hash(sample_domain()) equals it. - Solidity: test_cooperativeClose_digestMatchesVector recomputes the digest with the contract's public COOPERATIVE_CLOSE_TYPEHASH and the fixed domain, and test_cooperativeClose_domainMatchesVector ties the deployed contract's ERC-5267 eip712Domain() name/version to the vector. Verified the vector catches the drift class: bumping the domain version on either side fails the corresponding test. Test-only; no production code changed. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * test(contracts): refresh .gas-snapshot for cooperative-close vector tests The #1010 vector tests add two functions plus fixtures to PaymentChannel.t.sol, enlarging that suite's test-contract bytecode and shifting per-test deployment gas across PaymentChannelTest, plus the two new entries (test_cooperativeClose_digestMatchesVector, test_cooperativeClose_domainMatchesVector). Regenerated via `FOUNDRY_PROFILE=ci forge snapshot --snap .gas-snapshot`; non-reproducible fuzz `runs:` lines left at committed values (the CI gate strips them). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Part of #947. PR 1 of ~3 for off-chain cooperative close. Foundation only — no behavior change yet; the node handler and CLI reconcile build on this. Pairs with the contract PR #948 (
PaymentChannel.cooperativeClose).protocol (
cdn/client/v1)ClientMessagevariants, appended (discriminants 7, 8 — ADR-013 append-only, ALPN unchanged):CooperativeCloseRequest { channel_id }— payer → node.CooperativeCloseAuth { channel_id, amount, nonce, bytes_delivered, signature }— node → payer.COOPERATIVE_CLOSE_SIG_LEN(65) +CooperativeCloseAuth::validatelength check;InvalidCooperativeCloseSigLenerror; discriminant test pins 7/8 and round-trips the payloads.decdn-client-pull'svariant_namematch extended for the two variants.incentive
cooperative_closemodule: the provider's EIP-712CooperativeClosewaiver (sign / recover / verify), sharing the same PaymentChannel EIP-712 domain as vouchers but a distinct typehash — so a client voucher signature can't be replayed as a provider waiver or vice versa (mirrors the on-chain_verifyCooperativeClosevs_verifyVouchersplit).cooperativeClosefunction +ChannelCooperativelyClosedevent added to thePaymentChannelalloysol!binding.Tests
cooperative_close: round-trip sign/verify, wrong-signer, high-srejection (off-chain accept-set matches on-chain), typehash locked to the contract wording, and waiver-digest ≠ voucher-digest. Protocol discriminant freeze updated.cargo nextest run -p decdn-incentive -p decdn-protocol→ 295 passing;cargo clippy --workspaceclean;cargo fmt --checkclean.🤖 Generated with Claude Code