Repository navigation
perf(node): hoist voucher ecrecover out of the per-lane lock (#1735) - #1742
Merged
Merged
Conversation
`commit_one_voucher` held the per-lane `Mutex<LaneDeliveryState>` across `verify_voucher` → `stage_voucher` → `verify_signer`, i.e. across the elliptic-curve `ecrecover` — the most expensive op on the serve path. Concurrent same-lane streams (which the #1697 `active_streams` cap supports) therefore serialized on the crypto. Signature validity depends only on the voucher bytes and the lane's immutable pinned `signer`/`pool_id`/`provider`, never the mutable watermark. So recover + verify the signature OUTSIDE the lock (identity read from `lane_key`), and keep only the watermark-dependent monotonicity re-check + advance inside it. - incentive: split `LaneState::advance_presigned` out of `stage_voucher` (the amount/bytes monotonicity + cap + advance half, signature already verified). `stage_voucher` now = pool/provider check + verify_signer + advance_presigned, byte-for-byte identical behavior. - node: `commit_one_voucher` recovers the signer lock-free (high-`s` rejection #836 preserved; malformed → BadSignature, wrong → WrongSigner, neither watermark-gated so no resume bundle), then re-checks monotonicity against the LIVE watermark under the lock and advances. The monotonicity-check + advance stay atomic per lane — no lost update. - Preserves AlreadySatisfied benign-supersede and the #1699 divergent equal-amount rejection. Tests: add `wrong_signer_is_rejected_without_the_lane_lock` and `concurrent_advances_recheck_the_live_watermark_no_lost_update`. All existing voucher tests stay green. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR reduces lock contention on the node’s paid-delivery serve path by moving voucher signature recovery (ecrecover) out of the per-lane mutex critical section, while keeping watermark monotonicity checks and advances atomic under the lock. It also refactors the incentive lane state machine to expose a “signature already verified” advance path used by the node.
Changes:
- Hoist voucher signature reconstruction + signer verification out of the per-lane lock in
commit_one_voucher. - Split
LaneState::stage_voucherso the watermark-dependent monotonicity + cap + advance logic can run asadvance_presignedafter signature verification. - Add targeted tests validating that wrong-signer rejection happens lock-free and that live-watermark rechecks prevent lost updates under concurrency.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/node/src/handlers/client/voucher.rs | Verify signer lock-free, then re-check monotonicity + advance under the lane mutex; adds concurrency-focused tests. |
| crates/incentive/src/lane.rs | Introduces advance_presigned and wires stage_voucher through it to enable the node-side lock hoisting. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Coverage reportTotal: 80.70% (was 80.63%, ▲ +0.07%) — 58438/72415 lines
History
|
…riant asserts - watermark_bundle_for_reject no longer re-runs `recover_signer` under the per-lane lock: `commit_one_voucher` already verifies the signature against the pinned `signer` OUTSIDE the lock (#1735), so a wrong-signer voucher is rejected as WrongSigner and never reaches this reject path. Re-recovering here would re-do the ecrecover in the very critical section this PR removes. Now an associated fn (no `self`). - verify_voucher: debug_assert that `signed` matches `wire` (advance reads `signed.*`, rate/floor checks read `wire.*` — they must agree). - LaneState::advance_presigned: debug_assert the voucher's pool_id/provider match the lane, since the fast path skips those identity checks. Co-Authored-By: Claude Opus 4.8 <[email protected]>
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.
Problem
commit_one_voucherheld the per-laneMutex<LaneDeliveryState>(crates/node/src/handlers/client/voucher.rs) acrossverify_voucher→stage_voucher→verify_signer, i.e. across the elliptic-curveecrecover(~tens of µs) — the single most expensive operation on the serve path.Concurrent same-lane streams, which the #1697
active_streamsadmission cap explicitly supports (N streams sharing one lane(pool_id, signer, provider)), therefore serialized on the crypto: each stream's voucher blocked the others across the recovery.Fix
Signature validity depends only on the voucher bytes and the lane's immutable pinned
signer/pool_id/provider— never the mutable watermark. So theecrecovermoves out of the critical section:lane_keyand recover + verify the signer. Reject a wrong/malformed signature here with no lock held.credit_advance, andrecord.This shrinks the critical section from ecrecover-time to a few map/compare ops. Concurrent same-lane streams now recover signatures in parallel and only briefly serialize on the advance.
Changes
lane.rs): splitLaneState::advance_presignedout ofstage_voucher— the amount/bytes monotonicity + cap + advance half, for a voucher whose signature the caller already verified.stage_voucheris now pool/provider check +verify_signer+advance_presigned, behavior byte-for-byte unchanged.voucher.rs):commit_one_voucherrecovers the signer lock-free, thenverify_vouchercallsadvance_presignedunder the lock against the live watermark.Correctness
snon-canonical rejection (incentive: high-s signature malleability asymmetry — vouchers accepted off-chain are unsettleable on-chain (free delivery / settlement griefing) #836) stays on the recovery path.BadSignature, wrong signer →WrongSigner; neither is watermark-gated, so neither carries a wallet-less-resume bundle (Publisher-pays channels: open-on-behalf + adopt-by-id + reject-bundle resume #1481 §5) — matching prior behavior.AlreadySatisfiedbenign-supersede and the feat(payments): self-describing vouchers to enable concurrent same-lane settlement #1699 divergent equal-amount rejection.Tests
wrong_signer_is_rejected_without_the_lane_lock— the signature gate is fully outside the lock (verify_signerrejects) whileadvance_presignedignores the signature and would advance, proving the accept/reject decision is hoisted out of the critical section.concurrent_advances_recheck_the_live_watermark_no_lost_update— a straggler recovered against a stale snapshot is a benignAmountRegressionagainst the live watermark, not a second advance.voucher.rstests stay green.cargo build && cargo clippy && cargo nextest run -p decdn-node -p decdn-incentive && cargo fmt -- --checkall pass (1142 tests); anvil-e2e compile gate green.Closes #1735.
🤖 Generated with Claude Code