This is a minimal subset from #318 needed to match the shim introduced by https://github.com/bitcoin/bitcoin/pull/35084. Should unblock #322, see #322 (comment).
Include #322 here, because CI will not pass now since https://github.com/bitcoin/bitcoin/pull/35084 merged.