https://github.com/bitcoin/bitcoin/pull/17154/commits/b6f486a02b463ffeaf82ec11fc6f74f439c037ae
note: the first commit
(https://github.com/bitcoin/bitcoin/pull/17154/commits/8bba91b22d22a8dfea7c947b542b1022bfc1c0ea) didn't really apply to us.
Depends on D7111
Partial backport of Core PR17154