This is a backport of [[https://github.com/bitcoin/bitcoin/pull/23154 | core#23154]]
with updates from core#25667 and core#25740[[https://github.com/bitcoin/bitcoin/pull/25667 | core#25667]] and [[https://github.com/bitcoin/bitcoin/pull/25740 | core#25740]]