Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/walletdb.cpp
Show First 20 Lines • Show All 781 Lines • ▼ Show 20 Lines | for (uint256 &hash : vTxHash) { | ||||
if (!EraseTx(hash)) { | if (!EraseTx(hash)) { | ||||
return DB_CORRUPT; | return DB_CORRUPT; | ||||
} | } | ||||
} | } | ||||
return DB_LOAD_OK; | return DB_LOAD_OK; | ||||
} | } | ||||
void ThreadFlushWalletDB() { | void MaybeCompactWalletDB() { | ||||
// Make this thread recognisable as the wallet flushing thread. | static std::atomic<bool> fOneThread; | ||||
RenameThread("bitcoin-wallet"); | if (fOneThread.exchange(true)) { | ||||
static bool fOneThread; | |||||
if (fOneThread) { | |||||
return; | return; | ||||
} | } | ||||
fOneThread = true; | |||||
if (!GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET)) { | if (!GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET)) { | ||||
return; | return; | ||||
} | } | ||||
unsigned int nLastSeen = CWalletDB::GetUpdateCounter(); | static unsigned int nLastSeen = CWalletDB::GetUpdateCounter(); | ||||
unsigned int nLastFlushed = CWalletDB::GetUpdateCounter(); | static unsigned int nLastFlushed = CWalletDB::GetUpdateCounter(); | ||||
int64_t nLastWalletUpdate = GetTime(); | static int64_t nLastWalletUpdate = GetTime(); | ||||
while (true) { | |||||
MilliSleep(500); | |||||
if (nLastSeen != CWalletDB::GetUpdateCounter()) { | if (nLastSeen != CWalletDB::GetUpdateCounter()) { | ||||
nLastSeen = CWalletDB::GetUpdateCounter(); | nLastSeen = CWalletDB::GetUpdateCounter(); | ||||
nLastWalletUpdate = GetTime(); | nLastWalletUpdate = GetTime(); | ||||
} | } | ||||
if (nLastFlushed != CWalletDB::GetUpdateCounter() && | if (nLastFlushed != CWalletDB::GetUpdateCounter() && | ||||
GetTime() - nLastWalletUpdate >= 2) { | GetTime() - nLastWalletUpdate >= 2) { | ||||
const std::string &strFile = pwalletMain->strWalletFile; | const std::string &strFile = pwalletMain->strWalletFile; | ||||
if (CDB::PeriodicFlush(strFile)) { | if (CDB::PeriodicFlush(strFile)) { | ||||
nLastFlushed = CWalletDB::GetUpdateCounter(); | nLastFlushed = CWalletDB::GetUpdateCounter(); | ||||
} | } | ||||
} | } | ||||
} | fOneThread = false; | ||||
} | } | ||||
// | // | ||||
// Try to (very carefully!) recover wallet file if there is a problem. | // Try to (very carefully!) recover wallet file if there is a problem. | ||||
// | // | ||||
bool CWalletDB::Recover(const std::string &filename, void *callbackDataIn, | bool CWalletDB::Recover(const std::string &filename, void *callbackDataIn, | ||||
bool (*recoverKVcallback)(void *callbackData, | bool (*recoverKVcallback)(void *callbackData, | ||||
CDataStream ssKey, | CDataStream ssKey, | ||||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |