The miner needs read-only access to the mempool. Instead of using the mutable global ::mempool, keep a immutable reference to a mempool that is passed to the miner. Apart from the obvious benefits of removing a global and making things immutable, this might also simplify testing with multiple mempools.
Backport of core PR17781.
Depends on D7984.
This differs quite a bit from the original PR because we already passed
a mempool. This is mostly rename and factorization to make it looks more
like core.