[WIP] [wallet] Remove Wallet dependencies from init.cpp #10762

Open
wants to merge 16 commits into
from

Conversation

Projects
None yet
4 participants
Member

jnewbery commented Jul 7, 2017 edited

Work in progress. This will eventually build off #10767, but is now yet ready for review. Currently looking for feedback on concept and approach.

This continues the work of #7965. This PR, along with #10583, #10579, #10571, #8843 and one more PR to split createmultisig, would remove the remaining dependencies from libbitcoin_server.a on libbitcoin_wallet.a.

I've used the same boost::signal approach that is used in the validationinterface. bitcoind.cpp and qt/bitcoin.cpp register wallet initialization/destruction callbacks as slots in a WalletInitInterface, and init.cpp emits those signals during startup/shutdown. This could potentially be extended in future to allow multiple wallets or other modules to register.

To create the interface, I've just translated all the old init.cpp wallet function calls into signals. I've not done any thinking about whether it makes sense to change that interface by combining/splitting those calls. This is a purely internal interface, so there's no problem in changing it later.

jnewbery added some commits Jul 3, 2017

@jnewbery jnewbery [wallet] Add walletinit.cpp
This commit adds a new walletinit translation unit and moves
GetWalletHelpString() to walletinit from a static member function of
CWallet.
73b2df7
@jnewbery jnewbery [wallet] move WalletParameterInteraction() to walletinit.cpp 19e018f
@jnewbery jnewbery [wallet] move VerifyWallets() to walletinit.cpp 81bbc92
@jnewbery jnewbery [wallet] Allow individual wallets to be verified dbda84b
@jnewbery jnewbery [wallet] move InitLoadWallets() to walletinit.cpp b7ad935
@jnewbery jnewbery [wallet] move calls to postInitProcess() to walletinit.cpp dc67233
@jnewbery jnewbery [wallet] move FlushWallets and DeleteWallets to walletinit.cpp
This completes the movement of wallet initialization functions to
walletinit.cpp. init.cpp now has an interface to the wallet consisting
of the following functions:

- GetWalletHelpString()
- RegisterWalletRPCCommands()
- WalletParameterInteraction()
- VerifyWallets()
- InitLoadWallets()
- WalletCompleteStartup()
- FlushWallets()
- DeleteWallets()
6317b40
@jnewbery jnewbery [wallet] add CDBEnv::Shutdown() function 08467a8
@jnewbery jnewbery [wallet] call CDBEnv.shutdown() from FlushWallets()
This commit removes the call to CDBEnv.Shutdown() from CDBEnv.Flush()
and calls CDBEnv.Shutdown directly from ShutdownWallets() in
walletinit.cpp.

This also changes the interface to CDBEnv.Flush() to allow an individual
wallet to be flushed.
c1fadcb
@jnewbery jnewbery [wallet] remove early call to FlushWallets()
This commit removes the early call to FlushWallets() in Shutdown() and
renames the function in walletinit.cpp to ShutdownWallets().
c3bf190
@jnewbery jnewbery [wallet] create wallet init interface 0b7918e
@jnewbery jnewbery [wallet] move wallet init functions into WalletInit class 702a1fa
@jnewbery jnewbery [wallet] move RegisterWalletRPC to walletinit.cpp e5a8210
@jnewbery jnewbery [wallet] call wallet initialization/destruction functions through sig…
…nals
223e1f5
@jnewbery jnewbery fixup: forward declaration of WalletInitInterface df513e3
@jnewbery jnewbery fixup: register wallet initialization callbacks in bitcoin-qt 306fe41
Contributor

promag commented Jul 7, 2017

Will take a look.

Member

jnewbery commented Jul 7, 2017

Thanks @promag - this is very rough-and-ready at the moment. It builds and passes tests, but is not ready for code review. I'd be very happy to get feedback about general concept though.

Member

jnewbery commented Jul 7, 2017

I see that @theuni has opened #10756 to replace CNodeSignals with an interface class. Would that be a better approach here?

Contributor

ryanofsky commented Jul 7, 2017

I see that @theuni has opened #10756 to replace CNodeSignals with an interface class. Would that be a better approach here?

Yeah I was just about to make this suggestion. You could delete the WalletInitSignals struct and replace the WalletInitSignals global variable with a std::unique_ptr<WalletInitInterface> global. This would get rid of all the boost signals code and make the control flow simpler.

Also you should prefix global variables with g_. And I think this PR would be less error prone and simpler to review if you just left the init code in wallet.cpp for now and moved the relevant functions to walletinit.cpp in followup MOVEONLY PR.

Member

jnewbery commented Jul 7, 2017

I think this PR would be less error prone and simpler to review if you just left the init code in wallet.cpp for now and moved the relevant functions to walletinit.cpp in followup MOVEONLY PR.

Thanks @ryanofsky, you've convinced me - I'll split this PR into two. But I think I'll do it the other way round - first move the wallet initialization/destruction functions into their own walletinit translation unit, and then introduce the interface class in a second PR. The reason is that #10740 is built on walletinit.cpp so this PR and #10740 will no longer be interdependent.

jnewbery changed the title from [WIP] Remove Wallet dependencies from init.cpp to [WIP] [wallet] Remove Wallet dependencies from init.cpp Jul 11, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment