Skip to content

Commit 695e2b9

Browse files
committed
Merge bitcoin/bitcoin#33353: log: show reindex progress in ImportBlocks
d7de5b1 logs: show reindex progress in `ImportBlocks` (Lőrinc) Pull request description: ### 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 ```bash cmake -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: ``` 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 we add a percentage: ``` 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 ``` ACKs for top commit: enirox001: Concept ACK d7de5b1 rkrux: lgtm ACK d7de5b1 danielabrozzoni: tACK d7de5b1 - code reviewed and tested on my archival node. maflcko: review ACK d7de5b1 💇 Tree-SHA512: 359a539b781ad8b73e2a616c951567062a76be27cf90e5b88bb5309295af9cd7994e327f185bacc1482b43b892b38329593b4043a5e71d8800e3e4b7a3954310
2 parents 1f151e7 + d7de5b1 commit 695e2b9

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/node/blockstorage.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,26 +1247,27 @@ void ImportBlocks(ChainstateManager& chainman, std::span<const fs::path> import_
12471247

12481248
// -reindex
12491249
if (!chainman.m_blockman.m_blockfiles_indexed) {
1250-
int nFile = 0;
1250+
int total_files{0};
1251+
while (fs::exists(chainman.m_blockman.GetBlockPosFilename(FlatFilePos(total_files, 0)))) {
1252+
total_files++;
1253+
}
1254+
12511255
// Map of disk positions for blocks with unknown parent (only used for reindex);
12521256
// parent hash -> child disk position, multiple children can have the same parent.
12531257
std::multimap<uint256, FlatFilePos> blocks_with_unknown_parent;
1254-
while (true) {
1258+
1259+
for (int nFile{0}; nFile < total_files; ++nFile) {
12551260
FlatFilePos pos(nFile, 0);
1256-
if (!fs::exists(chainman.m_blockman.GetBlockPosFilename(pos))) {
1257-
break; // No block files left to reindex
1258-
}
12591261
AutoFile file{chainman.m_blockman.OpenBlockFile(pos, /*fReadOnly=*/true)};
12601262
if (file.IsNull()) {
12611263
break; // This error is logged in OpenBlockFile
12621264
}
1263-
LogInfo("Reindexing block file blk%05u.dat...", (unsigned int)nFile);
1265+
LogInfo("Reindexing block file blk%05u.dat (%d%% complete)...", (unsigned int)nFile, nFile * 100 / total_files);
12641266
chainman.LoadExternalBlockFile(file, &pos, &blocks_with_unknown_parent);
12651267
if (chainman.m_interrupt) {
12661268
LogInfo("Interrupt requested. Exit reindexing.");
12671269
return;
12681270
}
1269-
nFile++;
12701271
}
12711272
WITH_LOCK(::cs_main, chainman.m_blockman.m_block_tree_db->WriteReindexing(false));
12721273
chainman.m_blockman.m_blockfiles_indexed = true;

0 commit comments

Comments
 (0)