New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wallet] Clarify wallet initialization / destruction interface #10767
Conversation
src/init.cpp
Outdated
@@ -187,11 +187,6 @@ void Shutdown() | |||
StopREST(); | |||
StopRPC(); | |||
StopHTTPServer(); | |||
#ifdef ENABLE_WALLET |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing replacing this code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct - I don't believe the early wallet flush is necessary (although I may be wrong). See PR description:
The most important one is that Flush() no longer gets called twice on shutdown. I think this is fine, and all the tests pass, but this probably requires some careful consideration from people who are more familiar with the wallet code.
src/init.cpp
Outdated
@@ -230,9 +225,7 @@ void Shutdown() | |||
pblocktree = NULL; | |||
} | |||
#ifdef ENABLE_WALLET |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about moving these #ifdef ENABLE_WALLET
to walletinit.cpp
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because walletinit.cpp
is in libbitcoin_wallet, so is not linked if ENABLE_WALLET
isn't defined. #10762 will remove the libbitcoin_server -> libbitcoin_wallet dependencies entirely from init.cpp.
Rebase needed :-) |
This isn't going in until after 0.15. which includes some wallet changes. I'll rebase after 0.15 has been cut. |
@jnewbery Got it! Thanks for the clarification. |
Rebased on @ryanofsky's #10976 and reduced scope. This PR now only moves the remaining wallet startup/shutdown functions to There should be no change in behavior from this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 3f425ee4263f66ab039c089d189b6cad0abbc23c. Looks like a simple cleanup with no change in behavior. FWIW I have similar functions in #10973, but am using {start, stop, shutdown} instead of {WalletCompleteStartup, FlushWallets, ShutdownWallets}. Links: declarations, definitions
src/wallet/init.h
Outdated
@@ -22,4 +22,7 @@ bool WalletVerify(); | |||
//! Load wallet databases. | |||
bool InitLoadWallet(); | |||
|
|||
//! Flush all wallets in preparation for shutdown. | |||
// Call with shutdown = true to actually shutdown the wallet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "[wallet] move wallet flush calls to wallet/init.cpp"
I think you need to use //!
prefix on each line of the comment for doxygen to pick it up.
src/init.cpp
Outdated
delete pwallet; | ||
} | ||
vpwallets.clear(); | ||
DetachWallets(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "[wallet] move wallet detach calls to wallet/init.cpp"
Maybe go with "close" or "free" instead of "detach". Detach sounds like it could be keeping the wallets open but handing them off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 FreeWallets
.
src/wallet/init.h
Outdated
@@ -6,14 +6,22 @@ | |||
#ifndef BITCOIN_WALLET_INIT_H | |||
#define BITCOIN_WALLET_INIT_H | |||
|
|||
#include "wallet/rpcwallet.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
src/wallet/init.cpp
Outdated
@@ -245,3 +253,28 @@ bool InitLoadWallet() | |||
|
|||
return true; | |||
} | |||
|
|||
void WalletCompleteStartup(CScheduler& scheduler) { | |||
for (CWalletRef pwallet : vpwallets) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Offtopic, we could ditch CWalletRef
.
src/init.cpp
Outdated
delete pwallet; | ||
} | ||
vpwallets.clear(); | ||
DetachWallets(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 FreeWallets
.
src/wallet/init.h
Outdated
void ShutdownWallets(); | ||
|
||
//! Detach all wallets | ||
void DetachWallets(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline after.
src/wallet/init.h
Outdated
//! Shutdown all wallets. Wallets will be flushed first. | ||
void ShutdownWallets(); | ||
|
||
//! Detach all wallets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
src/wallet/init.h
Outdated
@@ -22,4 +30,15 @@ bool WalletVerify(); | |||
//! Load wallet databases. | |||
bool InitLoadWallet(); | |||
|
|||
//! Complete startup of wallets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
src/wallet/init.h
Outdated
//! Return the wallets help message. | ||
std::string GetWalletHelpString(bool showDebug); | ||
|
||
//! Wallets parameter interaction | ||
bool WalletParameterInteraction(); | ||
|
||
//! Register wallet RPCs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing period?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix above too.
Re: naming of unload/close/free/detach wallet function. I want the wallet loading/unloading RPC verbs to be antonyms so it's obvious they're carrying out opposite actions. I started with load/unload, but dropped that to avoid any ambiguity with adding keys and addresses to an already open wallet. attach/detach is bad for the reason Russ mentioned. Is everyone happy with open/close? (I guess the name of the function doesn't need to map exactly to the name of the RPC, but I think it makes sense to do that if we can) |
open/close or load/unload is what I would call it |
I've addressed the comments and changed names a little. @ryanofsky do you mind taking a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK ca94bf2c39b06f1ed643c24dfcd78ef5af00562a. Note that what you're calling flush, I'm calling stop in #10973, and what you're calling stop, I'm calling shutdown. But I'm not too worried about the names.
#10973 links: declarations, definitions
Also just a suggestion, but this might be easier to review if it were just 2 commits, one commit for RPC stuff and one commit for the start/stop/flush stuff, so you could see the related parts together. |
Thanks @ryanofsky . Other reviewers/maintainers - I'm happy to rebase/squash as Russ suggests if that makes things easier to review. Please let me know if you want that. |
utACK ca94bf2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK ca94bf2c39b06f1ed643c24dfcd78ef5af00562a. I'm willing to bet this materially reduces the memory usage/compile time of init.cpp due to the wallet.h import removal.
@@ -44,7 +44,6 @@ | |||
#include "validationinterface.h" | |||
#ifdef ENABLE_WALLET | |||
#include "wallet/init.h" | |||
#include "wallet/wallet.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Holy fuck yes, kill the imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK. Is mostly move-only
@@ -1567,7 +1559,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) | |||
|
|||
// ********************************************************* Step 8: load wallet | |||
#ifdef ENABLE_WALLET | |||
if (!InitLoadWallet()) | |||
if (!OpenWallets()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the rationale for rename in the commit message? Why not keep it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jnewbery Or add it to the OP, so it can be seen in the merge commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
src/wallet/init.h
Outdated
//! 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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment should say "WalletParameterInteraction"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added as trivial commit
Rationale: - this init function can now open multiple wallets (hence Wallet->Wallets) - This is named as the antonym to CloseWallets(), which carries out the opposite action.
This function can now verify multiple wallets.
ca94bf2
to
5d2a399
Compare
@MarcoFalke - nits addressed. Should be ready for merge if Travis agrees. |
re-utACK commit-by-commit 5d2a399 |
…terface 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
…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
…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
…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
…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
…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
…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
…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
…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
…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
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.