This makes two improvements to the index init phase:
1) Prevent index corruption in case a reorg happens when the index was switched off:
This is done by reading in the top block stored in the locator instead of looking for a fork point already in BaseIndex::Init()
.
Before, we’d just go back to the fork point by calling FindForkInGlobalIndex()
, which would have corrupted the coinstatsindex because its saved muhash needs to be reverted step by step by un-applying all blocks in between, which wasn’t done before. This is now being done a bit later in ThreadSync()
, which has existing logic to call the custom Rewind()
method when going back along the chain to the forking point (thanks ryanofsky for pointing this out to me!).
2) Allow using the -reindex-chainstate
option without needing to disabling indexes:
With BaseIndex::Init()
not calling FindForkInGlobalIndex()
anymore, we can allow reindex-chainstate
with active indexes. reindex-chainstate
deletes the chain and rebuilds it later in ThreadImport
, so there is no chain available during BaseIndex::Init()
, which would lead to problems (see #24789).
But now we’ll only need the chain a bit later in BaseIndex::ThreadSync
, which will wait for the reindex-chainstate in ThreadImport
to finish and will continue syncing after that.