Partial backport of PR11389:
https://github.com/bitcoin/bitcoin/pull/11389/commits/18e071841e83044b47aa45c3e98c0796a407d445
Reviewers please also confirm that the rest of the PR is not worth
backporting (it has to do with segwit activation / versionbits), so we
can mark it 'done'.
This is not a totally faithful backport, due to divergence (D1262).
Depends on D3365 due to how the miner_tests build on a weird chain.