The for loop around the chain loading logic in init.cpp
allows users of the GUI to retry once on failure with reindexing without having to manually set the reindex flag on startup. However this current mechanism has problems:
- It is badly documented and has led to confusion among developers and bugs making it into master. Examples:
- It can only ever iterate once, making the choice of a for loop questionable.
- With its large scope it is easy for re-entry bugs to sneak in. Example:
Attempt to fix this by moving the bulk of the logic into a separate function and replacing the for loop with a simpler if
statement.
The diff’s in this pull request are best reviewed with --color-moved-ws=ignore-all-space --color-moved=dimmed-zebra
. The error behaviour can be tested by either manually making LoadChainstate
return a failure, or deleting some of the block index database files.