Review report

core: PR #32575

5 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · TestBlockValidity lacks regression coverage for deferred script-cache writes

Existing tests would not catch a missing cache write or one made before all queued script checks pass.

Location: src/validation.cpp:2725 (head).

Details and suggested fix

With fJustCheck=true, ConnectBlock collects script-cache keys while queuing checks and writes them only after control->Complete() and a valid block state. This loop is now the only place block validation writes script-cache entries; multithreaded nodes did not write them before. The updated cache tests exercise CheckInputScripts and GetScriptCacheEntry directly, while TestChain100Setup::CreateBlock appends transactions after building the template. The connect_block fuzz target checks only that connected matches state.IsValid(). Add tests that run TestBlockValidity on a block containing transactions never submitted to the mempool, then verify each transaction's cache entry using GetScriptCacheEntry with cacheFullScriptStore=true and the block's script flags. Also test a block with one valid transaction and one whose input script fails; verify the block is rejected and neither transaction is cached. A zero-worker variant would cover the configuration this change affects most.


Link

[suggestion] · Mempool and block validation duplicate script-check construction

The two validation paths build checks separately, and only the mempool path documents why the wtxid-and-flags cache key is safe.

Location: src/validation.cpp:2686 (head).

Details and suggested fix

CheckInputScripts and ConnectBlock now each construct CScriptCheck objects using the spent outputs, input index, flags, signature-cache setting, and txdata. Only the CheckInputScripts loop explains that the checks use data committed to by the transaction's witness hash. That property also matters on the block path: mempool acceptance writes script-cache entries under block flags, and a cache hit lets ConnectBlock skip script execution. The copies are identical today, but a future change to one could miss the other. A shared helper could construct a transaction's checks and carry the comment; ConnectBlock could pass the result to control->Add, while CheckInputScripts runs checks in order and stops at the first failure. The tradeoff is that the mempool path would build the entire vector before running checks, even when a transaction fails early.


Link

[suggestion] · GetScriptCacheEntry omits its erase-on-hit behavior and input precondition

Block connection relies on the helper's erase-on-hit behavior, but its documentation describes only a lookup and omits the caller's input-view precondition.

Location: src/validation.cpp:2073 (head).

Details and suggested fix

GetScriptCacheEntry passes !cacheFullScriptStore as the erase argument to IsScriptValidated, so a cache hit with cacheFullScriptStore=false marks the entry for eviction. ConnectBlock relies on this when connecting a block because it passes fCacheResults=false. The helper's comment does not describe that side effect. The previous note that a cache hit assumes the caller's inputs match the transaction's prevouts was also dropped. The cache key covers only the wtxid and flags, so callers must supply an input view consistent with those prevouts. Current callers pass the appropriate flags and meet this precondition. Document the erase behavior and input precondition at GetScriptCacheEntry (or rename the parameter to make the behavior clear), and remove the obsolete block wording from CheckInputScripts.


Link

[suggestion] · CheckInputScriptsFor::Block is unreachable after block validation moved

All current callers pass Mempool, leaving a dead Block case and a header comment that incorrectly describes block use.

Location: src/validation.cpp:2137 (head).

Details and suggested fix

Before this change, ConnectBlock was the only caller that passed CheckInputScriptsFor::Block; the remaining callers pass Mempool. The Block case and its block-script-verify-flag-failed result are therefore unreachable. ConnectBlock now reports block script failures itself after control->Complete(). The enum's header comment still says the parameter controls whether failures are reported as consensus failures for blocks, which suggests CheckInputScripts still serves block validation. Remove the check_for parameter and enum, or explain in the comment if they are intentionally retained for future block callers.


Link

[suggestion] · GetScriptCacheEntry's declaration is duplicated instead of shared

The production file and unit test repeat the function declaration, repeating a pattern base commit 703ebdf had just removed for CheckInputScripts.

Location: src/test/txvalidationcache_tests.cpp:25 (head).

Details and suggested fix

GetScriptCacheEntry is not declared in a header. validation.cpp forward-declares it, and the unit test repeats its full signature, including the lock annotation. Base commit 703ebdf moved CheckInputScripts into validation.h to avoid this pattern and removed its corresponding redeclaration comment. If a parameter changes, the test fails to link. If only the return type changes, the mismatch can still link on Itanium-ABI platforms and cause undefined behavior. Declare GetScriptCacheEntry in validation.h next to CheckInputScripts, then remove both manual declarations and the redeclaration note.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.