This PR extends the optimization added in #23880 which applies to peers that have requested HB blocks from us to also cache the serialized blocks for low-bandwidth peers. The core change here comes from the closed #26755 made by andrewtoth, but also includes other refactors and type safety improvements.
Performance is less critical for low-bandwidth peers, so this change on its own should have little impact on block propagation, but these refactors are useful as part of #35558 which adds prefilling of compact blocks, and where we run the risk of potentially having to serialize more than one cmpctblock_msg (one prefilled and one not-prefilled).