wallet, refactor: Remove Legacy check and error #33082

pull pablomartin4btc wants to merge 2 commits into bitcoin:master from pablomartin4btc:wallet-refactor-remove-legacy-checks-and-errors changing 4 files +1 −6
  1. pablomartin4btc commented at 6:36 pm on July 28, 2025: member

    Remove dead code due to legacy wallet removal.

    Leftovers from previous #32481.


    Note:

    While attempting to remove the legacy check in CWallet::UpgradeDescriptorCache() (which is called from DBErrors WalletBatch::LoadWallet(CWallet* pwallet)), I once again ran into the fact that LoadWallet() is used in two distinct scenarios — something I was already aware of:

    • Wallet creation – the upgrade is ignored here because no wallet flags are yet set; attempting to set a flag (ie WALLET_FLAG_LAST_HARDENED_XPUB_CACHED at the end of the upgrade function, if the legacy check is removed) would produce a failure (DBErrors CWallet::LoadWallet() -> Assert(m_wallet_flags == 0)).
    • Wallet loading – the upgrade proceeds correctly and the flag WALLET_FLAG_LAST_HARDENED_XPUB_CACHED is set.

    While revisiting this, I also noticed that some LoadWallet() calls in the wallet tests are unnecessary and I’ve removed them in the first commit.

    The following change in UpgradeDescriptorCache() could be done in PR #32636 as part of the separation between wallet loading and creation responsibilities.

    0 
    1 void CWallet::UpgradeDescriptorCache()
    2 {
    3+    // Only descriptor wallets can upgrade descriptor cache
    4+    Assert(IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
    5+
    6-    if (!IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS) || IsLocked() || IsWalletFlagSet(WALLET_FLAG_LAST_HARDENED_XPUB_CACHED)) {
    7+    if (IsLocked() || IsWalletFlagSet(WALLET_FLAG_LAST_HARDENED_XPUB_CACHED)) {
    8         return;
    9     }
    
  2. DrahtBot commented at 6:36 pm on July 28, 2025: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33082.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK davidgumberg, l0rinc
    Stale ACK brunoerg

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #32636 (Split CWallet::Create() into CreateNew and LoadExisting by davidgumberg)

    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.

  3. pablomartin4btc marked this as a draft on Jul 28, 2025
  4. DrahtBot added the label CI failed on Jul 28, 2025
  5. DrahtBot commented at 11:35 pm on July 28, 2025: contributor

    🚧 At least one of the CI tasks failed. Task MSan, depends: https://github.com/bitcoin/bitcoin/runs/46884702924 LLM reason (✨ experimental): The CI failure is caused by an assertion failure in wallet/wallet.cpp:521 due to IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS), leading to subprocess abortion.

    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.

  6. fanquake commented at 9:35 am on July 29, 2025: member

    https://github.com/bitcoin/bitcoin/actions/runs/16577317093/job/46884696846?pr=33082#step:7:2967:

    0 131/145 Test   [#7](/bitcoin-bitcoin/7/): bench_sanity_check ...................Subprocess aborted***Exception:  30.55 sec
    1Running with -sanity-check option, output is being suppressed as benchmark results will be useless.
    2wallet/wallet.cpp:521 UpgradeDescriptorCache: Assertion `IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)' failed.
    
  7. pablomartin4btc commented at 2:12 pm on July 29, 2025: member

    131/145 Test # 7: bench_sanity_check ……………….Subprocess aborted***Exception: 30.55 sec wallet/wallet.cpp:521 UpgradeDescriptorCache: Assertion `IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)’ failed.

    Yeah, I’m on it, that’s why I put it on draft yesterday. Thanks!

  8. pablomartin4btc force-pushed on Jul 31, 2025
  9. pablomartin4btc force-pushed on Jul 31, 2025
  10. test: Remove unnecessary LoadWallet() calls 30c6f64eed
  11. pablomartin4btc force-pushed on Aug 1, 2025
  12. pablomartin4btc commented at 1:19 am on August 1, 2025: member

    Updates

    • Reverted a legacy wallet check and removed some unnecessary LoadWallet() calls from a few wallet tests in the first commit.
  13. pablomartin4btc marked this as ready for review on Aug 1, 2025
  14. DrahtBot removed the label CI failed on Aug 1, 2025
  15. in src/wallet/wallet.cpp:3659 in 3d8a1895fc outdated
    3655@@ -3656,9 +3656,8 @@ util::Result<std::reference_wrapper<DescriptorScriptPubKeyMan>> CWallet::AddWall
    3656 {
    3657     AssertLockHeld(cs_wallet);
    3658 
    3659-    if (!IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
    3660-        return util::Error{_("Cannot add WalletDescriptor to a non-descriptor wallet")};
    3661-    }
    3662+    // Descriptors can only be added to descriptor wallets
    


    brunoerg commented at 7:05 pm on August 21, 2025:
    3d8a1895fcbc6802e1692fd57a4f63a948fda302: nit: Since we don’t have legacy wallet anymore, I’m not sure how effective is this comment.

    pablomartin4btc commented at 0:03 am on August 22, 2025:
    Ok, I’ll remove it.

    pablomartin4btc commented at 7:49 pm on August 22, 2025:
    Done.
  16. brunoerg commented at 7:10 pm on August 21, 2025: contributor

    code review ACK 3d8a1895fcbc6802e1692fd57a4f63a948fda302

    • Checked that the unecessary calls to LoadWallet were removed from the tests - I didn’t find any other occurance apart of TestLoadWallet.
  17. wallet, refactor: Remove Legacy check and error
    Remove dead code due to legacy wallet removal.
    d3c5e47391
  18. pablomartin4btc force-pushed on Aug 22, 2025
  19. pablomartin4btc commented at 7:58 pm on August 22, 2025: member

    Updates

    • Addressed @brunoerg’s feedback; removed redundant comment, as the added assertion makes the message clear enough.
  20. davidgumberg referenced this in commit 357b1b8513 on Aug 23, 2025
  21. davidgumberg commented at 6:50 am on August 23, 2025: contributor

    crACK https://github.com/bitcoin/bitcoin/pull/33082/commits/d3c5e47391e2f158001e3e199d625852c7f18998

    Removes unuseful legacy wallet code, also suggested here: #32636 (review)

    The suggestion in the PR description won’t work without https://github.com/bitcoin/bitcoin/pull/33082/commits/30c6f64eed304560464f9601b80c811c186db20a, if this gets merged first I’ll add it to #32636.

  22. DrahtBot requested review from brunoerg on Aug 23, 2025
  23. l0rinc approved
  24. l0rinc commented at 6:59 pm on September 4, 2025: contributor

    code review ACK d3c5e47391e2f158001e3e199d625852c7f18998 Somebody more familiar should verify it conceptually as well.

    It also removes an objectionable translation 👍


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: 2025-09-07 06:12 UTC

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