wallet: Require the descriptors flag when the FLAGS record is missing #36887

pull kah-ja wants to merge 2 commits into bitcoin:master from kah-ja:wallet-load-missing-flags changing 5 files +40 −9
  1. kah-ja commented at 6:52 AM on November 16, 2026: none

    LoadWalletFlags checks for WALLET_FLAG_DESCRIPTORS only inside if (batch.Read(DBKeys::FLAGS, flags)). A SQLite wallet file without a FLAGS record is loaded with no flags set and then handled as a legacy wallet, which ends in an Assert:

    • with a legacy record in the file: SetupLegacyDataSPKM, Assert(m_database->Format() == "bdb_ro" || m_database->Format() == "sqlite-mock")
    • without one: LoadActiveScriptPubKeyMan, Assert(IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS))

    loadwallet on such a file aborts the node. If the wallet is in the load on startup list, the node aborts on every start. The existing check for legacy records in a descriptor wallet (UNEXPECTED_LEGACY_ENTRY) does not catch this, because it also depends on the flag.

    The second commit does the check whether or not the record exists, so the file is rejected with the legacy wallet error.

    The first commit is needed for that: bitcoin-wallet create opened the new, empty database through PopulateWalletFromDB before it wrote the flags, which is the case the comment "The FLAGS key is absent during wallet creation" refers to. CWallet::CreateNew does not load anymore, and now the tool does not either. It writes the version records itself, as CreateNew does.

    Behavior change: a wallet database without a FLAGS record no longer loads. bitcoin-wallet create writes the same set of records as before (compared by record type on a new wallet).

    Measurement: regtest, RelWithDebInfo, base a527a0077a, descriptor wallet made with createwallet, then edited with sqlite3.

    file master this PR
    FLAGS record deleted node aborts, wallet.cpp:3577 error -4, node keeps running
    FLAGS record deleted, cscript record added node aborts, wallet.cpp:3404 error -4, node keeps running
    unchanged loads loads

    Tests: new case in wallet_descriptor.py for both files; on master the node aborts in it. Three unit tests that load a hand written database now write the flags first. Passing locally: test_bitcoin and test_runner.py with the default list. Not run: fuzz targets, lint.

    Contributed by turingpoint.

  2. wallettool: Do not load a newly created wallet database
    The create command opened the new, empty database through
    PopulateWalletFromDB before it set the wallet flags and generated the
    descriptors. There is nothing to load at that point, and it made the
    loading code accept a database without a FLAGS record.
    
    Skip the load when creating, and write the version records in
    WalletCreate as CWallet::CreateNew does, since loading no longer
    writes them.
    
    Signed-off-by: Jan Kahmen <jan@turingpoint.de>
    94787f83f6
  3. wallet: Require the descriptors flag when the FLAGS record is missing
    LoadWalletFlags only checked for WALLET_FLAG_DESCRIPTORS when the
    database had a FLAGS record. A SQLite wallet file without that record
    was loaded with no flags set and then handled as a legacy wallet,
    which ends in an Assert:
    
    - with a legacy record, in SetupLegacyDataSPKM, because the database
      is not bdb_ro
    - otherwise in LoadActiveScriptPubKeyMan, because the descriptors
      flag is not set
    
    loadwallet aborts the node on such a file, and with the wallet in the
    load on startup list the node no longer starts.
    
    Do the check whether or not the record exists, so the file is
    rejected as a legacy wallet. Nothing loads a database without the
    record anymore now that the wallet tool does not load on create. The
    unit tests that load a hand written database write the flags first.
    
    Signed-off-by: Jan Kahmen <jan@turingpoint.de>
    7af8fcd6fb
  4. DrahtBot added the label Wallet on Nov 16, 2026
  5. DrahtBot commented at 6:52 AM 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:

    • #36897 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36897.svg"></sub> (wallet, migration: Contain all legacy wallet and migration related things in its own subdirectory, namespace, and classes 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 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/test/walletload_tests.cpp: WalletDescriptor(std::make_shared<DummyDescriptor>(unknown_desc), 0, 0, 0, 0)
    • src/wallet/test/walletload_tests.cpp: WalletDescriptor(std::make_shared<DummyDescriptor>(desc), 0, 0, 0, 0)
    • src/wallet/test/walletload_tests.cpp: WalletDescriptor(descriptor, 0, 0, 0, 0)

    <sup>2026-11-16 06:52:49</sup>

Contributors
Labels

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