-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor: remove ::vpwallets and related global variables #19101
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
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
Qt tests currently are currently using two NodeContext structs at the same time, one in interfaces::NodeImpl::m_context, and the other in BasicTestingSetup::m_node, and the tests have hacks transferring state between them. Fix this by getting rid of the NodeImpl::m_context struct and making it a pointer. This way a common BitcoinApplication object can be used for all qt tests, but they can still have their own testing setups. Non-test code is changing but non-test behavior is still the same as before. Benefit of this PR is to being able to remove the existing "std::move(test.m_node.connman)" and mempool hacks. Motivation for this PR is to let qt wallet tests continue working when the ::vpwallets global variable is removed bitcoin#19101 and not have to add even more complicated hacks exposing duplicate WalletContext and WalletClient instances in addition to the duplicate NodeContext instances and having to manipulate them in the test setup.
Rebased 197a403 -> 7272686 ( |
Qt tests currently are currently using two NodeContext structs at the same time, one in interfaces::NodeImpl::m_context, and the other in BasicTestingSetup::m_node, and the tests have hacks transferring state between them. Fix this by getting rid of the NodeImpl::m_context struct and making it a pointer. This way a common BitcoinApplication object can be used for all qt tests, but they can still have their own testing setups. Non-test code is changing but non-test behavior is still the same as before. Benefit of this PR is to being able to remove the existing "std::move(test.m_node.connman)" and mempool hacks. Motivation for this PR is to let qt wallet tests continue working when the ::vpwallets global variable is removed bitcoin#19101 and not have to add even more complicated hacks exposing duplicate WalletContext and WalletClient instances in addition to the duplicate NodeContext instances and having to manipulate them in the test setup.
Concept ACK, need to update commits in OP. |
This change was originally part of both bitcoin#10102 and bitcoin#19101 and is required for both because it avoids the IPC wallet implementation in bitcoin#10102 and the WalletContext implementation in bitcoin#19101 needing to deal with notification objects that have stale pointers to deleted 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.
Code review ACK 6e6a7e1
Thanks Russ for your continued great work!
Move global wallet variables to WalletContext struct
Rebased 6e6a7e1 -> 62a09a3 ( |
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.
re-utACK 62a09a3
ACK 62a09a3 |
@kiminuo maybe you'll want to follow up here given some of the comments up thread? |
Yes, will do. Thanks for the notification. |
pwallet->postInitProcess(); | ||
} | ||
|
||
// Schedule periodic wallet flushes and tx rebroadcasts | ||
if (args.GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET)) { | ||
scheduler.scheduleEvery(MaybeCompactWalletDB, std::chrono::milliseconds{500}); | ||
if (context.args->GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET)) { |
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.
Previously this was an Assert
, now it is UB. Obviously doesn't matter, but I wanted to point out the difference.
break nodecontext usages inside of wallet rpc's and use chain interface functions to get node specific information
…variables 62a09a3 refactor: remove ::vpwallets and related global variables (Russell Yanofsky) Pull request description: Get rid of global wallet list variables by moving them to WalletContext struct - [`cs_wallets`](https://github.com/bitcoin/bitcoin/blob/e638acf6970394f8eb1957366ad2d39512f33b31/src/wallet/wallet.cpp#L56) is now [`WalletContext::wallet_mutex`](https://github.com/ryanofsky/bitcoin/blob/4be544c7ec08a81952fd3f4349151cbb8bdb60e8/src/wallet/context.h#L37) - [`vpwallets`](https://github.com/bitcoin/bitcoin/blob/e638acf6970394f8eb1957366ad2d39512f33b31/src/wallet/wallet.cpp#L57) is now [`WalletContext::wallets`](https://github.com/ryanofsky/bitcoin/blob/4be544c7ec08a81952fd3f4349151cbb8bdb60e8/src/wallet/context.h#L38) - [`g_load_wallet_fns`](https://github.com/bitcoin/bitcoin/blob/e638acf6970394f8eb1957366ad2d39512f33b31/src/wallet/wallet.cpp#L58) is now [`WalletContext::wallet_load_fns`](https://github.com/ryanofsky/bitcoin/blob/4be544c7ec08a81952fd3f4349151cbb8bdb60e8/src/wallet/context.h#L39) ACKs for top commit: achow101: ACK 62a09a3 meshcollider: re-utACK 62a09a3 Tree-SHA512: 74428180d57b4214c3d96963e6ff43e8778f6f23b6880262d1272f2de67d02714fdc3ebb558f62e48655b221a642c36f80ef37c8f89d362e2d66fd93cbf03b8f
… global variables" This reverts commit 07a9f67.
c3c2132 Use `context.args` in `src/wallet/load.cpp`. (Kiminuo) 25de4e7 Use `context.args` in `CWallet::Create` instead of `gArgs`. (Kiminuo) aa5e7c9 Fix typo in bitcoin-cli.cpp (Kiminuo) Pull request description: The PR attempts to move us an inch towards the [goal](#21244 (comment)) by using `WalletContext` in `wallet.{h|cpp}` code instead of relying on the global state (i.e. `gArgs`). Edit: The PR builds on #19101. ACKs for top commit: ryanofsky: Code review ACK c3c2132. Changes since last review: just rebasing and adding wallet load commit Tree-SHA512: 2b436f5a219e32c2d529f55a89edca086d949396cebf9e089a21aa7b1c180e3c0fb17468f415dfc834f8e1614f8b3914c7e9a0bd33b95e7e0199c0dfe5ca9490
c3c2132 Use `context.args` in `src/wallet/load.cpp`. (Kiminuo) 25de4e7 Use `context.args` in `CWallet::Create` instead of `gArgs`. (Kiminuo) aa5e7c9 Fix typo in bitcoin-cli.cpp (Kiminuo) Pull request description: The PR attempts to move us an inch towards the [goal](bitcoin#21244 (comment)) by using `WalletContext` in `wallet.{h|cpp}` code instead of relying on the global state (i.e. `gArgs`). Edit: The PR builds on bitcoin#19101. ACKs for top commit: ryanofsky: Code review ACK c3c2132. Changes since last review: just rebasing and adding wallet load commit Tree-SHA512: 2b436f5a219e32c2d529f55a89edca086d949396cebf9e089a21aa7b1c180e3c0fb17468f415dfc834f8e1614f8b3914c7e9a0bd33b95e7e0199c0dfe5ca9490
865ee1a Fix Qt test broken by #22219 (Russell Yanofsky) Pull request description: It looks like this should have been caught by CI but there might have been a conflict with a recently merged PR like #19101. Failure was reported by fanquake #22219 (comment) Fix avoids null WalletClient pointer dereference in address book test by adding MakeWalletClient call and making address book test initialization more consistent with wallet test initialization: https://github.com/bitcoin/bitcoin/blob/865ee1af201238f48671e3b79b8215f896db7a05/src/qt/test/addressbooktests.cpp#L63-L66 https://github.com/bitcoin/bitcoin/blob/865ee1af201238f48671e3b79b8215f896db7a05/src/qt/test/wallettests.cpp#L141-L144 ACKs for top commit: fanquake: ACK 865ee1a - I'm merging this now to unbreak the build. Tree-SHA512: 1f32b7fc79fa79fcf8600d23063896cbc7f8bbcff39d95747ecd546e754581f0f36ece3098ddecded175afccbb3709b4232da39a400dda23b7e550f361b515fb
This change was originally part of both bitcoin/bitcoin#10102 and bitcoin/bitcoin#19101 and is required for both because it avoids the IPC wallet implementation in bitcoin/bitcoin#10102 and the WalletContext implementation in bitcoin/bitcoin#19101 needing to deal with notification objects that have stale pointers to deleted wallets.
… node.h 24bf176 gui refactor: Inline SplashScreen::ConnectWallet (Russell Yanofsky) e4f4350 refactor: Move wallet methods out of chain.h and node.h (Russell Yanofsky) b266b3e refactor: Create interfaces earlier during initialization (Russell Yanofsky) Pull request description: Add WalletClient interface so node interface is cleaner and don't need wallet-specific methods. The new NodeContext::wallet_client pointer will also be needed to eliminate global wallet variables like ::vpwallets in bitcoin#19101, because createWallet(), loadWallet(), getWallets(), etc methods called by the GUI need a way to get a reference to the list of open wallets if it is no longer a global variable. ACKs for top commit: promag: Code review ACK 24bf176. MarcoFalke: ACK 24bf176 🐚 Tree-SHA512: a70d3776cd6723093db8912028c50075ec5fa0a48b961cb1a945f922658f5363754f8380dbb8378ed128c8c858913024f8264740905b8121a35c0d63bfaed7cf
… node.h 24bf176 gui refactor: Inline SplashScreen::ConnectWallet (Russell Yanofsky) e4f4350 refactor: Move wallet methods out of chain.h and node.h (Russell Yanofsky) b266b3e refactor: Create interfaces earlier during initialization (Russell Yanofsky) Pull request description: Add WalletClient interface so node interface is cleaner and don't need wallet-specific methods. The new NodeContext::wallet_client pointer will also be needed to eliminate global wallet variables like ::vpwallets in bitcoin#19101, because createWallet(), loadWallet(), getWallets(), etc methods called by the GUI need a way to get a reference to the list of open wallets if it is no longer a global variable. ACKs for top commit: promag: Code review ACK 24bf176. MarcoFalke: ACK 24bf176 🐚 Tree-SHA512: a70d3776cd6723093db8912028c50075ec5fa0a48b961cb1a945f922658f5363754f8380dbb8378ed128c8c858913024f8264740905b8121a35c0d63bfaed7cf
… node.h 24bf176 gui refactor: Inline SplashScreen::ConnectWallet (Russell Yanofsky) e4f4350 refactor: Move wallet methods out of chain.h and node.h (Russell Yanofsky) b266b3e refactor: Create interfaces earlier during initialization (Russell Yanofsky) Pull request description: Add WalletClient interface so node interface is cleaner and don't need wallet-specific methods. The new NodeContext::wallet_client pointer will also be needed to eliminate global wallet variables like ::vpwallets in bitcoin#19101, because createWallet(), loadWallet(), getWallets(), etc methods called by the GUI need a way to get a reference to the list of open wallets if it is no longer a global variable. ACKs for top commit: promag: Code review ACK 24bf176. MarcoFalke: ACK 24bf176 🐚 Tree-SHA512: a70d3776cd6723093db8912028c50075ec5fa0a48b961cb1a945f922658f5363754f8380dbb8378ed128c8c858913024f8264740905b8121a35c0d63bfaed7cf
… node.h 24bf176 gui refactor: Inline SplashScreen::ConnectWallet (Russell Yanofsky) e4f4350 refactor: Move wallet methods out of chain.h and node.h (Russell Yanofsky) b266b3e refactor: Create interfaces earlier during initialization (Russell Yanofsky) Pull request description: Add WalletClient interface so node interface is cleaner and don't need wallet-specific methods. The new NodeContext::wallet_client pointer will also be needed to eliminate global wallet variables like ::vpwallets in bitcoin#19101, because createWallet(), loadWallet(), getWallets(), etc methods called by the GUI need a way to get a reference to the list of open wallets if it is no longer a global variable. ACKs for top commit: promag: Code review ACK 24bf176. MarcoFalke: ACK 24bf176 🐚 Tree-SHA512: a70d3776cd6723093db8912028c50075ec5fa0a48b961cb1a945f922658f5363754f8380dbb8378ed128c8c858913024f8264740905b8121a35c0d63bfaed7cf
Get rid of global wallet list variables by moving them to WalletContext struct
cs_wallets
is nowWalletContext::wallet_mutex
vpwallets
is nowWalletContext::wallets
g_load_wallet_fns
is nowWalletContext::wallet_load_fns