This is a backport of [[https://github.com/bitcoin/bitcoin/pull/21055 | core#21055]] [2/16] and [[https://github.com/bitcoin/bitcoin/pull/21270 | core#21270]] [1/12]
https://github.com/bitcoin/bitcoin/pull/21055/commits/4927c9e6991b09a36a41aab93a0e05332d899611
https://github.com/bitcoin/bitcoin/pull/21270/commits/a04aac493fd564894166d58ed4cdfd9ad4f561cb