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
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);
return Write(make_pair(string("addr"), addr.GetKey()), addr);
}
+bool CAddrDB::WriteAddrman(const CAddrMan& addrman)
+{
+ return Write(string("addrman"), addrman);
+}
+
bool CAddrDB::EraseAddress(const CAddress& addr)
{
return Erase(make_pair(string("addr"), addr.GetKey()));
}
-bool CAddrDB::LoadAddresses()
+bool CAddrDB::LoadAddresses(bool &fUpdate)
{
- CRITICAL_BLOCK(cs_mapAddresses)
+ bool fAddrMan = false;
+ if (Read(string("addrman"), addrman))
{
- // Get cursor
- Dbc* pcursor = GetCursor();
- if (!pcursor)
+ printf("Loaded %i addresses\n", addrman.size());
+ fAddrMan = true;
+ }
+
+ vector<CAddress> vAddr;
+
+ // Get cursor
+ Dbc* pcursor = GetCursor();
+ if (!pcursor)
+ return false;
+
+ loop
+ {
+ // Read next record
+ CDataStream ssKey;
+ CDataStream ssValue;
+ int ret = ReadAtCursor(pcursor, ssKey, ssValue);
+ if (ret == DB_NOTFOUND)
+ break;
+ else if (ret != 0)
return false;
- loop
+ // Unserialize
+ string strType;
+ ssKey >> strType;
+ if (strType == "addr")
{
- // Read next record
- CDataStream ssKey;
- CDataStream ssValue;
- int ret = ReadAtCursor(pcursor, ssKey, ssValue);
- if (ret == DB_NOTFOUND)
- break;
- else if (ret != 0)
- return false;
-
- // Unserialize
- string strType;
- ssKey >> strType;
- if (strType == "addr")
+ if (fAddrMan)
+ fUpdate = true;
+ else
{
CAddress addr;
ssValue >> addr;
- mapAddresses.insert(make_pair(addr.GetKey(), addr));
+ vAddr.push_back(addr);
}
+
}
- pcursor->close();
+ }
+ pcursor->close();
- printf("Loaded %d addresses\n", mapAddresses.size());
+ if (!fAddrMan)
+ {
+ addrman.Add(vAddr, CNetAddr("0.0.0.0"));
+ printf("Loaded %i addresses\n", addrman.size());
}
return true;
bool LoadAddresses()
{
- return CAddrDB("cr+").LoadAddresses();
+ bool fUpdate = false;
+ bool fRet = CAddrDB("cr+").LoadAddresses(fUpdate);
+ if (fUpdate)
+ CDB::Rewrite("addr.dat", "\004addr");
+ return fRet;
}
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
{
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
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
{
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")
{
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;
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")
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")
- {
- CAddress addr;
- CDataStream ssValue2 = ssValue;
- // 0.6.0rc1 saved this as a CService, which causes failure when parsing as a CAddress
- try
- {
- ssValue >> addr;
- addrProxy = addr;
- }
- catch (std::ios_base::failure &e)
- {
- ssValue2 >> addrProxy;
- }
- }
- if (fHaveUPnP && strKey == "fUseUPnP") ssValue >> fUseUPnP;
- }
else if (strType == "minversion")
{
int nMinVersion = 0;
CScript script;
ssValue >> script;
if (!pwallet->LoadCScript(script))
+ {
+ printf("Error reading wallet database: LoadCScript failed\n");
return DB_CORRUPT;
+ }
}
}
pcursor->close();
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: