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

pull achow101 wants to merge 16 commits into bitcoin:master from achow101:contain-wallet-migration changing 24 files +2611 −2334
  1. achow101 commented at 11:11 PM on November 16, 2026: 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.

  2. wallet: (move-only) extract out migration specific CWallet methods
    From wallet/wallet.cpp to wallet/migration.cpp.
    
    This patch should be reviewed with --color-moved=dimmed-zebra option.
    1304dfb411
  3. wallet: extract out utility functions from wallet/wallet
    To wallet/walletutil.h
    
    Couple of functions had to be made non-static for them to be used by
    wallet/wallet.
    
    This patch should be reviewed with --color-moved=dimmed-zebra option.
    3b5bdc99b7
  4. wallet: extract out public facing MigrateLegacyToDescriptor functions
    To wallet/migration. Also, update the includes in the call sites.
    
    This patch should be reviewed with --color-moved=dimmed-zebra.
    7c680443f6
  5. wallet: extract out migration specific LegacySPKM CWallet methods
    to wallet/migration.
    
    This patch should be reviewed with --color-moved=dimmed-zebra.
    ef28c283fc
  6. wallet, refactor: rename file from migrate to legacybdb
    The wallet/migrate.h|cpp file contain all the code related to the
    Berkeley DB that was used in the legacy wallets. Although it's true
    that this code is used only within the context of wallet migration
    but the name of the file is not exact.
    
    This patch renames the file to legacybdb so that the intent is clearer in the
    call sites. I felt this rename might be necessary so that the name
    doesn't conflict with the new migration.cpp introduced in the preceding commits.
    cfedba66f8
  7. wallet: Skip copy of legacy wallet records rather than erasing
    Instead of erasing legacy wallet records and tx records from the
    migrated database, skip copying these records in the first place.
    40631b84ca
  8. wallet: Remove unused RemoveTxs and EraseTx ed9eff6efd
  9. wallet, walletdb: Remove unused DeleteRecordsWithDB and EraseRecords a5c507c87a
  10. walletdb: Make HasLegacyRecords static
    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.
    be7ddb4660
  11. wallet, migration: Move migration specific things to legacy subdir 755ab9b3ce
  12. wallet, migration: Put all migration related code into a namespace
    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.
    5b6ead13c9
  13. wallet, migration: Use a slimmed down wallet loading function
    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.
    ec58b5d6c8
  14. wallet, migration: Move legacy wallet loading code to migration module 5f3c370149
  15. wallet, migration: Add a LegacyWallet subclass of CWallet
    LegacyWallet owns all of the wallet migration functions so that they do
    not need to live in CWallet anymore.
    f7eeec88e2
  16. wallet, migration: Move LegacyDataSPKM to its own file within migration bb7c84a7ba
  17. wallet, migration: Move ReorderTransactions to LegacyWallet
    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.
    59fd47320f
  18. DrahtBot commented at 11:12 PM on November 16, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36887 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36887.svg"></sub> (wallet: Require the descriptors flag when the FLAGS record is missing by kah-ja)
    • #36825 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36825.svg"></sub> (wallet: fix migration with watch-only transactions by psychemist)
    • #36823 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36823.svg"></sub> (wallet, migration: Skip legacy wallet records rather than erasing them, and drop unused record erase functions by achow101)
    • #36820 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36820.svg"></sub> (refactor: remove more dead code by fanquake)
    • #36813 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36813.svg"></sub> (refactor: more prereqs for #36743 by fanquake)
    • #36767 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36767.svg"></sub> (wallet: fix crash when external signer wallet creation fails by zerog975)
    • #36743 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36743.svg"></sub> ([RFC] build: build with -Wmissing-declarations/prototypes by fanquake)
    • #36481 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36481.svg"></sub> (wallet, rpc, gui: Allow users to manually rebroadcast a wallet transaction by achow101)
    • #36444 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36444.svg"></sub> (wallet: Store information about created and imported multipath descriptors by achow101)
    • #36443 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36443.svg"></sub> (descriptor: Reconstruct a multipath descriptor from its expansion by achow101)
    • #36442 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36442.svg"></sub> (descriptor: Represent multipath descriptors in a single Descriptor object by achow101)
    • #36380 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36380.svg"></sub> (wallet: extend -walletbroadcast to allow initial send only by vasild)
    • #36268 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36268.svg"></sub> (refactor: prune unused semi-colons by fanquake)
    • #36167 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36167.svg"></sub> (build: Enable -Wunused by fanquake)
    • #36122 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36122.svg"></sub> (BIP460: CISA for Taproot key path spends by fjahr)
    • #35998 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35998.svg"></sub> (wallet: Handle or explicitly ignore WalletBatch write failures by achow101)
    • #35786 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35786.svg"></sub> (wallet: drop spent parents redundant cache invalidation and notification by furszy)
    • #35716 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35716.svg"></sub> (wallet: Replace mapWallet and wtxOrdered with a boost::multi_index by achow101)
    • #35302 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35302.svg"></sub> (Silent Payments: Sending (take 2) by Eunovo)
    • #34909 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34909.svg"></sub> (wallet, refactor: modularise wallet by extracting out legacy wallet migration by rkrux)
    • #34603 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34603.svg"></sub> (wallet: Fix detection of symlinks on Windows by achow101)
    • #34520 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34520.svg"></sub> (refactor: Add [[nodiscard]] to functions returning bool+mutable ref by maflcko)
    • #34193 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34193.svg"></sub> (wallet: make migration more robust against failures by furszy)
    • #33112 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/33112.svg"></sub> (wallet: relax external_signer flag constraints by Sjors)
    • #30343 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/30343.svg"></sub> (wallet, logging: Replace WalletLogPrintf() with LogInfo() by ryanofsky)
    • #27865 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/27865.svg"></sub> (wallet: Track no-longer-spendable TXOs separately by achow101)
    • #26022 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/26022.svg"></sub> (Add util::ResultPtr class by ryanofsky)
    • #25665 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/25665.svg"></sub> (refactor: Add util::Result failure types and ability to merge result values by ryanofsky)

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    LLM Linter (✨ experimental)

    Possible typos and grammar issues:

    • 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: Parse(desc_str, provider, error, false)
    • src/wallet/legacy/spkm.cpp: WalletDescriptor w_desc(std::move(descs.at(0)), creation_time, 0, 0, 0)
    • src/wallet/legacy/spkm.cpp: Parse(desc_str, provider, error, false)
    • src/wallet/legacy/spkm.cpp: WalletDescriptor w_desc(std::move(descs.at(0)), creation_time, 0, 0, 0)
    • src/wallet/legacy/spkm.cpp: WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0)
    • src/wallet/legacy/spkm.cpp: Parse(desc_str, parsed_keys, parse_error, false)
    • src/wallet/legacy/migration.cpp: WalletDescriptor w_desc(std::move(descs.at(0)), creation_time, 0, 0, 0)
    • src/wallet/legacy/migration.cpp: AddWalletDescriptor(w_desc, keys, "", false)
    • src/wallet/legacy/migration.cpp: WalletDescriptor w_desc(std::move(descs.at(0)), creation_time, 0, 0, 0)
    • src/wallet/legacy/migration.cpp: AddWalletDescriptor(w_desc, keys, "", false)

    <sup>2026-11-16 23:12:50</sup>

  19. DrahtBot added the label CI failed on Nov 16, 2026
  20. DrahtBot commented at 11:34 PM on November 16, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task macOS-cross to x86_64: https://github.com/bitcoin/bitcoin/actions/runs/43977159977/job/133683977345</sub> <sub>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.</sub>

    <details><summary>Hints</summary>

    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.

    </details>


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-19 19:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me