Skip to content

perf(node): move the accepted LaneState into the lane instead of cloning it (#1792 item 3) - #1872

Merged
alpergundogdu merged 1 commit into
mainfrom
claude/issue-1792-bnzq86
Aug 30, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
claude/issue-1792-bnzq86

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

What

Addresses the independently-achievable half of item 3 of #1792 (Group E of the serve-path hot-path audit): "Two LaneState clones per accepted proof, both under locks."

Each accepted voucher/preimage did:

guard.state = verified.next_state.clone();   // clone #1, under the lane lock
// …
self.channel_state_store.record(&verified.next_state);  // record() clones again internally

— two full LaneState duplications per proof, both inside the per-lane critical section.

Change

Move the verified candidate into guard.state and have record borrow it from the lane:

guard.state = verified.next_state;           // move, no clone
// …
self.channel_state_store.record(&guard.state);

LaneState is #[derive(Clone)] — not Copy — so this genuinely elides one duplication rather than being a no-op. verified.{new_bytes,amount} are Copy, so the partial move leaves them readable for the credit/receipt bookkeeping below. The preimage path hoists its O(1) receipt-amount read (next_state.owed()) above the move for the same reason.

Applied to both the voucher path (commit_one_proof) and the preimage path (commit_one_preimage).

Scope

The remaining clone is the one inside the store's record() (let mut next = state.clone()), which exists to reconcile registered_until against the buffered copy. That one is coupled to the process-global LaneBuffer and is the item 1 (buffer-resharding) change's to remove — left untouched here so this PR stays a small, self-contained, behavior-preserving refactor.

Correctness

Pure move-vs-clone: the stored LaneState and every downstream read are byte-identical to before; only the redundant intermediate copy is gone. No change to payment logic, lock scope order, or the durable record.

Testing

  • cargo build -p decdn-node — clean
  • cargo clippy -p decdn-node --all-targets — clean (no anti-panic policy violations)
  • cargo test -p decdn-node --lib — 771 passed
  • cargo test -p decdn-node --test client_loopback -- voucher preimage reveal chain capabilit — 16 passed (full accept-path coverage: voucher advance, hash-chain reveals, capability gating)
  • cargo fmt --check and cargo doc --workspace --no-deps --document-private-items (-D warnings) — clean

Closes #1792 item 3 (partial — the store-internal clone is deferred to item 1).

🤖 Generated with Claude Code

https://claude.ai/code/session_013MSiZrVoUQzy4J5Ci8RGEu


Generated by Claude Code

…ing it

Group E item 3 (independent half) of the serve-path hot-path audit
(#1792): each accepted voucher/preimage cloned the verified candidate
`LaneState` into the lane guard and then passed the same value to
`channel_state_store.record`, which clones it again — two full clones per
proof, both under the per-lane lock.

Move the candidate into `guard.state` and have `record` borrow it from
there, so the proof clones once (the store's internal clone) rather than
twice. `LaneState` is `Clone`, not `Copy`, so this genuinely elides one
duplication; `verified.{new_bytes,amount}` are `Copy`, so the partial move
leaves them readable. The preimage path hoists its O(1) receipt-amount
read above the move for the same reason.

The remaining clone lives inside the store's `record` and is coupled to
the buffer-resharding item (#1792 item 1); it is left for that change.
Behavior is unchanged — a pure move-vs-clone refactor.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_013MSiZrVoUQzy4J5Ci8RGEu
Copilot AI lite review requested due to automatic review settings August 30, 2026 11:39

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 reduces per-proof overhead in the node’s paid delivery accept path by eliminating an extra LaneState clone taken under the per-lane lock. It does so by moving the verified candidate state into the lane (guard.state) and then recording the store state by borrowing from the lane, while preserving existing acceptance logic and store behavior.

Changes:

  • Move verified.next_state into guard.state in the voucher accept path and pass &guard.state to channel_state_store.record().
  • In the preimage accept path, compute the receipt amount before moving next_state into the lane, then record via &guard.state.

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

@github-actions

Copy link
Copy Markdown

Coverage report

Total: 82.09% (was 82.10%, ● 0.00%) — 68205/83083 lines

File Coverage Lines Δ
crates/node/src/handlers/client/voucher.rs 93.21% 494/530 ● 0.00%
History
Commit Total Δ vs base
91e5704 (HEAD) 82.09% ● 0.00%

@alpergundogdu
alpergundogdu merged commit dbcdb65 into main Aug 30, 2026
26 checks passed
@alpergundogdu
alpergundogdu deleted the claude/issue-1792-bnzq86 branch August 30, 2026 11:52
yigitdot added a commit that referenced this pull request Aug 30, 2026
One conflict, in `dispatch.rs`'s `use super::{…}` list. Main's per-lane
perf work (#1870/#1872/#1873) dropped `Mutex` from it when the accepted
`LaneState` moved into the lane instead of being cloned; this branch had
added `FloorRefusalSite` for the split refusal logging. Took the union:
main's list, minus `Mutex` (no remaining use in the file), plus
`FloorRefusalSite`.

Everything else auto-merged, including both serve loops where the perf
commits and this branch's floor calls are adjacent. Verified the floor
surface survived intact: `release_if_repaid` and the pool-only mid-stream
re-check in `delivery.rs` / `serve_leg.rs`, both admission gates and the
refusal logging in `dispatch.rs`, and the accumulator itself.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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,incentive): voucher path — global LaneBuffer mutex nested under the per-lane lock; per-proof clones, allocs, and syscalls

3 participants