Repository navigation
feat(node): cooperative-close provider side — sign waiver + stop serving - #952
alpergundogdu wants to merge 2 commits into
Conversation
…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]>
There was a problem hiding this comment.
Code Review
This pull request implements the cooperative-close flow (ADR 003 §Cooperative close) by adding a cooperative_close_signed flag to ChannelState, persisting it across restarts, and refusing subsequent delivery requests once signed. The feedback highlights three important issues: first, decoding the cooperative-close flag should only occur when the schema version is 2 or greater to prevent corruption of older records; second, the synchronous disk write in mark_cooperative_close_signed should be offloaded to tokio::task::spawn_blocking to avoid blocking the async executor; and third, the method should return early if the flag is already set to prevent redundant and expensive disk writes.
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
Implements the provider/node half of cooperative close (ADR 003): the node can sign and return a cooperative-close waiver at the channel’s current voucher watermark, persist a “signed” flag, and stop serving/accepting vouchers on that channel thereafter.
Changes:
- Add
CooperativeCloseSignedas a newVoucherRejectReasonand emit it from the node when a cooperative-close waiver has been signed. - Add a
cdn/client/v1handler path forCooperativeCloseRequest→CooperativeCloseAuth, including signing + persisting a cooperative-close flag and gating both new streams and in-flight voucher collection. - Persist the cooperative-close flag in
channels.redbas an additive trailing postcard segment, plus metrics + tests (redb round-trip + loopback end-to-end).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/protocol/src/client.rs | Extends VoucherRejectReason with CooperativeCloseSigned and updates discriminant-order tests. |
| crates/node/src/handlers/client.rs | Dispatches CooperativeCloseRequest, signs waiver, persists flag, and gates serving/voucher collection when flagged. |
| crates/node/src/channel_store.rs | Persists the cooperative-close flag as an optional trailing postcard bool segment; adds reopen/back-compat tests. |
| crates/node/src/metrics.rs | Adds a per-reason counter for stream refusal due to cooperative-close flag. |
| crates/node/tests/client_loopback.rs | Adds end-to-end loopback test verifying waiver signature, persistence, and post-sign serving refusal. |
| crates/incentive/src/channel.rs | Adds cooperative_close_signed state + persisted setter/getter on ChannelState. |
| crates/incentive/src/store.rs | Updates in-memory store tests for the extended ChannelState::hydrate signature/round-trip. |
| crates/node/src/admin.rs | Updates admin-channel test fixtures to include the new hydrate parameter. |
| crates/cli/tests/admin_peers.rs | Updates CLI admin tests’ channel fixtures for the new hydrate parameter. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…read 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]>
…gned #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]>
|
Superseded by #957. GitHub auto-closed this PR (and refused to reopen it) when its stacked base branch |
…gned #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]>
…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]>
Part of #947. PR 2 of ~3 — the node (provider) half of cooperative close. Stacked on #949 (base =
claude/coop-close-protocol); review/merge that first. ADR 003 §Cooperative close.What the node does
Answers a waiver request. On
cdn/client/v1, aCooperativeCloseRequest { channel_id }is dispatched (alongside the existingStreamRequestpath) tohandle_cooperative_close: it signs aCooperativeClosewaiver over the channel's current voucher watermark (last_amount/nonce/bytes) with the node's eth key and repliesCooperativeCloseAuth. Best-effort — unknown channel or no voucher yet (nonce == 0) finishes with no auth and the client falls back tocloseChannel.Stops serving after signing (your "refuse payment after signing" guard). A persisted
cooperative_close_signedflag onChannelState. Once set, the node:StreamRequests (ServeRejectReason::CooperativeCloseSigned→NotFound, wire-indistinguishable from an unknown channel), andVoucherRejectReason::CooperativeCloseSigned).Gating at both points means signing mid-delivery just stops the in-flight stream at its next voucher (bounded by one interval) — so no separate "don't sign while delivering" interlock is needed, which is why I collapsed your two guards into one persisted flag.
Persistence
The flag rides as an additive trailing postcard segment after the v2 trailer in
channels.redb— no schema bump, defaultsfalsefor records written before it existed (old binaries ignore the extra byte; new binaries default-false a missing one).mark_cooperative_close_signeduses the same clone-record-swap durability discipline asapply_voucher(#527): persist before the waiver is returned, so a store failure leaves the channel serveable.Tests
false.CooperativeClosetyped data, the flag persists, and a subsequent delivery request is refused (blob present, so it would otherwise serve).cargo nextest run -p decdn-incentive -p decdn-protocol -p decdn-node→ 951 passing;cargo clippy --workspace --all-targets+cargo fmt --checkclean.Note
Adds
VoucherRejectReason::CooperativeCloseSignedto the protocol enum (handler-emitted-only, likeExpired/RetryLater) — a small protocol-crate addition that logically extends #949.🤖 Generated with Claude Code