X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fdb.cpp;h=e0f724c29377e0e1809eaa5b4d5c1baa206af7c8;hb=77a43545b4491b9703d803765da9059d2bdd5aaa;hp=cc069e15d3228fae1ccf8cce2a9624db6028c22f;hpb=d8f8063eda45b8dec864b28bb98839a2dd3a8170;p=novacoin.git diff --git a/src/db.cpp b/src/db.cpp index cc069e1..e0f724c 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -20,7 +20,7 @@ using namespace boost; unsigned int nWalletDBUpdated; - +extern bool fUseMemoryLog; // @@ -111,6 +111,31 @@ bool CDBEnv::Open(boost::filesystem::path pathEnv_) fDbEnvInit = true; fMockDb = false; +#ifndef USE_LEVELDB + // Check that the number of locks is sufficient (to prevent chain fork possibility, read http://bitcoin.org/may15 for more info) + u_int32_t nMaxLocks; + if (!dbenv.get_lk_max_locks(&nMaxLocks)) + { + int nBlocks, nDeepReorg; + std::string strMessage; + + nBlocks = nMaxLocks / 48768; + nDeepReorg = (nBlocks - 1) / 2; + + printf("Final lk_max_locks is %lu, sufficient for (worst case) %d block%s in a single transaction (up to a %d-deep reorganization)\n", (unsigned long)nMaxLocks, nBlocks, (nBlocks == 1) ? "" : "s", nDeepReorg); + if (nDeepReorg < 3) + { + if (nBlocks < 1) + strMessage = strprintf(_("Warning: DB_CONFIG has set_lk_max_locks %lu, which may be too low for a single block. If this limit is reached, NovaCoin may stop working."), (unsigned long)nMaxLocks); + else + strMessage = strprintf(_("Warning: DB_CONFIG has set_lk_max_locks %lu, which may be too low for a common blockchain reorganization. If this limit is reached, NovaCoin may stop working."), (unsigned long)nMaxLocks); + + strMiscWarning = strMessage; + printf("*** %s\n", strMessage.c_str()); + } + } +#endif + return true; } @@ -131,7 +156,7 @@ void CDBEnv::MakeMock() dbenv.set_lk_max_objects(10000); dbenv.set_flags(DB_AUTO_COMMIT, 1); #ifdef DB_LOG_IN_MEMORY - dbenv.log_set_config(DB_LOG_IN_MEMORY, 1); + dbenv.log_set_config(DB_LOG_IN_MEMORY, fUseMemoryLog ? 1 : 0); #endif int ret = dbenv.open(NULL, DB_CREATE | @@ -438,7 +463,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) void CDBEnv::Flush(bool fShutdown) { - int64 nStart = GetTimeMillis(); + int64_t nStart = GetTimeMillis(); // Flush log data to the actual data file // on all files that are not in use printf("Flush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started"); @@ -469,7 +494,7 @@ void CDBEnv::Flush(bool fShutdown) else mi++; } - printf("DBFlush(%s)%s ended %15"PRI64d"ms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart); + printf("DBFlush(%s)%s ended %15" PRId64 "ms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " db not started", GetTimeMillis() - nStart); if (fShutdown) { char** listp;