#35751 validation: use parallel input prevout fetching in TestBlockValidity
https://github.com/bitcoin/bitcoin/pull/35751 · · +39/-7 in 3 files, 2 commits · labels: Validation
Goal
- Speeds up block template validation for miners and Stratum v2 services
- Prevents dummy template checks from polluting the main coins cache
This PR updates TestBlockValidity to use the reusable CoinsViewOverlay via ConnectBlockView rather than allocating a temporary CCoinsViewCache. This enables parallel input prevout fetching during block template validation and prevents cache misses from populating the main coins cache. It also updates the AssembleBlock benchmark to fill blocks to maximum weight to accurately evaluate the performance impact.
Problem: TestBlockValidity previously constructed an ephemeral CCoinsViewCache on top of CoinsTip, missing out on the parallel input fetching implemented in #35295 and polluting the main cache with lookups from dummy checks. Miners and Stratum v2 services creating or checking block templates experience slower validation latency as a result.
Category: Validation (#23 of 48)
P3 · speedup
- P3 because it speeds up block template checking by roughly ten percent on full blocks
- The benefit applies to template assembly and Stratum v2 checks but leaves normal tip advancement unchanged
- It does not affect consensus rules or block connection during initial block download
P3 because it improves block template checking speed by around 10% on full blocks by reusing CoinsViewOverlay from #35295. While useful for block assembly and Stratum v2 template checking, it does not affect consensus rules, block connection during initial block download, or steady-state tip advancement.
Membership: Modifies TestBlockValidity and Chainstate in src/validation.cpp and src/validation.h to reuse the CoinsViewOverlay.
Factors: security/stability 0, bug 0, performance 1, user value 1, leverage 1
Reviewability: Paused: Waiting on author
- Wait for the author to push an agreed reentrancy assert before reviewing
Review is paused waiting on the author to push the agreed reentrancy assert requested by l0rinc.
Author status: Addressing review; proposed an assert to resolve reentrancy feedback on 2026-08-23, agreed to by reviewer on 2026-08-26, pending push.
Open concerns:
- Author needs to push the agreed Assert(overlay_view.GetCacheSize() == 0) to guard against reentrant calls from synchronous callbacks (l0rinc).
Resolved concerns:
- CoreCheck performance regression resolved by updating the benchmark to fill blocks to max weight (sedited, andrewtoth).
- Variable naming and commit description clarifications addressed (optout21).
Agreement: Disputed
- Concept approval for improving template verification performance for Stratum v2 (Sjors)
- Support for the performance improvement building on earlier parallel fetching work (optout21)
- Blocking objection on potential reentrancy issues awaits a promised assert fix (l0rinc)
Disputed: l0rinc requested changes regarding reentrancy; author proposed an assert that l0rinc agreed with, awaiting push.
A blocking Changes Requested review from l0rinc remains open because the proposed fix has not yet been pushed to the PR branch.
- Sjors Concept ACKed for improving checkBlock IPC performance for Stratum v2.
- optout21 approved the performance improvement as a follow-up to earlier parallel fetching work.
- l0rinc requested changes citing potential reentrancy issues if TestBlockValidity is called during an active fetch.
- andrewtoth proposed adding an assert on cache size, which l0rinc confirmed is the ideal solution.
Review verdicts (DrahtBot): 0 (+1)
Dependencies
Enables:
- Stratum v2 template validation efficiency (#35671)
Files
27 lines under test/bench/ci.
- src/bench/block_assemble.cpp +25/-2
- src/validation.cpp +6/-5
- src/validation.h +8/-0
Uncertainties
- Whether the agreement state should be considered Mild rather than Disputed given that both reviewer and author agreed on the resolution.
Card
This PR updates TestBlockValidity to reuse the CoinsViewOverlay introduced in PR 35295, enabling parallel prevout fetching and preventing cache-miss pollution in the main UTXO cache during template checks. It speeds up block template validation in AssembleBlock benchmarks by approximately 10 percent, which primarily benefits mining pool operators and Stratum v2 template checking workflows. The problem is a minor performance optimization rather than a critical consensus bottleneck. Review is currently paused while waiting on the author to push an agreed-upon reentrancy assertion requested by l0rinc. There are no blocking dependencies.