Skip to content

[zero] perf(zebra-consensus): overlap block-path UTXO lookups - #46

Open
aphelionz wants to merge 1 commit into
mainfrom
claude/overlap-utxo-lookups-2a26d1
Open

[zero] perf(zebra-consensus): overlap block-path UTXO lookups#46
aphelionz wants to merge 1 commit into
mainfrom
claude/overlap-utxo-lookups-2a26d1

Conversation

@aphelionz

@aphelionz aphelionz commented Aug 21, 2026

Copy link
Copy Markdown
Member

The overlapping-UTXO-lookups half of #34, split out per its review; the caching half is #45. The two are independent and can merge in either order.

block_spent_utxos awaited one state round trip per transparent input; the lookups now run through buffer_unordered(64) (inputs served by known_utxos resolve inline and never build a future). Results carry their input index, so the spent-output order that v5 sighashes commit to is unaffected by completion order. The mempool path is unchanged. One accepted narrowing, documented on MAX_CONCURRENT_UTXO_LOOKUPS: batched lookups start their 6-minute timeout clocks together, which only matters during out-of-order sync and recovers by the designed sync restart.

The new test serves every AwaitUtxo behind a batch barrier that releases only when 64 lookups are pending at once, so a regression to serial lookups deadlocks into the test's 10-second timeout instead of passing slowly (checked by hardcoding buffer_unordered(1): the test fails at 10.1s).

Benchmark (cargo bench -p zebra-consensus --bench utxo_lookup): block verification of a 1001-input P2SH consolidation with ~1ms of injected latency per AwaitUtxo. Run the same bench on the base commit for the serial baseline:

time
main (serial lookups) 2.28 s
this branch (64-way overlap) 45 ms

133/133 cargo nextest run -p zebra-consensus; fmt and clippy -D warnings clean.

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings August 21, 2026 14:23

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 improves zebra-consensus block-path transaction verification performance by overlapping transparent UTXO state lookups (up to a fixed concurrency), avoiding the prior “one awaited round trip per input” behavior for high-input transactions.

Changes:

  • Add a bounded concurrent UTXO lookup pipeline in BlockTxVerifier::block_spent_utxos using buffer_unordered(64) while preserving input-index order for v5 sighash commitments.
  • Add a regression test that deadlocks on serial UTXO fetching to detect accidental re-serialization.
  • Add a Criterion benchmark to measure block-path UTXO fetch performance under injected state-service latency.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
zebra/zebra-consensus/src/transaction.rs Overlaps state AwaitUtxo requests with a fixed max concurrency and preserves spent-output ordering by input index.
zebra/zebra-consensus/src/transaction/tests.rs Adds a concurrency regression test for block-path UTXO lookups (plus a new BoxError import).
zebra/zebra-consensus/Cargo.toml Registers the new utxo_lookup benchmark target.
zebra/zebra-consensus/benches/utxo_lookup.rs Adds a benchmark simulating ~1ms per-UTXO state latency to quantify overlap gains.

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

Comment thread zebra/zebra-consensus/src/transaction/tests.rs Outdated
Copilot AI review requested due to automatic review settings August 21, 2026 14:49

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

aphelionz added a commit that referenced this pull request Aug 26, 2026
Path-gated informational job (not a required check): runs the script-cache
and UTXO-lookup criterion benches on PRs and main pushes that touch the
benched crates, and posts the timings to the step summary. Bench steps are
guarded on their bench files existing, so this lands before #45/#46 and
activates as they merge. rust-cache persists target/criterion, so criterion
also reports a change estimate against the previous cached run.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
block_spent_utxos awaited one state round trip per transparent input, so a
1001-input consolidation paid the state latency 1001 times in series. Inputs
served by known_utxos resolve inline; the rest run through
buffer_unordered(64), and results carry their input index, so the
spent-output order that v5 sighashes commit to is unaffected by completion
order. The mempool path is unchanged. Batched lookups share timeout clocks,
an accepted narrowing documented on MAX_CONCURRENT_UTXO_LOOKUPS.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@aphelionz
aphelionz force-pushed the claude/overlap-utxo-lookups-2a26d1 branch from 5c2dcc4 to 3833031 Compare August 26, 2026 13:33
Copilot AI review requested due to automatic review settings August 26, 2026 13:33

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

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.

2 participants