This is a partial backport of [[https://gitlab.com/bitcoin-cash-node/bitcoin-cash-node/merge_requests/1820 | bchn#1820]]
https://gitlab.com/bitcoin-cash-node/bitcoin-cash-node/-/merge_requests/1820/diffs?commit_id=76c7b65a1e3016340aa845ac83f341414326fb59
Depends on D16904