This is a backport of core#22814 and core#27314[[https://github.com/bitcoin/bitcoin/pull/22814 | core#22814]] and [[https://github.com/bitcoin/bitcoin/pull/27314 | core#27314]]
Depends on D15425
Note that an intermediate PR [[https://github.com/bitcoin/bitcoin/pull/25838 | core#25838]] was already backported in D14065