Repository navigation
Description
Group E of the serve-path hot-path audit (siblings: #1788–#1791; doc drift: #1787). These items run mid-stream on every accepted Voucher/ChunkPreimage, mostly inside the per-lane tokio::Mutex that intentionally serializes same-lane streams (ADR 003/005). The per-lane serialization is by design; the problem is what happens under it and what couples different lanes together.
1. channel_state_store.record() takes a process-global mutex while the per-lane lock is held
voucher.rs:271 (voucher) and :403 (preimage) → channel_store.rs:377,679-691: every accepted proof on every lane acquires the single std::sync::Mutex<LaneBuffer> — while its async per-lane guard is held. The same mutex is held by the flush task across postcard-encoding every dirty lane (channel_store.rs:738-755) and by the redeemer's whole-map load_all/get clones on the async runtime (payment_settlement.rs:670,688,1126,1169).
Fix: per-lane dirty cells (e.g. DashMap<LaneKey, slot> + a lock-free dirty queue) so record() touches only its own lane; move flush snapshot and settlement reads off the shared structure (tracked as their own items in the background-contention sibling issue).
Improves: removes the only cross-lane / cross-pool serialization point on the paid delivery path; a flush or settlement sweep no longer stalls proof commits; the sync-mutex-under-async-lock worker blockage disappears.
Leaving as-is limits: aggregate voucher/preimage throughput across all lanes on the node is bounded by one blocking mutex — this is the first wall the payment path hits as concurrent paying streams grow. Because the caller holds an async lane lock while blocking on a sync mutex, contention also parks a runtime worker thread, degrading unrelated tasks. Worst case couples everything: a settlement sweep over many lanes freezes every stream's proof acceptance, which freezes delivery via the credit window.
2. Receipt formatting runs inline per credited voucher
wire.rs:35-41 → receipt_log.rs:158-172: two 64-char hex allocations, U256::to_string, and a SystemTime::now() on the stream task; only the disk append is offloaded.
Fix: send the raw binary receipt struct over the (already non-blocking) channel and format in the background writer; timestamp there or from a coarse clock.
Improves: the proof-commit path sheds three allocations and string formatting per voucher.
Leaving as-is limits: per-voucher CPU and allocator churn on the delivery path, scaling with paid throughput — pure overhead for an audit artifact whose write side was already moved off-path (#803).
3. Two LaneState clones per accepted proof, both under locks
voucher.rs:256 (verified.next_state.clone()) and the clone inside record (channel_store.rs:682) — the first under the per-lane lock, the second under both the per-lane and global buffer locks (until item 1).
Fix: restructure to one clone or copy-on-write (Arc<LaneState> snapshots).
Improves: shortens both critical sections.
Leaving as-is limits: clone cost scales with proof rate and extends exactly the lock holds that items 1 and 5 are trying to shrink — same-lane streams and (today) all lanes pay it.
4. SystemTime::now() syscalls under the lane lock
voucher.rs:227 (expiry gate), :282, :409 (activity stamps) — two to three clock reads per proof, two under the lane lock.
Fix: a background-updated coarse AtomicU64 clock; expiry needs ~second resolution.
Improves: removes syscalls from the lane critical section.
Leaving as-is limits: fixed per-proof syscall overhead inside the most contended per-lane region; trivial to remove, compounds at high proof rates.
5. The PayWord keccak walk runs under the per-lane lock, with payer-influenced length
voucher.rs:355-358 → incentive/src/lane.rs:462-512: up to 255 keccaks (index − verified steps) inside the lane guard. The comment in client-pull/src/ledger.rs:115 shows the buyer side deliberately keeps this walk off its issuance lock — the seller side should match.
Fix: optimistic verify — read (tip, verified) under the lock, walk outside, re-lock and apply iff the chain state is unchanged (retry on the rare race).
Improves: the lane lock hold becomes O(1) per preimage.
Leaving as-is limits: a payer that releases sparse indices makes every sibling stream on the lane wait out its walk — same-lane concurrent streams (the ADR 005 §Payment lanes case) inherit worst-case tens of µs per proof of serialized keccak, adding pause/resume latency at every credit-window boundary.
6. Per-voucher ecrecover still runs on the shared accept task
voucher.rs:199-213 — correctly outside the lane lock (#1735), but on the FuturesUnordered task (#1788 item 1). PayWord already amortizes signatures to ~one per 255 MiB per lane in steady state, so this ranks below the items above.
Fix: covered by #1788 item 1, or a crypto worker pool.
Improves: rollover vouchers stop stalling sibling streams on the connection.
Leaving as-is limits: every chain rollover and every non-chained voucher inserts ~100–200 µs of connection-wide stall.
7. pool_floor is one mutex over all pools
mod.rs:1016, touched at admission (:1650-1680), the 2 s solvency re-check (delivery.rs:413-434 → :1619-1627), and FloorReservation::drop (:469-484). Touches are O(1), never across await, and rate-limited — fine today.
Fix (when pool counts grow): shard per pool.
Improves: removes the last cross-pool lock on the paid path.
Leaving as-is limits: acceptable at testnet scale; at high pool/stream counts the fixed touch rate per stream turns one map mutex into a shared point. Ranked last deliberately — measure before sharding.
Metadata
Metadata
Assignees
Type
Fields
Priority
Projects
- StatusShow more project fieldsDone
Activity
perf(node): move download-receipt formatting off the voucher hot path (…
perf(node): coarse clock for the voucher-accept path's under-lock clo…
perf(node): move the accepted LaneState into the lane instead of clon…
perf(node,incentive): run the PayWord keccak walk off the per-lane lo…
perf(node): de-globalize the lane store working set (#1792 item 1) (#…