MCPcopy Create free account
hub / github.com/LUX-Core/lux / ThreadFlushWalletDB

Function ThreadFlushWalletDB

src/walletdb.cpp:976–1029  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

974}
975
976void ThreadFlushWalletDB(const string& strFile)
977{
978 // Make this thread recognisable as the wallet flushing thread
979 RenameThread("lux-wallet");
980
981 static bool fOneThread;
982 if (fOneThread)
983 return;
984 fOneThread = true;
985 if (!GetBoolArg("-flushwallet", true))
986 return;
987
988 unsigned int nLastSeen = CWalletDB::GetUpdateCounter();
989 unsigned int nLastFlushed = CWalletDB::GetUpdateCounter();
990 int64_t nLastWalletUpdate = GetTime();
991 while (true) {
992 MilliSleep(500);
993
994 if (nLastSeen != CWalletDB::GetUpdateCounter()) {
995 nLastSeen = CWalletDB::GetUpdateCounter();
996 nLastWalletUpdate = GetTime();
997 }
998
999 if (nLastFlushed != CWalletDB::GetUpdateCounter() && GetTime() - nLastWalletUpdate >= 2) {
1000 TRY_LOCK(bitdb.cs_db, lockDb);
1001 if (lockDb) {
1002 // Don't do this if any databases are in use
1003 int nRefCount = 0;
1004 map<string, int>::iterator mi = bitdb.mapFileUseCount.begin();
1005 while (mi != bitdb.mapFileUseCount.end()) {
1006 nRefCount += (*mi).second;
1007 mi++;
1008 }
1009
1010 if (nRefCount == 0) {
1011 boost::this_thread::interruption_point();
1012 map<string, int>::iterator mi = bitdb.mapFileUseCount.find(strFile);
1013 if (mi != bitdb.mapFileUseCount.end()) {
1014 LogPrint("db", "Flushing wallet.dat\n");
1015 nLastFlushed = CWalletDB::GetUpdateCounter();
1016 int64_t nStart = GetTimeMillis();
1017
1018 // Flush wallet.dat so it's self contained
1019 bitdb.CloseDb(strFile);
1020 bitdb.CheckpointLSN(strFile);
1021
1022 //bitdb.mapFileUseCount.erase(mi++); I'll reference this: https://github.com/bitcoin/bitcoin/issues/7475
1023 LogPrint("db", "Flushed wallet.dat %dms\n", GetTimeMillis() - nStart);
1024 }
1025 }
1026 }
1027 }
1028 }
1029}
1030
1031bool BackupWallet(const CWallet& wallet, const string& strDest)
1032{

Callers 1

removeprunedfundsFunction · 0.85

Calls 11

RenameThreadFunction · 0.85
GetBoolArgFunction · 0.85
GetTimeFunction · 0.85
MilliSleepFunction · 0.85
LogPrintFunction · 0.85
GetTimeMillisFunction · 0.85
CloseDbMethod · 0.80
CheckpointLSNMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected