Stabilize pre-init datadir and settings resolution #812

Closed
jarolrod wants to merge 1 commit from settings-stablize into qt6 AGit
jarolrod commented 2026-07-28 16:52:12 +00:00 (Migrated from github.com)

This is a follow-up to #742.

Pre-init onboarding was doing too much work against the live gArgs. It read config and settings to build the preview, then normal startup called InitConfig() on the same ArgsManager. If bitcoin.conf redirected the datadir, the second config read could start from a different place and fail before the main window opened.

-resetguisettings had a similar ordering problem. We could reset the bootstrap profile before Core had resolved the datadir and network it was actually going to use.

This switches the pre-init reads to a scratch ArgsManager built from the original argv. The datadir selected in onboarding is kept separate from the one resolved through config, and settings changes are finalized after InitConfig() and the chain-specific QSettings setup.

A few related pieces are handled in the same path:

  • -resetguisettings=0 is treated as false.
  • Reset uses the final Core settings precedence.
  • strDataDir is preserved when GUI settings are cleared.
  • Core and GUI settings are backed up and rolled back if a later write fails.
  • Settings stores are only opened and synced when they are actually needed.
  • An onboarding apply is rejected if the datadir, chain, settings path, or reset value changed while the window was open.
  • Reset can recover an unreadable settings.json through the existing reset-or-abort flow.

Cancelling onboarding remains non-mutating. No settings are cleared and no backups are created.

Fixes #773.

Fixes #774.

This is related to #600, but does not close it. The Settings-page actions and bitcoin.conf opening flow are still separate work.

#775 also remains open. An existing saved datadir that cannot be traversed can still fail before the chooser is shown.

This is a follow-up to #742. Pre-init onboarding was doing too much work against the live `gArgs`. It read config and settings to build the preview, then normal startup called `InitConfig()` on the same `ArgsManager`. If `bitcoin.conf` redirected the datadir, the second config read could start from a different place and fail before the main window opened. `-resetguisettings` had a similar ordering problem. We could reset the bootstrap profile before Core had resolved the datadir and network it was actually going to use. This switches the pre-init reads to a scratch `ArgsManager` built from the original argv. The datadir selected in onboarding is kept separate from the one resolved through config, and settings changes are finalized after `InitConfig()` and the chain-specific `QSettings` setup. A few related pieces are handled in the same path: - `-resetguisettings=0` is treated as false. - Reset uses the final Core settings precedence. - `strDataDir` is preserved when GUI settings are cleared. - Core and GUI settings are backed up and rolled back if a later write fails. - Settings stores are only opened and synced when they are actually needed. - An onboarding apply is rejected if the datadir, chain, settings path, or reset value changed while the window was open. - Reset can recover an unreadable `settings.json` through the existing reset-or-abort flow. Cancelling onboarding remains non-mutating. No settings are cleared and no backups are created. Fixes #773. Fixes #774. This is related to #600, but does not close it. The Settings-page actions and `bitcoin.conf` opening flow are still separate work. #775 also remains open. An existing saved datadir that cannot be traversed can still fail before the chooser is shown.
epicleafies (Migrated from github.com) reviewed 2026-07-31 13:40:42 +00:00
epicleafies (Migrated from github.com) left a comment

tested ACK 49c2f253

Built on Qt 6.4.2, unit and functional suites green, plus a headed pass under xcb. Confirmed the reset targets the resolved datadir's settings.json (custom datadir kept, default untouched), config-redirected datadirs reach the main window, and -resetguisettings=0 is a no-op.

Two items the green suites do not catch (both headed-only) are inline: #775 (an unreadable saved datadir still aborts at startup, a hard crash rather than a soft failure; details on the issue) and an empty reset backup when settings.json is unparseable. A few smaller issues inline too.

tested ACK 49c2f253 Built on Qt 6.4.2, unit and functional suites green, plus a headed pass under xcb. Confirmed the reset targets the resolved datadir's settings.json (custom datadir kept, default untouched), config-redirected datadirs reach the main window, and -resetguisettings=0 is a no-op. Two items the green suites do not catch (both headed-only) are inline: #775 (an unreadable saved datadir still aborts at startup, a hard crash rather than a soft failure; details on the issue) and an empty reset backup when settings.json is unparseable. A few smaller issues inline too.
epicleafies (Migrated from github.com) commented 2026-07-31 13:27:35 +00:00

Nit: this string lost the translator comment that the Widgets ErrorSettingsRead carries. In bitcoin/src/qt/bitcoin.cpp the same setInformativeText has a /*: ... */ comment above it explaining the reset-or-abort choice for translators. Since this is the one translated string in the new code, restoring the comment keeps parity and satisfies the translator-comment convention.

Nit: this string lost the translator comment that the Widgets `ErrorSettingsRead` carries. In `bitcoin/src/qt/bitcoin.cpp` the same `setInformativeText` has a `/*: ... */` comment above it explaining the reset-or-abort choice for translators. Since this is the one translated string in the new code, restoring the comment keeps parity and satisfies the translator-comment convention.
epicleafies (Migrated from github.com) commented 2026-07-31 13:27:35 +00:00

This is #775, flagged at the fix point. Worth noting it is a hard crash (uncaught filesystem_error -> SIGABRT on a mode-000 saved datadir), not the soft failure the issue text implies. Since this diff already reworks this path, a try/catch(const std::exception&) around the ReadResolvedProfile call routed to status.error, mirroring the SelectParams guard, would close it here. Not blocking if you prefer to keep it in the follow-up.

This is #775, flagged at the fix point. Worth noting it is a hard crash (uncaught `filesystem_error` -> SIGABRT on a mode-000 saved datadir), not the soft failure the issue text implies. Since this diff already reworks this path, a `try/catch(const std::exception&)` around the `ReadResolvedProfile` call routed to `status.error`, mirroring the `SelectParams` guard, would close it here. Not blocking if you prefer to keep it in the follow-up.
epicleafies (Migrated from github.com) commented 2026-07-31 13:27:35 +00:00

Nit: these new startup-error strings reach the user via InitError but are untranslated QStringLiterals. Wrap the user-visible ones in tr() (with %1 placeholders rather than concatenation).

Nit: these new startup-error strings reach the user via `InitError` but are untranslated `QStringLiteral`s. Wrap the user-visible ones in `tr()` (with `%1` placeholders rather than concatenation).
epicleafies (Migrated from github.com) commented 2026-07-31 13:27:35 +00:00

Suggestion: when settings.json is unreadable and a reset is requested, this backup captures an already-emptied file. InitConfig runs first; on an unparseable settings.json, ReadSettingsFile clears rw_settings and fails, the read-error handler returns false to proceed, and InitConfig immediately writes an empty document. Only afterward does BackupSettingsFile run, so settings.json.bak holds the emptied file, not the original bytes. Reproduced: seed a corrupt settings.json, launch with -resetguisettings, finish onboarding; the .bak contains only the auto-generated header. Low severity since the data was unreadable and the user asked to reset, but the backup gives false reassurance in the one case it exists for.

Test gaps around this path: run_malformed_settings_reset_recovers does not assert .bak contents, and resetLegacyCleanupRollsBackOnWriteFailure (the only rollback-failure test for the legacy-cleanup path) is QSKIP'd off POSIX, so it is unverified on Windows CI. Consider backing up before InitConfig, or documenting the limitation, plus asserting the backup content.

Suggestion: when `settings.json` is unreadable and a reset is requested, this backup captures an already-emptied file. `InitConfig` runs first; on an unparseable `settings.json`, `ReadSettingsFile` clears `rw_settings` and fails, the read-error handler returns false to proceed, and `InitConfig` immediately writes an empty document. Only afterward does `BackupSettingsFile` run, so `settings.json.bak` holds the emptied file, not the original bytes. Reproduced: seed a corrupt `settings.json`, launch with `-resetguisettings`, finish onboarding; the `.bak` contains only the auto-generated header. Low severity since the data was unreadable and the user asked to reset, but the backup gives false reassurance in the one case it exists for. Test gaps around this path: `run_malformed_settings_reset_recovers` does not assert `.bak` contents, and `resetLegacyCleanupRollsBackOnWriteFailure` (the only rollback-failure test for the legacy-cleanup path) is `QSKIP`'d off POSIX, so it is unverified on Windows CI. Consider backing up before `InitConfig`, or documenting the limitation, plus asserting the backup content.
epicleafies (Migrated from github.com) commented 2026-07-31 13:27:35 +00:00

Suggestion: this rollback opens a fresh QSettings on the same file while the original active_gui_settings owner is still alive, so two QSettings back the same file with independent caches. The explicit restore sync() should win, but RestoreStores in legacy_settings_migration.cpp handles the same shape by resetting the owner first. The two rollback paths are inconsistent; resetting or rewriting through the existing object would be less fragile.

Suggestion: this rollback opens a fresh `QSettings` on the same file while the original `active_gui_settings` owner is still alive, so two `QSettings` back the same file with independent caches. The explicit restore `sync()` should win, but `RestoreStores` in `legacy_settings_migration.cpp` handles the same shape by resetting the owner first. The two rollback paths are inconsistent; resetting or rewriting through the existing object would be less fragile.
johnny9 (Migrated from github.com) reviewed 2026-08-03 13:56:59 +00:00
johnny9 (Migrated from github.com) left a comment

Two settings concerns:

Two settings concerns:
johnny9 (Migrated from github.com) commented 2026-08-03 13:57:00 +00:00

This opens and checks the active GUI settings file even when there is no onboarding change and no reset. I reproduced an unreadable file causing startup to stop before the main window, even though nothing needs to be changed. Can this store be opened only when it is actually needed? A test with an unreadable active store and no pending apply or reset would catch this.

This opens and checks the active GUI settings file even when there is no onboarding change and no reset. I reproduced an unreadable file causing startup to stop before the main window, even though nothing needs to be changed. Can this store be opened only when it is actually needed? A test with an unreadable active store and no pending apply or reset would catch this.
johnny9 (Migrated from github.com) commented 2026-08-03 13:57:00 +00:00

I think this should be fixed here. The reset succeeds, but settings.json.bak should contain the original malformed file, not the empty file written by InitConfig(). Since this PR adds the backup sequence, can it stage the original bytes before InitConfig() changes the file, keep them as .bak only after the reset succeeds, and test the backup contents?

I think this should be fixed here. The reset succeeds, but `settings.json.bak` should contain the original malformed file, not the empty file written by `InitConfig()`. Since this PR adds the backup sequence, can it stage the original bytes before `InitConfig()` changes the file, keep them as `.bak` only after the reset succeeds, and test the backup contents?
johnny9 commented 2026-09-09 13:24:23 +00:00 (Migrated from github.com)

Superseded by 883

Superseded by 883
Sign in to join this conversation.
No description provided.