Problem
CheckInputScripts() currently serves two different purposes:
- In the single-threaded path it executes script checks inline and may cache successful results.
- In the multithreaded block validation path it instead prepares deferred
CScriptChecksfor thecheckqueue.
That makes the function name misleading and the control flow harder to follow in a consensus-sensitive area. The main issue is that these two uses are intertwined in one function.
Fix
This PR separates those responsibilities without changing behavior, making it a pure refactor with test coverage of the affected functionality.
It first cleans up the shared pieces around script checking by encapsulating script execution cache access in ValidationCache, extracting spent output collection, and extracting the common pre-check logic into PrepareScriptChecks().
It then splits deferred script-check collection out of CheckInputScripts() into a separate CollectScriptChecks() helper.
ConnectBlock() uses CollectScriptChecks() only in the existing multithreaded path when worker threads are available.
The single-threaded path still calls CheckInputScripts() directly, as before.
With that split in place, CheckInputScripts() no longer needs the pvChecks parameter and can go back to only doing inline script validation.
The tests are updated to cover both thread modes directly and to test the cache pre-check logic through PrepareScriptChecks().
Notes
This is a narrower alternative to #32575, keeping the original author and content in each commit where possible.
The original PR eventually went further that a refactor and unified the single-threaded and multithreaded cases by always going through the checkqueue. I found that approach too risky - especially since it seems to lead to a catastrophic slowdown with single-threaded validation.
This PR keeps the current thread-mode behavior intact and only separates the two uses into different functions so the code is easier to read, review, and reason about. If there is still interest in unifying the paths later, that can be discussed separately.