Summary
When triggering a reindex, users have no indication of progress.
Fix
This patch precomputes the total number of block files so progress can be shown. Instead of only displaying which block file is being processed, it now shows the percent complete.
Reproducer + expected results
0cmake -B build -DCMAKE_BUILD_TYPE=Release && make -C build -j && ./build/bin/bitcoind -datadir=demo -reindex
Before, the block files were shown one-by-one, there’s no way to see how much work is left:
0Reindexing block file blk00000.dat...
1Loaded 119920 blocks from external file in 1228ms
2Reindexing block file blk00001.dat...
3Loaded 10671 blocks from external file in 284ms
4Reindexing block file blk00002.dat...
5Loaded 5459 blocks from external file in 263ms
6Reindexing block file blk00003.dat...
7Loaded 5595 blocks from external file in 267ms
After the change we add a percentage:
0Reindexing block file blk00000.dat (0% complete)...
1Loaded 119920 blocks from external file in 1255ms
2Reindexing block file blk00001.dat (1% complete)...
3Loaded 10671 blocks from external file in 303ms
4Reindexing block file blk00002.dat (2% complete)...
5Loaded 5459 blocks from external file in 278ms
6Reindexing block file blk00003.dat (3% complete)...
7Loaded 5595 blocks from external file in 285ms