Skip to content

Conversation

@BrandonOdiwuor
Copy link
Contributor

Fixes #16220, see #16220 (comment)

  • util/system datadir code should not care about wallets or look for or create any wallet paths
  • If -walletdir is specified, wallet code should use that directory to locate and list wallets.
  • If -walletdir is specified and path is not a directory, wallet init should return a fatal error and refuse to start
  • If -walletdir is not specified, wallet code should use /wallets as the directory to locate and list wallets.
  • If -walletdir is not specified and /wallets does not exist, wallet init code should create it
    • Before creating /wallets wallet should call ListWalletDir ListDatabases on
    • If list is empty wallet should create /wallets as a directory, otherwise it should create it as a symlink pointing to .

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 21, 2023

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK TheCharlatan

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29641 (scripted-diff: Use LogInfo/LogDebug over LogPrintf/LogPrint by maflcko)

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.

@maflcko
Copy link
Member

maflcko commented Sep 21, 2023

Looks like the tests fail?

@BrandonOdiwuor BrandonOdiwuor force-pushed the fix-wallet-dir-init branch 3 times, most recently from ac74173 to 3b7d0e9 Compare September 25, 2023 18:30
@BrandonOdiwuor BrandonOdiwuor changed the title Fix wallet directory initialization Wallet: Fix wallet directory initialization Sep 26, 2023
@BrandonOdiwuor BrandonOdiwuor changed the title Wallet: Fix wallet directory initialization wallet: Fix wallet directory initialization Sep 26, 2023
@BrandonOdiwuor
Copy link
Contributor Author

@MarcoFalke not sure why this test is failing, since it passes locally
Screenshot from 2023-09-26 13-07-20

@maflcko
Copy link
Member

maflcko commented Sep 27, 2023

The CI task that failed is named "no wallet". This means, to reproduce the failure, you will have to compile without a wallet and run the test.

@BrandonOdiwuor BrandonOdiwuor force-pushed the fix-wallet-dir-init branch 3 times, most recently from 4544d03 to 9c3b79e Compare September 27, 2023 11:28
@DrahtBot DrahtBot added Wallet and removed CI failed labels Sep 27, 2023
@DrahtBot DrahtBot mentioned this pull request Sep 29, 2023
@fanquake
Copy link
Member

fanquake commented Oct 2, 2023

cc @ryanofsky @achow101

@ryanofsky
Copy link
Contributor

This seems promising, but it isn't exactly implementing what's described in #16220 (comment) or the PR description so it has a different set of advantages and disadvantages.

The difference between code and PR description is that code is not implementing: "If list is empty wallet should create <datadir>/wallets as a directory, otherwise it should create it as a symlink pointing to .". Because of this, the PR can't simplify the GetWalletDir function so it still needs to check existence <datadir>/wallets and can't just return it unconditionally.

Maybe this is ok, and the PR is still worthwhile, because it at least it simplifies the node code, even if it doesn't simplify the wallet code, and it makes the separation cleaner because node code no longer explicitly needs to create the "wallets" directory and can avoid creating it if the wallet is disabled.

Another consequence of not creating "wallets" -> "." symlink is that startup might be a little slower in a data directory that has wallets in the top level, since ListDatabases().empty() will be checked every time on startup, instead of just one time when symlink doesn't exist.

Other notes about the PR:

  • It is suspicious why wallet functional tests need to be changed. This change should be backwards compatible so it is surprising that tests should have to change in order to pass. It would be good to have an explanation for that.
  • I'm not sure if we currently have a test explicitly written to cover loading a datadir with no wallets/ subdirectory and wallets in the top-level directory. If there is not an existing test, probably one should be written to make sure code in this PR doesn't break and wallets can still be loaded there.
  • This PR isn't removing qt code that creates the "wallets" directory:
    TryCreateDirectories(GUIUtil::QStringToPath(dataDir) / "wallets");
    , which should no longer be necessary, after the other changes.
  • I think it would be better if this PR did not add a g_wallet_init_interface.InitWalletDir function, and instead just changed existing VerifyWallets function which is already determining the wallet directory. Getting rid of it would be nicer just to have fewer init functions, but also this code doesn't belong in WalletInit class because with Multiprocess bitcoin #10102 WalletInit wallet/init.cpp functions are run in the node process, not the wallet process.

@BrandonOdiwuor
Copy link
Contributor Author

Accidentally closed the PR

@BrandonOdiwuor
Copy link
Contributor Author

BrandonOdiwuor commented Oct 19, 2023

@ryanofsky

I have updated the PR and moved the wallet directory initialization code to VerifyWallets()

I have also added tests for the various init scenarios and removed the remaining TryCreateDirectories from QT

The tests changed in this PR are a reflection of the changes in the logic of the wallet dir init code as suggested, such as the wallet/ dir currently being created even if the data dir is not empty or the mainnet wallet/ dir only being created when running mainnet

I removed the symlink code (see screenshot attached) since it makes tests in wallet_multiwallet.py fail

Screenshot from 2023-10-18 16-46-18

Copy link
Contributor

Choose a reason for hiding this comment

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

In commit "Fix wallet directory initialization" (17b4955e4b1e4f02f00a948b432f18caa9b250a5)

Is there a reason this test is changing? I'd expect the change to be backwards compatible so existing tests should not need to change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ryanofsky This is because of the change in wallet dir init logic. The wallet/ dir is created when a new node is started and no wallet is detected in data_dir

Copy link
Contributor

Choose a reason for hiding this comment

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

In commit "Fix wallet directory initialization" (17b4955e4b1e4f02f00a948b432f18caa9b250a5)

Is there a reason this test is changing? I'd expect the change to be backwards compatible so existing tests should not need to change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is also because of the change in the wallet dir init logic. The wallet/ dir is created when a new node is started and no wallet is detected in data_dir

util/system datadir code should not care about wallets or create any wallet paths
If -walletdir is specified, wallet init code should use that directory
If -walletdir is specified and path is not a directory, return a fatal error
If -walletdir is not specified, use <datadir>/wallets if it is directory.
If -walletdir is not specified and <datadir>/wallets does not exist:
<datadir>/wallets wallet should call ListWalletDir ListDatabases on <datadir>
If list is empty wallet should create <datadir>/wallets as a directory,
otherwise it should create it as a symlink pointing to .
discussion at bitcoin#16220
Copy link
Contributor

@sedited sedited left a comment

Choose a reason for hiding this comment

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

Concept ACK

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 5, 2024

Could rebase for fresh CI, if still relevant?

@achow101
Copy link
Member

achow101 commented Apr 9, 2024

The PR didn't seem to attract much attention in the past. Also, the issue seems not important enough right now to keep it sitting around idle in the list of open PRs.

Closing due to lack of interest.

@achow101 achow101 closed this Apr 9, 2024
@bitcoin bitcoin locked and limited conversation to collaborators Apr 9, 2025
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.

odd behaviour of GetDataDir creating wallets/ subdirectory

8 participants