feat(wallet): add a Compact action to reclaim space after consolidating

Consolidating reduces the note count and stops the wallet growing, but Berkeley
DB never shrinks wallet.dat in place, so the freed space isn't returned to the OS
and the displayed size doesn't drop. Add an explicit "Compact wallet…" action
(next to "Consolidate notes…" in the large-wallet area of Node & Security) that
rewrites the file into a fresh, compact one.

App::compactWallet() arms the daemon's -salvagewallet flag for the next start and
calls restartDaemon() (reusing its full-node / busy / lifecycle guards); the
daemon rewrites wallet.dat into a smaller file, keeps the old one as a timestamped
.bak, and — because -salvagewallet implies -rescan — re-scans the chain. If the
restart is refused the salvage flag is disarmed so it can't fire on a later
restart. A confirmation overlay (mirroring the repair-wallet one) explains the
restart + rescan + that funds/balance are safe and a backup is kept. New strings
wallet_size_compact / tt_wallet_size_compact / compact_started /
confirm_compact_wallet_{title,msg,safe} / compact_wallet_confirm.

Build + tests + hygiene green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 17:24:21 -05:00
co-authored by Claude Opus 4.8
parent 1a01de9791
commit 4dfdf8a36f
4 changed files with 65 additions and 0 deletions
+18
View File
@@ -6500,6 +6500,24 @@ void App::maybeWarnLargeWallet()
TR("wallet_size_consolidate"), 12.0f);
}
void App::compactWallet()
{
auto& n = ui::Notifications::instance();
if (!supportsFullNodeLifecycleActions() || !daemon_controller_) {
n.warning(TR("appx_fullnode_lifecycle_unavailable_lite"));
return;
}
// Consolidation frees internal BDB pages but never returns the space to the OS; -salvagewallet on the
// next start rewrites wallet.dat into a fresh, compact file (and keeps the old one as a timestamped
// .bak). It implies a full rescan, so restartDaemon() takes the node down and back up re-scanning.
daemon_controller_->setSalvageOnNextStart(true);
restartDaemon(); // does its own full-node / busy / lifecycle guards and will refuse if the node is busy
if (daemon_restarting_.load())
n.info(TR("compact_started"));
else
daemon_controller_->setSalvageOnNextStart(false); // the restart was refused — disarm the stray salvage
}
// 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