Skip to content

feat(protocol,node,client-pull): tell the proven pool owner its deposit is short (#2013) - #2093

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/issue-2013-pr-option-2-ad17d2
Sep 21, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/issue-2013-pr-option-2-ad17d2

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #2013.

Decision

Issue #2013 needed a decision between three ways to close the buyer's M-estimate gap. Per the issue thread we go with option 2: speak a signed refusal reason to the authenticated lane owner, keep NotFound for probers. Option 1 (keep the estimate) leaves a silent dead-end; option 3 (advertise M) fails the trustless axiom (a self-declared counterparty number the buyer could over-trust into a capital-lockup grief).

Problem

A serving node refuses a new stream once a pool's on-chain remaining − M cannot cover a credit window, and reports that as NotFound alongside real misses so a prober cannot map pool balances (#1520). But M is node policy, not a protocol constant. A buyer that under-estimates one node's M re-opens with a deposit the node still refuses, sees NotFound, reassigns the range, and the pull dies as "held by no reachable provider" — even when it could afford the real floor.

What changed

  • protocol — new delivery-side StreamError::InsufficientDeposit, appended last so postcard discriminants stay frozen.
  • node — ServeRejectReason::InsufficientDeposit now maps to the true wire code instead of collapsing to NotFound. The safety argument is a code invariant: the floor gate is reachable only past the lane-ownership proof — a known lane keyed to a verified signer holding an owner-signed capability — so its audience is the proven pool owner (which already reads on-chain remaining), never an unauthenticated prober. The per-signer gates (SignerFloorAtCap, SignerCapExhausted) and the unconfirmed-pool gate stay collapsed. node_origin::classify_refusal scores the new code Transient.
  • client-pull — the driver routes an open-time InsufficientDeposit into its existing fund-and-retry loop (tops the deposit up toward the buyer's own working_deposit ceiling, then re-opens) and settle-waits it after a top-up like a stale resume. retry_disposition fails it over. The buyer's ceiling is the only clamp on how much a lying node can make it escrow, so the owner-only signal is money-safe.
  • cli — an InsufficientDeposit first-contact refusal no longer suppresses the peer via record_failure (our pool's shortfall, not the peer's fault).
  • ADR 003 / 005 — document the owner-scoped carve-out to serve: the InsufficientDeposit refusal is unobservable in practice — no log, no alert, no dashboard #1520 and the honest residual: an InsufficientDeposit reveals only the inequality remaining − M < window, an owner-only, self-funded bound on M, never M itself.

Tests

  • protocol: variant-order-frozen + domain-split round-trips extended.
  • client-pull: new an_insufficient_deposit_open_refusal_tops_up_and_reopens (buyer can afford the voucher, so genuine_exhaustion rejects it — only the new route recovers); retry_disposition failover case.
  • node: insufficient_deposit_speaks_its_true_code_but_signer_gates_stay_collapsed; updated the proven-owner floor-refusal loopback/e2e tests to expect the owner-facing code (they exercise exactly this scenario).

Known residual (follow-up, not this PR)

The CLI single-source first-contact throwaway handshake open surfaces InsufficientDeposit as a truthful terminal rather than recovering it (it needs total_bytes it can't get from a refused open). The issue's core case — a mid-fetch under-guess — recovers through the driver's re-open, and a first-contact refusal on a pool opened at working_deposit is the correct terminal anyway. A resumed-below-M first contact could be recovered by a top-up-and-re-handshake; left as a follow-up.

Full local gate: cargo build --workspace, cargo clippy --all-targets --all-features (protocol/node/client-pull/cli/e2e), cargo fmt --check, RUSTDOCFLAGS=-D warnings cargo doc, and cargo nextest run for protocol/client-pull/node/cli all pass; decdn-e2e --features anvil-e2e compiles.

🤖 Generated with Claude Code

…it is short (#2013)

A serving node refuses a new stream once a pool's on-chain `remaining − M`
cannot cover a credit window, and reports that as `NotFound` alongside real
misses so a prober cannot map pool balances (#1520). But `M` is node policy,
not a protocol constant: a buyer that under-estimates one node's `M` re-opens
with a deposit the node still refuses, sees `NotFound`, reassigns the range,
and the pull dies as "held by no reachable provider" — even when the buyer
could afford the real floor.

Adopt issue #2013 option 2: speak a signed refusal reason to the authenticated
lane owner, keep `NotFound` for probers.

- protocol: add the delivery-side `StreamError::InsufficientDeposit`, appended
  last to keep discriminants frozen.
- node: `ServeRejectReason::InsufficientDeposit` now maps to the true wire code
  instead of collapsing to `NotFound`. The floor gate is reached only past the
  lane-ownership proof (a known lane keyed to a verified signer holding an
  owner-signed capability), so its audience is the proven owner — which already
  reads on-chain `remaining` — never an unauthenticated prober. The per-signer
  gates (`SignerFloorAtCap`, `SignerCapExhausted`) and the unconfirmed-pool gate
  stay collapsed. `node_origin::classify_refusal` scores the new code
  `Transient` (our own upstream pool short of the peer's `M`, no peer fault).
- client-pull: the driver routes an open-time `InsufficientDeposit` into its
  fund-and-retry loop — tops the deposit up toward the buyer's own
  `working_deposit` ceiling and re-opens — and settle-waits it after a top-up
  like a stale resume. `retry_disposition` fails it over (a smaller-`M` provider
  may admit). The buyer's ceiling is the sole clamp on how much a lying node can
  make it escrow, so the owner-only signal is money-safe.
- cli: an `InsufficientDeposit` first-contact refusal no longer suppresses the
  peer via `record_failure` — it is our pool's shortfall, not the peer's fault.
- adr 003/005: document the owner-scoped carve-out to #1520 and the owner-only
  binary-search residual on `M`.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 21, 2026 09:59

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.

Copilot review overview

🟡 Changes recommended

The new is_insufficient_deposit predicate should ensure it only matches open-stage refusals, and ADR 005’s StreamError snippet is currently internally inconsistent with the protocol surface.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity · 2 Low severity

Open (3)
What changed in this PR

This PR adds an owner-scoped wire refusal (StreamError::InsufficientDeposit) so an authenticated pool owner can distinguish “pool can’t cover the floor/window” from a real cache miss, enabling the buyer to top up and retry without breaking the prober privacy goal.

Changes:

  • Protocol: append StreamError::InsufficientDeposit and extend variant-order/domain-split tests.
  • Node: map the pool-floor admission refusal to InsufficientDeposit (while keeping other privacy-collapsed gates as NotFound) and classify it as Transient.
  • Client-pull/CLI: route InsufficientDeposit into the existing fund-and-retry loop and avoid penalizing the peer for an owner-fixable shortfall; update ADRs to document the carve-out.
File Description
crates/​protocol/​src/​client.rs Adds StreamError::InsufficientDeposit and updates ordering/domain-split tests and docs.
crates/​node/​tests/​node_origin_pull.rs Updates expectations/comments for owner-facing refusal code in same-lane miss tests.
crates/​node/​tests/​client_loopback.rs Updates loopback tests to expect InsufficientDeposit for proven-owner floor refusals.
crates/​node/​src/​node_origin/​mod.rs Treats InsufficientDeposit as transient in upstream refusal classification/tests.
crates/​node/​src/​handlers/​client/​mod.rs Introduces ServeRejectReason::InsufficientDeposit wire mapping (non-collapsing) and clarifies collapse policy in docs/tests.
crates/​node/​src/​handlers/​client/​dispatch.rs Updates dispatch-path comments to reflect new owner-facing wire code.
crates/​e2e/​tests/​pool_floor_ceiling_aggregate.rs Updates e2e assertions/comments to expect InsufficientDeposit for proven-owner overflow refusal.
crates/​client-pull/​src/​retry.rs Ensures InsufficientDeposit triggers failover (after top-up loop gives up) and extends tests.
crates/​client-pull/​src/​lib.rs Adds is_insufficient_deposit predicate for routing refusal into top-up/retry behavior.
crates/​client-pull/​src/​driver.rs Adds driver handling to settle-wait / top-up-and-reopen on InsufficientDeposit; adds a driver test.
crates/​cli/​src/​commands/​fetch.rs Avoids suppressing peers on InsufficientDeposit because it’s not peer fault.
adr/​005-protocol.md Documents the new refusal code and its lifecycle position.
adr/​003-payments.md Documents the owner-only floor-refusal carve-out and what it leaks (inequality bound only).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/client-pull/src/lib.rs Resolved
Comment thread adr/005-protocol.md Resolved
Comment thread crates/client-pull/src/driver.rs Resolved
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 83.39% (was 83.37%, ▲ +0.02%) — 84526/101359 lines

File Coverage Lines Δ
crates/cli/src/commands/fetch.rs 44.82% 1098/2450 ▼ 0.04%
crates/client-pull/src/driver.rs 94.35% 1452/1539 ▲ +0.21%
crates/client-pull/src/lib.rs 89.76% 1788/1992 ▲ +0.22%
crates/client-pull/src/retry.rs 100.00% 60/60 ● 0.00%
crates/node/src/handlers/client/dispatch.rs 81.06% 518/639 ● 0.00%
crates/node/src/handlers/client/mod.rs 95.00% 2015/2121 ▲ +0.17%
crates/node/src/node_origin/mod.rs 92.51% 1186/1282 ▲ +0.02%
crates/protocol/src/client.rs 97.53% 1066/1093 ● 0.00%
History
Commit Total Δ vs base
c128d56 83.39% ▲ +0.02%
c2a08bb (HEAD) 83.39% ▲ +0.02%

…tage evidence; sync API + ADR snippets

Address review on #2093:

- `is_insufficient_deposit` now requires open-stage evidence
  (`UpstreamRefused::evidence().is_some()`). A legitimate `InsufficientDeposit`
  rides only in the signed open-stage `StreamResponse { ok: false }`; a
  protocol-violating bare mid-stream `StreamError::InsufficientDeposit` no longer
  drives the top-up loop. New test pins both directions.
- driver test now builds a real open-stage refusal via `UpstreamRefused::open`
  (signed `ok: false` + ext), matching its doc, instead of `mid_stream`.
- ADR 005: the illustrative `StreamError` snippet now lists `OriginBlacklisted`
  and `HashBlacklisted` (ADR 011) alongside the new `InsufficientDeposit`, so it
  matches the real wire surface.
- regenerate the `decdn-protocol` public-API insta snapshot for the new variant.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@alpergundogdu
alpergundogdu merged commit c0df360 into main Sep 21, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the claude/issue-2013-pr-option-2-ad17d2 branch September 21, 2026 13:14
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.

Buyer estimate of an upstream's refundable floor M: decide between estimate, signed refusal reason, or advertised M

2 participants