This is a backport of [[https://github.com/bitcoin/bitcoin/pull/19328 | core#19328]] [2/4]
https://github.com/bitcoin/bitcoin/pull/19328/commits/a712cf6f6801157667fcf36d1c498b6fff6d328a
Backport note: D507 kept the name `hash_serialized` instead of using `hash_serialized_2` which was introduced in [[https://github.com/bitcoin/bitcoin/pull/10426 | core#10426]]
Depends on D9978