Skip to content

[28.x] backports and 28.4rc2 - #34620

Merged
fanquake merged 9 commits into
bitcoin:28.xfrom
achow101:28.4rc2-backports
Mar 4, 2026
Merged

fanquake merged 9 commits into
bitcoin:28.xfrom
achow101:28.4rc2-backports

Conversation

@achow101

@achow101 achow101 commented Feb 19, 2026 •

Copy link
Copy Markdown
Member

…allet

If any other files exist in the directory, we cannot assume the sharable files are exclusively for this wallet.
But if they are, this also cleans up other log.* files

Github-Pull: bitcoin#34370
Rebased-From: 7475d13
…ils, log the correct wallet name in error message

Github-Pull: bitcoin#34370
Rebased-From: 60f5290
…eason

Since we no longer delete the wallet directory, there's no need to vacate it
The moving only served to risk errors by crossing filesystem boundaries (which fs::rename can't handle)

Github-Pull: 34370
Rebased-From: cef01d0
…ating from non-directory

While 30.x+ keep backup files in walletdir, 29.x places them in the migrated wallet directory

Github-Pull: bitcoin#34370
Rebased-From: 69a6b9b
…et, but not with a shared db environment

Github-Pull: bitcoin#34370
Rebased-From: 6517394
@DrahtBot

DrahtBot commented Feb 19, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK willcl-ark

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

@fanquake

Copy link
Copy Markdown
Member

Needs a bump to the version in the release-notes.

@fanquake fanquake added this to the 28.4 milestone Feb 19, 2026
@achow101

Copy link
Copy Markdown
Member Author

Needs a bump to the version in the release-notes.

Done

@fanquake

Copy link
Copy Markdown
Member

Can pull #34671 in here too.

@willcl-ark willcl-ark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK bfaec08634ba4fe7f466070aab83fb33f7f5fc5e

These all look good to me. Only conflict looks like the MigrateLegacyToDescriptor signature.

Release notes look good too. Can re-review if you add 34671

@achow101

Copy link
Copy Markdown
Member Author

Backported #34671

@willcl-ark willcl-ark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 44e6dda

Addition of 931f12d cleanly.

@fanquake
fanquake merged commit ed80bb2 into bitcoin:28.x Mar 4, 2026
17 checks passed
morozow pushed a commit to morozow/bitcoin_rd that referenced this pull request May 8, 2026
7d0417d doc: update manpages for v28.4rc2 (Ava Chow)
f2ae4bb doc: Update release notes for v28.4rc2 (Ava Chow)
1226837 build: bump version to v28.4rc2 (Ava Chow)
cc59e91 doc: Update Guix install for Debian/Ubuntu (MarcoFalke)
682dcdc QA: tool_wallet: Check that db.log is deleted with a lone legacy wallet, but not with a shared db environment (Luke Dashjr)
6a89e6f Bugfix: Wallet/Migration: Move backup into wallet directory when migrating from non-directory (Luke Dashjr)
b3d5440 Wallet/Migration: Skip moving the backup file back and forth for no reason (Luke Dashjr)
61e72e5 Wallet/Migration: If loading the new watchonly or solvables wallet fails, log the correct wallet name in error message (Luke Dashjr)
73f591c Wallet/bdb: Safely and correctly list files only used by the single wallet (Luke Dashjr)

Pull request description:

  Backports:

  * bitcoin#34370
  * bitcoin#34671

  And the rc2 release process things

ACKs for top commit:
  willcl-ark:
    ACK 7d0417d

Tree-SHA512: beb478a057b14c3ad9f1ce049f304fa1a5ff948c3492efbd39c51b9bb73a695a5382292513ee53f9ee64ecbbe6370cbbf2781bee01cf3dc262623be4110eacd8
knst added a commit to knst/dash that referenced this pull request Nov 2, 2026
BACKPORT NOTE:
These five commits have no master counterpart (they fix the BDB-era backport
bitcoin#34222 / bitcoin#34223). The 28.x copies in bitcoin#34620 (29abedc,
619480b, 6494072, c5d9f75, 242b9ae) were used as the code reference.
Dash has no load_after_restore (bitcoin#31451) and no blank-wallet branch
(bitcoin#28976); see the TODOs in MigrateLegacyToDescriptor.

6517394 QA: tool_wallet: Check that db.log is deleted with a lone legacy wallet, but not with a shared db environment (Luke Dashjr)
69a6b9b Bugfix: Wallet/Migration: Move backup into wallet directory when migrating from non-directory (Luke Dashjr)
cef01d0 Wallet/Migration: Skip moving the backup file back and forth for no reason (Luke Dashjr)
60f5290 Wallet/Migration: If loading the new watchonly or solvables wallet fails, log the correct wallet name in error message (Luke Dashjr)
7475d13 Wallet/bdb: Safely and correctly list files only used by the single wallet (Luke Dashjr)

Pull request description:

ACKs for top commit:
  achow101:
    ACK 6517394
  furszy:
    light ACK 6517394

Tree-SHA512: c10fe00dde512ca78cd6939a748b3875d0b40e9714997aedfd939a1dffdc7eaa2fd1779f3972a34b1c1d9a97d8f1ee1e082c970de15ac0e2ef5d9bbf3dc1d89a

Co-authored-by: merge-script <[email protected]>
knst added a commit to knst/dash that referenced this pull request Nov 2, 2026
BACKPORT NOTE:
These five commits have no master counterpart (they fix the BDB-era backport
bitcoin#34222 / bitcoin#34223). The 28.x copies in bitcoin#34620 (29abedc,
619480b, 6494072, c5d9f75, 242b9ae) were used as the code reference.
Dash has no load_after_restore (bitcoin#31451) and no blank-wallet branch
(bitcoin#28976); see the TODOs in MigrateLegacyToDescriptor.

6517394 QA: tool_wallet: Check that db.log is deleted with a lone legacy wallet, but not with a shared db environment (Luke Dashjr)
69a6b9b Bugfix: Wallet/Migration: Move backup into wallet directory when migrating from non-directory (Luke Dashjr)
cef01d0 Wallet/Migration: Skip moving the backup file back and forth for no reason (Luke Dashjr)
60f5290 Wallet/Migration: If loading the new watchonly or solvables wallet fails, log the correct wallet name in error message (Luke Dashjr)
7475d13 Wallet/bdb: Safely and correctly list files only used by the single wallet (Luke Dashjr)

Pull request description:

ACKs for top commit:
  achow101:
    ACK 6517394
  furszy:
    light ACK 6517394

Tree-SHA512: c10fe00dde512ca78cd6939a748b3875d0b40e9714997aedfd939a1dffdc7eaa2fd1779f3972a34b1c1d9a97d8f1ee1e082c970de15ac0e2ef5d9bbf3dc1d89a

Co-authored-by: merge-script <[email protected]>
knst added a commit to knst/dash that referenced this pull request Nov 2, 2026
BACKPORT NOTE:
These five commits have no master counterpart (they fix the BDB-era backport
bitcoin#34222 / bitcoin#34223). The 28.x copies in bitcoin#34620 (29abedc,
619480b, 6494072, c5d9f75, 242b9ae) were used as the code reference.
Dash has no load_after_restore (bitcoin#31451) and no blank-wallet branch
(bitcoin#28976); see the TODOs in MigrateLegacyToDescriptor.

6517394 QA: tool_wallet: Check that db.log is deleted with a lone legacy wallet, but not with a shared db environment (Luke Dashjr)
69a6b9b Bugfix: Wallet/Migration: Move backup into wallet directory when migrating from non-directory (Luke Dashjr)
cef01d0 Wallet/Migration: Skip moving the backup file back and forth for no reason (Luke Dashjr)
60f5290 Wallet/Migration: If loading the new watchonly or solvables wallet fails, log the correct wallet name in error message (Luke Dashjr)
7475d13 Wallet/bdb: Safely and correctly list files only used by the single wallet (Luke Dashjr)

Pull request description:

ACKs for top commit:
  achow101:
    ACK 6517394
  furszy:
    light ACK 6517394

Tree-SHA512: c10fe00dde512ca78cd6939a748b3875d0b40e9714997aedfd939a1dffdc7eaa2fd1779f3972a34b1c1d9a97d8f1ee1e082c970de15ac0e2ef5d9bbf3dc1d89a

Co-authored-by: merge-script <[email protected]>
knst added a commit to knst/dash that referenced this pull request Nov 3, 2026
BACKPORT NOTE:
These five commits have no master counterpart (they fix the BDB-era backport
bitcoin#34222 / bitcoin#34223). The 28.x copies in bitcoin#34620 (29abedc,
619480b, 6494072, c5d9f75, 242b9ae) were used as the code reference.
Dash has no load_after_restore (bitcoin#31451) and no blank-wallet branch
(bitcoin#28976); see the TODOs in MigrateLegacyToDescriptor.

6517394 QA: tool_wallet: Check that db.log is deleted with a lone legacy wallet, but not with a shared db environment (Luke Dashjr)
69a6b9b Bugfix: Wallet/Migration: Move backup into wallet directory when migrating from non-directory (Luke Dashjr)
cef01d0 Wallet/Migration: Skip moving the backup file back and forth for no reason (Luke Dashjr)
60f5290 Wallet/Migration: If loading the new watchonly or solvables wallet fails, log the correct wallet name in error message (Luke Dashjr)
7475d13 Wallet/bdb: Safely and correctly list files only used by the single wallet (Luke Dashjr)

Pull request description:

ACKs for top commit:
  achow101:
    ACK 6517394
  furszy:
    light ACK 6517394

Tree-SHA512: c10fe00dde512ca78cd6939a748b3875d0b40e9714997aedfd939a1dffdc7eaa2fd1779f3972a34b1c1d9a97d8f1ee1e082c970de15ac0e2ef5d9bbf3dc1d89a

Co-authored-by: merge-script <[email protected]>
PastaPastaPasta added a commit to dashpay/dash that referenced this pull request Nov 3, 2026
…itcoin#34370, partials bitcoin#31423, bitcoin#34156 (migratewallet fixes from 28.x)

1574eb0 Merge bitcoin#34370: [29.x] Fix bitcoin#34222 backport bugs (Konstantin Akimov)
9857f73 Merge bitcoin#34226: wallet: test: Relative wallet failed migration cleanup (Konstantin Akimov)
7b7d0c6 partial Merge bitcoin#34156: wallet: fix unnamed legacy wallet migration failure (Konstantin Akimov)
cfd0412 Merge bitcoin#34215: wallettool: fix unnamed createfromdump failure walletsdir deletion (Konstantin Akimov)
c8f51bb partial Merge bitcoin#31423: wallet: migration, avoid creating spendable wallet from a watch-only legacy wallet (Konstantin Akimov)
3fd819a Merge bitcoin#28868: wallet: Fix migration of wallets with txs that have both spendable and watchonly outputs (Konstantin Akimov)
8a922f1 Merge bitcoin#28609: wallet: Reload watchonly and solvables wallets after migration (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented
  A failed `migratewallet` could delete more than it created: for the unnamed (default) wallet the cleanup removed the whole `wallets/` directory, a relative wallet name removed the directory the name pointed at, and a failed `restorewallet` or `createfromdump` used `fs::remove_all` on a directory it did not own. Watch-only and solvables wallets created during migration were also left registered in the global context and were never reloaded, so a reload failure after migration went unnoticed.

  Upstream fixed this in bitcoin#34156 / bitcoin#34215 / bitcoin#34226 and backported it to 28.x and 29.x as bitcoin#34223 / bitcoin#34222; bitcoin#34370 fixes bugs of that backport. Neither 26.x nor 27.x received these fixes so 28.x and 29.x is a closest adaptation to the current Dash Core state.

  ## What was done?
  Master merge commits are cherry-picked with `-m1`. Conflicts are resolved against the 28.x copies (bitcoin#34223 and the fix commits in bitcoin#34620), because master's versions target the BERKELEY_RO-only migration path that Dash does not have.

  - bitcoin#28609: create watch-only/solvables wallets in a local context and reload all wallets after migration; copy full tx metadata. Prerequisite for the cleanup code below. Dash's "tx belongs to both wallets" handling from #7793 is kept.
  - bitcoin#31423 (partial): only `WalletDatabase::Files()` and the sqlite path cleanup. The watch-only migration behaviour change and the reload dedup are not taken (BERKELEY_RO only). `BerkeleyDatabase::Files()` and the `DummyDatabase` override come from 28.x.
  - bitcoin#34215: `createfromdump` cleanup removes only the files it created.
  - bitcoin#34156 (partial): `RestoreWallet` and migration cleanup remove only created files; `MigrationPrefixName` names the default wallet's backup and auxiliary wallets `default_wallet_*`; post-migration load failure is logged and rolls back. Skipped: `test_pruned_wallet_backup` (needs bitcoin#30678). The backup filename keeps Dash's basename reduction for path-style wallet names and only adopts `MigrationPrefixName` for the unnamed wallet.
  - bitcoin#34226: parameterised failed-migration cleanup test (unnamed, relative, absolute and plain names). Expected backup paths follow Dash's basename rule.
  - bitcoin#34370: BDB-aware `Files()`, backup moved into the wallet directory when a non-directory wallet becomes a directory, correct wallet name in the load-failure log, no more copying of the backup back and forth, `db.log` cleanup test.

  Not backported, with TODOs in `MigrateLegacyToDescriptor` saying what to replace:
  - bitcoin#32273: backups move to the top-level walletdir and are named from the wallet path. Then drop the basename reduction, `test_wallet_name_with_slashes` and the 28.x-only "move backup into wallet dir" block, re-derive the bitcoin#34226 path cases from master, and take bitcoin#33104 / bitcoin#33122.
  - bitcoin#31451: `load_after_restore` so a wallet that was not loaded before migration is not loaded after a failed one. Re-derive from the 29.x commits d91f56e and a074d36.
  - bitcoin#28976 (blank wallets) and bitcoin#30678 (backup writes the best block locator): not needed for these fixes, left for a follow-up.
  - When bitcoin#31248 lands, re-take the test commits from the 29.x series instead of the 28.x ones.

  ## How Has This Been Tested?
  New and changed tests:
  - `wallet_migration.py`: `test_failed_migration_cleanup`, `test_default_wallet_watch_only`, `test_migration_failure` for `""`, `../`, an absolute path and a plain name (checks that unrelated files survive and the original wallet is restored as BDB), `unsynced_wallet_on_pruned_node_fails`; `test_other_watchonly` now checks tx metadata in the watch-only wallet.
  - `wallet_backup.py`: `test_restore_existent_dir`, `test_restore_into_unnamed_wallet`; `restore_wallet_existent_name` and `restore_preserves_existing_directory` expect the new "Database file exists" error.
  - `tool_wallet.py`: `createfromdump` with an unnamed wallet keeps the wallets directory and `db.log` of a shared BDB environment.

  ## Breaking Changes
  - `restorewallet` now accepts an existing empty directory and refuses only an existing `wallet.dat`.
  - Migration backups are named `<name>_<time>.legacy.bak` (`default_wallet_<time>.legacy.bak` for the unnamed wallet) instead of `<name>-<time>.legacy.bak` / `wallet-<time>.legacy.bak`, and the unnamed wallet's auxiliary wallets are `default_wallet_watchonly` / `default_wallet_solvables` instead of `_watchonly` / `_solvables`.

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone

Top commit has no ACKs.

Tree-SHA512: c561c70e3273b2f1847eced60a9661c70262b2c9a0017e8cbb49eba092ecbb5e95aea383024b56ee6c7e54a4cbc452eb647d6c26f866662dc3c2a11b68a9e183
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Nov 3, 2026
…4226, bitcoin#34370, partials bitcoin#31423, bitcoin#34156 (migratewallet fixes from 28.x)

1574eb0 Merge bitcoin#34370: [29.x] Fix bitcoin#34222 backport bugs (Konstantin Akimov)
9857f73 Merge bitcoin#34226: wallet: test: Relative wallet failed migration cleanup (Konstantin Akimov)
7b7d0c6 partial Merge bitcoin#34156: wallet: fix unnamed legacy wallet migration failure (Konstantin Akimov)
cfd0412 Merge bitcoin#34215: wallettool: fix unnamed createfromdump failure walletsdir deletion (Konstantin Akimov)
c8f51bb partial Merge bitcoin#31423: wallet: migration, avoid creating spendable wallet from a watch-only legacy wallet (Konstantin Akimov)
3fd819a Merge bitcoin#28868: wallet: Fix migration of wallets with txs that have both spendable and watchonly outputs (Konstantin Akimov)
8a922f1 Merge bitcoin#28609: wallet: Reload watchonly and solvables wallets after migration (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented
  A failed `migratewallet` could delete more than it created: for the unnamed (default) wallet the cleanup removed the whole `wallets/` directory, a relative wallet name removed the directory the name pointed at, and a failed `restorewallet` or `createfromdump` used `fs::remove_all` on a directory it did not own. Watch-only and solvables wallets created during migration were also left registered in the global context and were never reloaded, so a reload failure after migration went unnoticed.

  Upstream fixed this in bitcoin#34156 / bitcoin#34215 / bitcoin#34226 and backported it to 28.x and 29.x as bitcoin#34223 / bitcoin#34222; bitcoin#34370 fixes bugs of that backport. Neither 26.x nor 27.x received these fixes so 28.x and 29.x is a closest adaptation to the current Dash Core state.

  ## What was done?
  Master merge commits are cherry-picked with `-m1`. Conflicts are resolved against the 28.x copies (bitcoin#34223 and the fix commits in bitcoin#34620), because master's versions target the BERKELEY_RO-only migration path that Dash does not have.

  - bitcoin#28609: create watch-only/solvables wallets in a local context and reload all wallets after migration; copy full tx metadata. Prerequisite for the cleanup code below. Dash's "tx belongs to both wallets" handling from dashpay#7793 is kept.
  - bitcoin#31423 (partial): only `WalletDatabase::Files()` and the sqlite path cleanup. The watch-only migration behaviour change and the reload dedup are not taken (BERKELEY_RO only). `BerkeleyDatabase::Files()` and the `DummyDatabase` override come from 28.x.
  - bitcoin#34215: `createfromdump` cleanup removes only the files it created.
  - bitcoin#34156 (partial): `RestoreWallet` and migration cleanup remove only created files; `MigrationPrefixName` names the default wallet's backup and auxiliary wallets `default_wallet_*`; post-migration load failure is logged and rolls back. Skipped: `test_pruned_wallet_backup` (needs bitcoin#30678). The backup filename keeps Dash's basename reduction for path-style wallet names and only adopts `MigrationPrefixName` for the unnamed wallet.
  - bitcoin#34226: parameterised failed-migration cleanup test (unnamed, relative, absolute and plain names). Expected backup paths follow Dash's basename rule.
  - bitcoin#34370: BDB-aware `Files()`, backup moved into the wallet directory when a non-directory wallet becomes a directory, correct wallet name in the load-failure log, no more copying of the backup back and forth, `db.log` cleanup test.

  Not backported, with TODOs in `MigrateLegacyToDescriptor` saying what to replace:
  - bitcoin#32273: backups move to the top-level walletdir and are named from the wallet path. Then drop the basename reduction, `test_wallet_name_with_slashes` and the 28.x-only "move backup into wallet dir" block, re-derive the bitcoin#34226 path cases from master, and take bitcoin#33104 / bitcoin#33122.
  - bitcoin#31451: `load_after_restore` so a wallet that was not loaded before migration is not loaded after a failed one. Re-derive from the 29.x commits d91f56e and a074d36.
  - bitcoin#28976 (blank wallets) and bitcoin#30678 (backup writes the best block locator): not needed for these fixes, left for a follow-up.
  - When bitcoin#31248 lands, re-take the test commits from the 29.x series instead of the 28.x ones.

  ## How Has This Been Tested?
  New and changed tests:
  - `wallet_migration.py`: `test_failed_migration_cleanup`, `test_default_wallet_watch_only`, `test_migration_failure` for `""`, `../`, an absolute path and a plain name (checks that unrelated files survive and the original wallet is restored as BDB), `unsynced_wallet_on_pruned_node_fails`; `test_other_watchonly` now checks tx metadata in the watch-only wallet.
  - `wallet_backup.py`: `test_restore_existent_dir`, `test_restore_into_unnamed_wallet`; `restore_wallet_existent_name` and `restore_preserves_existing_directory` expect the new "Database file exists" error.
  - `tool_wallet.py`: `createfromdump` with an unnamed wallet keeps the wallets directory and `db.log` of a shared BDB environment.

  ## Breaking Changes
  - `restorewallet` now accepts an existing empty directory and refuses only an existing `wallet.dat`.
  - Migration backups are named `<name>_<time>.legacy.bak` (`default_wallet_<time>.legacy.bak` for the unnamed wallet) instead of `<name>-<time>.legacy.bak` / `wallet-<time>.legacy.bak`, and the unnamed wallet's auxiliary wallets are `default_wallet_watchonly` / `default_wallet_solvables` instead of `_watchonly` / `_solvables`.

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone

Top commit has no ACKs.

Tree-SHA512: c561c70e3273b2f1847eced60a9661c70262b2c9a0017e8cbb49eba092ecbb5e95aea383024b56ee6c7e54a4cbc452eb647d6c26f866662dc3c2a11b68a9e183

v24.0.x backport notes (conflicts come from develop-only prerequisites;
none of them was backported, and no dashpay#8014 hunk or test was dropped):

- src/wallet/salvage.cpp, src/wallet/test/util.h: dashpay#8014 only adds a
  Files() override to DummyDatabase/MockableDatabase, which live there on
  develop (bitcoin#26715 and follow-ups). v24.0.x has DummyDatabase in
  src/wallet/db.h and the test mock FailDatabase in
  src/wallet/test/wallet_tests.cpp, so the same override is added there.
- src/wallet/wallet.cpp: only dashpay#8014's MigrationPrefixName() is taken;
  CWallet::CanGrindR() in the same hunk is develop-only context.
- test/functional/tool_wallet.py: dashpay#8014's added lines are taken as they
  are; the existing badload assertion keeps v24.0.x's form.
- test/functional/wallet_backup.py: the new "Database file exists" error
  is taken; wallet_file keeps v24.0.x's string form, so its existence check
  stays os.path.exists().
- test/functional/wallet_migration.py: dashpay#8014's
  test_failed_migration_cleanup and unsynced_wallet_on_pruned_node_fails
  are taken; test_conflict_txs and test_addressbook in the same conflict
  region are develop-only context and are not part of dashpay#8014. The pruned
  node is stopped with EXPECTED_STDERR_NO_GOV_PRUNE, because v24.0.x
  still prints the pruned-node governance warning that dashpay#7860 removed on
  develop (as in the rc.6 pick of dashpay#8005).
- All three tests: v24.0.x's test framework has neither
  TestNode.wallets_path nor datadir_path (bitcoin#27884), and its RPC proxy
  cannot serialize pathlib.Path. wallets_path is written as
  chain_path / "wallets", and datadir_path joins as os.path.join(datadir, ...),
  so paths passed to RPCs stay strings.

(cherry picked from commit 347c380)
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Nov 3, 2026
…4226, bitcoin#34370, partials bitcoin#31423, bitcoin#34156 (migratewallet fixes from 28.x)

1574eb0 Merge bitcoin#34370: [29.x] Fix bitcoin#34222 backport bugs (Konstantin Akimov)
9857f73 Merge bitcoin#34226: wallet: test: Relative wallet failed migration cleanup (Konstantin Akimov)
7b7d0c6 partial Merge bitcoin#34156: wallet: fix unnamed legacy wallet migration failure (Konstantin Akimov)
cfd0412 Merge bitcoin#34215: wallettool: fix unnamed createfromdump failure walletsdir deletion (Konstantin Akimov)
c8f51bb partial Merge bitcoin#31423: wallet: migration, avoid creating spendable wallet from a watch-only legacy wallet (Konstantin Akimov)
3fd819a Merge bitcoin#28868: wallet: Fix migration of wallets with txs that have both spendable and watchonly outputs (Konstantin Akimov)
8a922f1 Merge bitcoin#28609: wallet: Reload watchonly and solvables wallets after migration (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented
  A failed `migratewallet` could delete more than it created: for the unnamed (default) wallet the cleanup removed the whole `wallets/` directory, a relative wallet name removed the directory the name pointed at, and a failed `restorewallet` or `createfromdump` used `fs::remove_all` on a directory it did not own. Watch-only and solvables wallets created during migration were also left registered in the global context and were never reloaded, so a reload failure after migration went unnoticed.

  Upstream fixed this in bitcoin#34156 / bitcoin#34215 / bitcoin#34226 and backported it to 28.x and 29.x as bitcoin#34223 / bitcoin#34222; bitcoin#34370 fixes bugs of that backport. Neither 26.x nor 27.x received these fixes so 28.x and 29.x is a closest adaptation to the current Dash Core state.

  ## What was done?
  Master merge commits are cherry-picked with `-m1`. Conflicts are resolved against the 28.x copies (bitcoin#34223 and the fix commits in bitcoin#34620), because master's versions target the BERKELEY_RO-only migration path that Dash does not have.

  - bitcoin#28609: create watch-only/solvables wallets in a local context and reload all wallets after migration; copy full tx metadata. Prerequisite for the cleanup code below. Dash's "tx belongs to both wallets" handling from dashpay#7793 is kept.
  - bitcoin#31423 (partial): only `WalletDatabase::Files()` and the sqlite path cleanup. The watch-only migration behaviour change and the reload dedup are not taken (BERKELEY_RO only). `BerkeleyDatabase::Files()` and the `DummyDatabase` override come from 28.x.
  - bitcoin#34215: `createfromdump` cleanup removes only the files it created.
  - bitcoin#34156 (partial): `RestoreWallet` and migration cleanup remove only created files; `MigrationPrefixName` names the default wallet's backup and auxiliary wallets `default_wallet_*`; post-migration load failure is logged and rolls back. Skipped: `test_pruned_wallet_backup` (needs bitcoin#30678). The backup filename keeps Dash's basename reduction for path-style wallet names and only adopts `MigrationPrefixName` for the unnamed wallet.
  - bitcoin#34226: parameterised failed-migration cleanup test (unnamed, relative, absolute and plain names). Expected backup paths follow Dash's basename rule.
  - bitcoin#34370: BDB-aware `Files()`, backup moved into the wallet directory when a non-directory wallet becomes a directory, correct wallet name in the load-failure log, no more copying of the backup back and forth, `db.log` cleanup test.

  Not backported, with TODOs in `MigrateLegacyToDescriptor` saying what to replace:
  - bitcoin#32273: backups move to the top-level walletdir and are named from the wallet path. Then drop the basename reduction, `test_wallet_name_with_slashes` and the 28.x-only "move backup into wallet dir" block, re-derive the bitcoin#34226 path cases from master, and take bitcoin#33104 / bitcoin#33122.
  - bitcoin#31451: `load_after_restore` so a wallet that was not loaded before migration is not loaded after a failed one. Re-derive from the 29.x commits d91f56e and a074d36.
  - bitcoin#28976 (blank wallets) and bitcoin#30678 (backup writes the best block locator): not needed for these fixes, left for a follow-up.
  - When bitcoin#31248 lands, re-take the test commits from the 29.x series instead of the 28.x ones.

  ## How Has This Been Tested?
  New and changed tests:
  - `wallet_migration.py`: `test_failed_migration_cleanup`, `test_default_wallet_watch_only`, `test_migration_failure` for `""`, `../`, an absolute path and a plain name (checks that unrelated files survive and the original wallet is restored as BDB), `unsynced_wallet_on_pruned_node_fails`; `test_other_watchonly` now checks tx metadata in the watch-only wallet.
  - `wallet_backup.py`: `test_restore_existent_dir`, `test_restore_into_unnamed_wallet`; `restore_wallet_existent_name` and `restore_preserves_existing_directory` expect the new "Database file exists" error.
  - `tool_wallet.py`: `createfromdump` with an unnamed wallet keeps the wallets directory and `db.log` of a shared BDB environment.

  ## Breaking Changes
  - `restorewallet` now accepts an existing empty directory and refuses only an existing `wallet.dat`.
  - Migration backups are named `<name>_<time>.legacy.bak` (`default_wallet_<time>.legacy.bak` for the unnamed wallet) instead of `<name>-<time>.legacy.bak` / `wallet-<time>.legacy.bak`, and the unnamed wallet's auxiliary wallets are `default_wallet_watchonly` / `default_wallet_solvables` instead of `_watchonly` / `_solvables`.

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone

Top commit has no ACKs.

Tree-SHA512: c561c70e3273b2f1847eced60a9661c70262b2c9a0017e8cbb49eba092ecbb5e95aea383024b56ee6c7e54a4cbc452eb647d6c26f866662dc3c2a11b68a9e183

v24.0.x backport notes (conflicts come from develop-only context; no
dashpay#8014 hunk or test was dropped):

- Prerequisite: bitcoin#28542 (from dashpay#7762) is picked in the
  commit before this one. dashpay#8014's migration copies transactions into
  chainless wallets with LoadToWallet(), which reaches MarkConflicted() for
  a conflicted parent and child; without bitcoin#28542's guard that aborts in
  GetLastBlockHeight(). No other prerequisite was backported.

- src/wallet/salvage.cpp, src/wallet/test/util.h: dashpay#8014 only adds a
  Files() override to DummyDatabase/MockableDatabase, which live there on
  develop (bitcoin#26715 and follow-ups). v24.0.x has DummyDatabase in
  src/wallet/db.h and the test mock FailDatabase in
  src/wallet/test/wallet_tests.cpp, so the same override is added there.
- src/wallet/wallet.cpp: only dashpay#8014's MigrationPrefixName() is taken;
  CWallet::CanGrindR() in the same hunk is develop-only context.
- test/functional/tool_wallet.py: dashpay#8014's added lines are taken as they
  are; the existing badload assertion keeps v24.0.x's form.
- test/functional/wallet_backup.py: the new "Database file exists" error
  is taken; wallet_file keeps v24.0.x's string form, so its existence check
  stays os.path.exists().
- test/functional/wallet_migration.py: dashpay#8014's
  test_failed_migration_cleanup and unsynced_wallet_on_pruned_node_fails
  are taken, after test_conflict_txs from the bitcoin#28542 pick, as on
  develop; test_addressbook in the same conflict region is develop-only
  context and is not part of dashpay#8014. The pruned
  node is stopped with EXPECTED_STDERR_NO_GOV_PRUNE, because v24.0.x
  still prints the pruned-node governance warning that dashpay#7860 removed on
  develop (as in the rc.6 pick of dashpay#8005).
- All three tests: v24.0.x's test framework has neither
  TestNode.wallets_path nor datadir_path (bitcoin#27884), and its RPC proxy
  cannot serialize pathlib.Path. wallets_path is written as
  chain_path / "wallets", and datadir_path joins as os.path.join(datadir, ...),
  so paths passed to RPCs stay strings.

(cherry picked from commit 347c380)
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Nov 3, 2026
…4226, bitcoin#34370, partials bitcoin#31423, bitcoin#34156 (migratewallet fixes from 28.x)

1574eb0 Merge bitcoin#34370: [29.x] Fix bitcoin#34222 backport bugs (Konstantin Akimov)
9857f73 Merge bitcoin#34226: wallet: test: Relative wallet failed migration cleanup (Konstantin Akimov)
7b7d0c6 partial Merge bitcoin#34156: wallet: fix unnamed legacy wallet migration failure (Konstantin Akimov)
cfd0412 Merge bitcoin#34215: wallettool: fix unnamed createfromdump failure walletsdir deletion (Konstantin Akimov)
c8f51bb partial Merge bitcoin#31423: wallet: migration, avoid creating spendable wallet from a watch-only legacy wallet (Konstantin Akimov)
3fd819a Merge bitcoin#28868: wallet: Fix migration of wallets with txs that have both spendable and watchonly outputs (Konstantin Akimov)
8a922f1 Merge bitcoin#28609: wallet: Reload watchonly and solvables wallets after migration (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented
  A failed `migratewallet` could delete more than it created: for the unnamed (default) wallet the cleanup removed the whole `wallets/` directory, a relative wallet name removed the directory the name pointed at, and a failed `restorewallet` or `createfromdump` used `fs::remove_all` on a directory it did not own. Watch-only and solvables wallets created during migration were also left registered in the global context and were never reloaded, so a reload failure after migration went unnoticed.

  Upstream fixed this in bitcoin#34156 / bitcoin#34215 / bitcoin#34226 and backported it to 28.x and 29.x as bitcoin#34223 / bitcoin#34222; bitcoin#34370 fixes bugs of that backport. Neither 26.x nor 27.x received these fixes so 28.x and 29.x is a closest adaptation to the current Dash Core state.

  ## What was done?
  Master merge commits are cherry-picked with `-m1`. Conflicts are resolved against the 28.x copies (bitcoin#34223 and the fix commits in bitcoin#34620), because master's versions target the BERKELEY_RO-only migration path that Dash does not have.

  - bitcoin#28609: create watch-only/solvables wallets in a local context and reload all wallets after migration; copy full tx metadata. Prerequisite for the cleanup code below. Dash's "tx belongs to both wallets" handling from dashpay#7793 is kept.
  - bitcoin#31423 (partial): only `WalletDatabase::Files()` and the sqlite path cleanup. The watch-only migration behaviour change and the reload dedup are not taken (BERKELEY_RO only). `BerkeleyDatabase::Files()` and the `DummyDatabase` override come from 28.x.
  - bitcoin#34215: `createfromdump` cleanup removes only the files it created.
  - bitcoin#34156 (partial): `RestoreWallet` and migration cleanup remove only created files; `MigrationPrefixName` names the default wallet's backup and auxiliary wallets `default_wallet_*`; post-migration load failure is logged and rolls back. Skipped: `test_pruned_wallet_backup` (needs bitcoin#30678). The backup filename keeps Dash's basename reduction for path-style wallet names and only adopts `MigrationPrefixName` for the unnamed wallet.
  - bitcoin#34226: parameterised failed-migration cleanup test (unnamed, relative, absolute and plain names). Expected backup paths follow Dash's basename rule.
  - bitcoin#34370: BDB-aware `Files()`, backup moved into the wallet directory when a non-directory wallet becomes a directory, correct wallet name in the load-failure log, no more copying of the backup back and forth, `db.log` cleanup test.

  Not backported, with TODOs in `MigrateLegacyToDescriptor` saying what to replace:
  - bitcoin#32273: backups move to the top-level walletdir and are named from the wallet path. Then drop the basename reduction, `test_wallet_name_with_slashes` and the 28.x-only "move backup into wallet dir" block, re-derive the bitcoin#34226 path cases from master, and take bitcoin#33104 / bitcoin#33122.
  - bitcoin#31451: `load_after_restore` so a wallet that was not loaded before migration is not loaded after a failed one. Re-derive from the 29.x commits d91f56e and a074d36.
  - bitcoin#28976 (blank wallets) and bitcoin#30678 (backup writes the best block locator): not needed for these fixes, left for a follow-up.
  - When bitcoin#31248 lands, re-take the test commits from the 29.x series instead of the 28.x ones.

  ## How Has This Been Tested?
  New and changed tests:
  - `wallet_migration.py`: `test_failed_migration_cleanup`, `test_default_wallet_watch_only`, `test_migration_failure` for `""`, `../`, an absolute path and a plain name (checks that unrelated files survive and the original wallet is restored as BDB), `unsynced_wallet_on_pruned_node_fails`; `test_other_watchonly` now checks tx metadata in the watch-only wallet.
  - `wallet_backup.py`: `test_restore_existent_dir`, `test_restore_into_unnamed_wallet`; `restore_wallet_existent_name` and `restore_preserves_existing_directory` expect the new "Database file exists" error.
  - `tool_wallet.py`: `createfromdump` with an unnamed wallet keeps the wallets directory and `db.log` of a shared BDB environment.

  ## Breaking Changes
  - `restorewallet` now accepts an existing empty directory and refuses only an existing `wallet.dat`.
  - Migration backups are named `<name>_<time>.legacy.bak` (`default_wallet_<time>.legacy.bak` for the unnamed wallet) instead of `<name>-<time>.legacy.bak` / `wallet-<time>.legacy.bak`, and the unnamed wallet's auxiliary wallets are `default_wallet_watchonly` / `default_wallet_solvables` instead of `_watchonly` / `_solvables`.

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone

Top commit has no ACKs.

Tree-SHA512: c561c70e3273b2f1847eced60a9661c70262b2c9a0017e8cbb49eba092ecbb5e95aea383024b56ee6c7e54a4cbc452eb647d6c26f866662dc3c2a11b68a9e183

v24.0.x backport notes (conflicts come from develop-only context; no
dashpay#8014 hunk or test was dropped):

- Prerequisite: bitcoin#28542 (from dashpay#7762) is picked in the
  commit before this one. dashpay#8014's migration copies transactions into
  chainless wallets with LoadToWallet(), which reaches MarkConflicted() for
  a conflicted parent and child; without bitcoin#28542's guard that aborts in
  GetLastBlockHeight(). No other prerequisite was backported.

- src/wallet/salvage.cpp, src/wallet/test/util.h: dashpay#8014 only adds a
  Files() override to DummyDatabase/MockableDatabase, which live there on
  develop (bitcoin#26715 and follow-ups). v24.0.x has DummyDatabase in
  src/wallet/db.h and the test mock FailDatabase in
  src/wallet/test/wallet_tests.cpp, so the same override is added there.
- src/wallet/wallet.cpp: only dashpay#8014's MigrationPrefixName() is taken;
  CWallet::CanGrindR() in the same hunk is develop-only context.
- test/functional/tool_wallet.py: dashpay#8014's added lines are taken as they
  are; the existing badload assertion keeps v24.0.x's form.
- test/functional/wallet_backup.py: the new "Database file exists" error
  is taken; wallet_file keeps v24.0.x's string form, so its existence check
  stays os.path.exists().
- test/functional/wallet_migration.py: dashpay#8014's
  test_failed_migration_cleanup and unsynced_wallet_on_pruned_node_fails
  are taken, after test_conflict_txs from the bitcoin#28542 pick, as on
  develop; test_addressbook in the same conflict region is develop-only
  context and is not part of dashpay#8014. The pruned
  node is stopped with EXPECTED_STDERR_NO_GOV_PRUNE, because v24.0.x
  still prints the pruned-node governance warning that dashpay#7860 removed on
  develop (as in the rc.6 pick of dashpay#8005).
- All three tests: v24.0.x's test framework has neither
  TestNode.wallets_path nor datadir_path (bitcoin#27884), and its RPC proxy
  cannot serialize pathlib.Path. wallets_path is written as
  chain_path / "wallets", and datadir_path joins as os.path.join(datadir, ...),
  so paths passed to RPCs stay strings.

(cherry picked from commit 347c380)
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Nov 3, 2026
…4226, bitcoin#34370, partials bitcoin#31423, bitcoin#34156 (migratewallet fixes from 28.x)

1574eb0 Merge bitcoin#34370: [29.x] Fix bitcoin#34222 backport bugs (Konstantin Akimov)
9857f73 Merge bitcoin#34226: wallet: test: Relative wallet failed migration cleanup (Konstantin Akimov)
7b7d0c6 partial Merge bitcoin#34156: wallet: fix unnamed legacy wallet migration failure (Konstantin Akimov)
cfd0412 Merge bitcoin#34215: wallettool: fix unnamed createfromdump failure walletsdir deletion (Konstantin Akimov)
c8f51bb partial Merge bitcoin#31423: wallet: migration, avoid creating spendable wallet from a watch-only legacy wallet (Konstantin Akimov)
3fd819a Merge bitcoin#28868: wallet: Fix migration of wallets with txs that have both spendable and watchonly outputs (Konstantin Akimov)
8a922f1 Merge bitcoin#28609: wallet: Reload watchonly and solvables wallets after migration (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented
  A failed `migratewallet` could delete more than it created: for the unnamed (default) wallet the cleanup removed the whole `wallets/` directory, a relative wallet name removed the directory the name pointed at, and a failed `restorewallet` or `createfromdump` used `fs::remove_all` on a directory it did not own. Watch-only and solvables wallets created during migration were also left registered in the global context and were never reloaded, so a reload failure after migration went unnoticed.

  Upstream fixed this in bitcoin#34156 / bitcoin#34215 / bitcoin#34226 and backported it to 28.x and 29.x as bitcoin#34223 / bitcoin#34222; bitcoin#34370 fixes bugs of that backport. Neither 26.x nor 27.x received these fixes so 28.x and 29.x is a closest adaptation to the current Dash Core state.

  ## What was done?
  Master merge commits are cherry-picked with `-m1`. Conflicts are resolved against the 28.x copies (bitcoin#34223 and the fix commits in bitcoin#34620), because master's versions target the BERKELEY_RO-only migration path that Dash does not have.

  - bitcoin#28609: create watch-only/solvables wallets in a local context and reload all wallets after migration; copy full tx metadata. Prerequisite for the cleanup code below. Dash's "tx belongs to both wallets" handling from dashpay#7793 is kept.
  - bitcoin#31423 (partial): only `WalletDatabase::Files()` and the sqlite path cleanup. The watch-only migration behaviour change and the reload dedup are not taken (BERKELEY_RO only). `BerkeleyDatabase::Files()` and the `DummyDatabase` override come from 28.x.
  - bitcoin#34215: `createfromdump` cleanup removes only the files it created.
  - bitcoin#34156 (partial): `RestoreWallet` and migration cleanup remove only created files; `MigrationPrefixName` names the default wallet's backup and auxiliary wallets `default_wallet_*`; post-migration load failure is logged and rolls back. Skipped: `test_pruned_wallet_backup` (needs bitcoin#30678). The backup filename keeps Dash's basename reduction for path-style wallet names and only adopts `MigrationPrefixName` for the unnamed wallet.
  - bitcoin#34226: parameterised failed-migration cleanup test (unnamed, relative, absolute and plain names). Expected backup paths follow Dash's basename rule.
  - bitcoin#34370: BDB-aware `Files()`, backup moved into the wallet directory when a non-directory wallet becomes a directory, correct wallet name in the load-failure log, no more copying of the backup back and forth, `db.log` cleanup test.

  Not backported, with TODOs in `MigrateLegacyToDescriptor` saying what to replace:
  - bitcoin#32273: backups move to the top-level walletdir and are named from the wallet path. Then drop the basename reduction, `test_wallet_name_with_slashes` and the 28.x-only "move backup into wallet dir" block, re-derive the bitcoin#34226 path cases from master, and take bitcoin#33104 / bitcoin#33122.
  - bitcoin#31451: `load_after_restore` so a wallet that was not loaded before migration is not loaded after a failed one. Re-derive from the 29.x commits d91f56e and a074d36.
  - bitcoin#28976 (blank wallets) and bitcoin#30678 (backup writes the best block locator): not needed for these fixes, left for a follow-up.
  - When bitcoin#31248 lands, re-take the test commits from the 29.x series instead of the 28.x ones.

  ## How Has This Been Tested?
  New and changed tests:
  - `wallet_migration.py`: `test_failed_migration_cleanup`, `test_default_wallet_watch_only`, `test_migration_failure` for `""`, `../`, an absolute path and a plain name (checks that unrelated files survive and the original wallet is restored as BDB), `unsynced_wallet_on_pruned_node_fails`; `test_other_watchonly` now checks tx metadata in the watch-only wallet.
  - `wallet_backup.py`: `test_restore_existent_dir`, `test_restore_into_unnamed_wallet`; `restore_wallet_existent_name` and `restore_preserves_existing_directory` expect the new "Database file exists" error.
  - `tool_wallet.py`: `createfromdump` with an unnamed wallet keeps the wallets directory and `db.log` of a shared BDB environment.

  ## Breaking Changes
  - `restorewallet` now accepts an existing empty directory and refuses only an existing `wallet.dat`.
  - Migration backups are named `<name>_<time>.legacy.bak` (`default_wallet_<time>.legacy.bak` for the unnamed wallet) instead of `<name>-<time>.legacy.bak` / `wallet-<time>.legacy.bak`, and the unnamed wallet's auxiliary wallets are `default_wallet_watchonly` / `default_wallet_solvables` instead of `_watchonly` / `_solvables`.

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone

Top commit has no ACKs.

Tree-SHA512: c561c70e3273b2f1847eced60a9661c70262b2c9a0017e8cbb49eba092ecbb5e95aea383024b56ee6c7e54a4cbc452eb647d6c26f866662dc3c2a11b68a9e183

v24.0.x backport notes (conflicts come from develop-only context; no
dashpay#8014 hunk or test was dropped):

- Prerequisites, picked in the two commits before this one:
  - bitcoin#28038 (from dashpay#7863): dashpay#8014 reloads the watch-only
    and solvables wallets from disk, so address book entries that
    ApplyMigrationData() doesn't write (a "send" entry with an empty label)
    would be lost right after migration.
  - bitcoin#28542 (from dashpay#7762): dashpay#8014's migration copies
    transactions into chainless wallets with LoadToWallet(), which reaches
    MarkConflicted() for a conflicted parent and child; without bitcoin#28542's
    guard that aborts in GetLastBlockHeight().
  No other prerequisite was backported.

- src/wallet/salvage.cpp, src/wallet/test/util.h: dashpay#8014 only adds a
  Files() override to DummyDatabase/MockableDatabase, which live there on
  develop (bitcoin#26715 and follow-ups). v24.0.x has DummyDatabase in
  src/wallet/db.h and the test mock FailDatabase in
  src/wallet/test/wallet_tests.cpp, so the same override is added there.
- src/wallet/wallet.cpp: only dashpay#8014's MigrationPrefixName() is taken;
  CWallet::CanGrindR() in the same hunk is develop-only context.
- test/functional/tool_wallet.py: dashpay#8014's added lines are taken as they
  are; the existing badload assertion keeps v24.0.x's form.
- test/functional/wallet_backup.py: the new "Database file exists" error
  is taken; wallet_file keeps v24.0.x's string form, so its existence check
  stays os.path.exists().
- test/functional/wallet_migration.py: dashpay#8014's
  test_failed_migration_cleanup and unsynced_wallet_on_pruned_node_fails
  are taken, after test_conflict_txs and test_addressbook from the
  bitcoin#28542 and bitcoin#28038 picks, as on develop. The pruned
  node is stopped with EXPECTED_STDERR_NO_GOV_PRUNE, because v24.0.x
  still prints the pruned-node governance warning that dashpay#7860 removed on
  develop (as in the rc.6 pick of dashpay#8005).
- All three tests: v24.0.x's test framework has neither
  TestNode.wallets_path nor datadir_path (bitcoin#27884), and its RPC proxy
  cannot serialize pathlib.Path. wallets_path is written as
  chain_path / "wallets", and datadir_path joins as os.path.join(datadir, ...),
  so paths passed to RPCs stay strings.

(cherry picked from commit 347c380)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants