-
Notifications
You must be signed in to change notification settings - Fork 37.7k
system: allow GUI to initialize default data dir #27273
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. ReviewsSee the guideline for information on the review process. ConflictsNo conflicts as of last run. |
https://github.com/bitcoin/bitcoin/pull/27273/checks?check_run_id=12065322378 ********* Start testing of OptionTests *********
Config: Using QtTest library 5.15.5, Qt 5.15.5 (x86_64-little_endian-lp64 static release build; by Clang 8.0.1 (tags/RELEASE_801/final)), debian 10
PASS : OptionTests::initTestCase()
PASS : OptionTests::migrateSettings()
PASS : OptionTests::integerGetArgBug()
PASS : OptionTests::parametersInteraction()
PASS : OptionTests::extractFilter()
QWARN : OptionTests::initDataDir() This plugin does not support propagateSizeHints()
QWARN : OptionTests::initDataDir() This plugin does not support propagateSizeHints()
=== Received signal at function time: 299728ms, total time: 300005ms, dumping stack ===
=== End of stack trace ===
QFATAL : OptionTests::initDataDir() Test function timed out
FAIL! : OptionTests::initDataDir() Received a fatal error.
Loc: [Unknown file(0)]
Totals: 5 passed, 1 failed, 0 skipped, 0 blacklisted, 300009ms
********* Finished testing of OptionTests *********
FAIL qt/test/test_bitcoin-qt (exit status: 134) |
3636af3
to
c589b66
Compare
6f7fd82
to
25ee539
Compare
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.
I'm having second thoughts about this change, because while I do think the new behavior is simpler and better, the current behavior is not as crazy as I initially thought, and changing it now could cause problems.
I do think first of all that the PR could have clearer title and description to actually say what it does. For the PR title and description I would suggest:
-
gui: Make
bitcoin.conf
datadir reliably override the GUI datadirCurrent bitcoin-qt behavior is to apply the
datadir=
setting in abitcoin.conf
file ONLY when the datadir setting picked in the GUI is the same as the default datadir location for the platform (~/.bitcoin
on linux,~/Library/Application Support/Bitcoin/
on macos,%APPDATA%\Bitcoin
on windows). If the datadir picked in the GUI is set to any other value, thedatadir=
line inbitcoin.conf
is ignored. The PR changes behavior to reliably make thebitcoin.conf
datadir line take precedence over the GUI setting. It avoids the confusing behavior ofdatadir=
setting inbitcoin.conf
being ignored or sometimes applied depending on where thebitcoin.conf
file is located.
Here are the reasons I no longer think this change would be good:
-
While the new behavior of always obeying the
bitcoin.conf
datadir=
setting is simpler and easier to understand, I don't think there is actually a use-case that requires it. The use-case for settingdatadir=
inbitcoin.conf
generally is to be able to set an external storage location for wallet and block data, and this works fine now as long asbitcoin.conf
is put in the default location. I doubt anybody really needs to configure the GUI to locatebitcoin.conf
in a non-default second location, and then have thatbitcoin.conf
set a datadir in a third location. Most likely anybody who has done this did it by accident and would be better served by a warning about inconsistent datadir settings. -
This change could cause compatibility problems. Some user could have a set a
datadir=
line in theirbitcoin.conf
file, and later moved and changed their datadir location in the GUI, forgetting about thedatadir=
line inbitcoin.conf
file which the GUI would ignore. The change in this PR would suddenly cause the oldbitcoin.conf
datadir=
line to come back to life, and wallets would appear missing, and blocks would be downloaded from scratch using an old storage location. I don't know how likely it would be for this problem to happen, but it seems like it would be causing a lot of potential pain for no real benefit to users.
I do think code and test in the PR could be repurposed to take a more conservative approach, and just show a warning if a GUI bitcoin.conf datadir= line is being ignored. (If implementing this would suggest doing it in a new PR to avoid stale review comments and confusion between different approaches.)
@@ -260,8 +260,8 @@ bool Intro::showIfNeeded(bool& did_show_intro, int64_t& prune_MiB) | |||
* override -datadir in the bitcoin.conf file in the default data directory | |||
* (to be consistent with bitcoind behavior) | |||
*/ | |||
if(dataDir != GUIUtil::getDefaultDataDirectory()) { |
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.
In commit "system: allow GUI to initialize default data dir" (7a9b786)
This if
statement no longer does anything and could be dropped. Just calling InitDefaultDataDir
unconditionally would have the same effect and be easier to understand. Also the comment above needs to be updated. Could replace "Only override -datadir if different from the default, to make it possible [...]" with "Set chosen directory as the default datadir. It is possible [...]"
void ArgsManager::InitDefaultDataDir(const fs::path path) | ||
{ | ||
LOCK(cs_args); | ||
if (m_init_default_datadir_path.empty()) |
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.
In commit "system: allow GUI to initialize default data dir" (7a9b786)
This if
statment is unnecessary and causes InitDefaultDataDir
to do nothing if it is called a second time. Would be saner to rename InitDefaultDataDir
SetDefaultDataDir
and just set the path unconditionally without unnecessary stickiness and no way of knowing whether the path was set.
Wasn't that the user story in #27246 (comment) ? Either way I see your point about the compatibility issues. What actually might be more useful for that user or related cases is the option in the GUI to clear the QSettings and so the user can re-set the "initial directory" which "should" include a bitcoin.conf but doesn't need to be the actual datdir or blocksdir. While testing this out on macOS I found it extremely hard to clear the plist data which is cached by OS and not easy to bust. |
Yes but I think a better alternative for that user would be to use -includeconf which works today (or symlinks) rather than datadir daisy chaining which doesn't work and would need to be implemented, and could cause compatibility issues, and as far as we know would not be the simplest solution for the problem they are trying to solve.
This could be a good idea, but it would depend a lot on the specific details. There is -resetguisettings option which can help too. |
Closing for now, |
Currently if a you choose a non-default datadir in the GUI intro screen, the datadir is ignored by CLI tools. This means `bitcoin-cli` and `bitcoin-wallet` will try to use the wrong datadir and show errors if they are called without a -datadir arguments, and `bitcoind` will appear to work but use a different datadir, not loading the same wallets and settings, and downloading blocks into the wrong place. There are also more subtle inconsistencies between GUI and CLI selection of datadirs such as bitcoin#27273 where GUI might ignore a datadir= line in a bitcoin.conf that CLI tools would apply. This PR gets rid of inconsistencies between GUI and CLI tools and makes them use the same datadir setting by default. It is followup to bitcoin-core/gui#602 which made GUI and CLI tools use the same `-dbcache`, `-par`, `-spendzeroconfchange`, `-signer`, `-upnp`, `-natpmp`, `-listen`, `-server`, `-prune`, `-proxy`, `-onion`, and `-lang` settings as long as they loaded the same datadir. The reason for GUI and CLI tools using inconsistent datadirs, is that GUI stores the datadir path in a `strDataDir` field in `.config/Bitcoin/Bitcoin-Qt.conf`[^1] which CLI tools ignore. This PR changes the GUI to instead store the datadir path at the default datadir location `~/.bitcoin`[^2] as a symlink that CLI tools will already follow, or as a text file if the filesystem does not support creating symlinks. If upgrading from a previous version of the GUI and there is only a GUI datadir, the `strDataDir` setting will be automatically migrated to a symlink so CLI tools will start using it as well. If CLI and GUI tools are currently using different default datadirs, the GUI will show a prompt allowing either of the datadirs to be loaded and optionally set as the common default going forward.
Currently if a you choose a non-default datadir in the GUI intro screen, the datadir is ignored by CLI tools. This means `bitcoin-cli` and `bitcoin-wallet` will try to use the wrong datadir and show errors if they are called without a -datadir arguments, and `bitcoind` will appear to work but use a different datadir, not loading the same wallets and settings, and downloading blocks into the wrong place. There are also more subtle inconsistencies between GUI and CLI selection of datadirs such as bitcoin#27273 where GUI might ignore a datadir= line in a bitcoin.conf that CLI tools would apply. This PR gets rid of inconsistencies between GUI and CLI tools and makes them use the same datadir setting by default. It is followup to bitcoin-core/gui#602 which made GUI and CLI tools use the same `-dbcache`, `-par`, `-spendzeroconfchange`, `-signer`, `-upnp`, `-natpmp`, `-listen`, `-server`, `-prune`, `-proxy`, `-onion`, and `-lang` settings as long as they loaded the same datadir. The reason for GUI and CLI tools using inconsistent datadirs, is that GUI stores the datadir path in a `strDataDir` field in `.config/Bitcoin/Bitcoin-Qt.conf`[^1] which CLI tools ignore. This PR changes the GUI to instead store the datadir path at the default datadir location `~/.bitcoin`[^2] as a symlink that CLI tools will already follow, or as a text file if the filesystem does not support creating symlinks. If upgrading from a previous version of the GUI and there is only a GUI datadir, the `strDataDir` setting will be automatically migrated to a symlink so CLI tools will start using it as well. If CLI and GUI tools are currently using different default datadirs, the GUI will show a prompt allowing either of the datadirs to be loaded and optionally set as the common default going forward.
Currently if a you choose a non-default datadir in the GUI intro screen, the datadir is ignored by CLI tools. This means `bitcoin-cli` and `bitcoin-wallet` will try to use the wrong datadir and show errors if they are called without a -datadir arguments, and `bitcoind` will appear to work but use a different datadir, not loading the same wallets and settings, and downloading blocks into the wrong place. There are also more subtle inconsistencies between GUI and CLI selection of datadirs such as bitcoin#27273 where GUI might ignore a datadir= line in a bitcoin.conf that CLI tools would apply. This PR gets rid of inconsistencies between GUI and CLI tools and makes them use the same datadir setting by default. It is followup to bitcoin-core/gui#602 which made GUI and CLI tools use the same `-dbcache`, `-par`, `-spendzeroconfchange`, `-signer`, `-upnp`, `-natpmp`, `-listen`, `-server`, `-prune`, `-proxy`, `-onion`, and `-lang` settings as long as they loaded the same datadir. The reason for GUI and CLI tools using inconsistent datadirs, is that GUI stores the datadir path in a `strDataDir` field in `.config/Bitcoin/Bitcoin-Qt.conf`[^1] which CLI tools ignore. This PR changes the GUI to instead store the datadir path at the default datadir location `~/.bitcoin`[^2] as a symlink that CLI tools will already follow, or as a text file if the filesystem does not support creating symlinks. If upgrading from a previous version of the GUI and there is only a GUI datadir, the `strDataDir` setting will be automatically migrated to a symlink so CLI tools will start using it as well. If CLI and GUI tools are currently using different default datadirs, the GUI will show a prompt allowing either of the datadirs to be loaded and optionally set as the common default going forward.
closes #27246
Replaces a
SoftSetArg()
called by the GUI before parsingbitcoin.conf
with a new methodInitDefaultDataDir()
. This allows the GUI to look for the conf file in a user-specified, non-default location and still parse adatadir=
setting from that file. Adds unit tests for argsman and also for Qt and its QSettings.