MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / ThreadImport

Function ThreadImport

src/init.cpp:635–708  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

633}
634
635static void ThreadImport(std::vector<fs::path> vImportFiles)
636{
637 const CChainParams& chainparams = Params();
638 RenameThread("bitcoin-loadblk");
639 ScheduleBatchPriority();
640
641 {
642 CImportingNow imp;
643
644 // -reindex
645 if (fReindex) {
646 int nFile = 0;
647 while (true) {
648 CDiskBlockPos pos(nFile, 0);
649 if (!fs::exists(GetBlockPosFilename(pos, "blk")))
650 break; // No block files left to reindex
651 FILE *file = OpenBlockFile(pos, true);
652 if (!file)
653 break; // This error is logged in OpenBlockFile
654 LogPrintf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile);
655 LoadExternalBlockFile(chainparams, file, &pos);
656 nFile++;
657 }
658 pblocktree->WriteReindexing(false);
659 fReindex = false;
660 LogPrintf("Reindexing finished\n");
661 // To avoid ending up in a situation without genesis block, re-try initializing (no-op if reindexing worked):
662 LoadGenesisBlock(chainparams);
663 }
664
665 // hardcoded $DATADIR/bootstrap.dat
666 fs::path pathBootstrap = GetDataDir() / "bootstrap.dat";
667 if (fs::exists(pathBootstrap)) {
668 FILE *file = fsbridge::fopen(pathBootstrap, "rb");
669 if (file) {
670 fs::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 (const fs::path& path : vImportFiles) {
681 FILE *file = fsbridge::fopen(path, "rb");
682 if (file) {
683 LogPrintf("Importing blocks file %s...\n", path.string());
684 LoadExternalBlockFile(chainparams, file);
685 } else {
686 LogPrintf("Warning: Could not open blocks file %s\n", path.string());
687 }
688 }
689
690 // scan for better chains in the block chain database, that are not yet connected in the active best chain
691 CValidationState state;
692 if (!ActivateBestChain(state, chainparams)) {

Callers

nothing calls this directly

Calls 15

RenameThreadFunction · 0.85
ScheduleBatchPriorityFunction · 0.85
GetBlockPosFilenameFunction · 0.85
OpenBlockFileFunction · 0.85
LoadExternalBlockFileFunction · 0.85
LoadGenesisBlockFunction · 0.85
fopenFunction · 0.85
RenameOverFunction · 0.85
ActivateBestChainFunction · 0.85
FormatStateMessageFunction · 0.85
LoadMempoolFunction · 0.85
WriteReindexingMethod · 0.80

Tested by

no test coverage detected