WIP: wallet: Store information about created and imported multipath descriptors #36444

Draft
achow101 wants to merge 18 commits from wallet-store-multipath into master AGit
achow101 commented 2026-10-05 22:25:11 +00:00 (Migrated from github.com)

The wallet does not store any information about multipath descriptors. When a multipath descriptor is imported, it is first expanded, then the expansion descriptors are imported into the wallet.

This PR adds a field to WalletDescriptor which stores the IDs of the ScriptPubKeyMans of the descriptors that are part of the expansion, in the order that they are expanded. This allows us to use ReconstructMultipath to produce the multipath descriptor when necessary.

This is useful for working with hardware wallets that require policy registration, particularly those that require resending the descriptor that was registered.

listdescriptors is updated to include a multipath_descriptor field which contains the multipath descriptor for each individual descriptor if it originally came from a multipath descriptor.

Lastly, the automatically generated descriptors are now produced and stored as multipath descriptors, so listdescriptors will provide a multipath_descriptor for everything that the wallet automatically generates.

Note that the IDs stored in the wallet are ScriptPubKeyMan IDs, which we cannot compute from a descriptor as we assume to be opaque blobs since #35445.

Alternative to #36133, depends on #36442 and #36443

The wallet does not store any information about multipath descriptors. When a multipath descriptor is imported, it is first expanded, then the expansion descriptors are imported into the wallet. This PR adds a field to `WalletDescriptor` which stores the IDs of the ScriptPubKeyMans of the descriptors that are part of the expansion, in the order that they are expanded. This allows us to use `ReconstructMultipath` to produce the multipath descriptor when necessary. This is useful for working with hardware wallets that require policy registration, particularly those that require resending the descriptor that was registered. `listdescriptors` is updated to include a `multipath_descriptor` field which contains the multipath descriptor for each individual descriptor if it originally came from a multipath descriptor. Lastly, the automatically generated descriptors are now produced and stored as multipath descriptors, so `listdescriptors` will provide a `multipath_descriptor` for everything that the wallet automatically generates. Note that the IDs stored in the wallet are ScriptPubKeyMan IDs, which we cannot compute from a descriptor as we assume to be opaque blobs since #35445. Alternative to #36133, depends on #36442 and #36443
DrahtBot commented 2026-10-05 22:25:20 +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 w0xlt, 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:

  • #36885 (wallet, rpc: Add analyzedescriptor for multisig setups by pablomartin4btc)
  • #36820 (refactor: remove more dead code by fanquake)
  • #36648 (descriptor, rpc, wallet: do not echo key material in error messages by fametrano)
  • #36402 (refactor: wallet_importdescriptors to separate run_test() contents into specific functions by nebula-21)
  • #36122 (BIP460: CISA for Taproot key path spends by fjahr)
  • #36070 (wallet: Add deriveHDKey interface by PraneethGunas)
  • #36005 (rpc, descriptor: warn when multipath expansion clones single-path key expressions by pythcoiner)
  • #35918 (descriptor: Expose key expression parsing by pseudoramdom)
  • #35444 (wallet: make descriptor SPKM mutex non-recursive by w0xlt)
  • #35377 (wallet: Allow importing of descriptors without private keys when the wallet has the private keys by achow101)
  • #34909 (wallet, refactor: modularise wallet by extracting out legacy wallet migration by rkrux)
  • #31668 (Added rescan option for import descriptors by saikiran57)

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/util/bip32.h: give → given [word-form typo in “for a give multipath position”]

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/script/descriptor.cpp: std::make_unique<ConstPubkeyProvider>(key_exp_index, pubkey, false)
  • src/script/descriptor.cpp: std::make_unique<ConstPubkeyProvider>(key_exp_index, pubkey, true)
  • src/script/descriptor.cpp: std::make_unique<ConstPubkeyProvider>(0, pubkey, false)
  • src/script/descriptor.cpp: std::make_unique<ConstPubkeyProvider>(0, pubkey, true)
  • src/qt/test/wallettests.cpp: WalletDescriptor w_desc(std::move(desc), 0, 0, 1, 1)
  • src/wallet/scriptpubkeyman.cpp: Parse(desc_str, provider, error, false)
  • src/wallet/scriptpubkeyman.cpp: WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0)
  • src/wallet/scriptpubkeyman.cpp: WalletDescriptor w_desc(std::move(desc), 0, 0, chain_counter, 0)
  • src/wallet/test/fuzz/scriptpubkeyman.cpp: Parse(desc_str.value(), keys, error, false)
  • src/wallet/test/psbt_wallet_tests.cpp: WalletDescriptor w_desc(std::move(desc), 0, 0, 10, 0)
  • src/wallet/test/util.cpp: Parse(desc_str, keys, error, false)
  • src/wallet/test/wallet_tests.cpp: WalletDescriptor w_desc{std::move(desc), 0, 0, 0, 0}
  • src/wallet/walletutil.cpp: WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0)

2026-11-07 03:09:03

<!--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/36444 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36444.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36444#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 | [w0xlt](https://github.com/bitcoin/bitcoin/pull/36444#issuecomment-6066074390), [rkrux](https://github.com/bitcoin/bitcoin/pull/36444#issuecomment-7192570468) | 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: * [#36885](https://github.com/bitcoin/bitcoin/pull/36885) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36885.svg"></sub> (wallet, rpc: Add analyzedescriptor for multisig setups by pablomartin4btc) * [#36820](https://github.com/bitcoin/bitcoin/pull/36820) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36820.svg"></sub> (refactor: remove more dead code by fanquake) * [#36648](https://github.com/bitcoin/bitcoin/pull/36648) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36648.svg"></sub> (descriptor, rpc, wallet: do not echo key material in error messages by fametrano) * [#36402](https://github.com/bitcoin/bitcoin/pull/36402) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36402.svg"></sub> (refactor: `wallet_importdescriptors` to separate `run_test()` contents into specific functions by nebula-21) * [#36122](https://github.com/bitcoin/bitcoin/pull/36122) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36122.svg"></sub> (BIP460: CISA for Taproot key path spends by fjahr) * [#36070](https://github.com/bitcoin/bitcoin/pull/36070) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36070.svg"></sub> (wallet: Add deriveHDKey interface by PraneethGunas) * [#36005](https://github.com/bitcoin/bitcoin/pull/36005) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36005.svg"></sub> (rpc, descriptor: warn when multipath expansion clones single-path key expressions by pythcoiner) * [#35918](https://github.com/bitcoin/bitcoin/pull/35918) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35918.svg"></sub> (descriptor: Expose key expression parsing by pseudoramdom) * [#35444](https://github.com/bitcoin/bitcoin/pull/35444) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35444.svg"></sub> (wallet: make descriptor SPKM mutex non-recursive by w0xlt) * [#35377](https://github.com/bitcoin/bitcoin/pull/35377) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35377.svg"></sub> (wallet: Allow importing of descriptors without private keys when the wallet has the private keys by achow101) * [#34909](https://github.com/bitcoin/bitcoin/pull/34909) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34909.svg"></sub> (wallet, refactor: modularise wallet by extracting out legacy wallet migration by rkrux) * [#31668](https://github.com/bitcoin/bitcoin/pull/31668) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/31668.svg"></sub> (Added rescan option for import descriptors by saikiran57) 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/util/bip32.h`: `give` → `given` [word-form typo in “for a give multipath position”] 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/script/descriptor.cpp`: `std::make_unique<ConstPubkeyProvider>(key_exp_index, pubkey, false)` - `src/script/descriptor.cpp`: `std::make_unique<ConstPubkeyProvider>(key_exp_index, pubkey, true)` - `src/script/descriptor.cpp`: `std::make_unique<ConstPubkeyProvider>(0, pubkey, false)` - `src/script/descriptor.cpp`: `std::make_unique<ConstPubkeyProvider>(0, pubkey, true)` - `src/qt/test/wallettests.cpp`: `WalletDescriptor w_desc(std::move(desc), 0, 0, 1, 1)` - `src/wallet/scriptpubkeyman.cpp`: `Parse(desc_str, provider, error, false)` - `src/wallet/scriptpubkeyman.cpp`: `WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0)` - `src/wallet/scriptpubkeyman.cpp`: `WalletDescriptor w_desc(std::move(desc), 0, 0, chain_counter, 0)` - `src/wallet/test/fuzz/scriptpubkeyman.cpp`: `Parse(desc_str.value(), keys, error, false)` - `src/wallet/test/psbt_wallet_tests.cpp`: `WalletDescriptor w_desc(std::move(desc), 0, 0, 10, 0)` - `src/wallet/test/util.cpp`: `Parse(desc_str, keys, error, false)` - `src/wallet/test/wallet_tests.cpp`: `WalletDescriptor w_desc{std::move(desc), 0, 0, 0, 0}` - `src/wallet/walletutil.cpp`: `WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0)` <sup>2026-11-07 03:09:03</sup>
DrahtBot commented 2026-10-05 22:36:31 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/37382356159/job/112007221776
LLM reason (✨ experimental): CI failed the Python lint check: wallet_importdescriptors.py has undefined extended_key/xpub names, and wallet_listdescriptors.py has an unused import.

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/37382356159/job/112007221776</sub> <sub>LLM reason (✨ experimental): CI failed the Python lint check: `wallet_importdescriptors.py` has undefined `extended_key`/`xpub` names, and `wallet_listdescriptors.py` has an unused import.</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>
First-time contributor

14 additional verified findings in the full report.

🔴 Major · Method extraction silently skips the import test's final sections

The normal functional-test entry point now skips the multipath and older() sections and six existing subtests, including the PR's new multipath_descriptor assertions.

Location: test/functional/wallet_importdescriptors.py:1085 (head).

🟠 Minor · Hardened-prefix normalization produces invalid multipath origins

For imports such as wpkh(xprv/<0h;1h>/*), public listdescriptors returns an unparsable multipath_descriptor whose xpub also differs between member rows.

Location: src/wallet/scriptpubkeyman.cpp:1650 (head).

🟠 Minor · Multipath accessors violate the manager-lock annotations

The new accessors omit required manager locks, which should trigger Clang thread-safety diagnostics in warnings-as-errors builds.

Location: src/wallet/scriptpubkeyman.cpp:1634 (head).

🟠 Minor · Single-branch reimports erase that member's multipath relationship

Updating one branch persists singleton relatives, so its listdescriptors row loses multipath_descriptor while its sibling still reports the original policy.

Location: src/wallet/imports.cpp:232 (head).

🟠 Minor · Watch-only export persists groups that its exported members cannot reconstruct

After watch-only export and restore, hardened-prefix multipath groups lose multipath_descriptor or abort listdescriptors in builds that abort on failed Assume checks.

Location: src/wallet/export.cpp:153 (head).

🟠 Minor · createwalletdescriptor leaves generated receive/change pairs unlinked

Unlike wallet initialization, createwalletdescriptor stores singleton relatives for both generated branches, so neither row reports multipath_descriptor.

Location: src/wallet/wallet.cpp:3456 (head).

Review coverage was incomplete.


Reviewed: f57989d701d4 · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:055d1cd96b176486294e0a3d052a7e506a00c1f0c7c35fbf579b09cfe6d615cd:237cc81563f53f26a84ba90acce49f0597b0e28b0a77aa425401db6e90431c0b --> <!-- ralph-base:5bf3bc5e263407a252c14a17afe04fc3bf24a889 --> <!-- ralph-head:f57989d701d454eaae057a88a3a6de6e330b1414 --> <!-- ralph-case:9e6b31eadb5d04987be1b7d7d1571323cc2a11a9c919c1338dc4bcda9e7e8f3c --> [14 additional verified findings in the full report](<https://review.fish.foo/traces/36444-f57989d701d454eaae057a88a3a6de6e330b1414-2352-4.html>). **🔴 Major · Method extraction silently skips the import test's final sections** The normal functional-test entry point now skips the multipath and older() sections and six existing subtests, including the PR's new multipath_descriptor assertions. Location: [`test/functional/wallet_importdescriptors.py:1085`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/f57989d701d454eaae057a88a3a6de6e330b1414/test/functional/wallet_importdescriptors.py#L1085>) (head). **🟠 Minor · Hardened-prefix normalization produces invalid multipath origins** For imports such as wpkh(xprv/<0h;1h>/*), public listdescriptors returns an unparsable multipath_descriptor whose xpub also differs between member rows. Location: [`src/wallet/scriptpubkeyman.cpp:1650`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/f57989d701d454eaae057a88a3a6de6e330b1414/src/wallet/scriptpubkeyman.cpp#L1650>) (head). **🟠 Minor · Multipath accessors violate the manager-lock annotations** The new accessors omit required manager locks, which should trigger Clang thread-safety diagnostics in warnings-as-errors builds. Location: [`src/wallet/scriptpubkeyman.cpp:1634`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/f57989d701d454eaae057a88a3a6de6e330b1414/src/wallet/scriptpubkeyman.cpp#L1634>) (head). **🟠 Minor · Single-branch reimports erase that member's multipath relationship** Updating one branch persists singleton relatives, so its listdescriptors row loses multipath_descriptor while its sibling still reports the original policy. Location: [`src/wallet/imports.cpp:232`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/f57989d701d454eaae057a88a3a6de6e330b1414/src/wallet/imports.cpp#L232>) (head). **🟠 Minor · Watch-only export persists groups that its exported members cannot reconstruct** After watch-only export and restore, hardened-prefix multipath groups lose multipath_descriptor or abort listdescriptors in builds that abort on failed Assume checks. Location: [`src/wallet/export.cpp:153`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/f57989d701d454eaae057a88a3a6de6e330b1414/src/wallet/export.cpp#L153>) (head). **🟠 Minor · createwalletdescriptor leaves generated receive/change pairs unlinked** Unlike wallet initialization, createwalletdescriptor stores singleton relatives for both generated branches, so neither row reports multipath_descriptor. Location: [`src/wallet/wallet.cpp:3456`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/f57989d701d454eaae057a88a3a6de6e330b1414/src/wallet/wallet.cpp#L3456>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`f57989d701d4`](<https://git.fish.foo/bitcoin/bitcoin/commit/f57989d701d454eaae057a88a3a6de6e330b1414>) · [Full review report](<https://review.fish.foo/traces/36444-f57989d701d454eaae057a88a3a6de6e330b1414-2352-4.html>) · [Previous reports](<https://review.fish.foo/traces/36444/>) [permalink](<https://review.fish.foo/traces/36444-f57989d701d454eaae057a88a3a6de6e330b1414-2352-4.html>)
DrahtBot commented 2026-10-07 13:58:20 +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).
w0xlt commented 2026-10-08 18:06:50 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
DrahtBot commented 2026-11-05 12:06:32 +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 16:58:13 +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-26 12:52:19 +00:00 (Migrated from github.com)

Concept ACK more for relaying the multi-path info for the automatically generated (and imported) descriptors of the wallet.

Concept ACK more for relaying the multi-path info for the automatically generated (and imported) descriptors of the wallet.
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!36444
No description provided.