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

Open
kah-ja wants to merge 2 commits from wallet-load-missing-flags into master AGit
kah-ja commented 2026-11-16 06:52:19 +00:00 (Migrated from github.com)

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.

`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](https://www.turingpoint.de).
DrahtBot commented 2026-11-16 06:52:36 +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.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36897 (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.

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)

2026-11-16 06:52:49

<!--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/36887 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36887.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36887#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. A summary of reviews will appear here. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36897](https://github.com/bitcoin/bitcoin/pull/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>
First-time contributor

🔵 Suggestion · Missing FLAGS produces migration advice that cannot work

For a SQLite wallet missing FLAGS, the new rejection recommends migratewallet, which instead says it is already a descriptor wallet; occurrence outside deliberately edited test files is unconfirmed.

Location: src/wallet/walletdb.cpp:470 (head).

Review coverage was incomplete.


Reviewed: 7af8fcd6fb5b · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:4afac00dcf2100063250ef321636839508f727ef6ae0cc9ede404a011c46a59f:87c7358e6b1a9709279e41fe01f3f324759c2be7a6239dcb2b0a6d875f8630b0 --> <!-- ralph-base:a527a0077a0fcae913188410214efe98021c0cca --> <!-- ralph-head:7af8fcd6fb5ba94a10856c013842bd081e842867 --> <!-- ralph-case:0e1992d19d0b1295d45eec00c55d518dff50a19bd65e0852d759436d380eb774 --> **🔵 Suggestion · Missing `FLAGS` produces migration advice that cannot work** For a SQLite wallet missing `FLAGS`, the new rejection recommends `migratewallet`, which instead says it is already a descriptor wallet; occurrence outside deliberately edited test files is unconfirmed. Location: [`src/wallet/walletdb.cpp:470`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/7af8fcd6fb5ba94a10856c013842bd081e842867/src/wallet/walletdb.cpp#L470>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`7af8fcd6fb5b`](<https://git.fish.foo/bitcoin/bitcoin/commit/7af8fcd6fb5ba94a10856c013842bd081e842867>) · [Review report](<https://review.fish.foo/report/36887-7af8fcd6fb5ba94a10856c013842bd081e842867-2701-1.html>) · [Previous reports](<https://review.fish.foo/traces/36887/>) [permalink](<https://review.fish.foo/report/36887-7af8fcd6fb5ba94a10856c013842bd081e842867-2701-1.html>)
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!36887
No description provided.