Skip to content

fix(node): bind metrics/admin before the buyer PaymentChannel bootstrap (#1109) - #1112

Merged
thiras merged 1 commit into
mainfrom
fix/1109-background-buyer-bootstrap
Jul 12, 2026
Merged

thiras merged 1 commit into
mainfrom
fix/1109-background-buyer-bootstrap

Conversation

@thiras

@thiras thiras commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #1109. decdn-node bound its /metrics and admin RPC listeners only after the buyer-side PaymentChannel bootstrap completed. That bootstrap synchronously awaited a one-time USDC approve receipt, which can hang for many minutes on a slow/stuck tx (~27 min observed on a live Arbitrum-Sepolia node) — leaving an otherwise-healthy, serving node with no metrics/admin surface and no "node runtime ready" log for the whole window.

Changes

  • crates/node/src/runtime/mod.rs — the buyer BuyerChannelService::bootstrap and the NodeOrigin pull-through provisioning it feeds are now fully backgrounded into a single tasks.spawn, placed after the metrics bind and admin bind. Observability and the "node runtime ready" banner now come up independent of any chain RPC.
    • The task holds the Arc<BuyerChannelService> until shutdown, so its AbortOnDrop reclaim/reconcile sweeps keep running for the process lifetime exactly as before (even when pull-through is off).
    • A new buyer_bootstrap_stop_tx/_rx oneshot (fired in the shutdown block, biased select) lets graceful shutdown cancel a slow in-flight bootstrap.
    • Deferring provisioning is safe: NodeOrigin arms via a write-once OnceLock, so any pull that races ahead of provisioning lands as a clean miss (no spend, no panic) — the same window that already existed between cache build and provision.
  • crates/client-pull/src/buyer_channel.rs — ensure_allowance now bounds the approve receipt wait with a hardcoded 3-minute APPROVE_RECEIPT_TIMEOUT, converting an unbounded hang into a sticky "restart to retry" failure (same posture as an insufficient-gas approve). The timeout error names the broadcast tx hash for operator correlation; the re-approve stays idempotent via the allowance read.

Verification

  • cargo build, cargo clippy --workspace --all-targets, cargo fmt --check — clean
  • cargo nextest run — client-pull 35/35, node 745/745 pass (incl. the node_to_node_pull_through / node_origin_pull suites that exercise provisioning)
  • Reviewed by the multi-agent PR toolkit (code, error-handling, comments, tests); no correctness issues, actionable comment/operability findings applied.
  • Remaining live check (operator step, needs testnet/anvil): point a node at an RPC where the approve stalls and confirm /metrics + the ready banner come up in seconds while the buyer lane bootstraps in the background.

Notes / possible follow-up

The backgrounded task joins the existing tasks JoinSet convention, so a task panic (vs the handled non-fatal Err) is reaped at shutdown rather than fail-fast — deliberate, matching every other background task and the issue's non-fatal requirement. A pull_through_armed / buyer-bootstrap-outcome metric would make "pull-through never came up" alertable; called out as a candidate follow-up rather than scope-creeping this fix.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Prevented node startup from being blocked by buyer payment-channel initialization.
    • Added a bounded wait for USDC approval confirmations, with clearer timeout errors including the transaction hash.
    • Ensured buyer services shut down cleanly with the node.
  • Reliability
    • Buyer-side payment setup failures are handled without unexpectedly stopping runtime startup.
    • Node-to-node pull functionality is provisioned after successful buyer-channel initialization.

…ap (#1109)

`decdn-node` bound its /metrics and admin RPC listeners only after the
buyer-side PaymentChannel bootstrap completed. That bootstrap synchronously
awaited a one-time USDC `approve` receipt which could hang for many minutes on
a slow/stuck tx (~27 min observed on a live Arbitrum-Sepolia node), leaving an
otherwise-healthy, serving node with no observability surface and no "node
runtime ready" log for the whole window.

Fully background the buyer `BuyerChannelService::bootstrap` and the NodeOrigin
pull-through provisioning it feeds into a single `tasks.spawn`, placed after the
metrics and admin binds, so observability comes up independent of any chain RPC.
The task holds the `Arc<BuyerChannelService>` until shutdown so its AbortOnDrop
reclaim/reconcile sweeps keep running for the process lifetime as before, and a
new stop oneshot lets shutdown cancel a slow bootstrap. Provisioning is safe to
defer: NodeOrigin arms via a write-once OnceLock, so pulls before it land as
clean misses.

Also bound the `approve` receipt wait in `ensure_allowance` with a 3-minute
`APPROVE_RECEIPT_TIMEOUT`, converting an unbounded hang into a sticky
"restart to retry" failure; the timeout error names the broadcast tx hash.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 12, 2026 05:07
@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 81906f5c-4bde-4613-94fe-8e924441615e

📥 Commits

Reviewing files that changed from the base of the PR and between 941344d and c6f114a.

📒 Files selected for processing (2)
  • crates/client-pull/src/buyer_channel.rs
  • crates/node/src/runtime/mod.rs

Walkthrough

The change bounds USDC approval receipt waits and moves buyer payment-channel bootstrap and node-origin provisioning into a stoppable background task, with explicit shutdown signaling and non-fatal bootstrap errors.

Changes

Buyer service lifecycle

Layer / File(s) Summary
Bounded approval receipt wait
crates/client-pull/src/buyer_channel.rs
Adds APPROVE_RECEIPT_TIMEOUT, captures the approval transaction hash, and returns a timeout error containing the hash and duration.
Background buyer bootstrap
crates/node/src/runtime/mod.rs
Runs buyer bootstrap in a spawned task, provisions NodeOrigin after success, retains the service until shutdown, and signals task termination during runtime shutdown.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant NodeRuntime
  participant buyer_bootstrap_task
  participant BuyerChannelService
  participant NodeOrigin
  NodeRuntime->>buyer_bootstrap_task: spawn bootstrap task
  buyer_bootstrap_task->>BuyerChannelService: bootstrap
  BuyerChannelService-->>buyer_bootstrap_task: service result
  buyer_bootstrap_task->>NodeOrigin: provision after successful bootstrap
  NodeRuntime->>buyer_bootstrap_task: send buyer_bootstrap_stop_tx
  buyer_bootstrap_task-->>NodeRuntime: stop and release service hold
Loading

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

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

@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-actions

Copy link
Copy Markdown

Contracts coverage

Line coverage: 88.71% (2452/2764 lines)
▲ +0.00pp vs base (88.71% → 88.71%)
Run: 29180706783

@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 moves the buyer-side PaymentChannel bootstrap and node-to-node pull-through provisioning to a background task to avoid blocking the startup critical path. It also introduces a timeout for the USDC approve receipt. A compilation error was identified in the timeout definition, as Duration::from_mins is not a valid function in the Rust standard library.

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 thread crates/client-pull/src/buyer_channel.rs Resolved

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 fixes a node startup ordering issue where /metrics and admin RPC listeners were bound only after the buyer-side PaymentChannel bootstrap completed (which could block for many minutes while waiting for a one-time USDC approve receipt). The change ensures observability/admin surfaces (and the “node runtime ready” banner) come up independent of chain/RPC delays, while still preserving the buyer service’s process-lifetime reclaim behavior.

Changes:

  • Backgrounds buyer BuyerChannelService::bootstrap and the NodeOrigin pull-through provisioning into a JoinSet task, allowing metrics/admin bind and readiness logging to proceed immediately.
  • Adds a shutdown oneshot to cancel an in-flight buyer bootstrap during graceful shutdown and release the process-lifetime hold.
  • Bounds USDC approve receipt waiting with a 3-minute timeout and surfaces the tx hash in the timeout error for operator correlation.

Reviewed changes

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

File Description
crates/node/src/runtime/mod.rs Defers buyer bootstrap + pull-through provisioning to a background task and adds a shutdown cancel signal so metrics/admin and readiness are no longer blocked by chain/RPC latency.
crates/client-pull/src/buyer_channel.rs Adds APPROVE_RECEIPT_TIMEOUT and wraps get_receipt() in a timeout that reports the broadcast tx hash on timeout.

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

@github-actions

Copy link
Copy Markdown

Coverage report

Total: 80.37% (was 80.43%, ▼ 0.06%) — 44762/55698 lines

File Coverage Lines Δ
crates/client-pull/src/buyer_channel.rs 0.00% 0/93 ● 0.00%
crates/node/src/runtime/mod.rs 50.47% 1082/2144 ▼ 0.91%
History
Commit Total Δ vs base
c6f114a (HEAD) 80.37% ▼ 0.06%

@thiras
thiras merged commit 1bbfccd into main Jul 12, 2026
24 checks passed
@thiras
thiras deleted the fix/1109-background-buyer-bootstrap branch July 12, 2026 05:21
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.

Node metrics/admin listeners bind only after the buyer PaymentChannel bootstrap (blocks ~27 min on slow approve)

2 participants