This is a backport of [[https://github.com/bitcoin/bitcoin/pull/21270 | core#21270]] [7/12] and [[https://github.com/bitcoin/bitcoin/pull/21525 | core#21525] [7/10]
https://github.com/bitcoin/bitcoin/pull/21270/commits/4cde4a701b8856ac4ec9721b0226dbbfc52a71c3
https://github.com/bitcoin/bitcoin/pull/21525/commits/88aead263c61d86e5f836028f517cfbf2a575498
Depends on D11422