aboutsummaryrefslogtreecommitdiff
path: root/src/db.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/db.cpp')
-rw-r--r--src/db.cpp78
1 files changed, 41 insertions, 37 deletions
diff --git a/src/db.cpp b/src/db.cpp
index 645f725153..3bdfd64556 100644
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -84,8 +84,11 @@ CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL)
string strErrorFile = strDataDir + "/db.log";
printf("dbenv.open strLogDir=%s strErrorFile=%s\n", strLogDir.c_str(), strErrorFile.c_str());
+ int nDbCache = GetArg("-dbcache", 25);
dbenv.set_lg_dir(strLogDir.c_str());
- dbenv.set_lg_max(10000000);
+ dbenv.set_cachesize(nDbCache / 1024, (nDbCache % 1024)*1048576, 1);
+ dbenv.set_lg_bsize(10485760);
+ dbenv.set_lg_max(104857600);
dbenv.set_lk_max_locks(10000);
dbenv.set_lk_max_objects(10000);
dbenv.set_errfile(fopen(strErrorFile.c_str(), "a")); /// debug
@@ -156,7 +159,7 @@ void CDB::Close()
nMinutes = 1;
if (strFile == "addr.dat")
nMinutes = 2;
- if (strFile == "blkindex.dat" && IsInitialBlockDownload() && nBestHeight % 500 != 0)
+ if (strFile == "blkindex.dat" && IsInitialBlockDownload() && nBestHeight % 5000 != 0)
nMinutes = 1;
dbenv.txn_checkpoint(0, nMinutes, 0);
@@ -793,20 +796,16 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
vector<uint256> vWalletUpgrade;
bool fIsEncrypted = false;
- // Modify defaults
-#ifndef WIN32
- // Tray icon sometimes disappears on 9.10 karmic koala 64-bit, leaving no way to access the program
- fMinimizeToTray = false;
- fMinimizeOnClose = false;
-#endif
-
//// todo: shouldn't we catch exceptions and try to recover and continue?
CRITICAL_BLOCK(pwallet->cs_wallet)
{
// Get cursor
Dbc* pcursor = GetCursor();
if (!pcursor)
+ {
+ printf("Error getting wallet database cursor\n");
return DB_CORRUPT;
+ }
loop
{
@@ -817,7 +816,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
if (ret == DB_NOTFOUND)
break;
else if (ret != 0)
+ {
+ printf("Error reading next record from wallet database\n");
return DB_CORRUPT;
+ }
// Unserialize
// Taking advantage of the fact that pair serialization
@@ -888,8 +890,16 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
ssValue >> pkey;
key.SetPubKey(vchPubKey);
key.SetPrivKey(pkey);
- if (key.GetPubKey() != vchPubKey || !key.IsValid())
+ if (key.GetPubKey() != vchPubKey)
+ {
+ printf("Error reading wallet database: CPrivKey pubkey inconsistency\n");
return DB_CORRUPT;
+ }
+ if (!key.IsValid())
+ {
+ printf("Error reading wallet database: invalid CPrivKey\n");
+ return DB_CORRUPT;
+ }
}
else
{
@@ -897,11 +907,22 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
ssValue >> wkey;
key.SetPubKey(vchPubKey);
key.SetPrivKey(wkey.vchPrivKey);
- if (key.GetPubKey() != vchPubKey || !key.IsValid())
+ if (key.GetPubKey() != vchPubKey)
+ {
+ printf("Error reading wallet database: CWalletKey pubkey inconsistency\n");
+ return DB_CORRUPT;
+ }
+ if (!key.IsValid())
+ {
+ printf("Error reading wallet database: invalid CWalletKey\n");
return DB_CORRUPT;
+ }
}
if (!pwallet->LoadKey(key))
+ {
+ printf("Error reading wallet database: LoadKey failed\n");
return DB_CORRUPT;
+ }
}
else if (strType == "mkey")
{
@@ -910,7 +931,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
CMasterKey kMasterKey;
ssValue >> kMasterKey;
if(pwallet->mapMasterKeys.count(nID) != 0)
+ {
+ printf("Error reading wallet database: duplicate CMasterKey id %u\n", nID);
return DB_CORRUPT;
+ }
pwallet->mapMasterKeys[nID] = kMasterKey;
if (pwallet->nMasterKeyMaxID < nID)
pwallet->nMasterKeyMaxID = nID;
@@ -922,7 +946,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
vector<unsigned char> vchPrivKey;
ssValue >> vchPrivKey;
if (!pwallet->LoadCryptedKey(vchPubKey, vchPrivKey))
+ {
+ printf("Error reading wallet database: LoadCryptedKey failed\n");
return DB_CORRUPT;
+ }
fIsEncrypted = true;
}
else if (strType == "defaultkey")
@@ -941,24 +968,6 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
if (nFileVersion == 10300)
nFileVersion = 300;
}
- else if (strType == "setting")
- {
- string strKey;
- ssKey >> strKey;
-
- // Options
-#ifndef QT_GUI
- if (strKey == "fGenerateBitcoins") ssValue >> fGenerateBitcoins;
-#endif
- if (strKey == "nTransactionFee") ssValue >> nTransactionFee;
- if (strKey == "fLimitProcessors") ssValue >> fLimitProcessors;
- if (strKey == "nLimitProcessors") ssValue >> nLimitProcessors;
- if (strKey == "fMinimizeToTray") ssValue >> fMinimizeToTray;
- if (strKey == "fMinimizeOnClose") ssValue >> fMinimizeOnClose;
- if (strKey == "fUseProxy") ssValue >> fUseProxy;
- if (strKey == "addrProxy") ssValue >> addrProxy;
- if (fHaveUPnP && strKey == "fUseUPnP") ssValue >> fUseUPnP;
- }
else if (strType == "minversion")
{
int nMinVersion = 0;
@@ -974,7 +983,10 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
CScript script;
ssValue >> script;
if (!pwallet->LoadCScript(script))
+ {
+ printf("Error reading wallet database: LoadCScript failed\n");
return DB_CORRUPT;
+ }
}
}
pcursor->close();
@@ -984,14 +996,6 @@ int CWalletDB::LoadWallet(CWallet* pwallet)
WriteTx(hash, pwallet->mapWallet[hash]);
printf("nFileVersion = %d\n", nFileVersion);
- printf("fGenerateBitcoins = %d\n", fGenerateBitcoins);
- printf("nTransactionFee = %"PRI64d"\n", nTransactionFee);
- printf("fMinimizeToTray = %d\n", fMinimizeToTray);
- printf("fMinimizeOnClose = %d\n", fMinimizeOnClose);
- printf("fUseProxy = %d\n", fUseProxy);
- printf("addrProxy = %s\n", addrProxy.ToString().c_str());
- if (fHaveUPnP)
- printf("fUseUPnP = %d\n", fUseUPnP);
// Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc: