-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Fix datadir handling #15864
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
Fix datadir handling #15864
Conversation
src/util/system.cpp
Outdated
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.
Is this necessary? Looks like fs::absolute already does this in AbsPathForConfigVal.
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.
Yes, it is needed to not touch default datadir unnecessarily, before all configs are read.
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.
It seems like a better fix (simpler and more general) would be to add:
if (path.is_absolute()) return path;as the first line of AbsPathForConfigVal.
src/util/system.cpp
Outdated
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.
This doesn't check the default data dir.
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.
You are right. This behavior is intentional.
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.
You are right. This behavior is intentional.
Would be helpful to say what the function is supposed to do in the header. Maybe
//! Return true if -datadir value points to a valid directory or was not specified.It might be also be less confusing to write this as:
return !gArgs.IsArgSet("-datadir") || fs::is_directory(fs::system_complete(gArgs.GetArg("-datadir", "")))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 "Add CheckDataDirOption() function" (a45f692366d7bb4814af83e3b645c9e5a5a734e6)
I don't think IsArgSet is the right function to call here. If somebody has a datadir option specified in the config file, but wants to unset it on the command line by passing -nodatadir or -datadir="", it seems like this should be allowed. Would suggest:
std::string datadir = gArgs.GetArg("-datadir", "");
return datadir.empty() || fs::is_directory(fs::system_complete(datadir));
And a corresponding change in GetDataDir()
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 don't think IsArgSet is the right function to call here. If somebody has a datadir option specified in the config file, but wants to unset it on the command line by passing -nodatadir or -datadir="", it seems like this should be allowed.
Good catch! Agree.
|
@promag Thank you for your review. |
|
On my system: |
The same behavior is observed on master as well. This PR does not change it. |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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
left a comment
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.
This comment doesn't seem to be true: #15864 (comment)
To make reviewing easier only bitcoind code is modified (neither bitcoin-cli nor bitcoin-qt).
Since GetConfigFile is called all three places. It would also seem worrying if this were true, since it would mean the different binaries wouldn't behave consistently.
src/util/system.cpp
Outdated
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.
It seems like a better fix (simpler and more general) would be to add:
if (path.is_absolute()) return path;as the first line of AbsPathForConfigVal.
e7bf289 to
c4ab742
Compare
|
@ryanofsky Would you mind re-reviewing? |
ryanofsky
left a comment
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.
utACK c4ab7420ef5dc4e6925519f8571a936f38720862. It's not really clear to me which bugs are being fixed by these changes, and how exactly the fixes work, but the basic idea seems to be to avoid calling GetDataDir() various places early on startup when it isn't necessary, to avoid caching bad values.
The changes seem worth making as optimizations or for clarity regardless of the bugs. But it'd also make sense as followup to look into:
- Whether caching datadir is a useful optimization
- Whether it makes sense to interpret a non-absolute "-conf" argument relative to the datadir
Both of these seem questionable to begin with.
src/util/system.cpp
Outdated
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.
You are right. This behavior is intentional.
Would be helpful to say what the function is supposed to do in the header. Maybe
//! Return true if -datadir value points to a valid directory or was not specified.It might be also be less confusing to write this as:
return !gArgs.IsArgSet("-datadir") || fs::is_directory(fs::system_complete(gArgs.GetArg("-datadir", "")))
src/util/system.cpp
Outdated
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 "Add CheckDataDirOption() function" (a45f692366d7bb4814af83e3b645c9e5a5a734e6)
I don't think IsArgSet is the right function to call here. If somebody has a datadir option specified in the config file, but wants to unset it on the command line by passing -nodatadir or -datadir="", it seems like this should be allowed. Would suggest:
std::string datadir = gArgs.GetArg("-datadir", "");
return datadir.empty() || fs::is_directory(fs::system_complete(datadir));
And a corresponding change in GetDataDir()
The root of the reported bugs (#15240, #15745) is |
c4ab742 to
f8c9ef0
Compare
|
I think we could replace the directory creation with an assertion (that datadir already exists) and create the directory right before the first call to |
f8c9ef0 to
9bddf12
Compare
Is it a bit out of the scope of this PR? |
|
@ryanofsky |
ryanofsky
left a comment
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.
utACK 9bddf12763e1bcc41c176f8b7f0b883efed49823. Changes since last review are adding commit descriptions, documenting new CheckDataDirOption() method, and handling -nodatadir and -datadir="" better.
This PR should be tagged as needing release notes if release notes aren't added before it is merged in a doc/release-notes-15864.md file. I think you could take the description from #15864 (comment) and basically turn it into a release note, describing the class of bugs that are fixed and not mentioning specific function names.
src/util/system.cpp
Outdated
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 "Add CheckDataDirOption() function" (5df1581b9ee6f13593b33fa9629ea9fbadcad732)
Ideally commit message might also mention that it changes the behavior of the GetDataDir function. The effect I think is to now allow -nodatadir or -datadir='' options on the command line to override any datadir specified in the config file and reset it to default. In theory this could even be mentioned in release notes, but it's probably too niche.
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.
The effect I think is to now allow
-nodatadiror-datadir=''options on the command line to override any datadir specified in the config file and reset it to default.
Unfortunately, neither -nodatadir nor on the command line cannot unset datadir specified in the config file or reset it to default. See: #16097.-datadir=''
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.
Then, why is this changed?
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.
The initial idea was:
I don't think
IsArgSetis the right function to call here.
If we recall:
Lines 470 to 474 in 8c69fae
| bool ArgsManager::IsArgSet(const std::string& strArg) const | |
| { | |
| if (IsArgNegated(strArg)) return true; // special case | |
| return ArgsManagerHelper::GetArg(*this, strArg).first; | |
| } |
using IsArgNegated is (logically) inappropriate for -datadir option, IMO.
Also (but minor), the suggested code uses only one function call (GetArg) instead of two calls (IsArgSet and GetArg).
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.
The effect I think is to now allow
-nodatadiror-datadir=''options on the command line to override any datadir specified in the config file and reset it to default.
Actually, with this PR -datadir='' (with empty string) or -datadir will reset it to default. So, going to close #16416 in favor of this PR.
|
@MarcoFalke would you mind reviewing this PR? |
9bddf12 to
4f0de62
Compare
|
Rebased after #16205 merged. |
|
Concept ACK |
ryanofsky
left a comment
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.
utACK 4f0de6214ae591bfb37ef745140f45fcc97aec33. No changes since last review except rebase and replacing fprintf with tfm::format.
4f0de62 to
5f55360
Compare
|
Rebased on top of #16300. |
1fcc102 to
f346a65
Compare
This prevents premature GetDataDir() calls, e.g., when config file is not read yet.
This prevents premature tries to access or create the default datadir. This is useful when the -datadir option is specified and the default datadir is unreachable.
f346a65 to
5082409
Compare
This prevents premature tries to access or create the default datadir. This is useful when the -datadir option is specified and the default datadir is unreachable.
This prevents premature tries to access or create the default datadir. This is useful when the -datadir option is specified and the default datadir is unreachable.
All other clients and tools use CheckDataDirOption() rather fs::is_directory(GetDataDir(false)) for the first datadir check.
|
Rebased.
Commits have been rearranged. The test commit is the last one now. |
c508635 to
ffea41f
Compare
ffea41f Enable all tests in feature_config_args.py (Hennadii Stepanov) 66f5c17 Use CheckDataDirOption() for code uniformity (Hennadii Stepanov) 7e33a18 Fix datadir handling in bitcoin-cli (Hennadii Stepanov) b28dada Fix datadir handling in bitcoin-qt (Hennadii Stepanov) 5082409 Fix datadir handling in bitcoind (Hennadii Stepanov) 740d41c Add CheckDataDirOption() function (Hennadii Stepanov) c1f3251 Return absolute path early in AbsPathForConfigVal (Hennadii Stepanov) Pull request description: Fix #15240, see: #15240 (comment) Fix #15745 Fix broken `feature_config_args.py` tests (disabled by MarcoFalke@fabe28a0cdcfa13e0e595a0905e3642a960d3077). All test are enabled now. This PR is alternative to #13621. User's `$HOME` directory is not touched unnecessarily now. ~To make reviewing easier only `bitcoind` code is modified (neither `bitcoin-cli` nor `bitcoin-qt`).~ Refs: - #15745 (comment) by **laanwj** - #16220 Top commit has no ACKs. Tree-SHA512: 4a4cda10e0b67c8f374da0c9567003d2b566d948e7f8550fe246868b5794c15010e88ea206009480b9cd2f737f310a15e984f920730448f99a895893bed351df
ffea41f Enable all tests in feature_config_args.py (Hennadii Stepanov) 66f5c17 Use CheckDataDirOption() for code uniformity (Hennadii Stepanov) 7e33a18 Fix datadir handling in bitcoin-cli (Hennadii Stepanov) b28dada Fix datadir handling in bitcoin-qt (Hennadii Stepanov) 5082409 Fix datadir handling in bitcoind (Hennadii Stepanov) 740d41c Add CheckDataDirOption() function (Hennadii Stepanov) c1f3251 Return absolute path early in AbsPathForConfigVal (Hennadii Stepanov) Pull request description: Fix bitcoin#15240, see: bitcoin#15240 (comment) Fix bitcoin#15745 Fix broken `feature_config_args.py` tests (disabled by MarcoFalke@fabe28a0cdcfa13e0e595a0905e3642a960d3077). All test are enabled now. This PR is alternative to bitcoin#13621. User's `$HOME` directory is not touched unnecessarily now. ~To make reviewing easier only `bitcoind` code is modified (neither `bitcoin-cli` nor `bitcoin-qt`).~ Refs: - bitcoin#15745 (comment) by **laanwj** - bitcoin#16220 Top commit has no ACKs. Tree-SHA512: 4a4cda10e0b67c8f374da0c9567003d2b566d948e7f8550fe246868b5794c15010e88ea206009480b9cd2f737f310a15e984f920730448f99a895893bed351df
|
Label "Needs backport 0.18" ? |
Summary: **Pull Request#16366** fa6f402bde146f92ed131e0c9c8e15a55e723307 Call node->initError instead of InitError from GUI code (Russell Yanofsky) fad2502240a1c440ef03ac3f880475702e418275 init: Use InitError for all errors in bitcoind/qt (MarcoFalke) Description: Using the same InitError for startup error in the daemon and the gui makes it possible to run the tests with the gui again: (N.f.B: Depends on D5794) ```sh BITCOIND=bitcoin-qt ./test/functional/test_runner.py feature_includeconf feature_config_args ``` --- **Pull Request#15864** ffea41f5301d5582665cf10ba5c2b9547a1443de Enable all tests in feature_config_args.py (Hennadii Stepanov) Description: Fix broken `feature_config_args.py` tests (disabled by MarcoFalke@fabe28a0cdcfa13e0e595a0905e3642a960d3077). All test are enabled now. --- This is a backport of Core [[bitcoin/bitcoin#16366 | PR16366]] with a partial backport of core [[bitcoin/bitcoin#15864 | PR15864]] Test Plan: ninja check check-functional Reviewers: deadalnix, #bitcoin_abc Reviewed By: deadalnix, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D5807
Summary: Merge #15864: Fix datadir handling ~~ffea41f5301d5582665cf10ba5c2b9547a1443de Enable all tests in feature_config_args.py (Hennadii Stepanov)~~ (N.f.B. backported in D5807) 66f5c17f8a3fe06fc65191e379ffc04e43cbbc86 Use CheckDataDirOption() for code uniformity (Hennadii Stepanov) 7e33a18a34b1a9b0f115076c142661d6d30c0585 Fix datadir handling in bitcoin-cli (Hennadii Stepanov) b28dada37465c0a773cf08b0e6766f0081bcb943 Fix datadir handling in bitcoin-qt (Hennadii Stepanov) 50824093bb2d68fe1393dfd636fab5f8795faa5d Fix datadir handling in bitcoind (Hennadii Stepanov) 740d41ce9f7fdf209366e930bd0fdcc6b1bc6b79 Add CheckDataDirOption() function (Hennadii Stepanov) c1f325126cf51d28dce8da74bfdf5cd05ab237ea Return absolute path early in AbsPathForConfigVal (Hennadii Stepanov) Pull request description: Fix #15240, see: bitcoin/bitcoin#15240 (comment) Fix #15745 Fix broken `feature_config_args.py` tests (disabled by MarcoFalke@fabe28a0cdcfa13e0e595a0905e3642a960d3077). All test are enabled now. This PR is alternative to #13621. User's `$HOME` directory is not touched unnecessarily now. ~To make reviewing easier only `bitcoind` code is modified (neither `bitcoin-cli` nor `bitcoin-qt`).~ Refs: - bitcoin/bitcoin#15745 (comment) by **laanwj** - #16220 --- Depends on D5807 This is a partial backport of Core [[bitcoin/bitcoin#15864 | PR15864]] Test Plan: ninja check check-functional Reviewers: deadalnix, #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D5812
6358d70 Fix datadir handling in pivx-cli (Hennadii Stepanov) 8fbbd16 Fix datadir handling in pivx-qt (Hennadii Stepanov) aa397eb Fix datadir handling in pivxd (Hennadii Stepanov) 2862a75 Add CheckDataDirOption() function (Hennadii Stepanov) 3303376 Make PID file creating errors fatal (furszy) Pull request description: Backporting: * bitcoin#15278. * bitcoin#15864. ACKs for top commit: Fuzzbawls: ACK 6358d70 random-zebra: utACK 6358d70 Tree-SHA512: ad906fa2ae859d489b62a5a79830186fa6f252cc5fb88b1d628768d985fb93bd1d3c3eda38c83f77bb37f08a52df3278a78a4990de9e0d1dc29a6b77eb9209eb
Fix #15240, see: #15240 (comment)
Fix #15745
Fix broken
feature_config_args.pytests (disabled by MarcoFalke@fabe28a0cdcfa13e0e595a0905e3642a960d3077). All test are enabled now.This PR is alternative to #13621.
User's
$HOMEdirectory is not touched unnecessarily now.To make reviewing easier onlybitcoindcode is modified (neitherbitcoin-clinorbitcoin-qt).Refs: