X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fdb.cpp;h=56c59cbea7d3bcdf4c7a8b217b74e1ae647f85cf;hb=958fe01c327a5a758b432d768685e77304b737bc;hp=0ee518504bbcefc97694e45a3a84d1e1903a08f8;hpb=4538e45c46d3829a21aed7685e6fbac7e8aafad3;p=novacoin.git diff --git a/src/db.cpp b/src/db.cpp index 0ee5185..56c59cb 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); @@ -716,44 +719,65 @@ bool CAddrDB::WriteAddress(const CAddress& addr) 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 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; @@ -761,7 +785,11 @@ bool CAddrDB::LoadAddresses() bool LoadAddresses() { - return CAddrDB("cr+").LoadAddresses(); + bool fUpdate = false; + bool fRet = CAddrDB("cr+").LoadAddresses(fUpdate); + if (fUpdate) + CDB::Rewrite("addr.dat", "\004addr"); + return fRet; } @@ -866,6 +894,14 @@ int CWalletDB::LoadWallet(CWallet* pwallet) //// todo: shouldn't we catch exceptions and try to recover and continue? CRITICAL_BLOCK(pwallet->cs_wallet) { + int nMinVersion = 0; + if (Read((string)"minversion", nMinVersion)) + { + if (nMinVersion > CLIENT_VERSION) + return DB_TOO_NEW; + pwallet->LoadMinVersion(nMinVersion); + } + // Get cursor Dbc* pcursor = GetCursor(); if (!pcursor) @@ -1035,14 +1071,6 @@ int CWalletDB::LoadWallet(CWallet* pwallet) if (nFileVersion == 10300) nFileVersion = 300; } - else if (strType == "minversion") - { - int nMinVersion = 0; - ssValue >> nMinVersion; - if (nMinVersion > CLIENT_VERSION) - return DB_TOO_NEW; - pwallet->LoadMinVersion(nMinVersion); - } else if (strType == "cscript") { uint160 hash;