feat(wallet): one-click "switch to the built-in node and compact"

When connected to an external/standalone dragonxd (the wallet adopted a running
node, so daemon_controller_ is null), Compact couldn't run. Add a path that does
it in one click: compactViaEmbeddedSwitch() gates the connect loop, drops the RPC
connection, and on the worker gracefully stops the external node (RPC "stop" with
our credentials, via stopDaemonForWalletSwitch) and waits for the port; back on
the main thread it switches the wallet to its built-in node and starts it with a
one-shot compact_on_embedded_start_ flag that arms -salvagewallet, so the fresh
node rewrites wallet.dat (and rescans). On stop failure nothing is changed and
the external node stays up.

The Compact button is now enabled whenever the build can run the embedded node;
its confirmation branches — direct compact when the wallet already runs the
built-in node (canCompactWallet), else a clear message (confirm_compact_switch_
msg) that it will stop the external node, switch to the built-in one, and that
this changes which node binary runs. New strings confirm_compact_switch_msg /
compact_switching / compact_switch_stop_failed.

Mirrors restartDaemon's disconnect + background stop pattern; controller creation
stays on the main thread. Can't be runtime-verified here (no live daemon). Build
+ tests + hygiene green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-10-27 11:41:49 -05:00
co-authored by Claude Opus 4.8
parent a5cd211e89
commit 16d60a72f2
5 changed files with 73 additions and 5 deletions
+46
View File
@@ -6525,6 +6525,52 @@ void App::compactWallet()
daemon_controller_->setSalvageOnNextStart(false); // the restart was refused — disarm the stray salvage
}
void App::compactViaEmbeddedSwitch()
{
auto& n = ui::Notifications::instance();
if (!supportsFullNodeLifecycleActions() || !supportsEmbeddedDaemon()) {
n.warning(TR("appx_fullnode_lifecycle_unavailable_lite"));
return;
}
if (canCompactWallet()) { compactWallet(); return; } // already on the built-in node — just compact
if (daemon_restarting_.load() || isWalletSwitchInProgress() || show_seed_migration_ ||
(settings_ && settings_->getSeedMigrationPending())) {
n.warning(TR("merge_run_busy"));
return;
}
if (!worker_) return;
// Gate the connect loop / auto-start while we swap nodes, then drop the RPC connection to the external
// node (we're about to tell it to stop). onDisconnected shows the loading overlay.
daemon_restarting_ = true;
connection_status_ = TR("compact_switching");
if (rpc_ && rpc_->isConnected()) { abortMaintenanceCalls(); rpc_->disconnect(); }
onDisconnected("Compact: switch to the built-in node");
n.info(TR("compact_switching"), 12.0f);
worker_->post([this]() -> rpc::RPCWorker::MainCb {
// Graceful RPC "stop" to the external node + wait (up to ~20 s) for its RPC port to free. Blocking,
// so it runs on the worker; no RPC is needed meanwhile (we just disconnected).
const bool stopped = stopDaemonForWalletSwitch();
return [this, stopped]() { // back on the main thread
daemon_restarting_ = false;
if (shutting_down_.load()) return;
if (!stopped) {
ui::Notifications::instance().error(TR("compact_switch_stop_failed"));
return; // the external node is still up; nothing was changed
}
// Switch the wallet to its built-in node, arm the compacting start, and bring it up. The fresh
// node starts with -salvagewallet (rewrite + rescan); the connect loop reconnects to it. (Embedded
// mode is a runtime flag that defaults on for a full-node build, so this just ensures it's set —
// after the switch our own process is the running node.)
setUseEmbeddedDaemon(true);
compact_on_embedded_start_.store(true);
ui::Notifications::instance().info(TR("compact_started"));
startEmbeddedDaemon();
};
});
}
// Complementary on-disk safety net (full-node) for a wallet salvage we did NOT witness this launch — it
// happened on a prior run, or under an external daemon whose startup output we never captured, so
// detectWalletAutoRecovery() never fired. If the active wallet loads EMPTY while a sibling wallet file in