2 minor findings · 4 suggestions
Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.
Findings
[minor] · Pre-rename MoveDatabase failures still replace an intact directory wallet
For directory wallets, pre-rename MoveDatabase errors trigger deletion of the untouched original and restoration from backup, adding an avoidable restoration failure point.
Location: src/wallet/migration.cpp:175 (head).
Details and suggested fix
A leftover wallet.dat-journal is rejected before the rename, while the original directory wallet remains intact. Nevertheless, MigrateToSQLite throws, and rollback removes m_database->Files(), which still identifies the BerkeleyRO original, before calling RestoreWallet. If that copy fails, manual recovery from the retained backup is needed. Have MoveDatabase report whether replacement occurred, and clean up the temporary database and return false when a directory wallet remains untouched. Keep restoration for an already-erased plain-file wallet or a failure after replacement. The journal tests currently check only BDB magic, so they cannot distinguish preservation from deletion and restoration; retain a hard link and assert file identity after refusal.
[minor] · Temporary-directory cleanup assumes ownership without reserving the path
If another operation creates tmp_wallet_path after the absence check, failure cleanup can delete its files; no current caller producing this race was identified.
Location: src/wallet/migration.cpp:111 (head).
Details and suggested fix
The timestamp-derived name is predictable, and nothing reserves it between symlink_status and MakeDatabase. If a recognized database appears there during that window, MakeDatabase rejects it because require_create is set, but remove_tmp_and_fail then removes its directory entries. A symlink inserted in the same window makes enumeration follow the target directory. Ignoring the lookup's error code also permits proceeding without establishing absence. Create the directory atomically with fs::create_directory and continue only when this call created it. If it already exists or creation fails, return without enumerating or deleting its contents.
Optional improvements
[suggestion] · Escaped temporary databases are advertised as wallets
The temporary-build approach improves failure safety, but exceptions or process termination can leave _sqlite_*.tmp databases visible through listwalletdir.
Location: src/wallet/migration.cpp:125 (head).
Details and suggested fix
RunWithinTxn calls MakeBatch, whose SQLite constructor can throw while preparing statements. That skips remove_tmp_and_fail, and the outer rollback tracks only the main and auxiliary wallets, not the temporary database. Its schema and application_id are already initialized, so recursive wallet discovery recognizes the leftover directory. A retry at a later timestamp does not remove it. Use a scope guard to close and remove the owned temporary database on controlled exceptions. That guard cannot handle process termination; a reserved migration marker excluded from wallet discovery would also keep interrupted builds from being offered as wallets.
[suggestion] · Recoverable transaction failures lack migration coverage
The tests do not exercise the newly recoverable begin, record-write, or commit failures in MigrateToSQLite.
Location: src/wallet/migration.cpp:155 (head).
Details and suggested fix
These failures now return false after destroying the transaction batch and removing the temporary database, so the caller deliberately skips backup restoration. The permission test fails during database construction, and the journal tests fail during the move; neither verifies this preservation-and-cleanup path. Add an injectable database factory or builder accepting a WalletDatabase, then fail transaction begin, a mid-stream write, and commit separately. Assert that the original BDB file remains byte-identical, no _sqlite_*.tmp remains, and migration succeeds once the injected failure is removed.
[suggestion] · Auxiliary descriptor-import exceptions lack rollback coverage
Existing failure tests stop before creating the failing auxiliary wallet, so they do not verify cleanup after descriptor import throws.
Location: src/wallet/migration.cpp:503 (head).
Details and suggested fix
An AddWalletDescriptor failure occurs after out_wallet is assigned. The helper catches it and returns false, and rollback finds the partially populated wallet only because the caller copies it into res before checking that return value. The pre-existing-database tests do not exercise this dependency. Add a fault-injection seam that fails import after at least one descriptor has been added. Check that the original wallet's checksum is unchanged, no migration-created auxiliary directory remains, and migration succeeds after removing the injected failure.
[suggestion] · Changed migratewallet recovery behavior has no release note
The PR changes user-visible migration recovery and adds a manual sidecar-removal requirement, but provides no release note describing those changes.
Location: src/wallet/migration.cpp:632 (head).
Details and suggested fix
Handled creation, transaction, and migration failures can now leave the original untouched or restore it automatically instead of asserting or leaving partial migration state. An unexpected destination sidecar also refuses migration until the user moves it elsewhere. Add a short doc/release-notes-<PR>.md snippet explaining these recovery improvements and the sidecar prerequisite for retry. Describe the handled cases rather than promising recovery from every failure; the developer notes explicitly call for release notes for significant fixes and visible user-experience changes.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [suggestion]: Caught migration exceptions can retain
success = true(earlier report)
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
The original SQLite migration deliberately stopped execution after destructive replacement failed: the original database had already been deleted, and continuing with an absent or incompletely written replacement was considered unsafe. Its assertions explicitly relied on an existing backup; the low-level migration function did not create that backup itself.
At the pinned base, database creation and transaction begin/write/commit failures still use this fail-stop contract. The head changes how that boundary is handled, but the historical objective was preservation of recoverable wallet data—not a claim that replacement could never fail or that every failure was automatically reversible.
Migration backup naming was changed because wallet names are also filesystem paths. Reusing an absolute or relative wallet path as a filename could place the backup somewhere unintended or unwritable. The chosen behavior puts backups directly in walletdir and derives a single-component prefix from the wallet directory or plain-file name.
The head's MigrationFilePrefix preserves this distinction between a logical wallet name/path and a safe filename component. The backup remains in walletdir even when the source wallet is elsewhere; the temporary replacement database is instead built beside the source database.
Cleanup was narrowed from recursive directory deletion to migration-owned database files because a wallet's parent directory is not necessarily owned by that wallet. In particular, the unnamed wallet lives directly in walletdir, so deleting its parent could destroy other wallets and the backup. Restoration was consequently adapted to accept an existing directory without overwriting an existing database.
Both base and head track database Files(), preserve the original wallet directory, and remove auxiliary-wallet directories only non-recursively. RestoreWallet copies the backup without overwrite and migration requests restoration without loading the legacy wallet. These are bounded preservation guarantees, not authority to erase everything under a wallet path.
Source 1 · Source 2 · Source 3
Migration originally moved to an unloaded, locally loaded wallet without normal signal connections to avoid locking and lifetime problems, including waiting indefinitely for GUI-held shared pointers to disappear.
Cleanup ownership includes object lifetime as well as filenames. The pinned rollback waits for normally loaded wallets to be deleted, but requires sole ownership before resetting local wallets. Capturing file paths before dropping or reloading those objects preserves the cleanup inventory when a later load fails.
The earlier cleanup review explicitly required using the database file inventory to remove SQLite's journal as well as its main data file. It also recognized that successful conversion was not the final success condition: subsequent wallet loading could still fail and require rollback.
SQLite Files() already includes wallet.dat and wallet.dat-journal at the comparison base. Accordingly, the database object determines more than the principal filename, and rollback remains relevant after record conversion has completed. Moving or replacing the database must be understood together with this inventory and the later reload phase.
The writable-directory change sought to reject unusable wallets before later writes crashed the node. Its rationale distinguished actual writability from permission bits, using a temporary-file probe because permission metadata alone can be misleading.
Migration creation, replacement, and restoration all require filesystem operations beyond reading the original database. This history explains why read-only locations are operational failure conditions rather than merely unusual permissions, without implying that an initial writability check guarantees all subsequent operations will succeed.
Ralph's inferences
The head makes the old destructive-operation boundary explicit: failure before replacement can leave the original database untouched, whereas failure after possible erasure or replacement must enter backup restoration. A completed database transaction alone is not completion of the entire migration.
MigrateToSQLite returns false for construction failures, but throws after the original may have changed; its caller catches exceptions and reaches rollback. It also changes m_database ownership to the replacement so the existing Files()-based cleanup identifies the new database. This is an interpretation of the pinned control flow, not an independently documented guarantee of crash recovery.
Backup restoration preserves wallet contents more strongly than original filesystem layout. A directory wallet permits replacement of its data file by rename, while a plain-file wallet must change from a file into a directory and cannot use the same atomic replacement operation.
The head explicitly separates these cases and builds the temporary database beside the source to support same-filesystem movement. Earlier discussion already acknowledged that a failed plain-file migration could restore as a directory wallet. Thus 'restore the original wallet' historically did not necessarily mean recreating its original path shape.
A database's expected ancillary filenames are not proof that files already present at those names belong to the current migration. Interrupted work or another process can leave state that must not automatically be treated as disposable.
The head refuses pre-existing temporary paths and unexpected destination sidecars. Its movement code explains that a stale SQLite journal could be replayed into the replacement database. This connects corruption avoidance with the earlier cleanup-ownership rule: known files of a newly created database and unknown pre-existing destination files are different ownership classes.
The current legacy reader's single-file inventory is narrower than the artifacts historically created by Berkeley DB environments.
The later migration design intentionally removed the Berkeley DB dependency, and BerkeleyRODatabase now reports only its source file. This supports the head's single-file erasure assumption for plain-file migration, but does not imply ownership of every historical log, lock, or directory beside that file.
Unresolved disagreements
The inspected discussion did not settle the broader policy question of whether failed migration artifacts should ever be deleted. Some participants preferred preserving or renaming them for possible recovery; the implemented urgent fix retained deletion limited to migration-owned files.
This is the historical tradeoff behind cleanup ownership: automatic rollback avoids leaving partial wallets, while retaining artifacts can preserve recovery options. It contextualizes temporary-database and failed-wallet cleanup without establishing that either policy proves the present implementation correct or incorrect.