Skip to content

Commit

Permalink
Merge bitcoin#10767: [wallet] Clarify wallet initialization / destruc…
Browse files Browse the repository at this point in the history
…tion interface

5d2a399 [trivial] fixup comment for VerifyWallets() (John Newbery)
43b0e81 [wallet] Add StartWallets() function to wallet/init.cpp (John Newbery)
290f3c5 [wallet] Add RegisterWalletRPC() function to wallet/init.cpp (John Newbery)
062d631 [wallet] Add CloseWallets() function to wallet/init.cpp (John Newbery)
77fe07c [wallet] Add StopWallets() function to wallet/init.cpp (John Newbery)
2da5eaf [wallet] Add FlushWallets() function to wallet/init.cpp (John Newbery)
1b9cee6 [wallet] Rename WalletVerify() to VerifyWallets() (John Newbery)
9c76ba1 [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 bitcoin#10740 and bitcoin#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
  • Loading branch information
MarcoFalke authored and PastaPastaPasta committed Jan 10, 2020
1 parent ca4a749 commit 25d98e2
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 25 deletions.
24 changes: 7 additions & 17 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include "validationinterface.h"
#ifdef ENABLE_WALLET
#include "wallet/init.h"
#include "wallet/wallet.h"
#endif

#include "masternode/activemasternode.h"
Expand Down Expand Up @@ -238,9 +237,7 @@ void PrepareShutdown()
privateSendClient.fPrivateSendRunning = false;
privateSendClient.ResetPool();
}
for (CWalletRef pwallet : vpwallets) {
pwallet->Flush(false);
}
FlushWallets();
#endif
MapPort(false);

Expand Down Expand Up @@ -314,9 +311,7 @@ void PrepareShutdown()
evoDb = nullptr;
}
#ifdef ENABLE_WALLET
for (CWalletRef pwallet : vpwallets) {
pwallet->Flush(true);
}
StopWallets();
#endif

#if ENABLE_ZMQ
Expand Down Expand Up @@ -369,10 +364,7 @@ void Shutdown()
// Shutdown part 2: Stop TOR thread and delete wallet instance
StopTorControl();
#ifdef ENABLE_WALLET
for (CWalletRef pwallet : vpwallets) {
delete pwallet;
}
vpwallets.clear();
CloseWallets();
#endif
globalVerifyHandle.reset();
ECC_Stop();
Expand Down Expand Up @@ -1260,7 +1252,7 @@ bool AppInitParameterInteraction()

RegisterAllCoreRPCCommands(tableRPC);
#ifdef ENABLE_WALLET
RegisterWalletRPCCommands(tableRPC);
RegisterWalletRPC(tableRPC);
#endif

nConnectTimeout = gArgs.GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT);
Expand Down Expand Up @@ -1581,7 +1573,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
if (!CWallet::InitAutoBackup())
return false;

if (!WalletVerify())
if (!VerifyWallets())
return false;

// Initialize KeePass Integration
Expand Down Expand Up @@ -1958,7 +1950,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)

// ********************************************************* Step 8: load wallet
#ifdef ENABLE_WALLET
if (!InitLoadWallet())
if (!OpenWallets())
return false;
#else
LogPrintf("No wallet support compiled in!\n");
Expand Down Expand Up @@ -2228,9 +2220,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
uiInterface.InitMessage(_("Done loading"));

#ifdef ENABLE_WALLET
for (CWalletRef pwallet : vpwallets) {
pwallet->postInitProcess(scheduler);
}
StartWallets(scheduler);
#endif

// Final check if the user requested to kill the GUI during one of the last operations. If so, exit.
Expand Down
37 changes: 35 additions & 2 deletions src/wallet/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "utilmoneystr.h"
#include "validation.h"
#include "wallet/wallet.h"
#include "wallet/rpcwallet.h"

std::string GetWalletHelpString(bool showDebug)
{
Expand Down Expand Up @@ -189,7 +190,14 @@ bool WalletParameterInteraction()
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))
return true;
Expand Down Expand Up @@ -246,7 +254,7 @@ bool WalletVerify()
return true;
}

bool InitLoadWallet()
bool OpenWallets()
{
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
LogPrintf("Wallet disabled!\n");
Expand All @@ -263,3 +271,28 @@ bool InitLoadWallet()

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 changes: 21 additions & 3 deletions src/wallet/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,36 @@

#include <string>

class CRPCTable;
class CScheduler;

//! Return the wallets help message.
std::string GetWalletHelpString(bool showDebug);

//! Wallets parameter interaction
bool WalletParameterInteraction();

//! Register wallet RPCs.
void RegisterWalletRPC(CRPCTable &tableRPC);

//! 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
// being loaded (CWallet::ParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet).
bool WalletVerify();
// being loaded (WalletParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet).
bool VerifyWallets();

//! 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
3 changes: 0 additions & 3 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3230,9 +3230,6 @@ static const CRPCCommand commands[] =

void RegisterWalletRPCCommands(CRPCTable &t)
{
if (gArgs.GetBoolArg("-disablewallet", false))
return;

for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
}
3 changes: 3 additions & 0 deletions src/wallet/rpcwallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#ifndef BITCOIN_WALLET_RPCWALLET_H
#define BITCOIN_WALLET_RPCWALLET_H

#include <string>

class CRPCTable;
class CWallet;
class JSONRPCRequest;

void RegisterWalletRPCCommands(CRPCTable &t);
Expand Down

0 comments on commit 25d98e2

Please sign in to comment.