-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Deduplicate bitcoind and bitcoin-qt init code #27150
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.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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. |
Leaving as draft because #27073 could be merged first, and if it is, more duplicate code can be moved to the common function. |
concept ack |
Concept ACK - #27073 has now been merged. |
Concept ACK. |
ebc1659
to
e248926
Compare
Marking ready for review since I was able to merge the duplicate InitSettings functions after #27073. Rebased eeff271 -> e248926 ( |
e248926
to
25f9cbf
Compare
Updated e248926 -> 25f9cbf ( |
25f9cbf
to
15cb0a2
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.
Updated 25f9cbf -> 15cb0a2 (pr/oneconfig.3
-> pr/oneconfig.4
, compare) fixing lint error https://cirrus-ci.com/task/6543913792569344?logs=lint#L230
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.
Concept ACK
} catch (const std::exception& e) { | ||
return InitError(Untranslated(strprintf("%s", e.what()))); | ||
if (auto error = common::InitConfig(args)) { | ||
return InitError(error->message, error->details); | ||
} | ||
|
||
// Error out when loose non-argument tokens are encountered on command line |
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.
More a comment in case anybody else stumbles over this than a change request, but I'm surprised this is done in bitcoind
and not in bitcoin-qt
. Indeed I can start bitcoin-qt with any number of positional arguments, e.g. ./qt/bitcoin-qt h j k
, but not so bitcoind
. The historical context is that this is a leftover from when bitcoind
was also used as a command line client.
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.
Maybe it makes sense from the beginning to add src/common/init.cpp
to the list of files which are processed by IWYU in ci/test/06_script_b.sh
?
Some InitError calls had trailing \n characters, causing double newlines in error output. After this change InitError calls consistently output one newline instead of two. Appearance of messages in the GUI does not seem to be affected. Can be tested with: src/bitcoind -regtest -datadir=noexist src/qt/bitcoin-qt -regtest -datadir=noexist -BEGIN VERIFY SCRIPT- git grep -l InitError src/ | xargs sed -i 's/\(InitError(.*\)\\n"/\1"/' -END VERIFY SCRIPT-
Previous bilingual_str tinyformat::format accepted bilingual format strings, but not bilingual arguments. Extend it to accept both. This is useful when embedding one translated string inside another translated string, for example: `strprintf(_("Error: %s"), message)` which would fail previously if `message` was a bilingual_str.
This is only used in the current PR to avoid ugly `strprintf(Untranslated("%s:\n%s"), str, MakeUnorderedList(details)` boilerplate in init code. But in the future the function could be extended and more widely used to include more details in GUI error messages or display them in a more readable way, see code comment.
Add common InitConfig function to deduplicate bitcoind and bitcoin-qt code reading config files and creating the datadir. There are a few minor changes in behavior: - In bitcoin-qt, when there is a problem reading the configuration file, the GUI error text has changed from "Error: Cannot parse configuration file:" to "Error reading configuration file:" to be consistent with bitcoind. - In bitcoind, when there is a problem reading the settings.json file, the error text has changed from "Failed loading settings file" to "Settings file could not be read" to be consistent with bitcoin-qt. - In bitcoind, when there is a problem writing the settings.json file, the error text has changed from "Failed saving settings file" to "Settings file could not be written" to be consistent with bitcoin-qt. - In bitcoin-qt, if there datadir is not accessible (e.g. no permission to read), there is an normal error dialog showing "Error: filesystem error: status: Permission denied [.../settings.json]", instead of an uncaught exception
15cb0a2
to
802cc1e
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.
Thanks for the reviews!
Rebased 15cb0a2 -> 802cc1e (pr/oneconfig.4
-> pr/oneconfig.5
, compare) due to conflict with #27170 and applied suggestions
I don't know of a way to trigger the If it helps, I used the following commands for testing the other errors in the PR: src/bitcoind -regtest -conf=bad
src/qt/bitcoin-qt -regtest -conf=bad
src/qt/bitcoin-qt -regtest
echo bad > ~/.bitcoin/regtest/settings.json
sudo chown root ~/.bitcoin/regtest
sudo chmod 755 ~/.bitcoin/regtest
sudo chmod 700 ~/.bitcoin/regtest
sudo chown 1000:1000 ~/.bitcoin/regtest |
ACK 802cc1e |
ACK 802cc1e |
Add common InitConfig function to deduplicate bitcoind and bitcoin-qt code reading config files and creating the datadir.
Noticed the duplicate code while reviewing #27073 and want to remove it because difference in bitcoin-qt and bitcoind behavior make it hard to evaluate changes like #27073
There are a few minor changes in behavior: