diff options
Diffstat (limited to 'src/init.cpp')
| -rw-r--r-- | src/init.cpp | 75 |
1 files changed, 65 insertions, 10 deletions
diff --git a/src/init.cpp b/src/init.cpp index 557c23fc9..9b9415a8e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -84,6 +84,10 @@ void Shutdown(void* parg) fShutdown = true; nTransactionsUpdated++; bitdb.Flush(false); + { + LOCK(cs_main); + ThreadScriptCheckQuit(); + } StopNode(); { LOCK(cs_main); @@ -299,10 +303,12 @@ std::string HelpMessage() " -keypool=<n> " + _("Set key pool size to <n> (default: 100)") + "\n" + " -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n" + " -salvagewallet " + _("Attempt to recover private keys from a corrupt wallet.dat") + "\n" + - " -checkblocks=<n> " + _("How many blocks to check at startup (default: 2500, 0 = all)") + "\n" + - " -checklevel=<n> " + _("How thorough the block verification is (0-6, default: 1)") + "\n" + + " -checkblocks=<n> " + _("How many blocks to check at startup (default: 288, 0 = all)") + "\n" + + " -checklevel=<n> " + _("How thorough the block verification is (0-4, default: 3)") + "\n" + + " -txindex " + _("Maintain a full transaction index (default: 0)") + "\n" + " -loadblock=<file> " + _("Imports blocks from external blk000??.dat file") + "\n" + " -reindex " + _("Rebuild blockchain index from current blk000??.dat files") + "\n" + + " -par=N " + _("Set the number of script verification threads (1-16, 0=auto, default: 0)") + "\n" + "\n" + _("Block creation options:") + "\n" + " -blockminsize=<n> " + _("Set minimum block size in bytes (default: 0)") + "\n" + @@ -484,6 +490,15 @@ bool AppInit2() fDebug = GetBoolArg("-debug"); fBenchmark = GetBoolArg("-benchmark"); + // -par=0 means autodetect, but nScriptCheckThreads==0 means no concurrency + nScriptCheckThreads = GetArg("-par", 0); + if (nScriptCheckThreads == 0) + nScriptCheckThreads = boost::thread::hardware_concurrency(); + if (nScriptCheckThreads <= 1) + nScriptCheckThreads = 0; + else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS) + nScriptCheckThreads = MAX_SCRIPTCHECK_THREADS; + // -debug implies fDebug* if (fDebug) fDebugNet = true; @@ -579,11 +594,17 @@ bool AppInit2() if (fDaemon) fprintf(stdout, "Bitcoin server starting\n"); + if (nScriptCheckThreads) { + printf("Using %u threads for script verification\n", nScriptCheckThreads); + for (int i=0; i<nScriptCheckThreads-1; i++) + NewThread(ThreadScriptCheck, NULL); + } + int64 nStart; - // ********************************************************* Step 5: verify database integrity + // ********************************************************* Step 5: verify wallet database integrity - uiInterface.InitMessage(_("Verifying database integrity...")); + uiInterface.InitMessage(_("Verifying wallet integrity...")); if (!bitdb.Open(GetDataDir())) { @@ -729,12 +750,39 @@ bool AppInit2() return InitError(msg); } + // Upgrading to 0.8; hard-link the old blknnnn.dat files into /blocks/ + filesystem::path blocksDir = GetDataDir() / "blocks"; + if (!filesystem::exists(blocksDir)) + { + filesystem::create_directories(blocksDir); + bool linked = false; + for (unsigned int i = 1; i < 10000; i++) { + filesystem::path source = GetDataDir() / strprintf("blk%04u.dat", i); + if (!filesystem::exists(source)) break; + filesystem::path dest = blocksDir / strprintf("blk%05u.dat", i-1); + try { + filesystem::create_hard_link(source, dest); + printf("Hardlinked %s -> %s\n", source.string().c_str(), dest.string().c_str()); + linked = true; + } catch (filesystem::filesystem_error & e) { + // Note: hardlink creation failing is not a disaster, it just means + // blocks will get re-downloaded from peers. + printf("Error hardlinking blk%04u.dat : %s\n", i, e.what()); + break; + } + } + if (linked) + { + fReindex = true; + } + } + // cache size calculations size_t nTotalCache = GetArg("-dbcache", 25) << 20; if (nTotalCache < (1 << 22)) nTotalCache = (1 << 22); // total cache cannot be less than 4 MiB size_t nBlockTreeDBCache = nTotalCache / 8; - if (nBlockTreeDBCache > (1 << 21)) + if (nBlockTreeDBCache > (1 << 21) && !GetBoolArg("-txindex", false)) nBlockTreeDBCache = (1 << 21); // block tree db cache shouldn't be larger than 2 MiB nTotalCache -= nBlockTreeDBCache; size_t nCoinDBCache = nTotalCache / 2; // use half of the remaining cache for coindb cache @@ -742,7 +790,7 @@ bool AppInit2() nCoinCacheSize = nTotalCache / 300; // coins in memory require around 300 bytes uiInterface.InitMessage(_("Loading block index...")); - printf("Loading block index...\n"); + nStart = GetTimeMillis(); pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex); pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex); @@ -752,7 +800,15 @@ bool AppInit2() pblocktree->WriteReindexing(true); if (!LoadBlockIndex()) - return InitError(_("Error loading blkindex.dat")); + return InitError(_("Error loading block database")); + + uiInterface.InitMessage(_("Verifying block database integrity...")); + + if (!VerifyDB()) + return InitError(_("Corrupted block database detected. Please restart the client with -reindex.")); + + if (mapArgs.count("-txindex") && fTxIndex != GetBoolArg("-txindex", false)) + return InitError(_("You need to rebuild the databases using -reindex to change -txindex")); // as LoadBlockIndex can take several minutes, it's possible the user // requested to kill bitcoin-qt during the last operation. If so, exit. @@ -796,7 +852,7 @@ bool AppInit2() // ********************************************************* Step 8: load wallet uiInterface.InitMessage(_("Loading wallet...")); - printf("Loading wallet...\n"); + nStart = GetTimeMillis(); bool fFirstRun = true; pwalletMain = new CWallet("wallet.dat"); @@ -894,7 +950,7 @@ bool AppInit2() // ********************************************************* Step 10: load peers uiInterface.InitMessage(_("Loading addresses...")); - printf("Loading addresses...\n"); + nStart = GetTimeMillis(); { @@ -929,7 +985,6 @@ bool AppInit2() // ********************************************************* Step 12: finished uiInterface.InitMessage(_("Done loading")); - printf("Done loading\n"); if (!strErrors.str().empty()) return InitError(strErrors.str()); |