This commit is contained in:
l0rinc 2025-10-08 02:04:15 +02:00 committed by GitHub
commit 771eafb67e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 7 deletions

View File

@ -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;