aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp52
1 files changed, 30 insertions, 22 deletions
diff --git a/src/init.cpp b/src/init.cpp
index c2259f1d76..472af5331b 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -290,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" +
@@ -358,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 (up to 16, 0=auto, negative=leave N CPUs free, 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" +
@@ -466,9 +465,9 @@ bool AppInit2(boost::thread_group& threadGroup)
// Initialize Windows Sockets
WSADATA wsadata;
int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
- if (ret != NO_ERROR)
+ if (ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
{
- return InitError(strprintf("Error: TCP/IP socket library failed to start (WSAStartup returned error %d)", ret));
+ return InitError(strprintf("Error: Winsock library failed to start (WSAStartup returned error %d)", ret));
}
#endif
#ifndef WIN32
@@ -612,7 +611,7 @@ 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;
@@ -633,8 +632,22 @@ bool AppInit2(boost::thread_group& threadGroup)
if (!bitdb.Open(GetDataDir()))
{
- string msg = strprintf(_("Error initializing wallet database environment %s!"), strDataDir.c_str());
- return InitError(msg);
+ // try moving the database env out of the way
+ boost::filesystem::path pathDatabase = GetDataDir() / "database";
+ boost::filesystem::path pathDatabaseBak = GetDataDir() / strprintf("database.%"PRI64d".bak", GetTime());
+ try {
+ boost::filesystem::rename(pathDatabase, pathDatabaseBak);
+ printf("Moved old %s to %s. Retrying.\n", pathDatabase.string().c_str(), pathDatabaseBak.string().c_str());
+ } catch(boost::filesystem::filesystem_error &error) {
+ // failure is ok (well, not really, but it's not worse than what we started with)
+ }
+
+ // try again
+ if (!bitdb.Open(GetDataDir())) {
+ // if it still fails, it probably means we can't even create the database env
+ string msg = strprintf(_("Error initializing wallet database environment %s!"), strDataDir.c_str());
+ return InitError(msg);
+ }
}
if (GetBoolArg("-salvagewallet"))
@@ -761,15 +774,6 @@ bool AppInit2(boost::thread_group& threadGroup)
fReindex = GetBoolArg("-reindex");
- // Todo: Check if needed, because in step 5 we do the same
- if (!bitdb.Open(GetDataDir()))
- {
- string msg = strprintf(_("Error initializing database environment %s!"
- " To recover, BACKUP THAT DIRECTORY, then remove"
- " everything from it except for wallet.dat."), strDataDir.c_str());
- 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))
@@ -967,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());
@@ -988,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)
{
@@ -996,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