Skip to content

fix(node): confirm a pool on-chain before admitting a serve - #1956

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/debug-logs-connection-pool-26aea7
Sep 9, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/debug-logs-connection-pool-26aea7

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Problem

A node served a cache hit for any pool its in-memory projection had not confirmed. When pool_status was None (a pool opened before the settlement watcher's cold-start head, an unknown/nonexistent pool, or an RPC-blind window), the floor-solvency gate failed open and the node signed ok: true and streamed — trusting "the on-chain redeem is the backstop." That backstop cannot exist for a pool the node never confirmed: the mid-stream re-check also fails open on None, so an unconfirmed, nonexistent, or drained pool was served indefinitely, granting one credit window after another for cryptographically-valid but uncashable vouchers.

This is the laziest attack surface — open one dust pool, then pull unlimited data during any solvency-blind window, paying in vouchers the node can never redeem — and it quietly undercuts the per-byte payment model the capability machinery exists to enforce.

Fix

Confirm the pool on-chain at admission instead of failing open. This reuses the existing PoolView split (status() may block at admit; cached_status() must not, mid-stream):

  • New ResolvingPoolView: on a projection miss, status() does one getPool, folds a servable pool into the shared projection via record_resolved, and refuses an absent / closed / errored pool (retryable — wire-collapses to NotFound). A short-TTL negative cache stops a dead-pool request flood from storming getPool.
  • cached_status() (mid-stream re-check) stays in-memory — no per-voucher getPool. Once seeded, the settlement watcher folds PoolRedeemed deltas, so remaining stays fresh with no further chain reads. A repeat fetch on a confirmed pool does zero eth_calls.
  • dispatch.rs: refuse when a pool-view is wired and status() returns None; intake_capability now takes a confirmed owner.
  • Deleted: the async fire-and-forget pool-owner resolver + its hint channel, and the intake silent-drop-on-unknown-owner path — all redundant once admission confirms synchronously.
  • No pool-view wired (dev/test, no chain): prior fail-open behavior unchanged.

ADR

Amends ADR 003 §Pool solvency with the confirm-before-serve admission precondition ("Admission confirms the pool on-chain", "Capability validity is an admission gate") and scopes "serve partly blind" to other parties' vouchers only.

Scope

Deliberately limited to pool existence + solvency. The concurrency fan-out reservations (per-lane cap #1697, per-pool floor reservation, abandonment buckets) are untouched and being scrutinized separately.

Testing

All gates pass locally (independently re-run):

  • cargo build · cargo clippy --all-targets --all-features -D warnings · cargo fmt --check · RUSTDOCFLAGS="-D warnings" cargo doc … --document-private-items — clean
  • cargo nextest run -p decdn-node — 1116 passed, 0 skipped
  • New admit coverage: unknown→getPool→admit (+ repeat = no eth_call); absent/closed→refuse+negative-cache; getPool fault→refuse+negative-cache; cached_status never calls getPool.

🤖 Generated with Claude Code

A node served a cache hit for any pool its in-memory projection had not
confirmed, failing open on a `None` pool status and trusting an on-chain
redeem "backstop" that cannot exist for an unconfirmed pool. An
unconfirmed, nonexistent, or drained pool was served indefinitely,
granting one credit window after another for vouchers the node can never
cash — the laziest attack, needing at most one dust pool.

Confirm the pool on-chain at admission instead. On a projection miss the
admit-path `PoolView::status()` does ONE `getPool`, folds a servable pool
into the shared projection, and refuses an absent, closed, or errored one
(retryable; wire `NotFound`). The mid-stream `cached_status()` stays
in-memory, so a repeat fetch on a confirmed pool does no eth_call. This
deletes the async fire-and-forget pool-owner resolver, its hint channel,
and the intake silent-drop-on-unknown-owner path; `intake_capability` now
takes a confirmed owner. With no pool-view wired (dev/test, no chain) the
prior fail-open behavior is unchanged.

Amends ADR 003 Pool solvency with the confirm-before-serve admission
precondition.

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

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.

🟡 Changes recommended

There are remaining correctness/operability issues in the updated documentation and rejection/metrics classification that should be addressed before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR hardens the node’s paid serve admission path by requiring on-chain confirmation of a pool (via a projection-first getPool fallback) before admitting a stream when a pool-view is wired, preventing indefinite service against unconfirmed/nonexistent/drained pools.

Changes:

  • Introduces an admit-time ResolvingPoolView that does a one-time getPool on projection miss, seeds the shared projection on success, and uses a short negative cache on non-servable/error results.
  • Updates the serve dispatcher to refuse admission when a wired pool-view cannot confirm a pool, and tightens capability intake to require a confirmed pool owner.
  • Removes the prior background pool-owner resolve-hint channel/resolver plumbing and amends ADR 003 to document confirm-before-serve admission.
File summaries
File Description
crates/node/tests/anvil_settlement_e2e.rs Removes the now-deleted pool resolve-hint channel wiring in the E2E harness.
crates/node/src/runtime/mod.rs Wires ResolvingPoolView into handler deps and removes resolve-hint channel setup.
crates/node/src/pool_view.rs Updates PoolView/projection docs to reflect admission vs mid-stream behavior.
crates/node/src/payment_settlement.rs Deletes the background resolver and adds ResolvingPoolView + unit tests.
crates/node/src/handlers/client/mod.rs Removes resolve-hint plumbing and makes intake require a confirmed owner.
crates/node/src/handlers/client/dispatch.rs Adds the refuse-on-unconfirmed-pool admission gate and gates intake on confirmed status.
adr/003-payments.md Documents confirm-before-serve admission and capability validity as admission gates.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Lite

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

Comment thread crates/node/src/pool_view.rs Resolved
…tatus doc

Address PR review: the confirm-before-serve gate reused
`InsufficientDeposit`, conflating an unconfirmed/absent/RPC-faulted pool
with real deposit exhaustion in the per-reason metric. Add a distinct
`ServeRejectReason::PoolUnconfirmed` (wire-collapses to `NotFound` like
its siblings, so no balance/existence leak) with its own
`decdn_serve_stream_rejected_pool_unconfirmed_total` counter, so an
operator can tell a chain/RPC problem from a drained pool.

Also correct the `pool_view` module doc: a mid-stream `cached_status()`
`None` does not mean the entry "aged out" — the projection never ages
entries out; a seeded entry persists until `PoolReclaimed` removes it.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 82.76% (was 82.73%, ▲ +0.03%) — 75646/91404 lines

File Coverage Lines Δ
crates/node/src/handlers/client/dispatch.rs 84.42% 504/597 ▼ 0.81%
crates/node/src/handlers/client/mod.rs 94.43% 2611/2765 ▼ 0.11%
crates/node/src/handlers/client/wire.rs 93.94% 403/429 ▼ 0.66%
crates/node/src/metrics.rs 94.65% 884/934 ▲ +0.01%
crates/node/src/payment_settlement.rs 56.77% 771/1358 ▲ +4.69%
crates/node/src/pool_view.rs 97.70% 340/348 ▲ +0.86%
crates/node/src/runtime/mod.rs 47.70% 1171/2455 ▲ +0.08%
History
Commit Total Δ vs base
7789063 82.76% ▲ +0.04%
962aa82 (HEAD) 82.76% ▲ +0.03%

@alpergundogdu
alpergundogdu merged commit 166492b into main Sep 9, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the claude/debug-logs-connection-pool-26aea7 branch September 9, 2026 09:35
alpergundogdu added a commit that referenced this pull request Sep 9, 2026
…rve (#1958)

* fix(node): confirm signer cap headroom on-chain before admitting a serve

The signer-level twin of #1956. A capability's `spending_cap` is shared
across every provider, so a signer that has drawn its full cap at other
nodes is uncashable — yet the pool-confirm gate only checks pool-level
solvency. A "spent" capability presented to a new/unaware node passed
admission and got served for vouchers the node can never redeem
(`redeemMany` pays `min(desired, cap − spent) = 0`), and the same
exhausted capability sprayed across N fresh nodes yields N × cap free
bytes.

Confirm the signer at admission too. `PoolView` gains
`signer_cap_headroom_micro`; the production `ResolvingPoolView` reads the
signer's on-chain `{cap, spent}` with one `getAuthorization` (briefly
cached, so a repeat fetch does no eth_call) and the admit gate refuses
`SignerCapExhausted` when a registered signer's `cap − spent` cannot
cover a serve floor. An unregistered signer has spent nothing on-chain,
so it admits on its off-chain capability; a `getAuthorization` fault
refuses. Wire-collapses to `NotFound` (no leak) with its own
`decdn_serve_stream_rejected_signer_cap_exhausted_total` counter. No
chain wired (dev/test) keeps prior behavior.

Amends ADR 003 §Pool solvency with the signer cap-headroom admission
precondition.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(node): address PR review on the signer cap-headroom gate

- Fail-open fix: a registered signer with a zero `spendingCap`
  (`cap == 0` but `expiry != 0`) is NOT the all-zero unregistered
  authorization. Treat only `cap == 0 && expiry == 0` as unconstrained;
  a registered zero-cap (or fully-spent) signer now reports `0` headroom
  and is refused instead of admitted as uncashable. Adds a test.
- Bound the signer-auth cache (`AUTH_CACHE_MAX`): at the cap, prune
  expired entries and skip caching if still full, so a flood of distinct
  `(pool, signer)` pairs cannot grow the map without bound (mirrors the
  negative cache).
- Reword the `SIGNER_AUTH_TTL` doc: the stale-cache exposure is
  TTL-bounded, not "one more stream".

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
alpergundogdu added a commit that referenced this pull request Sep 9, 2026
)

The hint-driven redeemer re-issued a `getAuthorizations` eth_call for a
lane on every accepted voucher (~1 per MiB) whenever the signer was not
yet marked registered. The read only answered "is this signer registered,
so should I attach a CapabilityReg?" — a question the node can answer
locally: it already holds a validated `owner_sig` (captured and verified
against the pool owner at admit, #1956/#1958), stored in the same fsynced
row as the frontier (#1906), so a lane with redeemable value always has
the material to register its signer. And `_registerCapability` is
idempotent, so re-attaching a CapabilityReg for a signer another provider
already registered is a harmless no-op. The read was dead weight issued
per voucher — thousands of billed eth_calls per stuck lane.

Resolve registration locally instead: a lane is Registered iff this node
has landed its registration (persisted `registered_until` still live),
else Unregistered → attach a CapabilityReg from the held `owner_sig`. The
first landed redemption persists `registered_until`, so every later pass
attaches nothing. The redeemer's only on-chain-derived gate is now pool
solvency (the event-fed projection), exactly like the serve path.

The no-`owner_sig` case stops telling the client to "re-send its
capability" — the client sent it once; a redeemable lane without
`owner_sig` is a node durability fault, logged at error! and skipped.
Deletes `batched_authorizations` and the `RegistrationStatus::Fetched`
read path.

Co-authored-by: Claude Opus 4.8 <[email protected]>
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.

2 participants