bitcoin/bitcoin — pull request #2145 by sipa (2013-01-03 15:30:18+00:00)
Title: Checkcoins

-checklevel gets a new meaning:
0: verify blocks can be read from disk (like before)
1: verify (contextless) block validity (like before)
2: verify coin database is consistent with the last few blocks (close to level 6 before)
3: verify all validity rules of the last few blocks (including signature checks)

Level 2 is the new default, as it's reasonably fast. As level 2 and 3 are implemented using an in-memory rollback of the database, they are limited to as many blocks as possible without exceeding the limits set by -dbcache. The default of -dbcache=25 allows for some 100-150 blocks to be rolled back.

In case an error is found, the application quits with a message instructing the user to restart with -reindex. Better instructions, and automatic recovery (when possible) or automatic reindexing are left as future work.