remove unnecessary casts, use braced initialization and add an assertion
Summary:
This is a partial backport of core#22677, core#23649 and core#23683
https://github.com/bitcoin/bitcoin/pull/22677/commits/bedf246f1e2497a3641093c6e8fa11fb34dddac4
https://github.com/bitcoin/bitcoin/pull/23649/commits/b01784f0270dc20f8076ea4e46203c97b40b93ef
https://github.com/bitcoin/bitcoin/pull/23683/commits/b4adc5ad6769e4a5a6179dfff271cd4c9dc47a5b
Note that core#23683 mostly reverts the commit from core#22677. The remaining diff after applying both commits consists of just an additional assertion and comment.
Also note that core#23683 was applied out of sequence to avoid introducing a bug. In the source material, the assertion is added to the code after a piece of it was moved to validation.cpp.
Depends on D12440
Test Plan: ninja all check-all
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Differential Revision: https://reviews.bitcoinabc.org/D12441