#36066 validation: Separate check-only version of ConnectBlock
https://github.com/bitcoin/bitcoin/pull/36066 · · +65/-20 in 4 files, 1 commits · labels: Validation
Goal
- Clarify mutability guarantees when checking blocks without applying state updates
- Eliminate boolean check flags and mutable dummy objects in validation tests
Separates the check-only execution path in `Chainstate::ConnectBlock` into a dedicated `TestConnectBlock` method taking `const CBlockIndex&`. The shared UTXO validation checks are moved into an internal helper `ConnectBlockChecks`, eliminating the public `fJustCheck` boolean parameter.
Problem: In check-only validation mode (used by `TestBlockValidity` and fuzz testing), `ConnectBlock` required a mutable `CBlockIndex*` even though the block index was not modified, obscuring mutability guarantees and requiring caller-side dummy objects.
Category: Validation (#39 of 48)
P3 · cleanup
- P3 because it is a low-risk internal code cleanup with no performance or security impact
- Improves const correctness for developers and aligns with work toward stateless validation
The PR is a code-hygiene refactor that improves const-correctness in validation interfaces and removes a boolean flag (`fJustCheck`). As noted in the description, 'The mutability of the pindex parameter is in sync with the semantics' and it aligns with efforts to decouple validation side effects (#35904).
Membership: Directly alters `Chainstate::ConnectBlock` and introduces `TestConnectBlock` in src/validation.cpp and src/validation.h.
Factors: security/stability 0, bug 0, performance 0, user value 0, leverage 1
Reviewability: Ready
- Ready for review
- Latest update addressed review feedback and resolved a silent fuzz test conflict
The author resolved previous review suggestions from l0rinc and fixed a silent merge conflict with fuzz tests in the latest push.
Author status: active
Resolved concerns:
- l0rinc suggested passing the block index by const reference, reusing the stored block hash, and updating related comments, all of which the author applied.
- purpleKarrot noted that `Chainstate` still mutates internal timing and counter state during check-only calls; the author acknowledged this as part of longer-term work toward stateless validation in #35904.
Agreement: Positive
- Concept approval because separating the check-only path clarifies mutability (l0rinc)
- Noted that internal chainstate mutations remain until later stateless validation work (purpleKarrot)
Concept ACK from l0rinc; specific review requests were addressed in the latest push.
l0rinc provided a Concept ACK with change requests regarding const references and comments, which the author incorporated. purpleKarrot raised architectural considerations around side effects without blocking.
- l0rinc: 'Concept ACK... Separating the check-only entry point makes the CBlockIndex mutability clearer and removes fJustCheck from the public ConnectBlock() interface.'
- purpleKarrot: 'What about the mutability and mutations of the Chainstate... Please have a look at #35904'
- optout21: 'Applied review suggestions, minor changes.'
Review verdicts (DrahtBot): 0
- Concept ACK: l0rinc
Files
11 lines under test/bench/ci.
- src/validation.cpp +44/-13
- src/validation.h +16/-1
- src/test/fuzz/connect_block.cpp +4/-5
- test/functional/interface_usdt_utxocache.py +1/-1
Card
This PR refactors `Chainstate::ConnectBlock` by separating its check-only mode into a distinct `TestConnectBlock` method that accepts a `const CBlockIndex&`. This removes the `fJustCheck` boolean parameter and clarifies const-correctness for callers that only validate blocks without mutating chainstate, such as `TestBlockValidity` and fuzz tests. The work is code hygiene that also supports ongoing modularization toward side-effect-free validation (#35904). Review feedback from l0rinc has been incorporated and the PR is ready for review.