3 suggestions
Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive for their assessments.
Optional improvements
[suggestion] · No regression test covers cache writes from TestBlockValidity
No test would catch removing this cache write or moving it before script checks finish, which could cache a transaction whose scripts failed.
Location: src/validation.cpp:2642 (head).
Details and suggested fix
When fJustCheck is set, ConnectBlock collects script-cache keys and writes them only after control->Complete() and the state.IsValid() check. Existing tests fill the cache through CheckInputScripts, which ConnectBlock no longer calls, and the block helpers do not exercise this path. Add a test using transactions that never entered the mempool: call TestBlockValidity and verify each transaction remains a cache miss. Then validate a block containing one valid transaction and one with a failing input script; verify the block is rejected and the valid transaction remains a cache miss. This covers both omitted writes and writes made before all checks finish. Unit tests normally use two worker threads; add a zero-worker variant where practical.
[suggestion] · Block validation duplicates script-check construction
Block and mempool validation build CScriptCheck objects in separate loops, while the cache-soundness comment appears only on the mempool path, increasing the risk that the copies drift.
Location: src/validation.cpp:2604 (head).
Details and suggested fix
ConnectBlock now constructs CScriptCheck objects in its own loop, using the same arguments as the loop in CheckInputScripts. The comment explaining that only data committed to by the transaction's witness hash is passed to CScriptCheck appears only in the latter. That property also matters on the block path, where a script-execution-cache hit lets ConnectBlock skip script execution. Extract a shared helper to construct the checks and keep the comment there. ConnectBlock can pass the results to control->Add; CheckInputScripts can run them in order and stop at the first failure, at the cost of building the vector first.
[suggestion] · The cache lookup comment omits its erase-on-hit behavior
Block validation reaches the erase-on-hit behavior through GetScriptCacheEntry, but its comment describes only a lookup.
Location: src/validation.cpp:2071 (head).
Details and suggested fix
GetScriptCacheEntry passes !cacheFullScriptStore as the erase argument to ValidationCache::IsScriptValidated. When cacheFullScriptStore is false, a cache hit sets the CuckooCache garbage-collect flag for that entry. ConnectBlock uses this behavior while connecting blocks, but its comment describes only a lookup. The explanation remains on CheckInputScripts, which now has only mempool callers and tests, and still refers to block-checking callers. Move the cacheFullScriptStore=false explanation to GetScriptCacheEntry, document the behavior next to IsScriptValidated in validation.h, and remove the block-caller wording from CheckInputScripts.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [suggestion]: Preserve fail-fast behavior when there are no workers
- [suggestion]: Document the cache-lookup input precondition