Skip to content

refactor(client-pull): promote discovery/probe/endpoint/provider to public modules - #1022

Merged
alpergundogdu merged 1 commit into
mainfrom
claude/admiring-darwin-6933b5
Jun 30, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
claude/admiring-darwin-6933b5

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

What

Promotes the client-side fetch toolkit out of the decdn-cli bin crate into public decdn-client-pull modules, so any client of the cdn/client/v1 data plane — not just the decdn binary — can reuse the full "discover → probe → open/reuse channel → paid-fetch" path.

Pure relocation, no behavior change:

From (bin-locked) To (public library module)
cli/commands/discovery.rs (active_nodes, select_candidates, rank) client-pull/src/discovery.rs
cli/commands/probe_client.rs (probe_once, ProbeMetrics) client-pull/src/probe.rs
cli/commands/client_endpoint.rs (relay/discovery endpoint builder) client-pull/src/endpoint.rs
cli/commands/chain_ctx::build_provider (wallet provider builder) client-pull/src/provider.rs

Why

decdn-client-pull already held the reusable cdn/client/v1 paid-fetch and buyer-channel kernels, but the discovery half lived in the decdn-cli bin crate (marked "only ever a dev-dependency"), so it was unreachable as a library. This removes that asymmetry and gives the repo one documented public client-fetch surface shared by the CLI and any future client. Justified on its own merits; also unblocks the out-of-repo decdn-gateway spun out of #866.

Changes

  • Move the three modules (git mv, history preserved) + extract build_provider into provider.rs.
  • Repoint cli call sites: fetch, bundle_pull, channel, probe, bond, register, setup.
  • Repoint node/tests/probe_0rtt.rs to decdn_client_pull::probe; drop the now-unused decdn-cli dev-dep from node.
  • client-pull gains a decdn-common dep (for endpoint) — iroh-blobs-free per CLI binary-split regression: publisher links cache crate (iroh-blobs/AWS SDK) #578, so the CLI's iroh-blobs-free invariant is preserved (verified with cargo tree -p decdn-cli -e normal -i iroh-blobs → empty).
  • chain_ctx keeps its CLI-coupled config/keystore plumbing; only build_provider moved.

The node crate's separate probe_client.rs (a Send + Sync variant for its concurrent probe loop) is intentionally left in place — consolidating it is a different, riskier change out of scope here.

Verification

  • cargo build, cargo clippy --all-targets, cargo fmt --check, cargo doc -D warnings, cargo deny check — all clean (pre-commit + local).
  • cargo nextest run -p decdn-client-pull -p decdn-cli → 261 passed (includes the relocated discovery::/endpoint:: tests).
  • cargo nextest run -p decdn-node -E 'binary(probe_0rtt)' → 5 passed (the repointed import).

Closes #1021.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added shared client-side support for discovery, endpoint lookup, probing, and provider creation across CLI commands.
    • Improved command flows for bonding, fetching, registering, setup, probing, and cooperative close by using the shared client components.
  • Bug Fixes

    • Standardized blockchain connection handling across commands for more consistent behavior.
    • Improved error handling when an RPC address is invalid by avoiding exposure of sensitive connection details.

…ublic modules

The client fetch path was split: decdn-client-pull held the reusable
cdn/client/v1 paid-fetch + buyer-channel kernels, but discovery, probe,
the client iroh-endpoint builder, and the wallet provider builder lived
in the decdn-cli *bin* crate, which nothing can depend on. That left one
shared "discover -> probe -> open/reuse channel -> paid-fetch" path with
its discovery half unreachable as a library.

Move them into public decdn-client-pull modules (pure relocation, no
behavior change):

  cli/commands/discovery.rs       -> client-pull/src/discovery.rs
  cli/commands/probe_client.rs    -> client-pull/src/probe.rs
  cli/commands/client_endpoint.rs -> client-pull/src/endpoint.rs
  cli/commands/chain_ctx::build_provider -> client-pull/src/provider.rs

Repoint cli (fetch, bundle_pull, channel, probe, bond, register, setup)
and the node probe_0rtt test at the new locations. The node's decdn-cli
dev-dep existed only for that test's probe_once import and is now removed.
endpoint pulls in decdn-common (iroh-blobs-free per #578, so the CLI's
iroh-blobs-free invariant still holds).

Closes #1021.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI review requested due to automatic review settings June 30, 2026 12:00
@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c37ede3-af44-48d2-8d37-37a0a43345bf

📥 Commits

Reviewing files that changed from the base of the PR and between d255e14 and fdc025a.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock, !**/*.lock
📒 Files selected for processing (17)
  • crates/cli/src/commands/bond.rs
  • crates/cli/src/commands/bundle_pull.rs
  • crates/cli/src/commands/chain_ctx.rs
  • crates/cli/src/commands/channel.rs
  • crates/cli/src/commands/fetch.rs
  • crates/cli/src/commands/mod.rs
  • crates/cli/src/commands/probe.rs
  • crates/cli/src/commands/register.rs
  • crates/cli/src/commands/setup.rs
  • crates/client-pull/Cargo.toml
  • crates/client-pull/src/discovery.rs
  • crates/client-pull/src/endpoint.rs
  • crates/client-pull/src/lib.rs
  • crates/client-pull/src/probe.rs
  • crates/client-pull/src/provider.rs
  • crates/node/Cargo.toml
  • crates/node/tests/probe_0rtt.rs
💤 Files with no reviewable changes (2)
  • crates/cli/src/commands/mod.rs
  • crates/node/Cargo.toml

Walkthrough

build_provider is extracted from chain_ctx.rs into a new public decdn_client_pull::provider module. discovery, endpoint, and probe are also promoted as public modules in decdn-client-pull. All CLI commands (bond, bundle_pull, channel, fetch, probe, register, setup) are rewired to import from decdn_client_pull instead of local wrappers. The now-redundant client_endpoint, discovery, and probe_client pub modules are removed from commands/mod.rs, and the decdn-cli dev-dependency is dropped from decdn-node.

Changes

Promote shared client modules into decdn-client-pull

Layer / File(s) Summary
New build_provider in decdn-client-pull
crates/client-pull/Cargo.toml, crates/client-pull/src/provider.rs, crates/client-pull/src/lib.rs, crates/client-pull/src/probe.rs
Adds build_provider to a new provider.rs module, exposes discovery, endpoint, probe, and provider as public modules in lib.rs, and adds decdn-common + tempfile dependencies.
Remove build_provider from chain_ctx and local module exports
crates/cli/src/commands/chain_ctx.rs, crates/cli/src/commands/mod.rs
Deletes the build_provider function and its provider-related imports from chain_ctx.rs; removes pub mod client_endpoint, pub mod discovery, and pub mod probe_client from commands/mod.rs.
Rewire CLI commands to decdn_client_pull
crates/cli/src/commands/bond.rs, ...bundle_pull.rs, ...channel.rs, ...fetch.rs, ...probe.rs, ...register.rs, ...setup.rs
Updates imports and build_provider call sites across all affected CLI commands to use decdn_client_pull::provider, decdn_client_pull::endpoint, decdn_client_pull::probe, and decdn_client_pull::discovery.
Drop decdn-cli dev-dep from decdn-node and fix integration test
crates/node/Cargo.toml, crates/node/tests/probe_0rtt.rs
Removes the decdn-cli dev-dependency; updates probe_0rtt test import to use decdn_client_pull::probe.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately describes the main refactor: promoting client-pull discovery/probe/endpoint/provider modules.
Linked Issues check ✅ Passed The PR matches #1021 by moving discovery/probe/endpoint/provider into client-pull and repointing CLI/tests to the new modules.
Out of Scope Changes check ✅ Passed The remaining edits are supporting refactor work, like dependency and import cleanup, without unrelated behavior changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/admiring-darwin-6933b5

Comment @coderabbitai help to get the list of available commands.

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.

Pull request overview

This PR promotes the client-side “discover → probe → endpoint → provider” toolkit out of the decdn-cli bin crate into public modules in decdn-client-pull, enabling reuse of the full cdn/client/v1 client fetch path by non-CLI consumers while keeping behavior unchanged.

Changes:

  • Added new public decdn-client-pull modules: discovery, probe, endpoint, and provider.
  • Repointed CLI commands and the node 0-RTT probe integration test to use decdn-client-pull instead of decdn-cli::commands.
  • Removed the decdn-cli dev-dependency from decdn-node tests and updated Cargo metadata accordingly.

Reviewed changes

Copilot reviewed 15 out of 18 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/node/tests/probe_0rtt.rs Switch probe helper import to decdn_client_pull::probe.
crates/node/Cargo.toml Drop decdn-cli dev-dependency previously used only by the integration test.
crates/client-pull/src/provider.rs New public provider builder (build_provider) extracted from CLI plumbing.
crates/client-pull/src/probe.rs Update rustdoc links to point at the new public probe module path.
crates/client-pull/src/lib.rs Export new public modules (discovery, endpoint, probe, provider).
crates/client-pull/src/endpoint.rs New public endpoint + relay/discovery resolution module (with tests).
crates/client-pull/src/discovery.rs New public registry-backed discovery + selection/ranking module (with tests).
crates/client-pull/Cargo.toml Add decdn-common dependency and tempfile dev-dependency to support endpoint module + tests.
crates/cli/src/commands/setup.rs Repoint provider construction to decdn_client_pull::provider::build_provider.
crates/cli/src/commands/register.rs Repoint provider construction to decdn_client_pull::provider::build_provider.
crates/cli/src/commands/probe.rs Repoint probe + endpoint imports to decdn_client_pull::{probe, endpoint}.
crates/cli/src/commands/mod.rs Stop exporting CLI-private discovery/endpoint/probe_client modules.
crates/cli/src/commands/fetch.rs Repoint discovery/probe/endpoint/provider wiring to decdn-client-pull.
crates/cli/src/commands/channel.rs Repoint endpoint/provider usage to decdn-client-pull.
crates/cli/src/commands/chain_ctx.rs Remove in-CLI provider builder and document the new library entrypoint.
crates/cli/src/commands/bundle_pull.rs Repoint discovery/endpoint/provider usage to decdn-client-pull.
crates/cli/src/commands/bond.rs Repoint provider construction to decdn_client_pull::provider::build_provider.
Cargo.lock Reflect dependency graph updates (add decdn-common/tempfile under decdn-client-pull, remove decdn-cli under node).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

Copy link
Copy Markdown

Coverage report

Total: 83.20% (was 83.20%, ● 0.00%) — 41946/50417 lines

File Coverage Lines Δ
crates/cli/src/commands/bond.rs 32.06% 67/209 ● 0.00%
crates/cli/src/commands/bundle_pull.rs 28.94% 101/349 ● 0.00%
crates/cli/src/commands/chain_ctx.rs 76.51% 127/166 ▲ +5.56%
crates/cli/src/commands/channel.rs 54.44% 98/180 ● 0.00%
crates/cli/src/commands/fetch.rs 36.63% 174/475 ● 0.00%
crates/cli/src/commands/probe.rs 75.14% 139/185 ● 0.00%
crates/cli/src/commands/register.rs 29.89% 52/174 ● 0.00%
crates/cli/src/commands/setup.rs 49.78% 336/675 ● 0.00%
crates/client-pull/src/discovery.rs 79.29% 111/140 new
crates/client-pull/src/endpoint.rs 50.35% 71/141 new
crates/client-pull/src/lib.rs 85.54% 503/588 ▲ +0.17%
crates/client-pull/src/probe.rs 88.89% 104/117 new
crates/client-pull/src/provider.rs 0.00% 0/13 new
History
Commit Total Δ vs base
fdc025a (HEAD) 83.20% ● 0.00%

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors and extracts several client-side paid-pull components (such as discovery, endpoint, probe, and provider) from the decdn-cli crate into the decdn-client-pull crate to make them reusable. This includes moving the build_provider helper and updating all command invocations and integration tests to use the new paths. Feedback on the changes suggests improving debuggability in crates/client-pull/src/provider.rs by using redact_userinfo to redact only credentials from invalid RPC URLs rather than hiding the entire URL.

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.

Comment on lines +19 to +37
/// # Errors
///
/// Fails if `rpc_url` is not a valid URL. The value is never echoed into the
/// error: an `rpc_url` secret commonly lives in the path/query, which userinfo
/// redaction wouldn't scrub, so the value is hidden entirely (matching
/// `config validate`'s `<redacted> (N chars)`).
pub fn build_provider(
rpc_url: &str,
signer: &PrivateKeySigner,
) -> anyhow::Result<impl Provider + Clone> {
Ok(ProviderBuilder::new()
.wallet(EthereumWallet::from(signer.clone()))
.connect_http(rpc_url.parse().with_context(|| {
format!(
"rpc_url is not a valid URL (<redacted>, {} chars)",
rpc_url.len()
)
})?))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current error message for an invalid rpc_url redacts the entire URL, which can make debugging difficult. While this is done for security reasons to avoid leaking secrets in the path or query string, it violates the repository's general rule to avoid omitting the URL entirely to preserve debugging context.

A better approach, consistent with how relay_url errors are handled in endpoint.rs, is to use the redact_userinfo function. This improves debuggability by showing the host and path, which are often crucial for diagnosing connection issues, while still redacting credentials in the userinfo part of the URL.

Please also update the function's documentation to reflect this change and warn that secrets in the path or query string may still be visible. You'll need to add use decdn_common::redact::redact_userinfo; to the file.

Suggested change
/// # Errors
///
/// Fails if `rpc_url` is not a valid URL. The value is never echoed into the
/// error: an `rpc_url` secret commonly lives in the path/query, which userinfo
/// redaction wouldn't scrub, so the value is hidden entirely (matching
/// `config validate`'s `<redacted> (N chars)`).
pub fn build_provider(
rpc_url: &str,
signer: &PrivateKeySigner,
) -> anyhow::Result<impl Provider + Clone> {
Ok(ProviderBuilder::new()
.wallet(EthereumWallet::from(signer.clone()))
.connect_http(rpc_url.parse().with_context(|| {
format!(
"rpc_url is not a valid URL (<redacted>, {} chars)",
rpc_url.len()
)
})?))
}
/// # Errors
///
/// Fails if rpc_url is not a valid URL. The error will include a redacted
/// version of the URL to aid in debugging. Note that only the userinfo part
/// (e.g., user:pass@) is redacted; secrets in the path or query string may
/// still be visible in logs.
pub fn build_provider(
rpc_url: &str,
signer: &PrivateKeySigner,
) -> anyhow::Result<impl Provider + Clone> {
Ok(ProviderBuilder::new()
.wallet(EthereumWallet::from(signer.clone()))
.connect_http(rpc_url.parse().with_context(|| {
format!(
"rpc_url is not a valid URL: {}",
redact_userinfo(rpc_url)
)
})?))
}
References
  1. When displaying or logging URLs that may contain sensitive credentials or API keys (such as RPC URLs), redact the userinfo (e.g., 'user:pass@') before outputting them to logs or error messages, rather than omitting the URL entirely, to preserve debugging context while preventing credential leakage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — but keeping the full redaction here is intentional, and redact_userinfo would be a regression for this specific field.

redact_userinfo only strips the user:pass@ userinfo and preserves the host + path + query. For relay URLs (where it's used in endpoint.rs) that's correct. But rpc_url secrets almost always live in the path, not userinfo — e.g. Alchemy https://eth-mainnet.g.alchemy.com/v2/<API_KEY> or Infura .../v3/<KEY>. redact_userinfo would leave that key fully visible in the error.

That's exactly why the codebase has two tiers: redact_userinfo (relay URLs) vs sanitize_rpc_display/strip_urls → full <redacted-url> (rpc_url). The full-redaction form here matches:

  • the sibling discovery::active_nodes in this same crate (identical <redacted>, N chars on the rpc_url parse), and
  • the config validate policy of never echoing rpc_url.

This PR is also a pure relocation (no behavior change), and build_provider came over verbatim from chain_ctx. Changing the redaction tier would both diverge from active_nodes and risk leaking provider API keys, so I'm leaving it as-is.

@alpergundogdu
alpergundogdu merged commit 44afd1c into main Jun 30, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the claude/admiring-darwin-6933b5 branch June 30, 2026 12:58
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.

refactor(client-pull): promote discovery/probe/endpoint/provider into public decdn-client-pull modules

2 participants