logs: show reindex progress in `ImportBlocks`
What changed, and why it matters
This commit is a user-experience improvement, not a security fix. It adds a percentage-complete indicator to the log message shown while Bitcoin Core reindexes old block files. Before, users only saw which file was being processed; now they can see roughly how many files remain. There is no change to security-sensitive logic.
No security action required. Treat as a normal logging/UX improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors the reindex loop in src/node/blockstorage.cpp::ImportBlocks. It first counts how many blk*.dat files exist, then iterates through them with a for loop instead of an unbounded while(true), and adds a progress percentage to the LogInfo output. The filesystem checks, file opening, and block-loading calls remain functionally identical. No input validation, cryptography, consensus, networking, or privilege logic is modified.
Changed components
src/node/blockstorage.cpp::ImportBlocksInspect captured patch +8 / −7
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index 3c01ff2e..1163feb3 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -1220,26 +1220,27 @@ void ImportBlocks(ChainstateManager& chainman, std::span<const fs::path> import_
// -reindex
if (!chainman.m_blockman.m_blockfiles_indexed) {
- int nFile = 0;
+ int total_files{0};
+ while (fs::exists(chainman.m_blockman.GetBlockPosFilename(FlatFilePos(total_files, 0)))) {
+ total_files++;
+ }
+
// Map of disk positions for blocks with unknown parent (only used for reindex);
// parent hash -> child disk position, multiple children can have the same parent.
std::multimap<uint256, FlatFilePos> blocks_with_unknown_parent;
- while (true) {
+
+ for (int nFile{0}; nFile < total_files; ++nFile) {
FlatFilePos pos(nFile, 0);
- if (!fs::exists(chainman.m_blockman.GetBlockPosFilename(pos))) {
- break; // No block files left to reindex
- }
AutoFile file{chainman.m_blockman.OpenBlockFile(pos, /*fReadOnly=*/true)};
if (file.IsNull()) {
break; // This error is logged in OpenBlockFile
}
- LogInfo("Reindexing block file blk%05u.dat...", (unsigned int)nFile);
+ LogInfo("Reindexing block file blk%05u.dat (%d%% complete)...", (unsigned int)nFile, nFile * 100 / total_files);
chainman.LoadExternalBlockFile(file, &pos, &blocks_with_unknown_parent);
if (chainman.m_interrupt) {
LogInfo("Interrupt requested. Exit reindexing.");
return;
}
- nFile++;
}
WITH_LOCK(::cs_main, chainman.m_blockman.m_block_tree_db->WriteReindexing(false));
chainman.m_blockman.m_blockfiles_indexed = true;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.