Skip to content

Conversation

ryanofsky
Copy link
Contributor

@ryanofsky ryanofsky commented May 28, 2020

Get rid of global wallet list variables by moving them to WalletContext struct

@DrahtBot
Copy link
Contributor

DrahtBot commented May 29, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, 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.

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request May 29, 2020
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.
@ryanofsky
Copy link
Contributor Author

ryanofsky commented May 29, 2020

Rebased 197a403 -> 7272686 (pr/novp.1 -> pr/novp.2, compare) with updated base prs and fixed walletcontroller lifetime bug in test
Rebased 7272686 -> 924561d (pr/novp.2 -> pr/novp.3, compare) to fix UndefinedBehaviorSanitizer error https://travis-ci.org/github/bitcoin/bitcoin/jobs/692548214#L4281 from #19098, also making changes to fix disable wallet build errors https://travis-ci.org/github/bitcoin/bitcoin/jobs/692548213#L3864 and importwallet_rescan segfault https://travis-ci.org/github/bitcoin/bitcoin/jobs/692548218#L10769
Rebased 924561d -> f2d9af6 (pr/novp.3 -> pr/novp.4, compare) with no changes to avoid travis ARM buster "sudo: unable to resolve host travis-job-bitcoin-bitcoin-69472326" error https://travis-ci.org/github/bitcoin/bitcoin/jobs/694723263 reported in #19171
Rebased f2d9af6 -> de89a09 (pr/novp.4 -> pr/novp.5, compare) with no changes after base pr #19096 merged
Rebased de89a09 -> e805b16 (pr/novp.5 -> pr/novp.6, compare) on rebased base pr #19099 pr/wclient.4
Rebased e805b16 -> 0b60ae5 (pr/novp.6 -> pr/novp.7, compare) due to conflicts with #19250 and #19261 on rebased base pr #19099 pr/wclient.5
Rebased 0b60ae5 -> 6c9a117 (pr/novp.7 -> pr/novp.8, compare) due to conflicts with #19300
Rebased 6c9a117 -> d22a053 (pr/novp.8 -> pr/novp.9, compare) on top of #19099 pr/wclient.6
Rebased d22a053 -> 6f799b1 (pr/novp.9 -> pr/novp.10, compare) on top of #19099 pr/wclient.7
Rebased 6f799b1 -> 58c9550 (pr/novp.10 -> pr/novp.11, compare) due to conflict with #19334
Rebased 58c9550 -> a00fc53 (pr/novp.11 -> pr/novp.12, compare) on top of #19099 pr/wclient.8
Rebased a00fc53 -> 7fa4e3b (pr/novp.12 -> pr/novp.13, compare) after #19099 merge and conflicts due to bitcoin-core/gui#35 and #19099
Rebased 7fa4e3b -> 9070db9 (pr/novp.13 -> pr/novp.14, compare) due to conflicts with #19717 and #19671
Rebased 9070db9 -> 3df8f44 (pr/novp.14 -> pr/novp.15, compare) due to conflict with #19754

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request May 29, 2020
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.
@promag
Copy link
Contributor

promag commented May 31, 2020

Concept ACK, need to update commits in OP.

stratospher pushed a commit to stratospher/bitcoin that referenced this pull request Aug 14, 2021
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.
Copy link
Contributor

@meshcollider meshcollider left a 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
@ryanofsky
Copy link
Contributor Author

Rebased 6e6a7e1 -> 62a09a3 (pr/novp.28 -> pr/novp.29, compare) due to conflict with #22541

Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-utACK 62a09a3

@achow101
Copy link
Member

ACK 62a09a3

@fanquake fanquake merged commit 638855a into bitcoin:master Aug 19, 2021
@fanquake
Copy link
Member

@kiminuo maybe you'll want to follow up here given some of the comments up thread?

@kiminuo
Copy link
Contributor

kiminuo commented Aug 19, 2021

@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)) {
Copy link
Member

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.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 20, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 22, 2021
break nodecontext usages inside of wallet rpc's and use chain interface functions to get node specific information
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 22, 2021
…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
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 22, 2021
maflcko pushed a commit that referenced this pull request Aug 26, 2021
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
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 28, 2021
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
fanquake added a commit that referenced this pull request Sep 16, 2021
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
janus pushed a commit to BitgesellOfficial/bitgesell that referenced this pull request Oct 29, 2021
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.
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 7, 2022
… 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
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 7, 2022
… 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
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 10, 2022
… 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
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 14, 2022
… 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
@bitcoin bitcoin locked and limited conversation to collaborators Jan 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants