InitAndLoadChainstate
is problematic, when called twice in the GUI. This can happen when it returns a failure and the user selects an interactive reindex.
There are several bugs that have been introduced since the last time this was working correctly:
- The first one is a crash (assertion failure), which happens due to a cached tip block in the notifiications from the previous run. See #31346 (review)
- The second one is UB (use-after-free), which happens because the block index db in the blockmanager is not reset. See #30965 (review)
Fix both bugs by resetting any dirty state in InitAndLoadChainstate
.
Also, add a test, because I don’t really want to keep testing this manually every time. (A failing test run can be seen in https://github.com/bitcoin/bitcoin/pull/32979/checks)