Skip to content

Payment channels aren't resilient to a fetch exiting early: it strands the channel + deposit (durable watermark, resumable fetch, resync, coop-close reconciliation) #1122

Closed

Description

@alpergundogdu

Summary

A single transient transport drop mid-transfer permanently strands a payment channel (and its on-chain deposit). The payment layer is not resilient to disconnects: the client's persisted voucher watermark lags what it actually signed/sent, so an unclean exit desyncs it below the node's last-accepted nonce; every subsequent fetch on that channel then re-signs a stale nonce and is rejected, and there is no non-terminal way to recover — coop-close's over-claim guard refuses to settle above the client's (now-behind) record.

This turns an ordinary flaky-network event into a lost channel + locked deposit. It is easy to hit on large transfers and single-stack/NAT'd nodes.

Real-world repro (observed)

Serving a 708 MB blob; the first fetch exited before persisting its full voucher watermark. The exact trigger (a timeout, an interrupt, a transient drop) is incidental — normal transfers complete fine — the point is the client had advanced further than it durably saved:

  1. First fetch ran and vouchers flowed; the client signed/sent up to nonce 182 (the node accepted them) but exited having persisted only up to nonce 119.
  2. Retry → Error: frame read failed: frame I/O error: early eof (client re-signs a stale nonce ≤119; node drops the stream after the first chunk).
  3. decdn channel coop-close → Error: provider over-claimed: waiver (1792, 182, 187522216) exceeds authorized (1162, 119, 121461928).

The node holds vouchers up to nonce 182 (amount 1792 µUSDC, 187,522,216 bytes); the client only persisted up to nonce 119 (1162 µUSDC, 121,461,928 bytes) — it signed the rest but lost them on the unclean exit. The channel is now unusable and its deposit un-reclaimable without a unilateral on-chain close. (Recovery required abandoning the channel and opening a fresh one.)

Proposed fixes (resilience, in priority order)

  1. Durable, write-ahead voucher watermark (client). Persist the outgoing nonce/amount to the buyer-channel store before the voucher is put on the wire (or make send+persist atomic), so a crash/drop can never leave the persisted watermark behind what the node accepted. This alone prevents the desync. Relevant: decdn_client_pull (voucher signing/send loop) + the buyer-channel redb store; see the existing "the next reuse may re-sign a stale nonce" warning in crates/cli/src/commands/fetch.rs.
  2. Resumable fetch. The wire protocol already supports byte-offset resume (StreamRequest.byte_offset, "resume from the last BLAKE3-verified byte" — crates/protocol/src/client.rs:158-178). Have decdn fetch keep a partial output + resume from the last verified byte on a transient drop, instead of restarting (which re-poisons the channel and re-downloads).
  3. Non-terminal channel-state resync query. Add a client→node request that returns the node's signed last-accepted {nonce, amount, bytes_delivered} WITHOUT setting the cooperative-close-signed flag (unlike CooperativeCloseRequest, which is terminal — handle_cooperative_close → mark_cooperative_close_signed, after which serves reject with CooperativeCloseSigned). A client with a lagging watermark can then resync and resume the same channel.
  4. Coop-close reconciliation when the client is behind. When the node's declared state exceeds the client's record, the node holds the client's OWN signed vouchers for the gap — it should return them (or the highest signed voucher) as proof so the client can verify (they're its own signatures), advance its watermark, and settle at the true state, instead of the current over-claim dead-end that strands the deposit.

Impact

Any mid-transfer disconnect (common on large blobs / single-stack / NAT'd nodes) currently strands a channel and its deposit and blocks further fetches on it. Fix #1 makes drops non-fatal; #2 makes large transfers survive them; #3/#4 provide recovery when a desync happens anyway.

Related

Activity

  1. alpergundogdu commented on Jul 13, 2026

    @alpergundogdu
    ContributorAuthor

    Sharper spec for fixes #3 (resync) + #4 (coop-close reconciliation): "channel sync"

    The recovery primitive for both is the same and is cryptographically clean: the node returns the client's OWN signed voucher(s) above the client's persisted watermark as proof. The client verifies the signature is its own; if valid, it advances its watermark to that nonce. It can never be tricked into over-paying, because it only ever advances on a voucher it actually signed — the node cannot forge a higher one.

    Surface it two ways:

    1. Explicit — decdn channel sync --provider-address …: asks the node for the highest voucher it holds from this client; the node returns that signed voucher; the client verifies its own signature and advances its persisted watermark to that nonce.

    2. Automatic (self-healing): when the node rejects a voucher mid-fetch for an invalid/stale nonce, it returns its highest-held client voucher; the client verifies + bumps its watermark + resumes — no manual step.

    This subsumes the earlier stopgap idea of a --accept-overclaim / DECDN_ACCEPT_OVERCLAIM flag (which just "trusts the node"): with sync, the client reconciles against its own signatures, and the coop-close over-claim dead-end disappears entirely (once synced, coop-close settles normally). Recommend implementing #3/#4 as this single "channel sync" mechanism (explicit command + automatic on nonce-reject).

  2. yigitdot commented on Jul 18, 2026

    @yigitdot
    Contributor

    Cross-reference: #1293 (DECDNMAN chunk-manifest reconstruction, #1183) lands a partial, chunk-granularity version of fix #2 (resumable fetch) for manifest-published files specifically.

    For a chunked file, part files at ~/.decdn/downloads/<manifest-hash>/chunk-<index>.part are retained by default, and a retained part that still verifies against its ChunkEntry BLAKE3 hash is reused rather than re-fetched. So an interrupted multi-chunk download resumes at chunk granularity without re-paying for chunks already pulled and verified.

    Two things that does not cover, so this issue stays fully open:

    • It's chunk-granular, not byte-granular. A drop within a 256 MiB chunk still discards that chunk's progress; the StreamRequest{byte_offset} resume this issue asks for is untouched.
    • It does nothing for the single-blob publish path — the 708 MB repro in the issue description is exactly that case.

    Worth flagging one thing #1293 surfaced that bears directly on the watermark-desync mechanism at the heart of this issue. ChannelContext snapshots the channel's voucher watermark (prior_nonce) at construction, and fetch_blob advances it in the store as it pays. Hoisting a single context across a multi-chunk file would therefore re-sign an already-spent nonce and the node would reject it — the same stale-nonce failure this issue reports, reachable without any crash or disconnect. #1293 avoids it by rebuilding the channel context per chunk (see the comment at crates/cli/src/commands/fetch.rs:527).

    That is a workaround at the call site, not a fix to the underlying invariant. It reinforces fix #1 (write-ahead durable watermark): as long as the persisted watermark can lag what was actually signed, every new multi-request caller has to know to rebuild context or silently poison the channel.

  3. altanoruc commented on Jul 24, 2026

    @altanoruc
    Contributor

    Automated implementation triage note for a later run: this combines four independently mergeable fixes (write-ahead voucher durability, byte-range fetch resume, non-terminal signed-voucher sync, and cooperative-close reconciliation), so one agent cannot satisfy the closure condition within the small-PR ceiling. Please split them in dependency order. For the first slice, pin the exact durability boundary (persist-before-sign vs persist-before-send and rollback/retry behavior); for channel sync, pin the wire request/response/error variants and whether automatic stale-nonce recovery ships with or after the explicit CLI command. Each slice then has a deterministic crash/drop regression.

  4. added this to the v0.1 milestone on Jul 28, 2026
  5. self-assigned this
    on Jul 28, 2026
  6. thiras commented on Jul 28, 2026

    @thiras
    Contributor

    Status update after working through this alongside #1132 and #1120. Three of the four proposed fixes are addressed; the fourth is split out to #1495.

    1. Durable write-ahead voucher watermark — recommend closing as superseded, not implementing.

    A pre-send persist would add a client-side fsync per voucher, which cuts directly against the group-commit direction #1483 just took, to close a residual the reconciliation path already recovers from. The VoucherProgress docs (crates/client-pull/src/lib.rs) already scope the gap to one-sided ack loss and name a reconciliation read as the fix — which is what #1481 shipped. Both fetch paths persist the acked watermark on the error path, so an unclean exit loses at most the one voucher whose ack was in flight.

    2. Resumable fetch — done.

    decdn fetch now writes each bao chunk group to <output>.partial as it verifies and renames it into place, instead of buffering the blob and writing once. A partial from an interrupted run is picked up automatically, the node is asked for the un-fetched tail only, and only that tail is paid for. Peak memory is one chunk group rather than ~2x the blob.

    One thing that fell out of implementing it, worth recording: a prefix inherited from disk cannot be verified in isolation. bao verifies a chunk group through the parent hashes covering the rest of the tree, and a client holding only a prefix never received them — so the plan of "recompute the prefix's outboard" does not actually work. A resumed fetch instead re-hashes the assembled file against the content hash before promoting it, and discards the partial on mismatch. A fetch from byte 0 skips that, since every byte was verified on the wire.

    3. Non-terminal channel-state resync — already delivered by #1481.

    The WatermarkBundle on a watermark-gated VoucherRejected is exactly this: the client verifies the higher watermark against its own signature and reseeds, without the channel being frozen. Confirmed non-terminal — mark_cooperative_close_signed is called only from the coop-close handler (crates/node/src/handlers/client/voucher.rs:575), never from the reject path.

    4. Coop-close reconciliation — still open, moved to #1495.

    This one needs a wire change, so it was kept out of the batch. CooperativeCloseAuth carries only the provider's waiver signature, so the client has nothing to check against its own key and prepare_close can only refuse. The node holds the client's last-accepted voucher signature but does not send it. Details and proposed surface in #1495.

    Net effect on the repro: reaching the stranded-channel dead-end now requires a desync and never fetching again on that channel before closing, since any fetch heals the watermark.

    Leaving this issue open to track item 4 via #1495, or it can be closed in favour of #1495 if you prefer that shape.

  7. removed their assignment
    on Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions