This is a partial backport of core#25704
https://github.com/bitcoin/bitcoin/pull/25704/commits/fa43188d86288fa6666307a77c106c8f069ebdbe
Note that additional changes in setup_common.cpp and miner_tests.cpp were required to make miner_tests pass with checkpoints disabled.
Depends on D15813