Skip to content

Commit 791a0e6

Browse files
author
MarcoFalke
committed
Merge #10767: [wallet] Clarify wallet initialization / destruction 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 #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
2 parents efb4383 + 5d2a399 commit 791a0e6

File tree

5 files changed

+66
-25
lines changed

5 files changed

+66
-25
lines changed

src/init.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include "validationinterface.h"
4646
#ifdef ENABLE_WALLET
4747
#include "wallet/init.h"
48-
#include "wallet/wallet.h"
4948
#endif
5049
#include "warnings.h"
5150
#include <stdint.h>
@@ -189,9 +188,7 @@ void Shutdown()
189188
StopRPC();
190189
StopHTTPServer();
191190
#ifdef ENABLE_WALLET
192-
for (CWalletRef pwallet : vpwallets) {
193-
pwallet->Flush(false);
194-
}
191+
FlushWallets();
195192
#endif
196193
MapPort(false);
197194

@@ -249,9 +246,7 @@ void Shutdown()
249246
pblocktree = nullptr;
250247
}
251248
#ifdef ENABLE_WALLET
252-
for (CWalletRef pwallet : vpwallets) {
253-
pwallet->Flush(true);
254-
}
249+
StopWallets();
255250
#endif
256251

257252
#if ENABLE_ZMQ
@@ -272,10 +267,7 @@ void Shutdown()
272267
UnregisterAllValidationInterfaces();
273268
GetMainSignals().UnregisterBackgroundSignalScheduler();
274269
#ifdef ENABLE_WALLET
275-
for (CWalletRef pwallet : vpwallets) {
276-
delete pwallet;
277-
}
278-
vpwallets.clear();
270+
CloseWallets();
279271
#endif
280272
globalVerifyHandle.reset();
281273
ECC_Stop();
@@ -1034,7 +1026,7 @@ bool AppInitParameterInteraction()
10341026

10351027
RegisterAllCoreRPCCommands(tableRPC);
10361028
#ifdef ENABLE_WALLET
1037-
RegisterWalletRPCCommands(tableRPC);
1029+
RegisterWalletRPC(tableRPC);
10381030
#endif
10391031

10401032
nConnectTimeout = gArgs.GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT);
@@ -1256,7 +1248,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
12561248

12571249
// ********************************************************* Step 5: verify wallet database integrity
12581250
#ifdef ENABLE_WALLET
1259-
if (!WalletVerify())
1251+
if (!VerifyWallets())
12601252
return false;
12611253
#endif
12621254
// ********************************************************* Step 6: network initialization
@@ -1576,7 +1568,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
15761568

15771569
// ********************************************************* Step 8: load wallet
15781570
#ifdef ENABLE_WALLET
1579-
if (!InitLoadWallet())
1571+
if (!OpenWallets())
15801572
return false;
15811573
#else
15821574
LogPrintf("No wallet support compiled in!\n");
@@ -1715,9 +1707,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
17151707
uiInterface.InitMessage(_("Done loading"));
17161708

17171709
#ifdef ENABLE_WALLET
1718-
for (CWalletRef pwallet : vpwallets) {
1719-
pwallet->postInitProcess(scheduler);
1720-
}
1710+
StartWallets(scheduler);
17211711
#endif
17221712

17231713
return !fRequestShutdown;

src/wallet/init.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "utilmoneystr.h"
1111
#include "validation.h"
1212
#include "wallet/wallet.h"
13+
#include "wallet/rpcwallet.h"
1314

1415
std::string GetWalletHelpString(bool showDebug)
1516
{
@@ -171,7 +172,14 @@ bool WalletParameterInteraction()
171172
return true;
172173
}
173174

174-
bool WalletVerify()
175+
void RegisterWalletRPC(CRPCTable &t)
176+
{
177+
if (gArgs.GetBoolArg("-disablewallet", false)) return;
178+
179+
RegisterWalletRPCCommands(t);
180+
}
181+
182+
bool VerifyWallets()
175183
{
176184
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET))
177185
return true;
@@ -228,7 +236,7 @@ bool WalletVerify()
228236
return true;
229237
}
230238

231-
bool InitLoadWallet()
239+
bool OpenWallets()
232240
{
233241
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
234242
LogPrintf("Wallet disabled!\n");
@@ -245,3 +253,28 @@ bool InitLoadWallet()
245253

246254
return true;
247255
}
256+
257+
void StartWallets(CScheduler& scheduler) {
258+
for (CWalletRef pwallet : vpwallets) {
259+
pwallet->postInitProcess(scheduler);
260+
}
261+
}
262+
263+
void FlushWallets() {
264+
for (CWalletRef pwallet : vpwallets) {
265+
pwallet->Flush(false);
266+
}
267+
}
268+
269+
void StopWallets() {
270+
for (CWalletRef pwallet : vpwallets) {
271+
pwallet->Flush(true);
272+
}
273+
}
274+
275+
void CloseWallets() {
276+
for (CWalletRef pwallet : vpwallets) {
277+
delete pwallet;
278+
}
279+
vpwallets.clear();
280+
}

src/wallet/init.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,36 @@
88

99
#include <string>
1010

11+
class CRPCTable;
12+
class CScheduler;
13+
1114
//! Return the wallets help message.
1215
std::string GetWalletHelpString(bool showDebug);
1316

1417
//! Wallets parameter interaction
1518
bool WalletParameterInteraction();
1619

20+
//! Register wallet RPCs.
21+
void RegisterWalletRPC(CRPCTable &tableRPC);
22+
1723
//! Responsible for reading and validating the -wallet arguments and verifying the wallet database.
1824
// This function will perform salvage on the wallet if requested, as long as only one wallet is
19-
// being loaded (CWallet::ParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet).
20-
bool WalletVerify();
25+
// being loaded (WalletParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet).
26+
bool VerifyWallets();
2127

2228
//! Load wallet databases.
23-
bool InitLoadWallet();
29+
bool OpenWallets();
30+
31+
//! Complete startup of wallets.
32+
void StartWallets(CScheduler& scheduler);
33+
34+
//! Flush all wallets in preparation for shutdown.
35+
void FlushWallets();
36+
37+
//! Stop all wallets. Wallets will be flushed first.
38+
void StopWallets();
39+
40+
//! Close all wallets.
41+
void CloseWallets();
2442

2543
#endif // BITCOIN_WALLET_INIT_H

src/wallet/rpcwallet.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3250,9 +3250,6 @@ static const CRPCCommand commands[] =
32503250

32513251
void RegisterWalletRPCCommands(CRPCTable &t)
32523252
{
3253-
if (gArgs.GetBoolArg("-disablewallet", false))
3254-
return;
3255-
32563253
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
32573254
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
32583255
}

src/wallet/rpcwallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
#ifndef BITCOIN_WALLET_RPCWALLET_H
66
#define BITCOIN_WALLET_RPCWALLET_H
77

8+
#include <string>
9+
810
class CRPCTable;
11+
class CWallet;
912
class JSONRPCRequest;
1013

1114
void RegisterWalletRPCCommands(CRPCTable &t);

0 commit comments

Comments
 (0)