mirror of https://github.com/bitcoin/bitcoin.git
Merge d7de5b109f
into b510893d00
This commit is contained in:
commit
771eafb67e
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue