diff options
Diffstat (limited to 'src/init.cpp')
-rw-r--r-- | src/init.cpp | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/src/init.cpp b/src/init.cpp index 48495c446a..02997cd357 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -28,6 +28,15 @@ using namespace boost; CWallet* pwalletMain; CClientUIInterface uiInterface; +#ifdef WIN32 +// Win32 LevelDB doesn't use filedescriptors, and the ones used for +// accessing block files, don't count towards to fd_set size limit +// anyway. +#define MIN_CORE_FILEDESCRIPTORS 0 +#else +#define MIN_CORE_FILEDESCRIPTORS 150 +#endif + // Used to pass flags to the Bind() function enum BindFlags { BF_NONE = 0, @@ -281,8 +290,7 @@ std::string HelpMessage() " -? " + _("This help message") + "\n" + " -conf=<file> " + _("Specify configuration file (default: bitcoin.conf)") + "\n" + " -pid=<file> " + _("Specify pid file (default: bitcoind.pid)") + "\n" + - " -gen " + _("Generate coins") + "\n" + - " -gen=0 " + _("Don't generate coins") + "\n" + + " -gen " + _("Generate coins (default: 0)") + "\n" + " -datadir=<dir> " + _("Specify data directory") + "\n" + " -dbcache=<n> " + _("Set database cache size in megabytes (default: 25)") + "\n" + " -timeout=<n> " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n" + @@ -349,7 +357,7 @@ std::string HelpMessage() " -txindex " + _("Maintain a full transaction index (default: 0)") + "\n" + " -loadblock=<file> " + _("Imports blocks from external blk000??.dat file") + "\n" + " -reindex " + _("Rebuild block chain index from current blk000??.dat files") + "\n" + - " -par=<n> " + _("Set the number of script verification threads (1-16, 0=auto, default: 0)") + "\n" + + " -par=<n> " + _("Set the number of script verification threads (up to 16, 0 = auto, <0 = leave that many cores free, default: 0)") + "\n" + "\n" + _("Block creation options:") + "\n" + " -blockminsize=<n> " + _("Set minimum block size in bytes (default: 0)") + "\n" + @@ -453,6 +461,14 @@ bool AppInit2(boost::thread_group& threadGroup) typedef BOOL (WINAPI *PSETPROCDEPPOL)(DWORD); PSETPROCDEPPOL setProcDEPPol = (PSETPROCDEPPOL)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "SetProcessDEPPolicy"); if (setProcDEPPol != NULL) setProcDEPPol(PROCESS_DEP_ENABLE); + + // Initialize Windows Sockets + WSADATA wsadata; + int ret = WSAStartup(MAKEWORD(2,2), &wsadata); + if (ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2) + { + return InitError(strprintf("Error: Winsock library failed to start (WSAStartup returned error %d)", ret)); + } #endif #ifndef WIN32 umask(077); @@ -510,6 +526,16 @@ bool AppInit2(boost::thread_group& threadGroup) SoftSetBoolArg("-rescan", true); } + // Make sure enough file descriptors are available + int nBind = std::max((int)mapArgs.count("-bind"), 1); + nMaxConnections = GetArg("-maxconnections", 125); + nMaxConnections = std::max(std::min(nMaxConnections, FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS), 0); + int nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS); + if (nFD < MIN_CORE_FILEDESCRIPTORS) + return InitError(_("Not enough file descriptors available.")); + if (nFD - MIN_CORE_FILEDESCRIPTORS < nMaxConnections) + nMaxConnections = nFD - MIN_CORE_FILEDESCRIPTORS; + // ********************************************************* Step 3: parameter-to-internal-flags fDebug = GetBoolArg("-debug"); @@ -517,8 +543,8 @@ bool AppInit2(boost::thread_group& threadGroup) // -par=0 means autodetect, but nScriptCheckThreads==0 means no concurrency nScriptCheckThreads = GetArg("-par", 0); - if (nScriptCheckThreads == 0) - nScriptCheckThreads = boost::thread::hardware_concurrency(); + if (nScriptCheckThreads <= 0) + nScriptCheckThreads += boost::thread::hardware_concurrency(); if (nScriptCheckThreads <= 1) nScriptCheckThreads = 0; else if (nScriptCheckThreads > MAX_SCRIPTCHECK_THREADS) @@ -585,7 +611,8 @@ bool AppInit2(boost::thread_group& threadGroup) if (!fLogTimestamps) printf("Startup time: %s\n", DateTimeStrFormat("%Y-%m-%d %H:%M:%S", GetTime()).c_str()); printf("Default data directory %s\n", GetDefaultDataDir().string().c_str()); - printf("Used data directory %s\n", strDataDir.c_str()); + printf("Using data directory %s\n", strDataDir.c_str()); + printf("Using at most %i connections (%i file descriptors available)\n", nMaxConnections, nFD); std::ostringstream strErrors; if (fDaemon) @@ -944,11 +971,11 @@ bool AppInit2(boost::thread_group& threadGroup) RandAddSeedPerfmon(); CPubKey newDefaultKey; - if (!pwalletMain->GetKeyFromPool(newDefaultKey, false)) - strErrors << _("Cannot initialize keypool") << "\n"; - pwalletMain->SetDefaultKey(newDefaultKey); - if (!pwalletMain->SetAddressBookName(pwalletMain->vchDefaultKey.GetID(), "")) - strErrors << _("Cannot write default address") << "\n"; + if (pwalletMain->GetKeyFromPool(newDefaultKey, false)) { + pwalletMain->SetDefaultKey(newDefaultKey); + if (!pwalletMain->SetAddressBookName(pwalletMain->vchDefaultKey.GetID(), "")) + strErrors << _("Cannot write default address") << "\n"; + } } printf("%s", strErrors.str().c_str()); @@ -965,6 +992,8 @@ bool AppInit2(boost::thread_group& threadGroup) CBlockLocator locator; if (walletdb.ReadBestBlock(locator)) pindexRescan = locator.GetBlockIndex(); + else + pindexRescan = pindexGenesisBlock; } if (pindexBest && pindexBest != pindexRescan) { @@ -973,6 +1002,8 @@ bool AppInit2(boost::thread_group& threadGroup) nStart = GetTimeMillis(); pwalletMain->ScanForWalletTransactions(pindexRescan, true); printf(" rescan %15"PRI64d"ms\n", GetTimeMillis() - nStart); + pwalletMain->SetBestChain(CBlockLocator(pindexBest)); + nWalletDBUpdated++; } // ********************************************************* Step 9: import blocks |