From 4b9d6f7db5b21eb89fd034d87385afd3e4ea94c9 Mon Sep 17 00:00:00 2001 From: DanS Date: Fri, 5 Jun 2026 11:32:54 -0500 Subject: [PATCH] fix(lite): rebuild controller on lite-server change (stale-settings audit HIGH) The LiteWalletController was constructed once at App::init() with the lite connection settings known at startup; changing the lite server in Settings persisted to disk but never reached the live controller, so the new server had no effect until the next launch. Factor the construction into App::rebuildLiteWallet() and call it after a successful server-selection save. The rebuild deliberately preserves a live session: if a wallet is already open (and possibly mid-sync), it no-ops and the new selection applies on the next controller build, rather than discarding the open wallet and its uninterruptible in-flight sync. Closes the last remaining HIGH from the session audit. Co-Authored-By: Claude Opus 4.8 --- src/app.cpp | 22 ++++++++++++++++------ src/app.h | 3 +++ src/ui/pages/settings_page.cpp | 3 +++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index 22ef018..2e3e277 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -169,12 +169,7 @@ bool App::init() // Lite builds with a linked SDXL backend own a lite wallet controller that drives // real create/open/restore through the bridge. Full-node and unlinked-lite builds // leave lite_wallet_ null (the UI falls back to validation-only). - if (supportsLiteBackend()) { - lite_wallet_ = wallet::LiteWalletController::createLinked( - walletCapabilities(), - wallet::liteConnectionSettingsFromAppSettings(*settings_)); - lite_wallet_->setPersistCallback([this]() { settings_->save(); }); - } + rebuildLiteWallet(); // Apply verbose logging preference from saved settings util::Logger::instance().setVerbose(settings_->getVerboseLogging()); @@ -370,6 +365,21 @@ void App::preFrame() } } +void App::rebuildLiteWallet() +{ + if (!supportsLiteBackend() || !settings_) return; + // Don't tear down a live session: if a wallet is already open (and possibly mid-sync), the + // new server selection is already persisted to settings and will take effect the next time + // the controller is built (next launch, or before another wallet is opened). Rebuilding now + // would discard the open wallet and its in-flight, uninterruptible sync. + if (lite_wallet_ && lite_wallet_->walletOpen()) return; + + lite_wallet_ = wallet::LiteWalletController::createLinked( + walletCapabilities(), + wallet::liteConnectionSettingsFromAppSettings(*settings_)); + lite_wallet_->setPersistCallback([this]() { settings_->save(); }); +} + void App::update() { PERF_SCOPE("Update.Total"); diff --git a/src/app.h b/src/app.h index 4629112..2abb5e7 100644 --- a/src/app.h +++ b/src/app.h @@ -157,6 +157,9 @@ public: config::Settings* settings() { return settings_.get(); } // Lite wallet controller (non-null only in lite builds with a linked backend). wallet::LiteWalletController* liteWallet() { return lite_wallet_.get(); } + // (Re)build the lite controller from current settings so a changed lite-server selection + // takes effect. No-op on non-lite/unlinked builds; preserves a live wallet (see app.cpp). + void rebuildLiteWallet(); WalletState& state() { return state_; } const WalletState& state() const { return state_; } const WalletState& getWalletState() const { return state_; } diff --git a/src/ui/pages/settings_page.cpp b/src/ui/pages/settings_page.cpp index 40ca07f..83177fd 100644 --- a/src/ui/pages/settings_page.cpp +++ b/src/ui/pages/settings_page.cpp @@ -197,6 +197,9 @@ static void saveLiteServerSelectionFromPageState(App* app) { const auto result = wallet::executeLiteWalletServerSelectionUi(*app->settings(), input); if (result.settingsWritten) { s_settingsState.lite_server_status = "Saved"; + // Rebuild the lite controller so the newly-saved server actually takes effect (it is + // otherwise captured once at startup). No-op if a wallet is already open mid-session. + app->rebuildLiteWallet(); } else if (!result.error.empty()) { s_settingsState.lite_server_status = result.error; Notifications::instance().warning(result.error);