Skip to content

feat(cli): check the buyer wallet's USDC in setup on a pull-through node - #2755

Merged
thiras merged 2 commits into
mainfrom
feat/setup-buyer-usdc-preflight
Oct 29, 2026
Merged

thiras merged 2 commits into
mainfrom
feat/setup-buyer-usdc-preflight

Conversation

@thiras

@thiras thiras commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What

A node with pull-through on (the default with no origin since #2674) buys its cache misses from peers. Opening the pool those pulls pay from escrows blockchain.buyer_working_deposit_micro_usdc (10 USDC). Before this change, decdn setup, which is where the operator funds the node, did not check USDC at all.

  • New buyer_usdc pre-flight row, shown only when pull-through resolves on. It prints the working deposit and the wallet's USDC; the token address comes from PaymentPool.usdc(). When the balance is below the deposit, the row is WARN and names the shortfall, the operator address and, on Arbitrum Sepolia, the Circle faucet. It also notes that a pool already open draws only refills, so a re-run on a working node does not read as "cannot buy". The row never blocks: all_ok() is unchanged.
  • The pool is resolved the way decdn-node resolves it: DECDN_PAYMENT_POOL_ADDRESS, else blockchain.payment_pool_address. There is no known-chain fallback. If the address is missing or zero, or the deposit is zero, the row says decdn-node refuses to start. A failed chain read gives a redacted reason and a hint to re-run.
  • --json: preflight.buyer_usdc is null when pull-through is off. Otherwise it is {state, working_deposit_micro_usdc, balance_micro_usdc, shortfall_micro_usdc, ok, error}, where state is one of covered, short, no_wallet, config_error or read_error.
  • Keyless dry run: prints the row with state no_wallet (no chain read). A config error still shows up there.

Example (keyless dry run against the testnet, no pool configured):

  buyer_usdc: WARN (pull-through on: working deposit 10.000000 USDC; blockchain.payment_pool_address is not set (nor DECDN_PAYMENT_POOL_ADDRESS): decdn-node refuses to start until it is fixed)

Closes #2676

Reviewer notes

  • Setup reads only part of the config, so that a typo in an unrelated section does not block onboarding. That stays the same. To decide pull-through, it now also reads [cache]: the explicit flag, plus whether an origin table is present. The role rule lives in decdn_common::config::role_derived_pull_through, which both the daemon's resolver and chain_ctx::FileConfig::pull_through call. Checking presence rather than resolved origins disagrees with the daemon only on configs it refuses to start with.
  • The read-failure reason is printed in the row itself, which bypasses main's sanitizer. It therefore goes through sanitize_err_chain. A unit test against a refused …/v3/SECRET URL pins this, and fails when the sanitizer is removed.
  • The JSON amounts are numbers in micro-USDC, matching admin_v1_status's buyer_wallet_micro_usdc.
  • The row reports the wallet only, not an open pool's remaining deposit. Reading the pool as well is left out of scope.

Verification

  • Unit tests:
    • the status threshold and shortfall for every balance state;
    • all_ok ignoring a warning row;
    • every branch of the detail text;
    • the JSON shape for the short, covered, read_error and no_wallet states, with null checked as present;
    • pool resolution (env beats file; unset, zero address and zero deposit give config errors; pull-through off gives no row);
    • the keyless row;
    • the faucet lookup;
    • redaction of a failed read;
    • FileConfig::pull_through and the deposit default.
  • g_node_01_onboarding (anvil): the live setup --json asserts preflight.buyer_usdc is present and null (the fixture pins pull-through off). A new step runs setup --dry-run with pull-through on and the wallet holding 2.5 USDC. It asserts a WARN row with short 7.500000 and the operator address, and an exit code of 0. All 3 tests pass.
  • Manual: keyless setup --dry-run against the public Arbitrum Sepolia RPC, both with and without DECDN_PAYMENT_POOL_ADDRESS.

Always:

  • pre-commit run (commit hooks on the changed files all pass; cargo deny reports only the existing warn-only crypto-bigint advisory)
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run -p decdn-cli -p decdn-common (1744 passed) plus the g_node_01_onboarding e2e. I did not run the full workspace suite locally.
  • PR title: feat(cli): …, lowercase subject

Only if touched:

  • User-visible change: CHANGELOG.md entry under Added

🤖 Generated with Claude Code

A node with pull-through on buys its cache misses from peers and escrows
blockchain.buyer_working_deposit_micro_usdc in a PaymentPool pool. With
an empty wallet every openPool reverts, and setup, where the operator
funds the node, said nothing.

Setup now prints a buyer_usdc pre-flight row: the working deposit and
the wallet's USDC, read from PaymentPool.usdc(). Below the deposit it
warns with the shortfall, the address to fund and the testnet faucet.
The row never blocks. --json reports it as preflight.buyer_usdc (null
with pull-through off), and the keyless dry run prints it too.

Pull-through is derived from the partial config by the daemon's rule,
now shared as decdn_common::config::role_derived_pull_through.

Closes #2676

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras thiras self-assigned this Oct 29, 2026
Copilot AI balanced review requested due to automatic review settings October 29, 2026 17:23

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.

🟢 Approval recommended

No active review issues remain for the non-blocking buyer-USDC setup check.

No open issues 🎉

What changed in this PR

Adds a non-blocking buyer-USDC check to decdn setup, helping pull-through node operators fund cache-miss purchases before starting the daemon.

Changes:

  • Reports the working deposit, wallet balance, shortfall, and funding guidance in text and JSON, including keyless dry runs.
  • Shares the daemon’s pull-through default rule and sanitizes balance-read errors.
  • Adds unit and onboarding coverage for warning behavior, configuration, and output.
File Description
crates/​e2e/​tests/​g_node_01_onboarding.rs Tests underfunded-wallet warnings and omission when pull-through is off.
crates/​common/​src/​config/​mod.rs Extracts the shared pull-through default rule.
crates/​cli/​src/​known_chains/​tests.rs Checks the testnet faucet URL.
crates/​cli/​src/​known_chains.rs Adds USDC faucet metadata.
crates/​cli/​src/​commands/​setup/​tests.rs Tests thresholds, warning details, and JSON output.
crates/​cli/​src/​commands/​setup.rs Implements buyer-USDC reads and non-blocking pre-flight reporting.
crates/​cli/​src/​commands/​node.rs Exposes USDC formatting for reuse by setup.
crates/​cli/​src/​commands/​chain_ctx/​tests.rs Tests pull-through derivation and working-deposit configuration.
crates/​cli/​src/​commands/​chain_ctx.rs Reads setup’s pull-through and working-deposit settings.
CHANGELOG.md Documents the new setup check.

Review effort: Balanced

@github-code-quality

github-code-quality Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 2e44283 feat/setup-buyer-usd... d527db3 +/-
77% 77% 0%
View coverage of the 5 most impacted files.
File main 2e44283 feat/setup-buyer-usd... d527db3 +/-
crates/client/src/lib.rs 89% 89% 0%
crates/node/src...s/client/mod.rs 91% 91% 0%
crates/common/s...c/config/mod.rs 97% 97% 0%
crates/cli/src/...ds/chain_ctx.rs 79% 80% +1%
crates/cli/src/...mmands/setup.rs 34% 42% +8%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 29, 2026 17:49 UTC

… row state

Review follow-ups on the buyer_usdc pre-flight row:

- Read the PaymentPool address from DECDN_PAYMENT_POOL_ADDRESS, else
  blockchain.payment_pool_address, as decdn-node does. Drop the
  known-chain fallback: it could check a pool the node never uses and
  pass a config the node refuses to start with.
- Split the row's balance into Read / NoWallet / ConfigError /
  ReadError. A config the daemon refuses (no or zero pool, zero deposit)
  says so; a failed read says to re-run. --json gains a `state` field,
  so the keyless dry run's `no_wallet` no longer reads like an empty
  wallet read from the chain.
- Word the shortfall for a pool already open: opening escrows the full
  deposit, an open pool draws only refills.
- Derive the detail text from shortfall() so text and JSON cannot drift.
- Tests: the pool plan (env, file, unset, zero, zero deposit, off), the
  keyless row, the faucet lookup, a failed read's redaction, and
  present-and-null checks for buyer_usdc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thiras
thiras merged commit 1a89e20 into main Oct 29, 2026
37 checks passed
@thiras
thiras deleted the feat/setup-buyer-usdc-preflight branch October 29, 2026 17:52
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.

setup: print the buyer working deposit and check the buyer wallet's USDC

2 participants