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).
This is not an optimal solution, as we’re relying on the scheduler call sites to make sure the scheduler doesn’t overflow. Ideally, the scheduler would guarantee this directly, but that needs a few further changes (moving the signal emissions out of cs_main) to prevent deadlocks.
I have manually tested the invalidateblock
changes (including interrupting, and running with -checkblockindex and -checkmempool), but haven’t tried the rewinding (which is probably becoming increasingly unnecessary, as very few pre-0.13.1 nodes remain that would care to upgrade).