Skip to content

wallet, migration: Contain all legacy wallet and migration related things in its own subdirectory, namespace, and classes - #36897

Draft
achow101 wants to merge 14 commits into
bitcoin:masterfrom
achow101:contain-wallet-migration
Draft

achow101 wants to merge 14 commits into
bitcoin:masterfrom
achow101:contain-wallet-migration

Conversation

@achow101

Copy link
Copy Markdown
Member

Originally, legacy wallet migration was built upon the foundation of being able to load legacy wallets. Now that we no longer support loading legacy wallets, there is no reason to keep any of the legacy wallet loading and migration code in the main wallet objects. Having this co-mingling of never-to-be-changed legacy wallet code and new descriptor wallet code makes it difficult to implement new things into the wallet.

This PR fully separates out all of the legacy wallet related things into a subdirectory wallet/legacy, with everything in that directory under a wallet::legacy_migration namespace so as to prevent accidental usage outside of legacy wallets. This includes a little bit of duplication with current loading code, but not that much, and we are able to both remove unrelated descriptor wallet loading from the legacy wallet loading, and unrelated legacy wallet loading from normal descriptor wallet loading.

LegacyWallet is introduced as a subclass of CWallet which contains all of the relevant legacy wallet and migration functions so that CWallet cannot accidentally use some legacy wallet function. Additionally, LegacyDataSPKM is moved into a new file and this new namespace so that it cannot be used outside of migration.

Lastly, ReorderTransactions is a legacy wallet only function that is also moved into LegacyWallet.

Builds upon #34909, and depends on #36823 for removing some functions that were previously used by migration.

@DrahtBot

DrahtBot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK rkrux

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #37097 (refactor: drop duplicate typedefs by fanquake)
  • #37055 (refactor: drop format calls on strings without arguments by fanquake)
  • #36887 (wallet: Require the descriptors flag when the FLAGS record is missing by kah-ja)
  • #36844 (iwyu: Fix warnings in more modules in src/ and treat them as errors by hebasto)
  • #36820 (refactor: remove more dead code by fanquake)
  • #36767 (wallet: fix crash when external signer wallet creation fails by zerog975)
  • #36481 (wallet, rpc, gui: Allow users to manually rebroadcast a wallet transaction by achow101)
  • #36380 (wallet: extend -walletbroadcast to allow initial send only by vasild)
  • #36167 (build: Enable -Wunused by fanquake)
  • #36122 (BIP460: CISA for Taproot key path spends by fjahr)
  • #35998 (wallet: Handle or explicitly ignore WalletBatch write failures by achow101)
  • #35786 (wallet: drop spent parents redundant cache invalidation and notification by furszy)
  • #35733 (sign: Remove FillableSigningProvider by achow101)
  • #35302 (Silent Payments: Sending (take 2) by Eunovo)
  • #34520 (refactor: Add [[nodiscard]] to functions returning bool+mutable ref by maflcko)
  • #33112 (wallet: relax external_signer flag constraints by Sjors)
  • #27865 (wallet: Track no-longer-spendable TXOs separately by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • src/wallet/legacy/migration.cpp: entires → entries [misspelling]
  • src/wallet/walletdb.cpp: descriptor walletsv → descriptor wallets [misspelling]

Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

  • src/wallet/legacy/spkm.cpp: WalletDescriptor w_desc(std::move(descs.at(0)), creation_time, 0, 0, 0) — for the non-HD key descriptor
  • src/wallet/legacy/spkm.cpp: WalletDescriptor w_desc(std::move(descs.at(0)), 0, 0, chain_counter, 0)
  • src/wallet/legacy/spkm.cpp: Parse(desc_str, provider, error, false)
  • src/wallet/legacy/spkm.cpp: WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0) — for the inferred descriptor
  • src/wallet/legacy/spkm.cpp: Parse(desc_str, parsed_keys, parse_error, false)

2026-11-30 23:04:02

@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task macOS-cross to x86_64: https://github.com/bitcoin/bitcoin/actions/runs/43977159977/job/133683977345
LLM reason (✨ experimental): The build failed because legacy/load.cpp captures batch in a lambda without using it, and Clang treats the warning as an error.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

This was referenced Nov 17, 2026
@achow101
achow101 force-pushed the contain-wallet-migration branch from 59fd473 to e27ef87 Compare November 23, 2026 22:42
@achow101
achow101 force-pushed the contain-wallet-migration branch 2 times, most recently from 5a5b797 to 8844dd8 Compare November 24, 2026 08:01
@achow101
achow101 force-pushed the contain-wallet-migration branch from 8844dd8 to 79b5c85 Compare November 24, 2026 22:32
@achow101
achow101 force-pushed the contain-wallet-migration branch from 7d6b709 to d5a3f21 Compare November 25, 2026 21:36
Instead of erasing legacy wallet records and tx records from the
migrated database, skip copying these records in the first place.
Instead copying all of the address book entries and deleting the ones
that are no longer relevant, avoid writing the address book entries in
the first place and write only the ones that are relevant to the
migrated wallets.
HasLegacyRecords is only used by LoadLegacyWalletRecords to check
whether a descriptor wallet has any legacy wallet records. This does not
require a CWallet, and is no longer called by anything outside of
walletdb.cpp.
Put all legacy wallet migration related code into a custom namespace to
clearly delineate which functions are migration and which are not, and
to prevent accidentally calling into migration functions from outside of
migration.
Instead of calling CWallet::LoadExisting, use a custom loading function
for migration only that does fewer things. This will be used in later
commits to implement a custom, migration specific, loading flow.
LegacyWallet owns all of the wallet migration functions so that they do
not need to live in CWallet anymore.
Reordering transactions is something that only legacy wallets will need
to do. All newly created descriptor wallets will have transactions with
order information. Migrated descriptor wallets will have computed the
order information during migration, and the updated tx records are
written to the new wallet, so always contain the order information.
When migrating a legacy wallet, there is no need to try to write
anything back into the legacy wallet, it won't work anyways.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants