Skip to content

Optimize reindex

Placeholder Pieter Wuille requested to merge github/fork/sipa/betterreindex into master

Several changes:

  • Make reindex/import use AcceptBlock rather than ProcessNewBlock, so activation of the resulting best chain is delayed.
  • That delayed activation is handled by the existing "Activating best chain" step in the startup process, which is moved to ThreadImport.
  • Optimize ActivateBestChain to not walk the entire chain to find the most work chain to connect for each block (O(n^2) -> O(n)).

This has several advantages:

  • As the actual activation is done after all blocks have been added back to the index, it gets to use the checkpoints information (better progress indicator, skipping of signature checks, ...).
  • Having a block index with many unactivated blocks (for example, after deleting the chainstate directory) becomes much faster
  • That case also runs in the background now (as it's simply treated as part of the importing process).

Downsides:

  • All blocks are read twice from disk during reindex (once to rebuild the index, once to activate).

Todo:

  • Better progress indicator during the index rebuild phase.

Merge request reports

Loading