Skip to content
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

Remove gArgs from wallet.h and wallet.cpp #22183

Merged
merged 3 commits into from
Aug 26, 2021

Conversation

kiminuo
Copy link
Contributor

@kiminuo kiminuo commented Jun 7, 2021

The PR attempts to move us an inch towards the goal by using WalletContext in wallet.{h|cpp} code instead of relying on the global state (i.e. gArgs).

Edit: The PR builds on #19101.

@ryanofsky
Copy link
Contributor

The effort here seems good, but it seems to me this approach adds as many (or more?) gArgs usages as it removes. I think a better approach would build on #19101 to use WalletContext::args instead of gArgs. #19101 is pretty simple PR and some more review would be welcome

@kiminuo
Copy link
Contributor Author

kiminuo commented Jun 7, 2021

The effort here seems good, but it seems to me this approach adds as many (or more?) gArgs usages as it removes.

The idea of this PR is just to "move gArgs" one level up. That's not that interesting result but it's very easy to review and to decide whether people see a benefit in the change in general.

Your PR seems like a more robust approach to the problem. 👍 I'll try to have a look at #19101 the day after tomorrow.

@ryanofsky
Copy link
Contributor

I guess it's possible the two PR's only overlap in some places and are mostly orthogonal since #19101 does not update the CWallet constructor and this PR does, but:

  • I think no new uses of gArgs should be necessary here, it should always be possible to pass WalletContext::args instead.
  • For the places where refactor: remove ::vpwallets and related global variables #19101 passes a WalletContext argument and this PR just passes an ArgsManager argument, I think it would be nice if this PR just passed a WalletContext so the same parts of code wouldn't need to churn in both PRs

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 7, 2021

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #22787 (refactor: actual immutable pointing by kallewoof)
  • #22766 (refactor: Clarify and disable unused ArgsManager flags by ryanofsky)

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.

@kiminuo
Copy link
Contributor Author

kiminuo commented Jun 8, 2021

I guess it's possible the two PR's only overlap in some places and are mostly orthogonal since #19101 does not update the CWallet constructor and this PR does

It seems so. I would like to avoid competing with your PR so I will try to review your PR tomorrow, I'll leave this PR as a draft and I'll try to make an alternative PR based on yours to show how it would look like.

If anyone else has a different opinion on this, please share it to avoid unnecessary work. :)

@ryanofsky
Copy link
Contributor

Thanks. Just to be clear about the previous comment #22183 (comment), I am saying I think the overlap between two PRs actually not so great, and my first suggestion there to avoid adding lots of new references to gArgs variable and instead pass *context.args, should be applicable with or without #19101. My second suggestion would just be to resolve the few conflicts there are between this PR and #19101 where #19101 adds WalletContext& parameters and this PR adds ArgsManager& parameters by favoring #19101 to avoid code churn. (This could also be rebased on top of #19101 to accomplish the same thing)

@kiminuo
Copy link
Contributor Author

kiminuo commented Aug 22, 2021

@ryanofsky This PR is very modest follow-up to your #19101 at the moment as there are still some occurrences of gArgs in src/wallet/wallet.cpp file.

To remove the rest of gArgs from wallet.cpp, it seems I would need to pass WalletContext parameter to a CWallet constructor. I wonder what you think about this idea.

Copy link
Contributor

@ryanofsky ryanofsky 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 1153ad3, and this seems acceptable to merge even though it's still marked as draft. It also looks like it would be pretty straightforward to extend this and remove gArgs from wallet/load.cpp (but it would require a rebase to avoid conflicts from recent #22217 merge).

To remove the rest of gArgs from wallet.cpp, it seems I would need to pass WalletContext parameter to a CWallet constructor. I wonder what you think about this idea.

I think you could do this, but I'd suggest passing ArgsManager* parameter instead of WalletContext. In that case, it would also make sense to add a CWallet ArgsManager* m_args member.

The difference between passing ArgsManager* and WalletContext is not hugely significant, but I suggest it because the wallet context struct is really meant to hold the state needed to load/save/manage multiple wallets, and shouldn't be required to deal with just a single wallet. It's nice if CWallet objects don't have access to unnecessary state and less state is needed to create them.

(Related to the topic of ArgsManager cleanup @kiminuo, I'd also be happy if you could review #22766, in case you're inclined)

src/wallet/wallet.cpp Outdated Show resolved Hide resolved
@kiminuo kiminuo force-pushed the feature/2021-06-07-wallet-n-gArgs-min branch 2 times, most recently from 3ec555e to b1c01bc Compare August 23, 2021 11:20
@kiminuo kiminuo marked this pull request as ready for review August 23, 2021 13:00
@kiminuo
Copy link
Contributor Author

kiminuo commented Aug 23, 2021

It also looks like it would be pretty straightforward to extend this and remove gArgs from wallet/load.cpp (but it would require a rebase to avoid conflicts from recent #22217 merge).

I'll have a look. Thanks.

To remove the rest of gArgs from wallet.cpp, it seems I would need to pass WalletContext parameter to a CWallet constructor. I wonder what you think about this idea.

I think you could do this, but I'd suggest passing ArgsManager* parameter instead of WalletContext. In that case, it would also make sense to add a CWallet ArgsManager* m_args member.

When passing ArgsManager*, one would get to the situation that on this line, one would have two options: Either get ArgsManager from WalletContext (passed by parameter to CWallet::Create) or use CWallet ArgsManager* m_args member. Do you find it acceptable? It feels not so great. Still it would be better than to use gArgs.

(Related to the topic of ArgsManager cleanup @kiminuo, I'd also be happy if you could review #22766, in case you're inclined)

I'll attempt to have a look when I have a chance.

@ryanofsky
Copy link
Contributor

Code review ACK b1c01bc. Only change since last review is using ArgsManager& args = *Assert(context.args); suggestion. Thanks for the update!

When passing ArgsManager*, one would get to the situation that on this line, one would have two options: Either get ArgsManager from WalletContext (passed by parameter to CWallet::Create) or use CWallet ArgsManager* m_args member. Do you find it acceptable?

CWallet::Create is a static member, so there should be no conflict on that line because a this->m_args member does not exist at all, and a walletInstance->m_args instance will not exist until a few lines below. So the whole function should be unaffected by the suggestion to prefer using ArgsManager* instead of WalletContext when replacing gArgs elsewhere in the CWallet class.

@kiminuo kiminuo force-pushed the feature/2021-06-07-wallet-n-gArgs-min branch from b1c01bc to 25de4e7 Compare August 24, 2021 06:06
@kiminuo
Copy link
Contributor Author

kiminuo commented Aug 25, 2021

It also looks like it would be pretty straightforward to extend this and remove gArgs from wallet/load.cpp (but it would require a rebase to avoid conflicts from recent #22217 merge).

@ryanofsky I have added a commit that fixes this up. Thanks for the suggestion.

Copy link
Contributor

@ryanofsky ryanofsky 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 c3c2132. Changes since last review: just rebasing and adding wallet load commit

@maflcko maflcko merged commit cea38b4 into bitcoin:master Aug 26, 2021
@kiminuo kiminuo deleted the feature/2021-06-07-wallet-n-gArgs-min branch August 26, 2021 08:03
Copy link
Contributor

@kallewoof kallewoof left a comment

Choose a reason for hiding this comment

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

Post-review ACK c3c2132

As a side-thought, it seems like WalletContext could use an args-parameter constructor alternative.

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
@ryanofsky
Copy link
Contributor

Saw this in IRC logs:

[21:05:16] <achow101> ryanofsky: is it possible to get a WalletContext from within a CWallet?

@achow101, it's intentional for CWallet not to have access to WalletContext. WalletContext is container for multiple wallets, and only meant to be used by RPC code and init code, not meant to be used by core wallet code. An individual CWallet is only meant to have access to the state it needs: a chain interface pointer, maybe an argsmanager pointer, it's own database, not to the list of other wallets or other global state. WalletContext is analogous to NodeContext. NodeContext is meant to be used by init and rpc code, not by validation code. Most normal code should not depend on or have access to the global state in these context structs.

maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Nov 10, 2021
…llet.cpp` (2)

2ec38bd Remove `gArgs` from `wallet.h` and `wallet.cpp` (Kiminuo)

Pull request description:

  This is a follow-up PR to bitcoin#22183 and is related to bitcoin#21005 issue.

ACKs for top commit:
  ryanofsky:
    Code review ACK 2ec38bd. No changes since last review, just rebase

Tree-SHA512: ae7fa1927b0a268f25697928ccaf1b3cf10ee1ccef3f9d2344001fbd7e11fe8ce768745c65e76bd7d1632c6c7650612b5b54eaf2be61093854f75a4c4dcb1784
@bitcoin bitcoin locked and limited conversation to collaborators Oct 30, 2022
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.

5 participants