This is a backport of Core [[https://github.com/bitcoin/bitcoin/pull/16681 | PR16681]] and [[https://github.com/bitcoin/bitcoin/pull/18069 | PR18069]]
I also replaced one occurence of 'regtest' in test_framework.py, that was missed in the backport of [[https://github.com/bitcoin/bitcoin/pull/16509 | PR16509]] (D5942)