This is a backport of [[https://github.com/bitcoin/bitcoin/pull/19806 | core#19806]] [7/8] and a test related changes from [[https://github.com/bitcoin/bitcoin/pull/21681 | core#21681]]
https://github.com/bitcoin/bitcoin/pull/19806/commits/769a1ef9fdc9c372f5bbe91d1961cabd60bc1895
https://github.com/bitcoin/bitcoin/pull/21681/files
Depends on D11240