This is a small code-hygiene refactor to ConnectBlock method.
Problem: In the "check-only" mode of ConnectBlock the mutability of the CBlockIndex parameter is inconsistent with the semantics. In the default operation, ConnectBlock changes the provided CBlockIndex. However, it has a special "check-only" mode, where the provided chain is not changed. This mode is used from only one call site (TestBlockValidity), and is signaled by the fJustCheck = true flag.
Solution: Provide two versions of ConnectBlock: one with mutable chain and one "check-only" with const chain. There is no need for the fJustCheck flag. Both reuse the same internal implementation.
Benefits:
- The mutability of the
pindexparameter is in sync with the semantics - One less feature flag (
fJustCheck) - Calling "check-only" mode is smoother, creating a dummy mutable
CBlockIndexis now unnecessary
Additional details:
- This has been triggered by #35187, there is also a new usage of "check-only"
ConnectBlock, with dummyCBlockIndex. - The "check-only" mode was introduced as early as 3cd01fdf0e540c4e06cd27b6c0d6b6abc00767d1 .
- No behavior change (pure refactor).
- Some internal variables (
blockundo,nInputs,nSigOpsCost) are now outputs of the internal method, and used in the default outer method (ConnectBlock). SetBestBlockhas been moved to the outerConnectBlock. It was also present in the special genesis block early return, this is preserved.- The tracepoints are in the outer methods
- Timing is present both in the inner method (logs) and the outer methods (logs, tracepoint)