wallet, migration: Skip legacy wallet records rather than erasing them, and drop unused record erase functions #36823

Open
achow101 wants to merge 5 commits from rm-erase-txs into master AGit
achow101 commented 2026-11-10 00:10:07 +00:00 (Migrated from github.com)

When migrating a legacy wallet, we can skip the records in MigrateToSQLite that we would delete later on during migration. These records are specifically all of the legacy wallet records, and transaction records. The legacy wallet records are replaced with descriptor records produced during migration, and transaction records are already being rewritten by migration, so not writing them in the first place is also fine. This allows us to remove several database record erase functions, specifically EraseTx and EraseRecords.

When migrating a legacy wallet, we can skip the records in `MigrateToSQLite` that we would delete later on during migration. These records are specifically all of the legacy wallet records, and transaction records. The legacy wallet records are replaced with descriptor records produced during migration, and transaction records are already being rewritten by migration, so not writing them in the first place is also fine. This allows us to remove several database record erase functions, specifically EraseTx and EraseRecords.
DrahtBot commented 2026-11-10 00:10:14 +00:00 (Migrated from github.com)

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:

  • #37055 (refactor: drop format calls on strings without arguments by fanquake)
  • #36767 (wallet: fix crash when external signer wallet creation fails by zerog975)
  • #36167 (build: Enable -Wunused by fanquake)
  • #35998 (wallet: Handle or explicitly ignore WalletBatch write failures by achow101)
  • #35786 (wallet: drop spent parents redundant cache invalidation and notification by furszy)
  • #35302 (Silent Payments: Sending (take 2) by Eunovo)
  • #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/migration.cpp: entires → entries [misspelling]

2026-11-30 20:41:52

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36823 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36823.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36823#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | Concept ACK | [rkrux](https://github.com/bitcoin/bitcoin/pull/36823#issuecomment-7130507309) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#37055](https://github.com/bitcoin/bitcoin/pull/37055) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/37055.svg"></sub> (refactor: drop format calls on strings without arguments by fanquake) * [#36767](https://github.com/bitcoin/bitcoin/pull/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) * [#36167](https://github.com/bitcoin/bitcoin/pull/36167) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36167.svg"></sub> (build: Enable `-Wunused` by fanquake) * [#35998](https://github.com/bitcoin/bitcoin/pull/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](https://github.com/bitcoin/bitcoin/pull/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) * [#35302](https://github.com/bitcoin/bitcoin/pull/35302) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35302.svg"></sub> (Silent Payments: Sending (take 2) by Eunovo) * [#27865](https://github.com/bitcoin/bitcoin/pull/27865) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/27865.svg"></sub> (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. <!--5faf32d7da4f0f540f40219e4f7537a3--> ### LLM Linter (✨ experimental) Possible typos and grammar issues: - `src/wallet/migration.cpp`: `entires` → `entries` [misspelling] <sup>2026-11-30 20:41:52</sup>
First-time contributor

Earlier concerns neither republished nor resolved: 1 minor finding · 1 suggestion. See the Run archive linked from the Review report for their assessments.

🔴 Major · Migration drops address-book entries from otherwise blank legacy wallets

A blank legacy wallet containing saved sending addresses migrates successfully but loses those entries after reload, although the .legacy.bak backup retains them.

Location: src/wallet/migration.cpp:82 (head).

🟠 Minor · WTX_VARIANT records are not rebuilt for retained transactions

Migration drops non-canonical witness variants if present in a legacy wallet's retained transactions; no released legacy-wallet writer producing these records was identified.

Location: src/wallet/migration.cpp:80 (head).

🟠 Minor · Malformed record keys bypass temporary migration database cleanup

CopyMigrationRecords can leave a temporary database behind when a malformed key throws; no current Bitcoin Core writer producing such keys was identified.

Location: src/wallet/migration.cpp:89 (head).

🔵 Suggestion · ApplyMigrationData ignores its only record-write results

WriteTxMetadata and func_store_addr now provide the main wallet's only transaction and address-book writes, but their failures do not necessarily prevent migration from committing.

Location: src/wallet/migration.cpp:367 (head).

🔵 Suggestion · CopyMigrationRecords duplicates the serialized wallet

Passing records by value deep-copies every serialized key and value, increasing migration's memory use without changing its behavior.

Location: src/wallet/migration.cpp:68 (head).

🔵 Suggestion · RECEIVE label distribution changes alongside the storage refactor

For a receiving address retained by the main wallet, auxiliary wallets no longer receive its label unless they also own the address, changing behavior beyond storage-copy removal.

Location: src/wallet/migration.cpp:391 (head).

Review coverage was incomplete.


Reviewed: 7e5389d97c87 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:312ddb2095238aa2ca395a9cc39b05ab5a38a7177afbdb0d69098df9c3e0bef9:9a7f127b15c6116c267953d38288a9f17ec7c7bcd3a975fb71a2db8bfd974dbf --> <!-- ralph-base:1ea904d983f8841c28cb8240c576e46ac2efe529 --> <!-- ralph-head:7e5389d97c876d30bb1b692bb84d32ff08e095d7 --> <!-- ralph-case:8447a5dc9f3d2a057988116d341fe2f0492cd82f54e12d89542000a2d2b23cb4 --> Earlier concerns neither republished nor resolved: 1 minor finding · 1 suggestion. See the Run archive linked from the Review report for their assessments. **🔴 Major · Migration drops address-book entries from otherwise blank legacy wallets** A blank legacy wallet containing saved sending addresses migrates successfully but loses those entries after reload, although the `.legacy.bak` backup retains them. Location: [`src/wallet/migration.cpp:82`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/7e5389d97c876d30bb1b692bb84d32ff08e095d7/src/wallet/migration.cpp#L82>) (head). **🟠 Minor · `WTX_VARIANT` records are not rebuilt for retained transactions** Migration drops non-canonical witness variants if present in a legacy wallet's retained transactions; no released legacy-wallet writer producing these records was identified. Location: [`src/wallet/migration.cpp:80`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/7e5389d97c876d30bb1b692bb84d32ff08e095d7/src/wallet/migration.cpp#L80>) (head). **🟠 Minor · Malformed record keys bypass temporary migration database cleanup** `CopyMigrationRecords` can leave a temporary database behind when a malformed key throws; no current Bitcoin Core writer producing such keys was identified. Location: [`src/wallet/migration.cpp:89`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/7e5389d97c876d30bb1b692bb84d32ff08e095d7/src/wallet/migration.cpp#L89>) (head). **🔵 Suggestion · `ApplyMigrationData` ignores its only record-write results** `WriteTxMetadata` and `func_store_addr` now provide the main wallet's only transaction and address-book writes, but their failures do not necessarily prevent migration from committing. Location: [`src/wallet/migration.cpp:367`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/7e5389d97c876d30bb1b692bb84d32ff08e095d7/src/wallet/migration.cpp#L367>) (head). **🔵 Suggestion · `CopyMigrationRecords` duplicates the serialized wallet** Passing `records` by value deep-copies every serialized key and value, increasing migration's memory use without changing its behavior. Location: [`src/wallet/migration.cpp:68`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/7e5389d97c876d30bb1b692bb84d32ff08e095d7/src/wallet/migration.cpp#L68>) (head). **🔵 Suggestion · `RECEIVE` label distribution changes alongside the storage refactor** For a receiving address retained by the main wallet, auxiliary wallets no longer receive its label unless they also own the address, changing behavior beyond storage-copy removal. Location: [`src/wallet/migration.cpp:391`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/7e5389d97c876d30bb1b692bb84d32ff08e095d7/src/wallet/migration.cpp#L391>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`7e5389d97c87`](<https://git.fish.foo/bitcoin/bitcoin/commit/7e5389d97c876d30bb1b692bb84d32ff08e095d7>) · [Review report](<https://review.fish.foo/report/36823-7e5389d97c876d30bb1b692bb84d32ff08e095d7-3363-9.html>) · [Previous reports](<https://review.fish.foo/traces/36823/>) [permalink](<https://review.fish.foo/report/36823-7e5389d97c876d30bb1b692bb84d32ff08e095d7-3363-9.html>)
DrahtBot commented 2026-11-11 18:02:31 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
rkrux commented 2026-11-24 11:45:27 +00:00 (Migrated from github.com)

Concept ACK - good find, helps in code clean up.

Concept ACK - good find, helps in code clean up.
DrahtBot commented 2026-11-24 16:48:09 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
DrahtBot commented 2026-11-24 22:32:06 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/45491569567/job/138790995980
LLM reason (✨ experimental): CI failed because the lint check assert_falsy found assert(false) in src/wallet/migration.cpp:117; replace it with AssertUnreachable().

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.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `lint`: https://github.com/bitcoin/bitcoin/actions/runs/45491569567/job/138790995980</sub> <sub>LLM reason (✨ experimental): CI failed because the lint check `assert_falsy` found `assert(false)` in `src/wallet/migration.cpp:117`; replace it with `AssertUnreachable()`.</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>
DrahtBot commented 2026-11-25 21:44:33 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36823
No description provided.