Skip to content

wallet, refactor: modularise wallet by extracting out legacy wallet migration - #34909

Merged
fanquake merged 5 commits into
bitcoin:masterfrom
rkrux:wallet-migration
Nov 24, 2026
Merged

fanquake merged 5 commits into
bitcoin:masterfrom
rkrux:wallet-migration

Conversation

@rkrux

@rkrux rkrux commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

I've been meaning to scratch this itch for quite some time. It has been noted
by many developers that the wallet/wallet.cpp file is quite hard to reason
about.

It is more than 4500 lines long currently and this patch is an attempt to
shortern it by around 800 lines by extracting out the wallet migration code into
a dedicated wallet/migration.cpp file.

The other benefits of this PR I see are that it moves the legacy wallet stuff
from the main wallet file that paves the way for it being descriptor specific
(as much as possible), and makes legacy wallet migration code a first-class
citizen in its own file.

I hope it makes it easier for everyone to go through the main wallet file.

This patchset should be reviewed with --color-moved=dimmed-zebra option.

@DrahtBot

DrahtBot commented Mar 24, 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
ACK achow101, maflcko
Concept ACK pablomartin4btc, w0xlt

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:

  • #36825 (wallet: fix migration with watch-only transactions by psychemist)
  • #36823 (wallet, migration: Skip legacy wallet records rather than erasing them, and drop unused record erase functions by achow101)
  • #36444 (wallet: Store information about created and imported multipath descriptors by achow101)
  • #36443 (descriptor: Reconstruct a multipath descriptor from its expansion by achow101)
  • #36442 (descriptor: Represent multipath descriptors in a single Descriptor object by achow101)
  • #36268 (refactor: prune unused semi-colons by fanquake)
  • #35998 (wallet: Handle or explicitly ignore WalletBatch write failures by achow101)
  • #35716 (wallet: Replace mapWallet and wtxOrdered with a boost::multi_index by achow101)
  • #34603 (wallet: Fix detection of symlinks on Windows by achow101)
  • #30343 (wallet, logging: Replace WalletLogPrintf() with LogInfo() by ryanofsky)
  • #27865 (wallet: Track no-longer-spendable TXOs separately by achow101)
  • #26022 (Add util::ResultPtr class by ryanofsky)
  • #25665 (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.

LLM Linter (✨ experimental)

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/migration.cpp: WalletDescriptor(std::move(descs.at(0)), creation_time, 0, 0, 0) (watch-only descriptors)
  • src/wallet/migration.cpp: AddWalletDescriptor(w_desc, keys, "", false)
  • src/wallet/migration.cpp: WalletDescriptor(std::move(descs.at(0)), creation_time, 0, 0, 0) (solvable descriptors)
  • src/wallet/migration.cpp: AddWalletDescriptor(w_desc, keys, "", false)

2026-11-23 09:54:33

@rkrux

rkrux commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

Fixed two things:

  • the linter issue where the trailing new line at the end of the file was missing.
  • forgot to update the migration portion in bench for which I didn't get an error in local, checking why.

@rkrux
rkrux force-pushed the wallet-migration branch from d41f17f to 1b3fc52 Compare March 25, 2026 11:01
@rkrux rkrux changed the title wallet, refactor: extract migration portion from the wallet file wallet, refactor: modularise wallet by extracting out legacy wallet migration Mar 25, 2026
@DrahtBot DrahtBot changed the title wallet, refactor: modularise wallet by extracting out legacy wallet migration wallet, refactor: modularise wallet by extracting out legacy wallet migration Mar 25, 2026
@rkrux

rkrux commented Mar 25, 2026

Copy link
Copy Markdown
Contributor Author

Pushed an update where three more migration specific CWallet methods are extracted out.

@rkrux

rkrux commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased over master to incorporate changes from #36397.

@achow101 achow101 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.

I think it would be better if we could put all of the legacy wallet migration stuff into its own subdirectory, e.g. src/wallet/legacy/ rather than having the multiple migration related files in the main wallet module directory. This would let us separate out all of the migration things without polluting the main module with these files, especially as there are more things that can be pulled out (in future PRs) from database things.

Comment thread src/wallet/migration.cpp Resolved
@achow101

Copy link
Copy Markdown
Member

ACK 60136a6

I've opened #36897 to implement the suggestions I made earlier, along with additional encapsulation.

Comment thread src/wallet/wallet.h Resolved
from wallet/wallet.cpp to wallet/migration.cpp.

This patch should be reviewed with --color-moved=dimmed-zebra option.
…lletutil.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.
to wallet/migration. Also, update the includes in the call sites.

This patch should be reviewed with --color-moved=dimmed-zebra.
to wallet/migration.

This patch should be reviewed with --color-moved=dimmed-zebra.
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.
@rkrux

rkrux commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased over master to fix conflicts with #36087.

@achow101

Copy link
Copy Markdown
Member

ACK 9fd8e54

@maflcko

maflcko commented Nov 24, 2026

Copy link
Copy Markdown
Member

review ACK 9fd8e54 🥗

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK 9fd8e543b3ceed08a4bb8ce3d8d342195403056e 🥗
NpOxjC6hlY0eU1ALpaDJMeqcXKUbtj1qfYSL0fWGyPUooGBsIq7Ve3ac4F0t6z8ifjvVKhigmOthb92XQ9vrCg==

@furszy

furszy commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

#34193 😭. Painful rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants