Review report

bitcoin/bitcoin: PR #35662

2 suggestions

Optional improvements

Link

[suggestion] · Cache-hit assertions do not protect lazy txdata construction

The cache-hit retry reuses txdata and checks only queued scripts, so it would miss a regression that constructs transaction data before consulting the script cache.

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

Details and suggested fix

ValidateCheckInputsForAllFlags passes the same optional to the inline call and the ret && add_to_cache retry. After a miss, that optional is already engaged, and successful inline verification with cache storage enabled leaves an entry for the immediate same-flags retry. Although CheckInputScripts currently checks the cache first, moving its entire if (!txdata) block above the lookup would preserve the existing assertions. Callers starting with an empty optional would then perform unnecessary coin lookups and possibly sighash precomputation on cache hits. Pass a separate, initially disengaged optional to this retry and assert that it remains disengaged, while keeping scriptchecks.empty() and the shared optional on the other calls. This preserves reuse coverage, and a cache hit creates no CScriptCheck that could outlive the local optional.


Link

[suggestion] · The no-copy binding leaves its lvalue requirement undocumented

The fallback optional prevents copies of caller-supplied txdata, but nothing at the binding explains why replacing it with a temporary would silently restore those per-call copies.

Location: src/kernel/bitcoinkernel.cpp:812 (head).

Details and suggested fix

Both get(precomputed_txdata) and owned_txdata.emplace(tx) yield lvalues, so the conditional binds txdata directly to the selected object. Replacing the fallback with PrecomputedTransactionData(tx), as in the base code, makes the conditional a prvalue and copies supplied txdata, including m_spent_outputs. The type remains copyable, so that rewrite would compile, and the result/status assertions in the kernel verification tests would not detect the extra copies. Add a short comment at the binding, such as // Keep both operands lvalues so caller-supplied txdata is referenced rather than copied.


Coverage details