Skip to content

perf(node,client-pull): unwedge and speed up the buyer/upstream pull leg (#1794) - #1881

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/issue-1794-investigation-dd5c50
Aug 31, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/issue-1794-investigation-dd5c50

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes #1794 (Group G of the serve-path hot-path audit). Five buyer-leg fixes, at the "all five, minimal depth" scope.

The buyer leg is what a cache miss waits on, so these are miss TTFB / miss-throughput fixes that scale with miss rate (highest while the network grows).

1. Bounded voucher send — the wedge (client-pull)

PoolLedger::issue/reanchor/meter hold the per-lane issuance lock across the upstream send (required for strict cumulative voucher order), but the send had no deadline. One stalled upstream froze voucher issuance for every concurrent pull on that (signer, provider) lane forever — and since nothing errored, per-blob failover never fired. Each send now runs under VOUCHER_SEND_DEADLINE (20s). A timeout is treated exactly like any ambiguous send (voucher stays armed, settlement settles high, committed unmoved), which releases the lock and turns the wedge into an ordinary failover.

2. Poison recovery on the funding slots (node)

The issue's "key single-flight by pool" premise is stale: the node owns exactly one pool (store.get_by_owner), so there are no unrelated pools to serialize. The applicable half — a poisoned slot being node-wide fatal for paying anyone — is fixed: join_or_spawn_{open,topup} now recover the inner value on poison (matching SlotGuard's own Drop) instead of returning a fatal error, and shed the now-dead Result.

3. Sharded reputation map (reputation)

LocalReputation splits its peer map into 16 independently-locked shards (by first NodeId byte). A score() read on the ranking path and the periodic evict() sweep no longer contend on one global RwLock; eviction walks shards one at a time instead of holding the write lock across an O(peers) scan.

4. O(1) get_or_seed hot path (node)

BuyerLedgers::get_or_seed now probes the map once on the common reuse path; the O(lanes) cardinality prune runs only when a genuinely new lane is inserted. Same bound as before, no per-miss scan — and it deliberately never drops a still-held ledger, whose in-memory watermark can lead the persisted row.

5. Probe early-exit (node)

probe_and_rank collects probe answers via FuturesUnordered and stops once PROBE_EARLY_EXIT_CANDIDATES (= MAX_PROVIDER_ATTEMPTS = 3) blob-holding providers answer, rather than join_all pacing the whole round to the slowest/dead probe. Item 5 asked to verify the ceiling wasn't already early-exiting — it wasn't. PROBE_TIMEOUT (500ms) stays the ceiling for sparse rounds. ADR 001 § Probe response collection updated.

Verification

  • cargo clippy --workspace --all-targets, cargo fmt --check, cargo doc (pre-commit) — all clean.
  • cargo nextest run: decdn-client-pull ledger (incl. new deadline test), decdn-reputation (27), decdn-node node_origin_pull (176, incl. silent_upstreams_do_not_starve_the_candidate_loop and the wedged/failover suite) + client_loopback — all pass.
  • anvil-e2e not run locally (gated).

🤖 Generated with Claude Code

…leg (#1794)

Group G of the serve-path hot-path audit. Five buyer-leg fixes, each the
minimal safe form:

1. Bound the voucher send. `PoolLedger::issue`/`reanchor`/`meter` hold the
   per-lane issuance lock across the upstream send (needed for strict
   cumulative order), but the send had no deadline — a stalled upstream wedged
   voucher issuance for every concurrent pull on the lane forever, and no error
   ever fired so failover never triggered. Each send now runs under
   `VOUCHER_SEND_DEADLINE` (20s); a timeout errors like any ambiguous send
   (voucher stays armed, `settlement` settles high), releasing the lock and
   letting the pull leg fail over.

2. Recover the funding single-flight slots on poison instead of treating a
   panic as node-fatal. The node owns a single pool (`get_by_owner`), so the
   "per-pool keying" of the issue does not apply — but a poisoned open/topup
   slot previously wedged ALL funding node-wide. `join_or_spawn_{open,topup}`
   now recover the inner value (matching `SlotGuard`'s own Drop) and drop the
   dead `Result`.

3. Shard the reputation map into 16 independently-locked shards. A `score()`
   read on the ranking path and the periodic `evict()` sweep no longer
   serialize on one global `RwLock`; eviction walks shards one at a time.

4. Make `BuyerLedgers::get_or_seed` O(1) on the hot reuse path. The O(lanes)
   prune now runs only when a genuinely new lane is inserted, preserving the
   exact cardinality bound without scanning on every miss — and never dropping
   a still-held ledger whose in-memory watermark leads the persisted row.

5. Early-exit probe collection. `probe_and_rank` collects answers via
   `FuturesUnordered` and stops once `PROBE_EARLY_EXIT_CANDIDATES`
   (= `MAX_PROVIDER_ATTEMPTS`) blob-holding providers answer, instead of
   `join_all` pacing the round to the slowest/dead probe. `PROBE_TIMEOUT`
   stays the ceiling for sparse rounds. ADR 001 updated.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 31, 2026 14:05

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 addresses serve-path “buyer/upstream pull leg” latency and throughput by bounding previously unbounded waits and removing lock/contention hot spots in the cache-miss path (client-pull issuance, node funding, node selection probing, buyer ledger lookup, and reputation scoring).

Changes:

  • Add a per-send voucher deadline in decdn-client-pull to prevent lane-wide issuance wedges on stalled upstreams.
  • Reduce contention/latency on the node miss path via early-exit probe collection and an O(1) buyer-ledger reuse fast path.
  • Shard local reputation storage to avoid global lock contention during ranking and periodic eviction, and update ADR 001 to reflect early-exit probe collection.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/client-pull/src/ledger.rs Add VOUCHER_SEND_DEADLINE and enforce it around voucher sends; add timeout-focused test.
crates/node/src/buyer_channel.rs Recover poisoned funding slots instead of treating them as node-fatal; simplify join-or-spawn APIs.
crates/reputation/src/local.rs Replace single peer-map lock with SHARD_COUNT shards; update record/score/snapshot/evict accordingly.
crates/node/src/buyer_ledgers.rs Make get_or_seed O(1) on reuse; run lane-pruning only on new-lane insertion.
crates/node/src/selection.rs Introduce PROBE_EARLY_EXIT_CANDIDATES to govern early-exit probe collection behavior.
crates/node/src/node_origin/mod.rs Collect probe responses via FuturesUnordered and early-exit once enough blob-holding candidates arrive.
adr/001-network.md Document early-exit probe-response collection while keeping the 500ms ceiling as fallback.

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

Comment thread crates/reputation/src/local.rs Resolved
Copilot review on #1881: use `.first()` instead of `as_bytes()[0]` in
`shard_for` so the workspace `clippy::indexing_slicing` anti-panic lint has
nothing to flag. Behaviour is identical (the key is always 32 bytes).

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

Copy link
Copy Markdown

Coverage report

Total: 82.29% (was 82.27%, ▲ +0.02%) — 69312/84224 lines

File Coverage Lines Δ
crates/client-pull/src/ledger.rs 97.06% 793/817 ▲ +0.03%
crates/node/src/buyer_channel.rs 34.03% 227/667 ▲ +0.40%
crates/node/src/buyer_ledgers.rs 100.00% 82/82 ● 0.00%
crates/node/src/node_origin/mod.rs 92.90% 968/1042 ▲ +0.03%
crates/node/src/selection.rs 97.07% 397/409 ● 0.00%
crates/reputation/src/local.rs 98.60% 562/570 ▼ 0.33%
History
Commit Total Δ vs base
f79eef7 (HEAD) 82.29% ▲ +0.02%

@alpergundogdu
alpergundogdu merged commit 54e17f3 into main Aug 31, 2026
25 checks passed
@alpergundogdu
alpergundogdu deleted the claude/issue-1794-investigation-dd5c50 branch August 31, 2026 14:36
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.

perf(node,client-pull): upstream pull leg — undeadlined lane-wide sends, process-wide funding single-flight, reputation lock on ranking

2 participants