HomePhabricator

Deduplicate bitcoind and bitcoin-qt init code

Description

Deduplicate bitcoind and bitcoin-qt init code

Summary:

Remove double newlines after some init errors

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

Add InitError(error, details) overload

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.

Deduplicate bitcoind and bitcoin-qt init code

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

This is a backport of core#27150 and core-gui#690 (dependency and bugfix)

Depends on D18215

Test Plan:
ninja all check-all

core-gui#690
add testnet=1 to bitcoin.conf and check error dialog (instead of runtime error) when calling src/qt/bitcoin-qt -regtest

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D18216

Details

Provenance
PiRKAuthored on Jun 6 2025, 13:14
PiRKPushed on Jun 9 2025, 09:43
Reviewer
Restricted Project
Differential Revision
D18216: Deduplicate bitcoind and bitcoin-qt init code
Parents
rABC02b2e1cd80b4: [Cashtab] Add code splitting to improve initial load time
Branches
Unknown
Tags
Unknown