Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
This is a partial backport of [[https://github.com/bitcoin/bitcoin/pull/22932 | core#22932]]
https://github.com/bitcoin/bitcoin/pull/22932/commits/eaeeb88768db529b5241ccd42f1e87579908b4df
Depends on D13036