[META] This commit should be followed up by removing the comments and assertions meant only to show that the change is correct.
This is a backport of core#20749 [14 & 15/17]
https://github.com/bitcoin/bitcoin/pull/20749/commits/ea4fed90219be17160136313c68c06d84176af08
https://github.com/bitcoin/bitcoin/pull/20749/commits/0cdad753903640ff4240b715dec9d62f68e51407
Depends on D11185