Repository navigation
Conversation
The upcoming refactor needs direct coverage of the single-threaded `TestBlockValidity()` path and the multithreaded `ConnectBlock()` path. The existing coverage only exercised pieces of that behavior indirectly. Add explicit thread-mode coverage in the affected tests. The unit tests now check whether `TestBlockValidity()` populates the script execution cache with zero worker threads but not with worker threads. The functional test exercises `generateblock` with `-par=1` and `-par=2`. A small test-harness override for `worker_threads_num` makes the unit setups deterministic.
Move `m_script_execution_cache` to private and expose `IsScriptValidated()` and `CacheScriptValidation()` methods. This ensures the `AssertLockHeld` check is consistently applied for both cache lookups and insertions, rather than relying on callers to assert the lock. Co-authored-by: l0rinc <[email protected]>
`CheckInputScripts()` needs the spent outputs only when `PrecomputedTransactionData` is not already initialized. Extract that calculation into `GetSpentOutputs()` and leave the readiness check and size assertion at the call site, so the helper only does the one piece of work that is actually being shared.
Separate the pre-check logic into `PrepareScriptChecks()`. It returns `std::optional<uint256>`: `nullopt` if no script checks are needed, or the cache entry hash for use by the caller when storing results later. `CheckInputScripts()` now calls `PrepareScriptChecks()` internally. This keeps the single-threaded execution path unchanged while making the shared setup reusable for deferred script check collection in a later step. Co-authored-by: l0rinc <[email protected]>
Update cache-hit and cache-miss assertions to call `PrepareScriptChecks()` directly instead of inferring the same result from the `pvChecks` vector. This keeps the tests focused on the cache pre-check contract while leaving the thread-mode coverage intact. Co-authored-by: l0rinc <[email protected]>
`CheckInputScripts()` still handled both inline execution and deferred `CScriptCheck` collection. That mixed the single-threaded path we want to preserve with the multithreaded path that only needs to gather work for the checkqueue. Introduce `CollectScriptChecks()` for the deferred path and use it from `ConnectBlock()` only when worker threads are available. The single-threaded branch still calls `CheckInputScripts()` exactly as before, and the multithreaded branch still only queues collected checks, so this stays a pure refactor.
Since `ConnectBlock()` now gathers deferred script checks through `CollectScriptChecks()`, no caller needs `CheckInputScripts()` to serve both inline execution and collection. Remove the `pvChecks` parameter and the associated dead branches. The remaining callers all want inline script execution, so this keeps the single-threaded path explicit without changing behavior. Co-authored-by: l0rinc <[email protected]>
Contributor
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. LLM Linter (✨ experimental)Possible places where named args for integral literals may be used (e.g.
2026-03-20 05:54:45 |
This was referenced Mar 23, 2026
This was referenced Jun 20, 2026
Contributor
|
🐙 This pull request conflicts with the target branch and needs rebase. |
Contributor
Author
|
I think this served its purpose to demonstrate smaller and safer migration suggestion of #32575 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
CheckInputScripts()currently serves two different purposes: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 intoGetSpentOutputs(), and extracting the common pre-check logic intoPrepareScriptChecks().It then splits deferred script-check collection out of
CheckInputScripts()into a separateCollectScriptChecks()helper.ConnectBlock()usesCollectScriptChecks()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 thepvChecksparameter 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 than a refactor and unified the single-threaded and multithreaded cases by always going through the
checkqueue.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.