4 suggestions
Optional improvements
[suggestion] · ToVector's comment suggests a replacement that can transfer the caller's vector
CTransaction's no-aliasing guarantee depends on ToVector copying into new storage, but the comment does not document or test that requirement.
Location: src/util/vector.h:23 (head).
Details and suggested fix
ToVector currently allocates a new vector and copies each element, preventing a retained CTxIn reference from changing a constructed transaction. The comment suggests replacing it with std::ranges::to<vector> in C++23, which can move-construct from an rvalue vector and take over its buffer. In that case, a reference held before construction could point into tx.vin; writing through it would leave the cached txid and wtxid stale. The existing caller passes prvalue std::arrays and retains no references, so it would not catch this change. Reword the comment to state that ToVector copies elements into new storage and that CTransaction relies on this. A test could pass std::move(inputs) while retaining a reference to one element, then verify that writing through the reference does not change tx.vin and that CMutableTransaction{tx}.GetHash() == tx.GetHash().
[suggestion] · New range code omits headers for the standard facilities it uses
util/vector.h uses <ranges> and <concepts> facilities without including those headers, and the changed test uses std::array and std::move without including their headers.
Location: src/util/vector.h:20 (head).
Details and suggested fix
RangeOf and ToVector use std::ranges facilities declared by <ranges> and std::convertible_to declared by <concepts>. The header includes neither, and the standard does not require its current includes to provide them indirectly. Add <concepts> and <ranges> to util/vector.h. The changed sigopcount_tests.cpp also uses std::array and std::move without including <array> and <utility>; add those includes there.
[suggestion] · The new CTransaction range constructor permits implicit conversions
Copy-list-initialization can construct a CTransaction and compute both hashes without naming the type, unlike the adjacent explicit CMutableTransaction conversions.
Location: src/primitives/transaction.h:319 (head).
Details and suggested fix
Although the constructor requires two arguments, its declaration allows CTransaction tx = {ins, outs}, return {ins, outs}, and f({ins, outs}) when f takes a const CTransaction&. These forms copy the inputs and outputs and compute the txid and wtxid without the call site naming CTransaction. The adjacent CMutableTransaction conversions are explicit, and doc/developer-notes.md recommends explicit constructors by default. Mark this template constructor explicit. BuildTxs uses direct-list-initialization and will still compile.
[suggestion] · CTxIn copies rvalue witnesses
Both constructors take the witness by const reference, so rvalues are copied; the current caller passes an lvalue, making this relevant only to future callers.
Location: src/primitives/transaction.h:123 (head).
Details and suggested fix
Both CTxIn constructors take const CScriptWitness& and copy-assign it. Passing std::move(witness) or a witness returned by a helper therefore copies the outer vector and every stack item. Take the witness by value and move it into scriptWitness. Lvalue callers such as BuildTxs will still make one copy, while rvalue callers will not. The scriptSigIn parameter could be moved into place the same way.