| 549 | } |
| 550 | |
| 551 | void ThreadImport(std::vector<boost::filesystem::path> vImportFiles) |
| 552 | { |
| 553 | RenameThread("bitcoin-loadblk"); |
| 554 | CImportingNow imp; |
| 555 | |
| 556 | // -reindex |
| 557 | if (fReindex) { |
| 558 | int nFile = 0; |
| 559 | while (true) { |
| 560 | CDiskBlockPos pos(nFile, 0); |
| 561 | if (!boost::filesystem::exists(GetBlockPosFilename(pos, "blk"))) |
| 562 | break; // No block files left to reindex |
| 563 | FILE *file = OpenBlockFile(pos, true); |
| 564 | if (!file) |
| 565 | break; // This error is logged in OpenBlockFile |
| 566 | LogPrintf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile); |
| 567 | LoadExternalBlockFile(file, &pos); |
| 568 | nFile++; |
| 569 | } |
| 570 | pblocktree->WriteReindexing(false); |
| 571 | fReindex = false; |
| 572 | LogPrintf("Reindexing finished\n"); |
| 573 | // To avoid ending up in a situation without genesis block, re-try initializing (no-op if reindexing worked): |
| 574 | InitBlockIndex(); |
| 575 | } |
| 576 | |
| 577 | // hardcoded $DATADIR/bootstrap.dat |
| 578 | boost::filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat"; |
| 579 | if (boost::filesystem::exists(pathBootstrap)) { |
| 580 | FILE *file = fopen(pathBootstrap.string().c_str(), "rb"); |
| 581 | if (file) { |
| 582 | boost::filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old"; |
| 583 | LogPrintf("Importing bootstrap.dat...\n"); |
| 584 | LoadExternalBlockFile(file); |
| 585 | RenameOver(pathBootstrap, pathBootstrapOld); |
| 586 | } else { |
| 587 | LogPrintf("Warning: Could not open bootstrap file %s\n", pathBootstrap.string()); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | // -loadblock= |
| 592 | BOOST_FOREACH(boost::filesystem::path &path, vImportFiles) { |
| 593 | FILE *file = fopen(path.string().c_str(), "rb"); |
| 594 | if (file) { |
| 595 | LogPrintf("Importing blocks file %s...\n", path.string()); |
| 596 | LoadExternalBlockFile(file); |
| 597 | } else { |
| 598 | LogPrintf("Warning: Could not open blocks file %s\n", path.string()); |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | // scan for better chains in the block chain database, that are not yet connected in the active best chain |
| 603 | CValidationState state; |
| 604 | if (!ActivateBestChain(state)) { |
| 605 | LogPrintf("Failed to connect best block"); |
| 606 | StartShutdown(); |
| 607 | } |
| 608 |
nothing calls this directly
no test coverage detected