Repository navigation
feat(client,node): add PoolContext::new and bind_endpoint, bind the example lanes - #2358
Conversation
…xample lanes PoolContext gains a general constructor, PoolContext::new(pool_id, deposit, signer, voucher_domain), which a delegated signer without a pool row can use. for_pool delegates to it. The struct is non_exhaustive outside the test-util feature, so workspace tests keep their literals. The node's local bookkeeping context uses the constructor. PoolContext::bind_endpoint signs the endpoint's node ID with the context's signer and attaches the ADR 005 client binding in one call. The download and stream examples attach none. A node that misses the blob in its cache refuses an unbound lane with NotFound, so on testnet both examples stalled while `decdn fetch` of the same blob succeeded. They now bind every lane, and the crate guide's step 5 says to. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The change is small, additive, behavior-preserving, matches an established in-crate pattern exactly, and all construction-site, import, and snapshot invariants were verified.
Review effort: Balanced
Findings: None
What changed in this PR
This PR adds two ergonomics/release-readiness items to the decdn-client SDK and fixes the shipped examples so they actually fetch against testnet. The root cause of the example failures was the missing ADR 005 client binding: a node that misses a blob refuses an unbound lane with NotFound, because it may only pull from its origin for a buyer that proves pool ownership. The CLI already signed and attached this binding inline; the examples attached nothing and sign_client_binding was #[doc(hidden)], so SDK users had no discoverable path to it.
Changes:
- Add
PoolContext::new(pool_id, deposit, signer, voucher_domain)as a general constructor (usable by delegated signers that hold noBuyerPoolState);for_poolnow delegates to it, and the node'slocal_bookkeeping_ctxproduction literal uses it. - Add
PoolContext::bind_endpoint(&endpoint, &bind_domain), a one-call wrapper oversign_client_binding+with_client_binding, and makePoolContext#[cfg_attr(not(feature = "test-util"), non_exhaustive)]so production code must use constructors while test literals stay. - Bind every example lane via the shared
common::Buyer, update the crate-guide step 5 doc, and regenerate the public-API snapshot.
| File | Description |
|---|---|
crates/client/src/lib.rs |
Adds new, bind_endpoint, non_exhaustive gate, and refactors for_pool to delegate to new; updates docs. |
crates/node/src/node_origin/pull_leg.rs |
Rewrites local_bookkeeping_ctx to use PoolContext::new (behavior-preserving; defaults match the removed literal). |
crates/client/examples/common/mod.rs |
Adds bind_domain to Buyer and binds each lane via bind_endpoint, so both examples prove pool ownership. |
crates/client/tests/snapshots/public_api__public_api.snap |
Records the non_exhaustive marker plus the new new and bind_endpoint entries. |
I verified: bind_endpoint reproduces the exact binding derivation used in crates/cli/src/commands/fetch.rs:3504-3505 and crates/node/src/node_origin/mod.rs:1872-1873; new initializes all nine fields identically to the removed local_bookkeeping_ctx literal; the Address import in pull_leg.rs remains used; bind_node_id_domain is re-exported from decdn_incentive; and every out-of-crate PoolContext { .. } literal lives in a #[cfg(test)] module whose crate dev-deps enable decdn-client/test-util, so the non_exhaustive gate is satisfied.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Summary
Two release-readiness items for the
decdn-clientSDK.The examples now work against testnet
I ran the
downloadandstreamexamples against Arbitrum Sepolia, using a fresh 5 USDC pool. Every holder answered the probe as a holder, then refused every paid open withNotFound.decdn fetchof the same blob, from the same pool and the same node, succeeded in under a second.The difference is the ADR 005 client binding. The CLI signs its own endpoint's node ID with the buyer key and attaches it to the lane; the examples attached nothing. A node that misses the blob in its cache refuses an unbound lane, because it may only pull from its origin for a buyer that proves it owns the pool. The crate guide's setup sequence never mentioned the binding, and
sign_client_bindingis hidden from the SDK docs, so an SDK user had no way to find it.PoolContext::bind_endpoint(&endpoint, &bind_domain)signs and attaches the binding in one call.After the fix, both examples fetched the Qwen2.5-7B manifest blob (
6e9b67de…, 296,581 bytes) with zero lane faults. The output is byte-identical todecdn fetch's copy, andpool listshows the lanes' payments recorded.PoolContext constructor
PoolContext::new(pool_id, deposit, signer, voucher_domain)is a general constructor. A delegated signer, which holds noBuyerPoolState, can use it.for_pooldelegates to it.PoolContextis#[cfg_attr(not(feature = "test-util"), non_exhaustive)], the same pattern as the fetch errors, so the roughly 30 test literals in the node and CLI stay as they are.local_bookkeeping_ctx) uses the constructor.Test plan
cargo clippy --workspace --all-targetswith and without--all-features. The plain build proves no production literal outside the client remains.RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-itemsnew,bind_endpoint, thenon_exhaustivemarker)cargo nextest run -p decdn-cli -p decdn-node -p decdn-client --lib.proof_wait::tests::stream_frames_count_stream_data_and_not_keep_alivesfailed once on a machine at load 35, then passed 3 out of 3 alone. That code is untouched here.cargo test --doc -p decdn-client, andcargo test --no-run -p decdn-e2e --features anvil-e2edownloadandstreamexamples run end to end on Arbitrum Sepolia, as above🤖 Generated with Claude Code