This is another preparation for #8580, avoiding performance problems and large code changes ahead of time (I was originally planning to do these afterwards, but that would temporarily introduce extra complexity).
In many places we’ve started using std::shared_ptr<const CTransaction>
instead of CTransaction
itself, as transactions are shared between many data structures (orphan pool, mempool, relay pool, partially-reconstructed transactions, …), but a notable exception was CBlock
, which so far always required a full copy in and out. If CTransaction is to become immutable, that will make things even worse when modifying the coinbase (https://github.com/bitcoin/bitcoin/pull/8580#issuecomment-243052533).
Advantages:
- The mining code no longer needs to create a deep copy of all transactions; the resulting CBlockTemplate just shares transactions with the mempool they’re taken from.
- Compact block reconstruction no longer copies transactions (not from the prefilled structure to the internal partial block, and not from the partial block to the full block).
- Block processing no longer copies full transactions to txChanged.
- CTransaction becomes constructable-from-serialization, preparing for #8580.
Disadvantages:
- An extra pointer indirection and atomic increments/decrements in some places.