Skip to content

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

Draft
achow101 wants to merge 18 commits into
bitcoin:masterfrom
achow101:wallet-store-multipath
Draft

achow101 wants to merge 18 commits into
bitcoin:masterfrom
achow101:wallet-store-multipath

Conversation

@achow101

@achow101 achow101 commented Oct 5, 2026

Copy link
Copy Markdown
Member

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 DrahtBot added the Wallet label Oct 5, 2026
@DrahtBot

DrahtBot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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

@achow101
achow101 force-pushed the wallet-store-multipath branch from 3246efb to a49e42b Compare October 5, 2026 22:33
@DrahtBot

DrahtBot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

🚧 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.

@w0xlt

w0xlt commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Concept ACK

Sjors added a commit to Sjors/bitcoin that referenced this pull request Oct 20, 2026
Apply the wallet relationship commits onto the latest bitcoin#36442 and bitcoin#36443 implementations. Integrate known-key substitution and repair extracted functional-test setup.
@Sjors Sjors mentioned this pull request Oct 20, 2026
7 tasks
Sjors added a commit to Sjors/bitcoin that referenced this pull request Oct 20, 2026
Apply the wallet relationship commits onto the latest bitcoin#36442 and bitcoin#36443 implementations. Integrate known-key substitution and repair extracted functional-test setup.

Integration fixes carried by this merge:
- Fix Clang -Wthread-safety errors by locking each descriptor manager when
  reading its multipath descriptor or updating its relationships.
- Snapshot local keys, cache and relative IDs before acquiring relatives'
  locks, and retain shared descriptor ownership during reconstruction.
- Reconstruct exported multipath descriptors before taking the caller's
  descriptor lock, avoiding receive/change lock-order inversions.
Sjors added a commit to Sjors/bitcoin that referenced this pull request Oct 20, 2026
Apply the wallet relationship commits onto the latest bitcoin#36442 and bitcoin#36443 implementations. Integrate known-key substitution and repair extracted functional-test setup.

Integration fixes carried by this merge:
- Fix Clang -Wthread-safety errors by locking each descriptor manager when
  reading its multipath descriptor or updating its relationships.
- Snapshot local keys, cache and relative IDs before acquiring relatives'
  locks, and retain shared descriptor ownership during reconstruction.
- Reconstruct exported multipath descriptors before taking the caller's
  descriptor lock, avoiding receive/change lock-order inversions.
Sjors added a commit to Sjors/bitcoin that referenced this pull request Oct 21, 2026
Apply the wallet relationship commits onto the latest bitcoin#36442 and bitcoin#36443 implementations. Integrate known-key substitution and repair extracted functional-test setup.

Integration fixes carried by this merge:
- Fix Clang -Wthread-safety errors by locking each descriptor manager when
  reading its multipath descriptor or updating its relationships.
- Snapshot local keys, cache and relative IDs before acquiring relatives'
  locks, and retain shared descriptor ownership during reconstruction.
- Reconstruct exported multipath descriptors before taking the caller's
  descriptor lock, avoiding receive/change lock-order inversions.
@achow101
achow101 force-pushed the wallet-store-multipath branch from a49e42b to ebb9ad9 Compare November 5, 2026 00:59
Internally, descriptor parsing will produce multipath descriptor objects
rather than std::vector<DescriptorImpl>. This single multipath
descriptor becomes std::vector<Descriptor> within Parse. Future commits
will return the single multipath descriptor object for all descriptor parsing.
Instead of a std::vector<std::unique_ptr<Descriptor>>, Parse can return
a single std::unique_ptr<Descriptor> that contains the multipath
information if the descriptor was multipath. Callers that
require the multipath expansion use GetMultipathExpansion() to get the
expanded descriptors.
Check that the correct multipath descriptor appears in listdescriptors
for a typical single key wallet. Also check that the correct
non-multipath descriptors appears, and also do for private
listdescriptors.
@DrahtBot

Copy link
Copy Markdown
Contributor

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

@rkrux

rkrux commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants