fix(node): detect a wallet salvage at startup, not only on connect

Reported: loading a BDB-inconsistent wallet silently renamed it and created a new
one — no recovery dialog. Two causes, both fixed:

1) Detection ran only in onConnected(). The salvage happens at STARTUP, and the
   node may never connect (block-index abort, long sync, crash) — or a long sync
   trims the salvage line out of the rolling output buffer before connect. Extract
   detectWalletAutoRecovery() and run it every tryConnect() tick (every ~5s during
   startup), so the salvage is caught the instant it appears, regardless of whether
   the node connects. Also hold the crash-restart loop while a salvage is pending,
   so the wallet can't be re-salvaged/shrunk while the Rebuild/Restore dialog is up.

2) walletAutoRecovered() only matched the SUCCESSFUL-salvage strings. A
   BDB-inconsistent file makes aggressive salvage FAIL ("found no records"), which
   prints different lines. Broaden the detector to the signals that fire in every
   case: "CDBEnv::Salvage", the "Renamed <wallet> to wallet.<ts>.bak" rename, and
   "found no records in wallet" — while still not matching normal startup or a
   block-DB abort.

Adds the exact failed-salvage sequence to the detector test. Build clean, suite
green (1/1).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-10 12:04:07 -05:00
parent 8ffcd9cc8c
commit 3216debc7d
5 changed files with 47 additions and 16 deletions

View File

@@ -6157,6 +6157,12 @@ void testBlockDbOutputDiagnosis()
EXPECT_TRUE(walletAutoRecovered(
"Warning: wallet.dat corrupt, data salvaged! Original wallet.dat saved as wallet.1786300000.bak in ..."));
EXPECT_TRUE(walletAutoRecovered("wallet.dat corrupt, salvage failed"));
// The FAILED-salvage sequence a BDB-inconsistent wallet actually produces (must also be detected —
// this is the case that previously slipped through and silently emptied the wallet).
EXPECT_TRUE(walletAutoRecovered(
"Renamed wallet.dat to wallet.1786375505.bak\n"
"CDBEnv::Salvage: Database salvage found errors, all data may not be recoverable.\n"
"Salvage(aggressive) found no records in wallet.1786375505.bak.\n"));
EXPECT_FALSE(walletAutoRecovered("Loading wallet...\nWallet completed loading\n")); // normal load
EXPECT_FALSE(walletAutoRecovered(": Error loading block database.")); // block-DB abort != salvage
EXPECT_FALSE(walletAutoRecovered(""));