Browse Source

Merge #10767: [wallet] Clarify wallet initialization / destruction interface

5d2a3995e [trivial] fixup comment for VerifyWallets() (John Newbery)
43b0e81d0 [wallet] Add StartWallets() function to wallet/init.cpp (John Newbery)
290f3c56d [wallet] Add RegisterWalletRPC() function to wallet/init.cpp (John Newbery)
062d63102 [wallet] Add CloseWallets() function to wallet/init.cpp (John Newbery)
77fe07c15 [wallet] Add StopWallets() function to wallet/init.cpp (John Newbery)
2da5eafa4 [wallet] Add FlushWallets() function to wallet/init.cpp (John Newbery)
1b9cee66e [wallet] Rename WalletVerify() to VerifyWallets() (John Newbery)
9c76ba18c [wallet] Rename InitLoadWallet() to OpenWallets() (John Newbery)

Pull request description:

  Apologies for the mostly code move only PR. This is a pre-req for both #10740 and #10762

  All wallet component initialization/destruction functions are now in their own `wallet/init.cpp` translation unit and are no longer static functions on the CWallet class. The bitcoin_server also no longer has any knowledge that there are multiple wallets in vpwallet.

  There should be no changes in behavior from this PR.

Tree-SHA512: 7c260eb094f2fa1a88d803769ba60935810968a7309f731135e4b17623b97f18c03bbcd293c942093d1efce62c6c978f9ff484d54dc9a60bc2fcb5af2d160fcd
0.16
MarcoFalke 7 years ago
parent
commit
791a0e6dda
No known key found for this signature in database
GPG Key ID: D2EA4850E7528B25
  1. 24
      src/init.cpp
  2. 37
      src/wallet/init.cpp
  3. 24
      src/wallet/init.h
  4. 3
      src/wallet/rpcwallet.cpp
  5. 3
      src/wallet/rpcwallet.h

24
src/init.cpp

@ -45,7 +45,6 @@
#include "validationinterface.h" #include "validationinterface.h"
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
#include "wallet/init.h" #include "wallet/init.h"
#include "wallet/wallet.h"
#endif #endif
#include "warnings.h" #include "warnings.h"
#include <stdint.h> #include <stdint.h>
@ -189,9 +188,7 @@ void Shutdown()
StopRPC(); StopRPC();
StopHTTPServer(); StopHTTPServer();
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
for (CWalletRef pwallet : vpwallets) { FlushWallets();
pwallet->Flush(false);
}
#endif #endif
MapPort(false); MapPort(false);
@ -249,9 +246,7 @@ void Shutdown()
pblocktree = nullptr; pblocktree = nullptr;
} }
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
for (CWalletRef pwallet : vpwallets) { StopWallets();
pwallet->Flush(true);
}
#endif #endif
#if ENABLE_ZMQ #if ENABLE_ZMQ
@ -272,10 +267,7 @@ void Shutdown()
UnregisterAllValidationInterfaces(); UnregisterAllValidationInterfaces();
GetMainSignals().UnregisterBackgroundSignalScheduler(); GetMainSignals().UnregisterBackgroundSignalScheduler();
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
for (CWalletRef pwallet : vpwallets) { CloseWallets();
delete pwallet;
}
vpwallets.clear();
#endif #endif
globalVerifyHandle.reset(); globalVerifyHandle.reset();
ECC_Stop(); ECC_Stop();
@ -1034,7 +1026,7 @@ bool AppInitParameterInteraction()
RegisterAllCoreRPCCommands(tableRPC); RegisterAllCoreRPCCommands(tableRPC);
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
RegisterWalletRPCCommands(tableRPC); RegisterWalletRPC(tableRPC);
#endif #endif
nConnectTimeout = gArgs.GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT); nConnectTimeout = gArgs.GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT);
@ -1256,7 +1248,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
// ********************************************************* Step 5: verify wallet database integrity // ********************************************************* Step 5: verify wallet database integrity
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
if (!WalletVerify()) if (!VerifyWallets())
return false; return false;
#endif #endif
// ********************************************************* Step 6: network initialization // ********************************************************* Step 6: network initialization
@ -1576,7 +1568,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
// ********************************************************* Step 8: load wallet // ********************************************************* Step 8: load wallet
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
if (!InitLoadWallet()) if (!OpenWallets())
return false; return false;
#else #else
LogPrintf("No wallet support compiled in!\n"); LogPrintf("No wallet support compiled in!\n");
@ -1715,9 +1707,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
uiInterface.InitMessage(_("Done loading")); uiInterface.InitMessage(_("Done loading"));
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
for (CWalletRef pwallet : vpwallets) { StartWallets(scheduler);
pwallet->postInitProcess(scheduler);
}
#endif #endif
return !fRequestShutdown; return !fRequestShutdown;

37
src/wallet/init.cpp

@ -10,6 +10,7 @@
#include "utilmoneystr.h" #include "utilmoneystr.h"
#include "validation.h" #include "validation.h"
#include "wallet/wallet.h" #include "wallet/wallet.h"
#include "wallet/rpcwallet.h"
std::string GetWalletHelpString(bool showDebug) std::string GetWalletHelpString(bool showDebug)
{ {
@ -171,7 +172,14 @@ bool WalletParameterInteraction()
return true; return true;
} }
bool WalletVerify() void RegisterWalletRPC(CRPCTable &t)
{
if (gArgs.GetBoolArg("-disablewallet", false)) return;
RegisterWalletRPCCommands(t);
}
bool VerifyWallets()
{ {
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET))
return true; return true;
@ -228,7 +236,7 @@ bool WalletVerify()
return true; return true;
} }
bool InitLoadWallet() bool OpenWallets()
{ {
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
LogPrintf("Wallet disabled!\n"); LogPrintf("Wallet disabled!\n");
@ -245,3 +253,28 @@ bool InitLoadWallet()
return true; return true;
} }
void StartWallets(CScheduler& scheduler) {
for (CWalletRef pwallet : vpwallets) {
pwallet->postInitProcess(scheduler);
}
}
void FlushWallets() {
for (CWalletRef pwallet : vpwallets) {
pwallet->Flush(false);
}
}
void StopWallets() {
for (CWalletRef pwallet : vpwallets) {
pwallet->Flush(true);
}
}
void CloseWallets() {
for (CWalletRef pwallet : vpwallets) {
delete pwallet;
}
vpwallets.clear();
}

24
src/wallet/init.h

@ -8,18 +8,36 @@
#include <string> #include <string>
class CRPCTable;
class CScheduler;
//! Return the wallets help message. //! Return the wallets help message.
std::string GetWalletHelpString(bool showDebug); std::string GetWalletHelpString(bool showDebug);
//! Wallets parameter interaction //! Wallets parameter interaction
bool WalletParameterInteraction(); bool WalletParameterInteraction();
//! Register wallet RPCs.
void RegisterWalletRPC(CRPCTable &tableRPC);
//! Responsible for reading and validating the -wallet arguments and verifying the wallet database. //! Responsible for reading and validating the -wallet arguments and verifying the wallet database.
// This function will perform salvage on the wallet if requested, as long as only one wallet is // This function will perform salvage on the wallet if requested, as long as only one wallet is
// being loaded (CWallet::ParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet). // being loaded (WalletParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet).
bool WalletVerify(); bool VerifyWallets();
//! Load wallet databases. //! Load wallet databases.
bool InitLoadWallet(); bool OpenWallets();
//! Complete startup of wallets.
void StartWallets(CScheduler& scheduler);
//! Flush all wallets in preparation for shutdown.
void FlushWallets();
//! Stop all wallets. Wallets will be flushed first.
void StopWallets();
//! Close all wallets.
void CloseWallets();
#endif // BITCOIN_WALLET_INIT_H #endif // BITCOIN_WALLET_INIT_H

3
src/wallet/rpcwallet.cpp

@ -3250,9 +3250,6 @@ static const CRPCCommand commands[] =
void RegisterWalletRPCCommands(CRPCTable &t) void RegisterWalletRPCCommands(CRPCTable &t)
{ {
if (gArgs.GetBoolArg("-disablewallet", false))
return;
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
t.appendCommand(commands[vcidx].name, &commands[vcidx]); t.appendCommand(commands[vcidx].name, &commands[vcidx]);
} }

3
src/wallet/rpcwallet.h

@ -5,7 +5,10 @@
#ifndef BITCOIN_WALLET_RPCWALLET_H #ifndef BITCOIN_WALLET_RPCWALLET_H
#define BITCOIN_WALLET_RPCWALLET_H #define BITCOIN_WALLET_RPCWALLET_H
#include <string>
class CRPCTable; class CRPCTable;
class CWallet;
class JSONRPCRequest; class JSONRPCRequest;
void RegisterWalletRPCCommands(CRPCTable &t); void RegisterWalletRPCCommands(CRPCTable &t);

Loading…
Cancel
Save