You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(node): per-lane lock is held across ecrecover, serializing concurrent same-lane vouchers #1735
commit_one_voucher takes the per-lane tokio::Mutex<LaneDeliveryState> (crates/node/src/handlers/client/voucher.rs:100) and holds it across verify_voucher → stage_voucher → verify_signer, i.e. across an elliptic-curve ecrecover (~tens of µs) — the single most expensive operation on the serve path.
Concurrent same-lane streams therefore serialize on the ecrecover. Same-lane concurrency is not rare or serialized upstream: the #1697active_streams admission cap exists precisely because N concurrent streams can share one lane (pool_id, signer, provider) — e.g. a payer running several parallel fetches against the same node funded by the same pool. Each such stream, on each voucher, blocks the others across the recovery.
(The network voucher read is already correctly outside the lock at voucher.rs:92 — good; this is about the crypto, not the read.)
Fix — hoist signature recovery out of the critical section
Signature validity does not depend on the mutable watermark — it needs only the voucher bytes and the lane's immutable pinned signer. So:
Outside the lock:recover_signer (the expensive part) and compare to state.signer. Reject if wrong — no lock needed.
Inside the lock: re-run the cheap amount/bytes monotonicity check against the current watermark, advance, credit_advance, and record.
This shrinks the critical section from ecrecover-time to a few map/compare ops, letting concurrent same-lane streams recover signatures in parallel and only briefly serialize on the advance.
Correctness
The monotonicity check and watermark advance must stay atomic per lane (two streams reading the same watermark and both advancing would lose one) — that stays inside the lock. Only the watermark-independent signature recovery moves out. The recovered signer is compared to the immutable signer field, so moving it out cannot change the accept/reject decision. Care point: stage_voucher today fuses sig + monotonicity + advance; splitting must re-validate monotonicity against the live watermark inside the lock (not against the snapshot recovered against).
Impact
Medium. Benefit scales with actual same-lane parallelism (bounded by the #1697 cap). Removes the longest-held critical section on the per-voucher path.
Activity
refactor(node): address review — drop under-lock re-recover, add inva…
perf(node): hoist voucher ecrecover out of the per-lane lock (#1735) (#…