2 suggestions
Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive for their assessments.
Optional improvements
[suggestion] · P2WPKH test rebuilds an unchanged transaction pair
The refactor leaves the original immutable spendingTx in scope, making the third BuildTxs call and its extra numbered transaction pair unnecessary.
Location: src/test/sigopcount_tests.cpp:166 (head).
Details and suggested fix
Restoring scriptPubKey[0] to 0x00 and calling BuildTxs again reproduces the original pair, which remains unchanged and in scope. The helper's AddCoins call only replaces the identical coinbase coin, and the final coinbase sigop check returns before reading the coin view. Remove the reset and third BuildTxs call, then initialize CMutableTransaction spendingTx4{spendingTx};. Keeping SetNull() and the final assertion preserves both the unknown-witness-version check and the coinbase witness-exclusion check without another fixture pair.
[suggestion] · Direct-construction defaults lack an equivalence test
BuildTxs always supplies version 1, leaving the new default-version contract and direct-construction equivalence unchecked, although existing conversion/deserialization tests already exercise the shared cache initialization.
Location: src/test/sigopcount_tests.cpp:88 (head).
Details and suggested fix
Changing the declared default version to 1 would leave these assertions unaffected because both BuildTxs constructions pass it explicitly. Add focused cases for CTransaction{vin, vout} and explicit non-default version/locktime, with and without witness data. Compare fields, serialized bytes, GetHash(), GetWitnessHash(), and HasWitness() against conversion of an equivalently populated CMutableTransaction, including txid/wtxid equality without witness. Conversion and deserialization delegate to the same implementation, so this tests the new API/default contract rather than independently validating shared cache computation.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [suggestion]: util/vector.h omits direct includes for range and concept facilities (earlier report)
- [suggestion]: The new CTransaction range constructor permits implicit conversions (earlier report)
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
The original mutable/immutable split was introduced to avoid repeated transaction hashing while keeping transaction-building code mutable. The proposal deliberately tolerated implicit conversions to keep the migration small, acknowledging possible performance costs in building, wallet, and test code rather than the main processing path.
This identifies the purpose of the construction boundary: a stable object can supply a cached identity instead of repeatedly hashing mutable contents. It documents a performance and migration tradeoff, rather than an explicit requirement that every transaction must first exist as a mutable object.
Source 1 · Source 2 · Source 3
The later immutability proposal explicitly sought to stop modifying transaction elements after construction, with a historical exception for witness data. It introduced both efficient rvalue conversion from CMutableTransaction and deserializing constructors. The author also wanted greater encapsulation, potentially permitting a different internal representation, and described immutable transaction sharing as a benefit of replacing wallet inheritance with a transaction-reference field.
The historical objective was construction followed by stable contents, with efficient ownership transfer and compatibility with deserialization and transaction consumers. The witness exception in that older proposal should not be mistaken for today's invariant: the pinned class also caches witness presence and witness identity.
C++ object-lifetime and constness guarantees constrained how immutability could be implemented. During #8580, a participant objected that replacement/assignment techniques could cause undefined behavior, explicitly noting the potential consequences for miners; the author responded that he would switch to a less efficient mechanism.
The historical tradeoff was not simply maximum construction speed. Preserving valid C++ construction and const-object semantics mattered even at a performance cost. Direct construction operates within that same requirement that finalized contents and caches form a valid, consistent object.
Ralph's inferences
The inspected record does not establish mutable-to-immutable conversion as an exclusive design mandate. The better-supported interpretation is that construction finalizes cached identity, while CMutableTransaction is the established staging mechanism. At the pinned base, conversion is the explicit field-finalizing path and deserialization delegates through it; at the head, conversion delegates to the new value constructor instead.
This distinguishes historical implementation structure from the underlying guarantee. A direct constructor changes how finalization is reached, but the historical rationale alone does not establish that bypassing a mutable staging object violates the intended design.
The concrete pinned invariants are that all transaction fields, including input witnesses, are installed before deriving the caches; witness presence reflects nonempty input witnesses; txid hashes serialization without witness; and wtxid hashes witness-inclusive serialization when witness exists, otherwise equaling txid. Witness presence and txid must already be initialized when the witness hash is computed. These caches are memory-only, and mutable transactions compute their txid on demand.
These are the identity and serialization compatibility requirements that any finalization route must retain. The head moves cache initialization into the value constructor and delegates the existing conversion constructors to it, making that constructor the new location of the same dependency chain.