Repository navigation
fix(node,cache,client-pull): unstick the fused serve-miss past the ramp floor and size node top-ups correctly (#1893) - #2010
Merged
Conversation
…rve leg needs (#1893) The fused serve-miss deadlocked on any blob large enough to leave the credit window's floor. The serve leg ramps its window on paid wire bytes; the pull leg ramps on the paid content frontier, which is always smaller. Past the floor the pull window closed while the serve window still had room, so the serve encoder parked on a proof node (or leaf) past the pulled frontier. While it waited it collected no voucher, so the served-paid frontier the pull waited on never advanced. An 8 MiB fused loopback delivery stalled every time. A parked serve read now records the content offset it waits on as the serve demand, on every live fill of the hash. The window pacer may always draw up to that offset, and the pull's wait wakes on a demand advance as well as a payment. The data reader demands the leaf span it awaits; the outboard reader demands the first byte of the node whose hash pair it awaits. ADR 037 states the added exposure: the encoder's bounded look-ahead past the serve credit window. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
…or (#1893) A reactive mid-pull top-up added almost nothing. NodeFunder turned the driver's `additional` into a spendable target from the pull's live ledger, and BuyerPoolService::top_up_pool re-derived the shortfall from the persisted lane progress. That progress is recorded when a pull ends, so mid-pull it omits the asking pull's own spend: in node_pull_topup the pool was ~3.7 USDC spent, the service saw ~0.02 USDC spent, and it topped up 0.02 USDC. The single allowed top-up was spent and the next voucher was refused. PoolOpener::top_up_pool now takes the amount to add, and NodeFunder passes the driver's `additional` through unchanged. node_pull_topup runs un-ignored. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
Coverage reportTotal: 82.73% (was 82.66%, ▲ +0.08%) — 78187/94503 lines
History
|
…rontier (#1893) Review of the serve-demand fix found an unbounded spend path. Demand fans out to every live fill of a hash, and the window pacer honoured it however far past the pull it sat. An unpaid request attached near the end of a cold blob could drag its sibling pull across the whole remaining gap. The pacer now honours a demand only within one chunk group past the pull's frontier — the only place a serve encoder parked on this pull can wait — and then draws one pull-window floor. A serve leg parks only while its own credit window has room, so a client that stops paying stops raising demand. Drawing a floor rather than one group keeps each unpark to one upstream open; one-group draws re-opened the upstream often enough near exhaustion to hit the seller's refundable-floor refusal, and node_pull_topup failed 2 of 5 runs. ADR 037 and the pacer, fill-session, serve-leg and pull-leg docs state the bound: the ramped credit window plus one pull-window floor. The top_up_pool doc and log state that a joined in-flight topUp can add less than asked. New tests pin the far-demand refusal, the data-reader demand, and a demand raise waking a parked pull. Stale top_up_channel references are fixed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical pacer-boundary and moderate demand-validation and ADR-bound issues remain.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes fused serve-miss stalls and reactive node top-up underfunding.
Changes:
- Adds serve-demand propagation and bounded demand-aware pacing.
- Uses additive top-up amounts.
- Adds regression, settlement, and E2E coverage; updates ADR 037.
File summaries
| File | Reviewed changes |
|---|---|
crates/node/tests/node_origin_pull.rs |
Adds fused-pull and top-up regressions. |
crates/node/tests/anvil_settlement_e2e.rs |
Updates exact top-up settlement assertions. |
crates/node/src/node_origin/pull_leg.rs |
Wakes pulls on payment or serve-demand advances. |
crates/node/src/node_origin/mod.rs |
Updates funder construction. |
crates/node/src/node_origin/funder.rs |
Passes additive top-up amounts unchanged. |
crates/node/src/handlers/client/serve_leg.rs |
Documents demand coordination. |
crates/node/src/handlers/client/serve_encoder.rs |
Records data and proof demand. Moderate (1 vote, line 145): verify live coverage before raising demand. |
crates/node/src/buyer_channel.rs |
Implements additive pool top-ups. |
crates/e2e/tests/node_pull_topup.rs |
Enables reactive top-up E2E coverage. |
crates/client-pull/src/pacer.rs |
Implements bounded demand-aware pacing. Critical (1 vote, line 255): handle the end-exclusive sentinel boundary correctly. |
crates/client-pull/src/lib.rs |
Exports frontier types. |
crates/client-pull/src/driver.rs |
Carries downstream frontier state through pacing. |
crates/cache/src/fill_session.rs |
Tracks and propagates serve demand. |
adr/037-regional-proxy-warming.md |
Documents demand exposure. Moderate (2 votes, line 59, also line 148): qualify the bound for credit_ramp_divisor = 0; Nit (1 vote, line 114): update the implementation-status qualification. |
Review details
Suppressed comments (3)
adr/037-regional-proxy-warming.md:114
- The implementation-status paragraph repeats the same unqualified claim, but
credit_ramp_divisor = 0is supported and makes the ramp returncredit_maxat zero payment; the new serve-demand floor can then extend exposure beyond that ceiling. Apply the non-zero-divisor qualification and state the divisor-zero case here as well, so the ADR's stated bound matches the implementation.
The node-side serving behavior of this ADR — the window-paced pull-through handler — lives in the `crates/node/src/handlers/client/` module (`window.rs`: `serve_via_window_pull_through` / `window_forward_loop`). It fuses a progressive upstream pull (`crate::client_requester::open_progressive_pull`, driven via `crate::node_origin::NodeOrigin::open_progressive_pull`) with downstream delivery: each upstream chunk is forwarded to the paying client and tee'd into the cache (`decdn_cache::CacheEngine::open_tee_sink`), and the pull pauses whenever the per-request frontier `bytes_pulled − bytes_paid` reaches the ramped credit window, resuming as the client's vouchers clear. The pull leg's `decdn_client_pull::RampPacer` computes that same window from the stream's own paid frontier via `decdn_incentive::ramped_credit_window` ([ADR 003 § Credit window](003-payments.md#credit-window)), so the upstream pull and the downstream serve loop ramp in lockstep — a non-paying client fronts at most about two chunks of speculative upstream spend, never the fully-ramped ceiling. The two windows count different bytes: the serve loop meters wire bytes, and the pull paces on the paid content frontier. As a result, the pull window can close while the serve loop still has credit room. The serve encoder then waits on a leaf or a proof node that only the pull can fetch, and it collects no voucher while it waits. To keep both legs live, the encoder records the content offset it waits on as the **serve demand**. The encoder waits on the first byte that the pull has not fetched, so the demand is at most one chunk group past the pull frontier. The pull then fetches one more pull-window floor (one chunk plus three chunk groups) past its own window. The pull ignores a demand that is further ahead, because that demand comes from a serve leg that the pull does not block. A serve leg waits on the pull only while its own credit window has room, so a client that stops paying stops the demand. The serve demand therefore adds at most one pull-window floor to the speculative spend. A complementary **pre-flight deposit guard** composes in front of the window: a cache-miss pull is refused outright (signed `NotFound`, metered as `serve_stream_rejected_insufficient_deposit`, or as `serve_stream_rejected_signer_floor_at_cap` when the pool is solvent and the requesting signer has filled its share of the floor) when the requesting pool's remaining deposit cannot cover the worst-case blob cost. With a finite `max_blob_size_bytes` the ceiling is the whole-blob cost; when the size cap is unbounded (`0`) the guard falls back to the per-request window cost (the ramp floor, one chunk) rather than failing open — disabling the size cap must not silently disable deposit protection. The **direct-serve** path carries the same guard against a narrower ceiling — `min(credit window, chunk-group-aligned request span)`, which bounds what it can deliver before the first voucher clears to that window plus one chunk.
adr/037-regional-proxy-warming.md:148
- The new demand override can add
PULL_WINDOW_FLOORafterWindowPacerhas already reached the ramped ceiling, so a stream atcredit_maxcan temporarily exceedcredit_max. This risk statement still says exposure never exceeds that ceiling; update the documented bound to include the extra floor or enforce a hard cap in code, otherwise operators are given an incorrect loss limit.
- **Manufactured-demand routing.** A client can route warming requests toward content it chooses, forcing nodes into speculative pulls. Bounded by the ramped credit window — a non-paying stream fronts at most about two chunks, and the exposure never exceeds `credit_max` regardless of how many peers or hashes the demand spreads across — and by the fact that the node is paid for bytes it serves. Not free; self-limiting.
crates/node/src/handlers/client/serve_encoder.rs:149
- The liveness check for the requested range happens after
demand_up_to, butdemand_up_tofans the frontier out to every live fill for this hash. If this range has no live coverer while an unrelated same-hash fill is still running, that other pull can be woken and authorized to draw aPULL_WINDOW_FLOOReven though this reader immediately takes the terminal/error path below. Check that a live fill still covers the range before raising demand (while preserving the existing race handling).
// The span is not here yet, so this read is about to wait on a pull.
// Tell every pull that may produce it: a pull whose window has closed
// would otherwise wait for a payment that this parked read blocks.
self.session
.demand_up_to(offset.saturating_add(need).min(self.total));
- Files reviewed: 14/14 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…and only on a covered read (#1893) ADR 037 stated the non-paying exposure bound without its preconditions. With `credit_ramp_divisor = 0` the window opens at `credit_max`, and the serve-demand floor adds to any window, so the bound reads "about two chunks" only for a nonzero divisor and "credit_max plus one pull-window floor" otherwise; the manufactured-demand risk no longer claims exposure never exceeds `credit_max`. The data reader raises serve demand only after it confirms a live fill still covers the span, so a read that is about to fail wakes no pull and takes no registry lock. The pacer comment records why the demand band is exactly one group: the encoder walks the tree in pre-order, so a parked encoder never waits on a node that starts a whole group past the pull. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
…r, and settle-wait past a landed leg (#1893) A serving node refuses a new stream once the pool's remaining deposit, less its refundable floor M, cannot cover a credit window, and it reports that refusal as a plain miss. The buyer's pacer topped up only once the next voucher was unaffordable, so a node pull that re-opened while its pool sat between one voucher and M plus a window was refused, and the fetch failed as "held by no reachable provider". BudgetPacer now tops up while the remaining deposit still covers the serving peer's floor plus the next voucher (PaceState::seller_reserve). The node's pull legs estimate the floor from the node's own `blockchain.pool_min_remaining_deposit_micro_usdc`; the CLI passes zero. The reserve only starts a top-up and never refuses a draw, because a peer with a smaller M still serves. ADR 003 states the rule. After a top-up, the driver's settle allowance now stays armed across landed legs: a peer can admit one stream on headroom it computed before its watcher saw the top-up and then refuse the next re-open, which was terminal. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
… concurrent transaction (#1893) A node signs its sellers' redeemMany transactions and its buyer topUp with one operator key, through providers that each read the pending nonce per send. A topUp sent while a redemption was in flight could take the same nonce and be rejected "nonce too low", which spent the pull's single reactive top-up and failed the fetch. tx::is_nonce_collision recognises that JSON-RPC rejection (nothing was broadcast, so re-sending is safe), and buyer_pool::top_up re-sends up to three more times, a quarter second apart. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
…1893) The encode reads ahead of the serve loop by up to its channel capacity, so its data and outboard readers park at a pull's frontier while the serve loop still has encoded bytes buffered, or is only doing its closed-window prefetch. The readers raised serve demand on every such park, so a client that had stopped paying could still drag the pull one floor past its window: window_pull_through_underpaid_voucher_abandons_bounded pulled and cached the whole 1.5 MiB blob under load. The readers now record the offset they park on in a shared cell (SessionOutboardReader::parked_on). CoherentFrameProducer publishes it as serve demand only when the encode is parked and the frame channel is empty — the stall the demand exists to break. ADR 037 states the rule. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j
Gas snapshotNo gas changes vs base. |
Contracts coverageLine coverage: 89.75% (2575/2869 lines) |
This was referenced Sep 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1893
The issue text is stale: its clean-miss symptom was the warming allowance, fixed in #2003. Two further bugs kept
node_pull_topupred. This PR fixes both and un-ignores the e2e.1. Fused serve-miss deadlock past the credit-window floor
The serve leg ramps its window on paid wire bytes. The pull leg's
RampPacerramps on the paid content frontier, which is always smaller. Once both leave their floors (~2 MiB paid at the default divisor), the pull window closes while the serve window still has room. The serve encoder then parks on a proof node past the pulled frontier: the hash pair for the next right-edge subtree arrives only when the pull fetches into it. While parked, the serve leg collects no voucher, soserved_paidnever advances and the pull never wakes.Instrumented loopback run at the stall: pull
Waitatpulled=4685824, serve atdelivered=4194304 room=524288 pending=1, and the reader's present-range watch fully up to date. The park was on the outboard, not on data.Fix: a parked serve read records the content offset it waits on as the serve demand, on every live fill of the hash (
FillSession::demand_up_to).WindowPacermay always draw up to the demand.ServedPaidWaitwakes on a demand advance as well as a payment.PacingWait::wait/drivenow carry aDownstreamFrontierpair, and client callers passNone.2. Reactive top-up added ~0.02 USDC instead of ~3.7 USDC
NodeFunderturned the driver'sadditionalinto a spendable target from the live pull ledger.BuyerPoolService::top_up_poolthen re-derived the shortfall from the persisted lane progress, which is recorded when a pull ends. Mid-pull the service saw only the warm-up spend, so it topped up23533µUSDC. The single allowed top-up was spent and the next voucher was refused.Fix:
PoolOpener::top_up_pooltakes the amount to add, andNodeFunderpassesadditionalthrough unchanged.Tests
window_pull_through_completes_a_blob_past_the_ramp_floor(8 MiB fused loopback): stalled 3/3 onmain; passes in ~1.5 s.ServedPaidWaitdemand raceadditionalthroughnode_pull_topup(anvil e2e) runs un-ignored and passes (~7.6 s).cargo nextest run --workspace: 3464 passed.cargo clippy --workspace --all-targets -D warnings,cargo fmt --checkandcargo doc -D warningsare clean. The touched anvil targets are also lint-clean under--features anvil-e2e.Heads-up:
cargo denyfails onmaincargo denyis red because of a new advisory, RUSTSEC-2026-0285 (rustls 0.23.37). This PR does not touchCargo.lock, and the commits skip only that hook. The rustls bump belongs in its own PR.Review follow-up (
4721c846)A multi-agent review found an unbounded spend path in the first serve-demand commit. Demand fanned out to every live fill of a hash, and
WindowPacerhonoured it however far past the pull it sat. An unpaid request attached near the end of a cold blob could therefore drag its sibling pull across the whole gap.The pacer now honours demand only within one chunk group past the pull's frontier, which is the only place a serve encoder parked on that pull can wait. It then draws one
PULL_WINDOW_FLOOR.node_pull_topupfailed 2 of 5 runs with them, and passes 11 of 11 with floor draws.The follow-up commit also adds three tests:
It also fixes stale
top_up_channelreferences and the top-up log text.Seller-floor top-up and e2e stability (
d819443b,cb1ade69,d1f5ecff)node_pull_topuphad three more intermittent failure causes. This PR fixes all of them.remaining − Mcan't cover a window, and it reports that asNotFound.BudgetPacernow tops up while the remaining deposit still covers the peer's floor plus the next voucher (PaceState::seller_reserve).pool_min_remaining_deposit_micro_usdc; the CLI passes 0.topUp. The node signsredeemManyandtopUpwith one key. AtopUprejectednonce too lowis re-sent up to three more times; nothing was broadcast, so re-sending is safe.window_pull_through_underpaid_voucher_abandons_boundedflaked. The readers now record the offset they park on, and the frame producer publishes it only when the frame channel is empty. ADR 037 states this.Verification on the final code:
node_pull_topuppasses 8 of 8.node_to_node_coalesce,cli_fetch_topup,coalesce_two_clients).cargo nextest run --workspace: 3473 passed, and clippy and rustdoc are clean.Known follow-ups (not in this PR)
Mequals its own. An upstream with a largerMcan still refuse re-opens in the gap. A signed reason to the authenticated pool owner would remove the guess, but that is a wire and privacy decision.Arc<AtomicU64>total_bytesindemand_up_totop_up_pool→top_up_pool_byandServedPaidWait→DownstreamWait🤖 Generated with Claude Code
https://claude.ai/code/session_013p4vAEc4scVHADBqA44K9j