diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/db.cpp | 10 | ||||
-rw-r--r-- | src/wallet/db.h | 4 | ||||
-rw-r--r-- | src/wallet/wallet.cpp | 2 | ||||
-rw-r--r-- | src/wallet/walletdb.cpp | 28 | ||||
-rw-r--r-- | src/wallet/walletdb.h | 11 |
5 files changed, 29 insertions, 26 deletions
diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index 25f6bdd9d9..7e1b94ffa4 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -434,6 +434,16 @@ void CDB::Flush() env->dbenv->txn_checkpoint(nMinutes ? GetArg("-dblogsize", DEFAULT_WALLET_DBLOGSIZE) * 1024 : 0, nMinutes, 0); } +void CWalletDBWrapper::IncrementUpdateCounter() +{ + ++nUpdateCounter; +} + +unsigned int CWalletDBWrapper::GetUpdateCounter() +{ + return nUpdateCounter.load(); +} + void CDB::Close() { if (!pdb) diff --git a/src/wallet/db.h b/src/wallet/db.h index 3c6870d169..1a583c3ce9 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -119,10 +119,14 @@ public: */ void Flush(bool shutdown); + void IncrementUpdateCounter(); + unsigned int GetUpdateCounter(); + private: /** BerkeleyDB specific */ CDBEnv *env; std::string strFile; + std::atomic<unsigned int> nUpdateCounter; /** Return whether this database handle is a dummy for testing. * Only to be used at a low level, application should ideally not care diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 547daf5c62..9d49b72308 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3884,7 +3884,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile) walletInstance->ScanForWalletTransactions(pindexRescan, true); LogPrintf(" rescan %15dms\n", GetTimeMillis() - nStart); walletInstance->SetBestChain(chainActive.GetLocator()); - CWalletDB::IncrementUpdateCounter(); + walletInstance->dbw->IncrementUpdateCounter(); // Restore wallet transaction metadata after -zapwallettxes=1 if (GetBoolArg("-zapwallettxes", false) && GetArg("-zapwallettxes", "1") != "2") diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 75dbb2edff..149d0e0c20 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -22,8 +22,6 @@ #include <boost/foreach.hpp> #include <boost/thread.hpp> -static std::atomic<unsigned int> nWalletDBUpdateCounter; - // // CWalletDB // @@ -762,20 +760,22 @@ void MaybeCompactWalletDB() return; } - static unsigned int nLastSeen = CWalletDB::GetUpdateCounter(); - static unsigned int nLastFlushed = CWalletDB::GetUpdateCounter(); + CWalletDBWrapper& dbh = pwalletMain->GetDBHandle(); + + static unsigned int nLastSeen = dbh.GetUpdateCounter(); + static unsigned int nLastFlushed = dbh.GetUpdateCounter(); static int64_t nLastWalletUpdate = GetTime(); - if (nLastSeen != CWalletDB::GetUpdateCounter()) + if (nLastSeen != dbh.GetUpdateCounter()) { - nLastSeen = CWalletDB::GetUpdateCounter(); + nLastSeen = dbh.GetUpdateCounter(); nLastWalletUpdate = GetTime(); } - if (nLastFlushed != CWalletDB::GetUpdateCounter() && GetTime() - nLastWalletUpdate >= 2) + if (nLastFlushed != dbh.GetUpdateCounter() && GetTime() - nLastWalletUpdate >= 2) { - if (CDB::PeriodicFlush(pwalletMain->GetDBHandle())) { - nLastFlushed = CWalletDB::GetUpdateCounter(); + if (CDB::PeriodicFlush(dbh)) { + nLastFlushed = dbh.GetUpdateCounter(); } } fOneThread = false; @@ -845,16 +845,6 @@ bool CWalletDB::WriteHDChain(const CHDChain& chain) return WriteIC(std::string("hdchain"), chain); } -void CWalletDB::IncrementUpdateCounter() -{ - nWalletDBUpdateCounter++; -} - -unsigned int CWalletDB::GetUpdateCounter() -{ - return nWalletDBUpdateCounter; -} - bool CWalletDB::TxnBegin() { return batch.TxnBegin(); diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h index 5f9aec9afd..64cebd4330 100644 --- a/src/wallet/walletdb.h +++ b/src/wallet/walletdb.h @@ -147,7 +147,7 @@ private: if (!batch.Write(key, value, fOverwrite)) { return false; } - IncrementUpdateCounter(); + m_dbw.IncrementUpdateCounter(); return true; } @@ -157,13 +157,14 @@ private: if (!batch.Erase(key)) { return false; } - IncrementUpdateCounter(); + m_dbw.IncrementUpdateCounter(); return true; } public: CWalletDB(CWalletDBWrapper& dbw, const char* pszMode = "r+", bool _fFlushOnClose = true) : - batch(dbw, pszMode, _fFlushOnClose) + batch(dbw, pszMode, _fFlushOnClose), + m_dbw(dbw) { } @@ -232,9 +233,6 @@ public: //! write the hdchain model (external chain child index counter) bool WriteHDChain(const CHDChain& chain); - static void IncrementUpdateCounter(); - static unsigned int GetUpdateCounter(); - //! Begin a new transaction bool TxnBegin(); //! Commit current transaction @@ -247,6 +245,7 @@ public: bool WriteVersion(int nVersion); private: CDB batch; + CWalletDBWrapper& m_dbw; CWalletDB(const CWalletDB&); void operator=(const CWalletDB&); |