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

Function ThreadImport

src/init.cpp:344–396  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

342};
343
344void ThreadImport(vector<boost::filesystem::path> vImportFiles) {
345 RenameThread("coin-loadblk");
346
347 // -reindex
348 if (SysCfg().IsReindex()) {
349
350 CImportingNow imp;
351 int32_t nFile = 0;
352 while (true) {
353 CDiskBlockPos pos(nFile, 0);
354 FILE *file = OpenBlockFile(pos, true);
355 if (!file)
356 break;
357
358 LogPrint(BCLog::INFO, "Reindexing block file blk%05u.dat...\n", (uint32_t)nFile);
359 LoadExternalBlockFile(file, &pos);
360 nFile++;
361 }
362 pCdMan->pBlockCache->WriteReindexing(false);
363 SysCfg().SetReIndex(false);
364 LogPrint(BCLog::INFO, "Reindexing finished\n");
365 // To avoid ending up in a situation without genesis block, re-try initializing (no-op if reindexing worked):
366 InitBlockIndex();
367 pWalletMain->ResendWalletTransactions();
368 }
369
370 // hardcoded $DATADIR/bootstrap.dat
371 filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat";
372 if (filesystem::exists(pathBootstrap)) {
373 FILE *file = fopen(pathBootstrap.string().c_str(), "rb");
374 if (file) {
375 CImportingNow imp;
376 filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old";
377 LogPrint(BCLog::INFO, "Importing bootstrap.dat...\n");
378 LoadExternalBlockFile(file);
379 RenameOver(pathBootstrap, pathBootstrapOld);
380 } else {
381 LogPrint(BCLog::INFO, "Warning: Could not open bootstrap file %s\n", pathBootstrap.string());
382 }
383 }
384
385 // -loadblock=
386 for (const auto &path : vImportFiles) {
387 FILE *file = fopen(path.string().c_str(), "rb");
388 if (file) {
389 CImportingNow imp;
390 LogPrint(BCLog::INFO, "Importing blocks file %s...\n", path.string());
391 LoadExternalBlockFile(file);
392 } else {
393 LogPrint(BCLog::INFO, "Warning: Could not open blocks file %s\n", path.string());
394 }
395 }
396}
397
398/** Initialize native_modules
399 * register routes for native tx(inline_transaction) dispatch

Callers

nothing calls this directly

Calls 10

RenameThreadFunction · 0.85
OpenBlockFileFunction · 0.85
LoadExternalBlockFileFunction · 0.85
InitBlockIndexFunction · 0.85
fopenFunction · 0.85
RenameOverFunction · 0.85
IsReindexMethod · 0.80
WriteReindexingMethod · 0.80
SetReIndexMethod · 0.80

Tested by

no test coverage detected