Please describe the feature you’d like to see added.
bitcoin-cli rollback
Arguments:
- height or hash
- delete blocks from storage
- delete headers
This should be used with networking turned off. As soon as you connect to a peer, it will sync back to the tip as normal.
It should rollback indexes too.
It should probably warn users if they have a wallet loaded, especially if the rollback is more than 10 (?) block; that’s the point where the rollback process stops placing transactions back into the mempool.
Is your feature related to a problem, if so please describe it.
We currently rely on invalidateblock
to roll back the chain to an arbitrary height. And then reconsiderblock
to go back to the tip. Rolling back the chain is used when creating snapshots for assume utxo.
This works but the RPC methods are not designed for this. It has annoying side-effects like disconnecting peers because they have “invalid” blocks. If there are stale blocks near the height you want to roll back to, you have to make sure to invalidate those too. IIRC there’s also no way to abort the process.
For functional tests it can be useful to forget a block and a header, e.g. to test behavior when a header is received multiple times from different peers, when receiving an unsolicited or mutated block. Currently such a test has to carefully sequence events, or use multiple unconnected nodes. This RPC would effectively add “undo” for such tests.
Describe the solution you’d like
See above
Describe any alternatives you’ve considered
Status quo.
Please leave any additional context
I’m not advocating to drop invalidateblock
entirely. For example it’s still useful if you want to fully validate a stale block.