[WIP] [wallet] dynamic loading/unloading of wallets #10740

Open
wants to merge 19 commits into
from
Commits
Jump to file or symbol
Failed to load files and symbols.
+507 −280
Split
View
@@ -164,6 +164,7 @@ BITCOIN_CORE_H = \
wallet/rpcwallet.h \
wallet/wallet.h \
wallet/walletdb.h \
+ wallet/walletinit.h \
warnings.h \
zmq/zmqabstractnotifier.h \
zmq/zmqconfig.h\
@@ -242,6 +243,7 @@ libbitcoin_wallet_a_SOURCES = \
wallet/rpcwallet.cpp \
wallet/wallet.cpp \
wallet/walletdb.cpp \
+ wallet/walletinit.cpp \
$(BITCOIN_CORE_H)
# crypto primitives library
View
@@ -43,7 +43,7 @@
#include "utilmoneystr.h"
#include "validationinterface.h"
#ifdef ENABLE_WALLET
-#include "wallet/wallet.h"
+#include "wallet/walletinit.h"
#endif
#include "warnings.h"
#include <stdint.h>
@@ -187,11 +187,6 @@ void Shutdown()
StopREST();
StopRPC();
StopHTTPServer();
-#ifdef ENABLE_WALLET
- for (CWalletRef pwallet : vpwallets) {
- pwallet->Flush(false);
- }
-#endif
MapPort(false);
UnregisterValidationInterface(peerLogic.get());
peerLogic.reset();
@@ -230,9 +225,7 @@ void Shutdown()
pblocktree = NULL;
}
#ifdef ENABLE_WALLET
- for (CWalletRef pwallet : vpwallets) {
- pwallet->Flush(true);
- }
+ ShutdownWallets();
#endif
#if ENABLE_ZMQ
@@ -252,10 +245,7 @@ void Shutdown()
#endif
UnregisterAllValidationInterfaces();
#ifdef ENABLE_WALLET
- for (CWalletRef pwallet : vpwallets) {
- delete pwallet;
- }
- vpwallets.clear();
+ DeleteWallets();
@jonasschnelli

jonasschnelli Jul 5, 2017

Member

It'd probably call this deallocWallets()

@jnewbery

jnewbery Jul 7, 2017

Member

Yes, DeleteWallets() is a bad name. DeallocWallets() is good, or perhaps DetachWallets()

#endif
globalVerifyHandle.reset();
ECC_Stop();
@@ -404,7 +394,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-maxuploadtarget=<n>", strprintf(_("Tries to keep outbound traffic under the given target (in MiB per 24h), 0 = no limit (default: %d)"), DEFAULT_MAX_UPLOAD_TARGET));
#ifdef ENABLE_WALLET
- strUsage += CWallet::GetWalletHelpString(showDebug);
+ strUsage += GetWalletHelpString(showDebug);
#endif
#if ENABLE_ZMQ
@@ -1052,8 +1042,7 @@ bool AppInitParameterInteraction()
nBytesPerSigOp = GetArg("-bytespersigop", nBytesPerSigOp);
#ifdef ENABLE_WALLET
- if (!CWallet::ParameterInteraction())
- return false;
+ if (!WalletParameterInteraction()) return false;
#endif
fIsBareMultisigStd = GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG);
@@ -1219,8 +1208,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
// ********************************************************* Step 5: verify wallet database integrity
#ifdef ENABLE_WALLET
- if (!CWallet::Verify())
- return false;
+ if (!VerifyWallets()) return false;
#endif
// ********************************************************* Step 6: network initialization
// Note that we absolutely cannot open any actual connections
@@ -1507,8 +1495,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
// ********************************************************* Step 8: load wallet
#ifdef ENABLE_WALLET
- if (!CWallet::InitLoadWallet())
- return false;
+ if (!InitLoadWallets()) return false;
#else
LogPrintf("No wallet support compiled in!\n");
#endif
@@ -1638,9 +1625,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
uiInterface.InitMessage(_("Done loading"));
#ifdef ENABLE_WALLET
- for (CWalletRef pwallet : vpwallets) {
- pwallet->postInitProcess(scheduler);
- }
+ WalletCompleteStartup(scheduler);
#endif
return !fRequestShutdown;
View
@@ -227,40 +227,12 @@ bool CDB::Recover(const std::string& filename, void *callbackDataIn, bool (*reco
bool CDB::VerifyEnvironment(const std::string& walletFile, const fs::path& dataDir, std::string& errorStr)
{
- LogPrintf("Using BerkeleyDB version %s\n", DbEnv::version(0, 0, 0));
@jonasschnelli

jonasschnelli Jul 5, 2017

Member

What's the reasons for keeping this function (that now always returns true)?

@jnewbery

jnewbery Jul 7, 2017

Member

You're right. This (and CWalletDB::VerifyEnvironment()) are now entirely vestigial and are not called. Both can be removed.

- LogPrintf("Using wallet %s\n", walletFile);
-
- // Wallet file must be a plain filename without a directory
- if (walletFile != fs::basename(walletFile) + fs::extension(walletFile))
- {
- errorStr = strprintf(_("Wallet %s resides outside data directory %s"), walletFile, dataDir.string());
- return false;
- }
-
- if (!bitdb.Open(dataDir))
- {
- // try moving the database env out of the way
- fs::path pathDatabase = dataDir / "database";
- fs::path pathDatabaseBak = dataDir / strprintf("database.%d.bak", GetTime());
- try {
- fs::rename(pathDatabase, pathDatabaseBak);
- LogPrintf("Moved old %s to %s. Retrying.\n", pathDatabase.string(), pathDatabaseBak.string());
- } catch (const fs::filesystem_error&) {
- // failure is ok (well, not really, but it's not worse than what we started with)
- }
-
- // try again
- if (!bitdb.Open(dataDir)) {
- // if it still fails, it probably means we can't even create the database env
- errorStr = strprintf(_("Error initializing wallet database environment %s!"), GetDataDir());
- return false;
- }
- }
return true;
}
bool CDB::VerifyDatabaseFile(const std::string& walletFile, const fs::path& dataDir, std::string& warningStr, std::string& errorStr, CDBEnv::recoverFunc_type recoverFunc)
{
+ LogPrintf("Using wallet %s\n", walletFile);
if (fs::exists(dataDir / walletFile))
{
std::string backup_filename;
@@ -558,22 +530,32 @@ bool CDB::Rewrite(CWalletDBWrapper& dbw, const char* pszSkip)
return false;
}
+void CDBEnv::Shutdown()
+{
+ char** listp;
+ if (mapFileUseCount.empty()) {
+ dbenv->log_archive(&listp, DB_ARCH_REMOVE);
+ Close();
+ if (!fMockDb)
+ fs::remove_all(fs::path(strPath) / "database");
+ }
+}
-void CDBEnv::Flush(bool fShutdown)
+void CDBEnv::Flush(std::string strFile)
{
int64_t nStart = GetTimeMillis();
// Flush log data to the actual data file on all files that are not in use
- LogPrint(BCLog::DB, "CDBEnv::Flush: Flush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " database not started");
+ LogPrint(BCLog::DB, "CDBEnv::Flush: Flush%s\n", fDbEnvInit ? "" : " database not started");
if (!fDbEnvInit)
return;
{
LOCK(cs_db);
std::map<std::string, int>::iterator mi = mapFileUseCount.begin();
while (mi != mapFileUseCount.end()) {
- std::string strFile = (*mi).first;
+ std::string foundStrFile = (*mi).first;
int nRefCount = (*mi).second;
- LogPrint(BCLog::DB, "CDBEnv::Flush: Flushing %s (refcount = %d)...\n", strFile, nRefCount);
- if (nRefCount == 0) {
+ if (foundStrFile == strFile && nRefCount == 0) {
+ LogPrint(BCLog::DB, "CDBEnv::Flush: Flushing %s (refcount = %d)...\n", strFile, nRefCount);
// Move log data to the dat file
CloseDb(strFile);
LogPrint(BCLog::DB, "CDBEnv::Flush: %s checkpoint\n", strFile);
@@ -586,16 +568,7 @@ void CDBEnv::Flush(bool fShutdown)
} else
mi++;
}
- LogPrint(BCLog::DB, "CDBEnv::Flush: Flush(%s)%s took %15dms\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " database not started", GetTimeMillis() - nStart);
- if (fShutdown) {
- char** listp;
- if (mapFileUseCount.empty()) {
- dbenv->log_archive(&listp, DB_ARCH_REMOVE);
- Close();
- if (!fMockDb)
- fs::remove_all(fs::path(strPath) / "database");
- }
- }
+ LogPrint(BCLog::DB, "CDBEnv::Flush: Flush took %15dms\n", GetTimeMillis() - nStart);
}
}
@@ -684,9 +657,9 @@ bool CWalletDBWrapper::Backup(const std::string& strDest)
return false;
}
-void CWalletDBWrapper::Flush(bool shutdown)
+void CWalletDBWrapper::Flush()
{
if (!IsDummy()) {
- env->Flush(shutdown);
+ env->Flush(strFile);
}
}
View
@@ -70,7 +70,8 @@ class CDBEnv
bool Open(const fs::path& path);
void Close();
- void Flush(bool fShutdown);
+ void Flush(std::string strFile);
+ void Shutdown();
void CheckpointLSN(const std::string& strFile);
void CloseDb(const std::string& strFile);
@@ -119,7 +120,7 @@ class CWalletDBWrapper
/** Make sure all changes are flushed to disk.
*/
- void Flush(bool shutdown);
+ void Flush();
void IncrementUpdateCounter();
Oops, something went wrong.