This is split off from #36521 (and not included in #36895), as it's effectively an independent improvement.
This introduces a number of additional checks that are applied during transaction deserialization, which reduce various worst case deserialization time scenarios:
- Reject transactions with more txins or more txouts than can possibly fit in a block (applied always)
- Reject transactions with 0 txins or 0 txouts (applied in P2P code only; there are RPCs like
fundrawtransactionthat explicitly support transactions with 0 inputs) - Count weight accurately during transaction or block deserialization, and bail out as soon as it exceeds 4M (applied in P2P code).
This is a mild behavior change, as detecting these problems early causes them to be treated as deserialization errors, which in P2P logic cause messages to be ignored instead of peer disconnection.