2 minor findings · 2 suggestions
Findings
[minor] · Unchecked transaction rewrites can leave records missing after migration
If a transaction rewrite fails without preventing commit, migration can report success while omitting that transaction because the original TX record is no longer copied; no production occurrence was identified.
Location: src/wallet/wallet.cpp:4240 (head).
Details and suggested fix
For retained transactions, local_wallet_batch.WriteTxMetadata(*wtx) is now the only write of the TX record, but its boolean result is discarded. Previously, the checked database-copy step had already persisted the original record. SQLite can return a statement-level failure without aborting the transaction, and RunWithinTxn checks only the callback result and commit. If the remaining operations succeed, the migrated wallet can therefore load without that transaction. An up-to-date copied best-block locator can suppress the historical rescan needed to recover it, leaving balance and history incomplete until a manual rescan or backup restore. Check the rewrite result and return util::Error on failure so the existing migration rollback restores the backup.
[minor] · Malformed unknown BDB keys now make migration throw
Migration now throws on malformed keys in otherwise loadable corrupted or hand-crafted BDB wallets that previously migrated; no Bitcoin Core producer of these malformed keys was found.
Location: src/wallet/wallet.cpp:3727 (head).
Details and suggested fix
Wallet loading reads known record prefixes, so an additional malformed key outside those prefixes is ignored. MigrateToSQLite now parses a type string from every raw key instead of copying unknown records unchanged. An empty key or an invalid serialized string length throws std::ios_base::failure, preventing migration even when the wallet's recognized records are intact. The exception occurs after backup creation and before removal of the original database, so neither file is lost. Compare raw keys against the serialized skip-type prefixes, as the prefix-based loaders already do, and preserve unmatched records without deserializing them.
Optional improvements
[suggestion] · The transaction-removal list is now write-only
Removing RemoveTxs leaves migration accumulating transaction IDs in an unused vector under a comment describing the deleted removal step.
Location: src/wallet/wallet.cpp:3984 (base).
Details and suggested fix
The deleted block was the only reader of txids_to_delete, so the remaining push_back operations allocate and store IDs without affecting migration. Remove the vector and its push_back, but keep the continue: that now prevents rewriting watch-only-only transactions into the main wallet after MigrateToSQLite skips their TX records. Update the comment to describe intentionally skipping the rewrite rather than marking a transaction for later removal.
[suggestion] · Skipped records still incur temporary key and value copies
The one-time migration still copies every skipped legacy or transaction record into owning buffers before discarding it, including full transaction values.
Location: src/wallet/wallet.cpp:3723 (head).
Details and suggested fix
Compare the raw key against serialized skip-type prefixes before constructing the SerializeData buffers, then copy only retained records. This avoids temporary allocations and byte copies for records the migration will never write. The saving is modest because BerkeleyRO already holds the records in memory. Do not merely move the constructions below ss_key >> type: extraction advances the stream and can clear its buffer when fully consumed, so that would lose part or all of a retained raw key.