Only remove database log files on shutdown after wallet encryption/rewrite
This commit is contained in:
parent
37971fcc76
commit
1c15f88653
4 changed files with 16 additions and 9 deletions
13
src/db.cpp
13
src/db.cpp
|
@ -28,7 +28,12 @@ DbEnv dbenv(0);
|
||||||
static map<string, int> mapFileUseCount;
|
static map<string, int> mapFileUseCount;
|
||||||
static map<string, Db*> mapDb;
|
static map<string, Db*> mapDb;
|
||||||
|
|
||||||
static void EnvShutdown(bool fRemoveLogFiles)
|
static bool fRemoveLogFiles = false;
|
||||||
|
void RemoveLogFilesOnShutdown(bool fIn)
|
||||||
|
{
|
||||||
|
fRemoveLogFiles = fIn;
|
||||||
|
}
|
||||||
|
static void EnvShutdown()
|
||||||
{
|
{
|
||||||
if (!fDbEnvInit)
|
if (!fDbEnvInit)
|
||||||
return;
|
return;
|
||||||
|
@ -71,7 +76,7 @@ public:
|
||||||
}
|
}
|
||||||
~CDBInit()
|
~CDBInit()
|
||||||
{
|
{
|
||||||
EnvShutdown(false);
|
EnvShutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
instance_of_cdbinit;
|
instance_of_cdbinit;
|
||||||
|
@ -289,7 +294,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DBFlush(bool fShutdown, bool fRemoveLogFiles)
|
void DBFlush(bool fShutdown)
|
||||||
{
|
{
|
||||||
// Flush log data to the actual data file
|
// Flush log data to the actual data file
|
||||||
// on all files that are not in use
|
// on all files that are not in use
|
||||||
|
@ -322,7 +327,7 @@ void DBFlush(bool fShutdown, bool fRemoveLogFiles)
|
||||||
if (mapFileUseCount.empty())
|
if (mapFileUseCount.empty())
|
||||||
{
|
{
|
||||||
dbenv.log_archive(&listp, DB_ARCH_REMOVE);
|
dbenv.log_archive(&listp, DB_ARCH_REMOVE);
|
||||||
EnvShutdown(fRemoveLogFiles);
|
EnvShutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
3
src/db.h
3
src/db.h
|
@ -29,7 +29,8 @@ extern unsigned int nWalletDBUpdated;
|
||||||
extern DbEnv dbenv;
|
extern DbEnv dbenv;
|
||||||
|
|
||||||
|
|
||||||
extern void DBFlush(bool fShutdown, bool fRemoveLogFiles);
|
extern void RemoveLogFilesOnShutdown(bool fRemoveLogFiles);
|
||||||
|
extern void DBFlush(bool fShutdown);
|
||||||
void ThreadFlushWalletDB(void* parg);
|
void ThreadFlushWalletDB(void* parg);
|
||||||
bool BackupWallet(const CWallet& wallet, const std::string& strDest);
|
bool BackupWallet(const CWallet& wallet, const std::string& strDest);
|
||||||
|
|
||||||
|
|
|
@ -55,9 +55,9 @@ void Shutdown(void* parg)
|
||||||
{
|
{
|
||||||
fShutdown = true;
|
fShutdown = true;
|
||||||
nTransactionsUpdated++;
|
nTransactionsUpdated++;
|
||||||
DBFlush(false, false);
|
DBFlush(false);
|
||||||
StopNode();
|
StopNode();
|
||||||
DBFlush(true, true);
|
DBFlush(true);
|
||||||
boost::filesystem::remove(GetPidFile());
|
boost::filesystem::remove(GetPidFile());
|
||||||
UnregisterWallet(pwalletMain);
|
UnregisterWallet(pwalletMain);
|
||||||
delete pwalletMain;
|
delete pwalletMain;
|
||||||
|
|
|
@ -193,8 +193,8 @@ bool CWallet::EncryptWallet(const string& strWalletPassphrase)
|
||||||
|
|
||||||
// Need to completely rewrite the wallet file; if we don't, bdb might keep
|
// Need to completely rewrite the wallet file; if we don't, bdb might keep
|
||||||
// bits of the unencrypted private key in slack space in the database file.
|
// bits of the unencrypted private key in slack space in the database file.
|
||||||
setKeyPool.clear();
|
if (CDB::Rewrite(strWalletFile))
|
||||||
CDB::Rewrite(strWalletFile);
|
RemoveLogFilesOnShutdown(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1154,6 +1154,7 @@ int CWallet::LoadWallet(bool& fFirstRunRet)
|
||||||
{
|
{
|
||||||
if (CDB::Rewrite(strWalletFile, "\x04pool"))
|
if (CDB::Rewrite(strWalletFile, "\x04pool"))
|
||||||
{
|
{
|
||||||
|
RemoveLogFilesOnShutdown(true);
|
||||||
setKeyPool.clear();
|
setKeyPool.clear();
|
||||||
// Note: can't top-up keypool here, because wallet is locked.
|
// Note: can't top-up keypool here, because wallet is locked.
|
||||||
// User will be prompted to unlock wallet the next operation
|
// User will be prompted to unlock wallet the next operation
|
||||||
|
|
Loading…
Reference in a new issue