This PR improves the codebase quite a bit, but is also difficult to backport because it is a "shotgun" change. It can backported in several small pieces. When cherry picking one of the commits, conflict will happen. If the conflict are trivial, then they can be solved. If they are more complex, then it is usually due to some other change done in Bitcoin Core and that needs to be backported first.
Note: this change needs to include https://github.com/bitcoin/bitcoin/pull/12906/files as well. Best done merged before committing to prevent breaking the windows build (see discussion).