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 wallet.dat path handling from wallet.cpp, rpcwallet.cpp #19619

Merged
merged 8 commits into from
Sep 6, 2020

Conversation

ryanofsky
Copy link
Contributor

Get rid of file path handling in wallet application code and move it down to database layer.

There is no change in behavior except for some changed error messages.

Motivation for this change is to make code more understandable, but also to prepare for adding SQLite support in #19077 so SQLite implementation can be contained at the database layer and wallet loading code does not need to become more complicated.

@hebasto
Copy link
Member

hebasto commented Jul 29, 2020

Concept ACK.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 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.

@achow101
Copy link
Member

achow101 commented Jul 29, 2020

Could the second commit be split up a bit? It seems to be doing a lot and several functions are being renamed and removed.

From what I understand, the second commit adds DatabaseOptions and DatabaseStatus. Then CreateWalletDatabase is renamed to MakeWalletDatabase and all of the various checks (file existence checks and database verify) are pushed into that function with DatabaseOptions informing the function what to actually do. And lastly MakeWalletDatabase becomes a separate distinct step that callers must do instead of letting CWallet::Create (renamed from CreateWalletFromFile) handle internally.

From this, I think you could add a few more commits:

  • Introduction of DatabaseOptions and DatabaseStatus to consolidate the current options and status
  • Moving everything into MakeWalletDatabase
  • Separating MakeWalletDatabase from CWallet::Create

@ryanofsky
Copy link
Contributor Author

Could the second commit be split up a bit? It seems to be doing a lot and several functions are being renamed and removed.

Sure, I think I can split up like you're suggesting. The main change is introducing the MakeBerkeleyDatabase function. Then that function is called various places to get rid of path operations. So I think introducing MakeBerkeleyDatabase could be one commit, and then this can be followed by more commits calling it from RPC code, and then gui code, and then wallet tool code

@ryanofsky
Copy link
Contributor Author

ryanofsky commented Jul 29, 2020

Oh, also I didn't want this PR to depend on #19099, but this would be a little smaller with #19099 merged frist, because then there would be no need to change interfaces/node and walletinitinterface code here


Rebased 8994145 -> 0e4cb50 (pr/path.2 -> pr/path.3, compare) due to conflict with #19102

@luke-jr
Copy link
Member

luke-jr commented Jul 31, 2020

I can see why we'd want to move anything about "wallet.dat" or the "wallet is a directory" stuff into the database layer, but IMO it doesn't make sense to hide the path the wallet is located within...

@meshcollider
Copy link
Contributor

Concept ACK, as a logical separation I think it makes sense to have database-format-specific stuff like this at a lower layer than the logical use of a generic database in the rest of the code.

@achow101
Copy link
Member

achow101 commented Sep 1, 2020

ACK 83a8f51

This removes a source of complexity and indirection that makes it harder to
understand path checking code. Path checks will be simplified in upcoming
commits.

There is no change in behavior in this commit other than a slightly more
descriptive error message in `loadwallet` if the default "" wallet can't be
found. (The error message is improved more in upcoming commit "wallet: Remove
path checking code from loadwallet RPC".)
New function is not currently called but will be called in upcoming commits. It
moves database path checking, and existence checking, and already-loaded
checking, and verification into a single function so this logic does not need
to be repeated all over higher level wallet code, and so higher level code does
not need to change when SQLite support is added in
bitcoin#19077. This also lets higher level
wallet code make fewer assumptions about the contents of wallet directories.

This commit just adds the new function and does not change behavior in any way.
No changes in behavior. Just replaces arguments and return types
Checks are now consolidated in MakeBerkeleyDatabase function instead of
happening in higher level code.

This commit does not change behavior except for error messages which now
include more complete information.
This commit does not change behavior except for error messages which now
include more complete information.
This commit does not change behavior except for error messages which now
include more complete information.
This commit does not change behavior except for error messages which now
include more complete information.
Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

ACK 83a8f51, tested on Linux Mint 20 (x86_64).

src/wallet/rpcwallet.cpp Outdated Show resolved Hide resolved
src/wallet/wallet.cpp Show resolved Hide resolved
src/wallet/wallet.cpp Show resolved Hide resolved
src/wallet/wallet.cpp Show resolved Hide resolved
src/wallet/wallet.cpp Show resolved Hide resolved
src/wallet/load.cpp Show resolved Hide resolved
src/wallet/salvage.cpp Show resolved Hide resolved
Copy link
Contributor Author

@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.

Rebased 83a8f51 -> 7bf6dfb (pr/path.8 -> pr/path.9, compare) due to conflict with #19754

Thanks for reviews! Reminder to anyone interested that sqlite PR #19077 currently depends on this. And so far achow and hebasto have acked, and meshcollider, promag, and sjors have concept acked this.

src/wallet/rpcwallet.cpp Outdated Show resolved Hide resolved
if (!location.Exists()) {
throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Wallet " + location.GetName() + " not found.");
} else if (fs::is_directory(location.GetPath())) {
if (fs::symlink_status(path).type() == fs::file_not_found) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I sort of liked that the functionality was wrapped in one function. This avoids issues exactly like this

Replied #19619 (review)

src/wallet/load.cpp Show resolved Hide resolved
src/wallet/wallet.cpp Show resolved Hide resolved
src/wallet/wallet.cpp Show resolved Hide resolved
src/wallet/wallet.cpp Show resolved Hide resolved
src/wallet/wallet.cpp Show resolved Hide resolved
src/wallet/salvage.cpp Show resolved Hide resolved
@achow101
Copy link
Member

achow101 commented Sep 4, 2020

ACK 7bf6dfb

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

re-ACk 7bf6dfb

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 re-review and functional test run ACK 7bf6dfb

@meshcollider meshcollider merged commit 56d47e1 into bitcoin:master Sep 6, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 9, 2020
… rpcwallet.cpp

7bf6dfb wallet: Remove path checking code from bitcoin-wallet tool (Russell Yanofsky)
77d5bb7 wallet: Remove path checking code from createwallet RPC (Russell Yanofsky)
a987438 wallet: Remove path checking code from loadwallet RPC (Russell Yanofsky)
8b5e729 refactor: Pass wallet database into CWallet::Create (Russell Yanofsky)
3c815cf wallet: Remove Verify and IsLoaded methods (Russell Yanofsky)
0d94e60 refactor: Use DatabaseStatus and DatabaseOptions types (Russell Yanofsky)
b5b4141 wallet: Add MakeDatabase function (Russell Yanofsky)
288b4ff Remove WalletLocation class (Russell Yanofsky)

Pull request description:

  Get rid of file path handling in wallet application code and move it down to database layer.

  There is no change in behavior except for some changed error messages.

  Motivation for this change is to make code more understandable, but also to prepare for adding SQLite support in bitcoin#19077 so SQLite implementation can be contained at the database layer and wallet loading code does not need to become more complicated.

ACKs for top commit:
  achow101:
    ACK 7bf6dfb
  meshcollider:
    Code re-review and functional test run ACK 7bf6dfb

Tree-SHA512: 23ad18324c9e8947f0cf88a3734c2e9fb25536b2cb4d552cf5d1a4ade320fbffb73bb2d1b3a99585c11630aa7092e0fcfc2dd4fe65b91e3a54161433a5cd13cb
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 5, 2021
Summary:
PR description:

> Get rid of file path handling in wallet application code and move it down to database layer.
>
> There is no change in behavior except for some changed error messages.
>
> Motivation for this change is to make code more understandable, but also to prepare for adding SQLite support in #19077 so SQLite implementation can be contained at the database layer and wallet loading code does not need to become more complicated.

This removes a source of complexity and indirection that makes it harder to
understand path checking code. Path checks will be simplified in upcoming
commits.

There is no change in behavior in this commit other than a slightly more
descriptive error message in `loadwallet` if the default "" wallet can't be
found. (The error message is improved more in upcoming commit "wallet: Remove
path checking code from loadwallet RPC".)

This is a backport of [[bitcoin/bitcoin#19619 | core#19619]] [1/8]
bitcoin/bitcoin@288b4ff

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10224
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 5, 2021
Summary:
New function is not currently called but will be called in upcoming commits. It
moves database path checking, and existence checking, and already-loaded
checking, and verification into a single function so this logic does not need
to be repeated all over higher level wallet code, and so higher level code does
not need to change when SQLite support is added in
bitcoin/bitcoin#19077. This also lets higher level
wallet code make fewer assumptions about the contents of wallet directories.

This commit just adds the new function and does not change behavior in any way.

This is a backport of [[bitcoin/bitcoin#19619 | core#19619]] [2/8]
bitcoin/bitcoin@b5b4141

Depends on D10224

Test Plan: `ninja`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10225
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 5, 2021
Summary:
No changes in behavior. Just replaces arguments and return types

This is a backport of [[bitcoin/bitcoin#19619 | core#19619]] [3/8]
bitcoin/bitcoin@0d94e60

Depends on D10225

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10226
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 5, 2021
Summary:
Checks are now consolidated in MakeBerkeleyDatabase function instead of
happening in higher level code.

This commit does not change behavior except for error messages which now
include more complete information.

This is a backport of [[bitcoin/bitcoin#19619 | core#19619]] [4/8]
bitcoin/bitcoin@3c815cf

Depends on D10226

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10227
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 5, 2021
Summary:
No changes in behavior

This is a backport of [[bitcoin/bitcoin#19619 | core#19619]] [5/8]
bitcoin/bitcoin@8b5e729

Depends on D10227

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10228
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 5, 2021
Summary:
This commit does not change behavior except for error messages which now
include more complete information.

This is a backport of [[bitcoin/bitcoin#19619 | core#19619]] [6/8]
bitcoin/bitcoin@a987438

Depends on D10228
Depends on D10213 (for rpc_createmultisig.py)

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10229
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 5, 2021
Summary:
This commit does not change behavior except for error messages which now
include more complete information.

This is a backport of [[bitcoin/bitcoin#19619 | core#19619]] [7/8]
bitcoin/bitcoin@77d5bb7

Depends on D10229

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10230
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 5, 2021
Summary:
This commit does not change behavior except for error messages which now
include more complete information.

This concludes backport of [[bitcoin/bitcoin#19619 | core#19619]] [8/8]
bitcoin/bitcoin@7bf6dfb

Depends on D10230

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10231
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants