This PR makes a number of improvements to the InvalidateBlock (invalidateblock RPC) and RewindBlockIndex functions, primarily around breaking up their long-term cs_main holding. In addition:
- They're made safely interruptible (bitcoind can be shutdown, and no progress in either will be lost, though if incomplete, invalidateblock won't continue after restart and will need to be called again)
- The validation queue is prevented from overflowing (meaning invalidateblock on a very old block will not drive bitcoind OOM) (see #14289).
- invalidateblock won't bother to move transactions back into the mempool after 10 blocks (optimization).
Partial Backport of Bitcoin Core PR15402 (commit 32b2696):
https://github.com/bitcoin/bitcoin/pull/15402/commits/32b2696ab4b079db736074b57bbc24deaee0b3d9
Move erasure of non-active blocks to a separate loop in RewindBlockIndex
This lets us simplify the iteration to just walking back in the chain,
rather than looping over all of mapBlockIndex.
Depends on D4653