log: show reindex progress in ImportBlocks #33353

pull l0rinc wants to merge 1 commits into bitcoin:master from l0rinc:l0rinc/show-reindex-progress changing 1 files +8 −7
  1. l0rinc commented at 7:08 pm on September 9, 2025: contributor

    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
    
  2. DrahtBot commented at 7:08 pm on September 9, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33353.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK Raimo33, enirox001

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  3. l0rinc renamed this:
    logs: show reindex progress in `ImportBlocks`
    log: show reindex progress in `ImportBlocks`
    on Sep 9, 2025
  4. DrahtBot added the label Utils/log/libs on Sep 9, 2025
  5. logs: show reindex progress in `ImportBlocks`
    ### Summary
    
    When triggering a reindex, users had no indication of how many files remained or how far along the process was.
    
    ### Fix
    
    This patch prefetches the target file block file count to be able to show progress information.
    Instead of just displaying which block file is being processed, it now indicates how many files remain.
    
    ### Reproducer + expected results
    
    Running
    ```bash
    cmake -B build && make -C build -DCMAKE_BUILD_TYPE=Release && ./build/bin/bitcoind -datadir=demo -reindex
    ```
    Shows the block files one-by-one currently, there's no way to see how much work is left:
    ```
    Reindexing block file blk00000.dat...
    Loaded 119920 blocks from external file in 1228ms
    Reindexing block file blk00001.dat...
    Loaded 10671 blocks from external file in 284ms
    Reindexing block file blk00002.dat...
    Loaded 5459 blocks from external file in 263ms
    Reindexing block file blk00003.dat...
    Loaded 5595 blocks from external file in 267ms
    ```
    
    After the change:
    ```
    Reindexing block file blk00000.dat (0% complete)...
    Loaded 119920 blocks from external file in 1255ms
    Reindexing block file blk00001.dat (1% complete)...
    Loaded 10671 blocks from external file in 303ms
    Reindexing block file blk00002.dat (2% complete)...
    Loaded 5459 blocks from external file in 278ms
    Reindexing block file blk00003.dat (3% complete)...
    Loaded 5595 blocks from external file in 285ms
    ```
    d7de5b109f
  6. l0rinc force-pushed on Sep 9, 2025
  7. in src/node/blockstorage.cpp:1238 in d7de5b109f
    1239             AutoFile file{chainman.m_blockman.OpenBlockFile(pos, /*fReadOnly=*/true)};
    1240             if (file.IsNull()) {
    1241                 break; // This error is logged in OpenBlockFile
    1242             }
    1243-            LogInfo("Reindexing block file blk%05u.dat...", (unsigned int)nFile);
    1244+            LogInfo("Reindexing block file blk%05u.dat (%d%% complete)...", (unsigned int)nFile, nFile * 100 / total_files);
    


    Raimo33 commented at 2:50 pm on September 13, 2025:
    precompute the division?

    enirox001 commented at 7:08 pm on September 16, 2025:
    Consider computing the progress as (nFile + 1) * 100 / total_files so the indicator advances past 0% on the first file. Is there a reason we intentionally show 0% initially?

    enirox001 commented at 7:08 pm on September 16, 2025:
    Use a defensive guard when computing percent, e.g. total_files ? (100 * (nFile + 1) / total_files) : 0, to avoid accidental divide-by-zero after future refactors.

    enirox001 commented at 7:12 pm on September 16, 2025:
    Would it make sense to log nFile+1/total_files (e.g. 4/125) alongside the percent? That gives clearer, more granular progress than an integer percent alone.

    l0rinc commented at 9:18 pm on September 16, 2025:
    Thanks @enirox001, I think the 0% is fine and we’ve just calculated total_files, no need to guard and the percentage is the same as the nFile+1/total_files, I don’t see the need to duplicate it.

    luke-jr commented at 7:26 am on September 18, 2025:
    Files are not necessarily the same size/complexity…

    l0rinc commented at 4:32 pm on September 18, 2025:
    It’s just an approximation - or do you think Reindexing block file blk%05u.dat (5/123)... would be clearer? We have progress in blocks as well, they’re all just approximations…

    Raimo33 commented at 4:34 pm on September 18, 2025:
    i think percentage is fine. it just means % of blocks instead of % of time
  8. Raimo33 commented at 2:52 pm on September 13, 2025: none
    Concept ACK
  9. enirox001 commented at 7:18 pm on September 16, 2025: contributor

    Concept ACK d7de5b1

    I tested this locally, the percentage logging provides a clear indication of progress during reindex and is useful visibility while the node processes block files.

    I have left a few non-blocking nits for consideration.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-10-10 18:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me