Now that CTransactions are typically created once and passed around as shared pointers, and blocks are frequently constructed from the transactions in our mempool (thanks to BIP 152 compact blocks), we can calculate the PrecomputedTransactionData once and save it in the CTransaction, to avoid doing extra work in ConnectBlock.
This PR adds a new deserialization flag to allow for deserializing a CTransaction without calculating these hashes, which is used in ProcessGetData.
Finally, this PR includes a commit which caches the witness hash inside CTransaction. @jl2012 This was inspired by #9572, although with the approach I’ve taken here, I don’t think it’s necessary to additionally skip the hashing for non-segwit transactions, as very few hashes are typically calculated during block validation now (just the ones that are requested via getblocktxn).
Thanks to @TheBlueMatt and @ryanofsky for reviewing several iterations of this.