Repository navigation
Description
Gap
The downstream credit window is enforced per stream, not per lane. serve_leg's delivered/paid are locals (serve_leg.rs), and the solvency reservation runs per request at open — pool_remaining_covers_window(remaining, window, rate) reserves one window each time (window.rs:114, :499, dispatch.rs:433). Nothing aggregates concurrent same-lane draws.
So N concurrent streams on one (pool_id, signer, provider) lane can put up to N × window of unpaid egress in flight, while the refundable-minimum floor M only ever guards a single window. A client (or a griefer) that opens many same-lane streams pulls the node's unpaid credit well past the one-window bound it believes it is enforcing.
Currently latent: the only shipped multi-stream client (CLI bundle pull) serializes same-lane access with a per-provider mutex (provider_lock, bundle_pull.rs:523), so it never opens a second stream on one lane. The over-exposure is only reachable by a non-serializing / hostile client.
Ask (node side)
An admission cap, not a shared/divided window. Because admission can guarantee every accepted stream its own full interval within budget, no admitted stream ever blocks another — so the existing per-stream window in serve_leg stays untouched and only the open-time gate changes:
- Track a per-lane active-stream counter in the shared
LaneDeliveryState(already behind the lane mutex). - Generalize
pool_remaining_covers_window(mod.rs:1002) to reserveactive_streams × windowinstead of one window. Check-and-increment atomically under the lane lock — otherwise two simultaneous opens each see room for one more (TOCTOU → admit N+1). - Refuse the surplus with a typed reject reason (
BudgetExhausted/LaneAtCapacity) on the signedStreamResponse { ok: false, error }path, so the client reads it as retryable ("back off / go serial"), not a hard failure. - Release the slot on every exit path — success, error, client disconnect, idle reap. Tie the decrement to a drop guard on the lane entry; a leaked slot makes the lane refuse forever. This is the main bug farm.
The cap is dynamic, not a constant
max_concurrent = floor((remaining − M in bytes) / window), capped by the policy window. "8× the floor → 8 streams" holds only at full budget; as the pool drains the ceiling drops, and eventually even one stream is refused — which is exactly the existing single-stream deposit refusal falling out of the same formula (the N = 1 edge). So this generalizes machinery that already exists rather than adding a parallel path.
Client side
Checked: for the case this cap targets, the honest client already does more than "the same." Bundle pull serializes same-lane to exactly one in-flight stream (provider_lock); --jobs concurrency spans only distinct lanes (bundle_pull.rs:744). There is no general budget-based concurrency cap on the client (the "budget" in client-pull is per-fetch settle/top-up pacing, not admission). So the honest client will never trip the node cap.
Client follow-up (smaller, can be a separate PR):
- Handle the new
BudgetExhaustedrefusal gracefully — treat it as retryable and back off toward serial, rather than surfacing a hard fetch failure. Needed only once a client actually opens concurrent same-lane streams. - Optional: a client that wants same-lane concurrency should self-limit its concurrent streams to
budget / windowso it does not open streams the node will just refuse. Not needed for bundle pull (already serial). - Note (related, out of scope): cross-lane
--jobsfan-out on one shared pool is not budget-bounded on the client today; the node enforces its own per-lane exposure regardless.
Out of scope — keep separate
This bounds exposure and makes concurrent delivery safe. It does not make concurrent settlement work: two admitted streams simultaneously collecting a cumulative voucher still hit the reconstruction-order problem (BadSignature), so the client still serializes voucher signing. That is the separate self-describing-voucher follow-up (see #1689 / #1690). Per-lane admission is fully compatible with serialized signing: concurrent delivery, one-at-a-time settlement.
Wire note
The BudgetExhausted refusal is a one-variant addition to the StreamResponse error enum. Pre-launch this is a free wire break (no compat shims); the accounting itself is node-internal.
Test hook
Prototype and regression-test against the synthetic concurrent same-lane client added in #1690 (concurrent_same_lane_streams_aggregate_across_the_voucher_interval, client_loopback.rs): open more same-lane streams than budget / window allows and assert the surplus is cleanly refused with BudgetExhausted while the admitted streams deliver and settle correctly, and that finished streams release their slots (a later open succeeds).
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsDone
Activity
test(payments): pin that a skip-ahead voucher on a concurrent lane is…
perf(node): hoist voucher ecrecover out of the per-lane lock (#1735) (#…
fix(node): heal a restarted client whose watermark fell behind (#1954)
refactor(node): cut per-signer abandonment subsystem; reduce #1697 to…