| 636 | } |
| 637 | |
| 638 | void ThreadImport(std::vector<boost::filesystem::path> vImportFiles) |
| 639 | { |
| 640 | RenameThread("lux-loadblk"); |
| 641 | const CChainParams& chainparams = Params(); |
| 642 | // -reindex |
| 643 | if (fReindex) { |
| 644 | CImportingNow imp; |
| 645 | int nFile = 0; |
| 646 | while (true) { |
| 647 | CDiskBlockPos pos(nFile, 0); |
| 648 | if (!boost::filesystem::exists(GetBlockPosFilename(pos, "blk"))) |
| 649 | break; // No block files left to reindex |
| 650 | FILE* file = OpenBlockFile(pos, true); |
| 651 | if (!file) |
| 652 | break; // This error is logged in OpenBlockFile |
| 653 | LogPrintf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile); |
| 654 | LoadExternalBlockFile(chainparams, file, &pos); |
| 655 | nFile++; |
| 656 | } |
| 657 | pblocktree->WriteReindexing(false); |
| 658 | fReindex = false; |
| 659 | LogPrintf("Reindexing finished\n"); |
| 660 | // To avoid ending up in a situation without genesis block, re-try initializing (no-op if reindexing worked): |
| 661 | InitBlockIndex(chainparams); |
| 662 | } |
| 663 | |
| 664 | // hardcoded $DATADIR/bootstrap.dat |
| 665 | filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat"; |
| 666 | if (filesystem::exists(pathBootstrap)) { |
| 667 | FILE* file = fopen(pathBootstrap.string().c_str(), "rb"); |
| 668 | if (file) { |
| 669 | CImportingNow imp; |
| 670 | filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old"; |
| 671 | LogPrintf("Importing bootstrap.dat...\n"); |
| 672 | LoadExternalBlockFile(chainparams, file); |
| 673 | RenameOver(pathBootstrap, pathBootstrapOld); |
| 674 | } else { |
| 675 | LogPrintf("Warning: Could not open bootstrap file %s\n", pathBootstrap.string()); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | // -loadblock= |
| 680 | for (boost::filesystem::path& path : vImportFiles) { |
| 681 | FILE* file = fopen(path.string().c_str(), "rb"); |
| 682 | if (file) { |
| 683 | CImportingNow imp; |
| 684 | LogPrintf("Importing blocks file %s...\n", path.string()); |
| 685 | LoadExternalBlockFile(chainparams, file); |
| 686 | } else { |
| 687 | LogPrintf("Warning: Could not open blocks file %s\n", path.string()); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | if (GetBoolArg("-stopafterblockimport", false)) { |
| 692 | LogPrintf("Stopping after block import\n"); |
| 693 | StartShutdown(); |
| 694 | } |
| 695 | } |
nothing calls this directly
no test coverage detected