wallet: fill PSBT_GLOBAL_XPUB #36154

Open
jeanpablojp wants to merge 2 commits from psbt-global-xpubs into master AGit
jeanpablojp commented 2026-09-02 22:53:06 +00:00 (Migrated from github.com)

Closes #27583.

PSBT_GLOBAL_XPUB already serializes, deserializes and merges when PSBTs are combined. Nothing writes it, so a PSBT produced by the wallet never carries it, and a signer that only has the file cannot rebuild the multisig from it. Today Specter fills the field itself after getting the PSBT from Core.

Before and after with the BitBox02 and Trezor simulators

A 2-of-3 wsh(sortedmulti(...)) on regtest with the simulator as one co-signer, signed through HWI 3.2.0. The "before" file is the same PSBT with its PSBT_GLOBAL_XPUB records removed, so nothing else differs.

without the field with the field
BitBox02 refuses, This BitBox02 is not one of the cosigners signs
Trezor T signs, co-signer nodes sent with zeroed chain codes and no derivation paths signs, nodes sent with the real chain codes and paths

What parse_multisig hands the Trezor for the change output:

without: global xpubs=0  zeroed chain codes=3/3  depths=[0, 0, 0]  paths=[[], [], []]
with   : global xpubs=3  zeroed chain codes=0/3  depths=[4, 4, 4]  paths=[[1, 0], [1, 0], [1, 0]]

A new Descriptor accessor returns the extended keys a descriptor is built from, and DescriptorScriptPubKeyMan::FillPSBT writes those of every descriptor with an input or an output in the PSBT. That covers walletcreatefundedpsbt, walletprocesspsbt, send, sendall, psbtbumpfee and the GUI send dialog, which all go through CWallet::FillPSBT.

Only the keys BIP 174 allows are added, the ones that derive, through unhardened steps alone, a key their descriptor produced, listed in the PSBT at the origin the descriptor gave it. So a key expression ending in /*h adds nothing.

Whoever holds a PSBT from the wallet can now derive the addresses of the descriptors it uses. Setting bip32derivs to false in walletcreatefundedpsbt or walletprocesspsbt stops the wallet from adding the field, along with the derivation paths, and does not remove what a PSBT already carries.

descriptorprocesspsbt is left out, since it signs from the descriptors it is given without going through the wallet, and I intend to cover it as a follow-up.

Closes #27583. `PSBT_GLOBAL_XPUB` already serializes, deserializes and merges when PSBTs are combined. Nothing writes it, so a PSBT produced by the wallet never carries it, and a signer that only has the file cannot rebuild the multisig from it. Today Specter [fills the field itself](https://github.com/cryptoadvance/specter-desktop/blob/8843e2f0640a9adc129f9ab6afe5ecb9632e7c5b/src/cryptoadvance/specter/wallet/wallet.py#L1866-L1881) after getting the PSBT from Core. <details><summary>Before and after with the BitBox02 and Trezor simulators</summary> A 2-of-3 `wsh(sortedmulti(...))` on regtest with the simulator as one co-signer, signed through HWI 3.2.0. The "before" file is the same PSBT with its `PSBT_GLOBAL_XPUB` records removed, so nothing else differs. | | without the field | with the field | |---|---|---| | BitBox02 | refuses, `This BitBox02 is not one of the cosigners` | signs | | Trezor T | signs, co-signer nodes sent with zeroed chain codes and no derivation paths | signs, nodes sent with the real chain codes and paths | What `parse_multisig` hands the Trezor for the change output: ``` without: global xpubs=0 zeroed chain codes=3/3 depths=[0, 0, 0] paths=[[], [], []] with : global xpubs=3 zeroed chain codes=0/3 depths=[4, 4, 4] paths=[[1, 0], [1, 0], [1, 0]] ``` </details> A new `Descriptor` accessor returns the extended keys a descriptor is built from, and `DescriptorScriptPubKeyMan::FillPSBT` writes those of every descriptor with an input or an output in the PSBT. That covers `walletcreatefundedpsbt`, `walletprocesspsbt`, `send`, `sendall`, `psbtbumpfee` and the GUI send dialog, which all go through `CWallet::FillPSBT`. Only the keys BIP 174 allows are added, the ones that derive, through unhardened steps alone, a key their descriptor produced, listed in the PSBT at the origin the descriptor gave it. So a key expression ending in `/*h` adds nothing. Whoever holds a PSBT from the wallet can now derive the addresses of the descriptors it uses. Setting `bip32derivs` to false in `walletcreatefundedpsbt` or `walletprocesspsbt` stops the wallet from adding the field, along with the derivation paths, and does not remove what a PSBT already carries. `descriptorprocesspsbt` is left out, since it signs from the descriptors it is given without going through the wallet, and I intend to cover it as a follow-up.
DrahtBot commented 2026-09-02 22:53:15 +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 vicjuma
Stale ACK fametrano

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:

  • #36986 (rpc, wallet: Convert walletprocesspsbt to use options parameter by jeanpablojp)
  • #36885 (wallet, rpc: Add analyzedescriptor for multisig setups by pablomartin4btc)
  • #36167 (build: Enable -Wunused by fanquake)
  • #36143 (descriptor: add CreateMultisigDescriptor() by rxbryan)
  • #36122 (BIP460: CISA for Taproot key path spends by fjahr)
  • #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)

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.

<!--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/36154 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36154.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36154#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 | [vicjuma](https://github.com/bitcoin/bitcoin/pull/36154#pullrequestreview-5810721745) | | Stale ACK | [fametrano](https://github.com/bitcoin/bitcoin/pull/36154#pullrequestreview-5765156206) | 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: * [#36986](https://github.com/bitcoin/bitcoin/pull/36986) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36986.svg"></sub> (rpc, wallet: Convert walletprocesspsbt to use options parameter by jeanpablojp) * [#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) * [#36167](https://github.com/bitcoin/bitcoin/pull/36167) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36167.svg"></sub> (build: Enable `-Wunused` by fanquake) * [#36143](https://github.com/bitcoin/bitcoin/pull/36143) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36143.svg"></sub> (descriptor: add CreateMultisigDescriptor() by rxbryan) * [#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) * [#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) 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-->
DrahtBot commented 2026-09-02 23:14:50 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task NetBSD Cross: https://github.com/bitcoin/bitcoin/actions/runs/33692512279/job/100454171219
LLM reason (✨ experimental): CI failed because the C++ build was stopped by a Clang -Wthread-safety-analysis error treated as -Werror in src/wallet/scriptpubkeyman.cpp (calling AddGlobalXpubs violates capability !cs_desc_man).

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 `NetBSD Cross`: https://github.com/bitcoin/bitcoin/actions/runs/33692512279/job/100454171219</sub> <sub>LLM reason (✨ experimental): CI failed because the C++ build was stopped by a Clang `-Wthread-safety-analysis` error treated as `-Werror` in `src/wallet/scriptpubkeyman.cpp` (calling `AddGlobalXpubs` violates capability `!cs_desc_man`).</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>
Sjors commented 2026-09-03 06:34:59 +00:00 (Migrated from github.com)

@jeanpablojp in the RP description, can you point to the source code in Specter where it adds the global xpub? This might be useful for those who want to verify that it's still needed. Similarly, it's useful to provide a before and after example flow with HWI (and e.g. a Trezor / simulator).

(It's also better to not to tag people in the PR description, because IIUC that text ends up in the merge commit, which then keeps triggering notifications as other projects backport it.)

@jeanpablojp in the RP description, can you point to the source code in Specter where it adds the global xpub? This might be useful for those who want to verify that it's still needed. Similarly, it's useful to provide a before and after example flow with HWI (and e.g. a Trezor / simulator). (It's also better to not to tag people in the PR description, because IIUC that text ends up in the merge commit, which then keeps triggering notifications as other projects backport it.)
jeanpablojp commented 2026-09-03 21:03:48 +00:00 (Migrated from github.com)

Both are in the description now.

The Specter link points at Wallet.fill_psbt, pinned to a commit so the line numbers don't drift.

On the flow: I ran the Trezor T simulator first, and it signs the same PSBT with or without the field, same signature, same prompts, same screens. What differs is only the data HWI hands it, since without the field parse_multisig fills the co-signer nodes with zeroed chain codes and no derivation paths. The device that does show a difference is the BitBox02: it refuses with This BitBox02 is not one of the cosigners and signs once the field is there. Both runs are in the collapsed block.

I had written that the Trezor needed the field. That was wrong, and the description is corrected.

Also dropped the tag, thanks for the note about the merge commit.

Both are in the description now. The Specter link points at `Wallet.fill_psbt`, pinned to a commit so the line numbers don't drift. On the flow: I ran the Trezor T simulator first, and it signs the same PSBT with or without the field, same signature, same prompts, same screens. What differs is only the data HWI hands it, since without the field `parse_multisig` fills the co-signer nodes with zeroed chain codes and no derivation paths. The device that does show a difference is the BitBox02: it refuses with `This BitBox02 is not one of the cosigners` and signs once the field is there. Both runs are in the collapsed block. I had written that the Trezor needed the field. That was wrong, and the description is corrected. Also dropped the tag, thanks for the note about the merge commit.
Sjors commented 2026-09-04 07:08:04 +00:00 (Migrated from github.com)

Thanks. It's useful to know that Trezor doesn't seem to need this, but BitBox02 and perhaps other devices do.

I suspect that once we support the new registerdescriptor command in HWI, and pass that registration back to HWI when signing, none of the devices will need the global xpub. That's because HWI can construct everything it needs from the descriptor, which itself contains the xpubs.

But providing global xpubs may still be useful for flows without HWI.

Thanks. It's useful to know that Trezor doesn't seem to need this, but BitBox02 and perhaps other devices do. I suspect that once we support the new `registerdescriptor` command in HWI, and pass that registration back to HWI when signing, none of the devices will need the global xpub. That's because HWI can construct everything it needs from the descriptor, which itself contains the xpubs. But providing global xpubs may still be useful for flows without HWI.
achow101 commented 2026-09-07 22:38:22 +00:00 (Migrated from github.com)

Please shorten your description. We don't need to know the exact details about every single device that needs to know about the global xpub.

Why is this restricted to only multisigs? Just because that is the described use case in the original issue does not mean that it is the only use case. PSBTs and Descriptors are generic objects, we should avoid doing things that are specific to one type of descriptor or psbt.

Please shorten your description. We don't need to know the exact details about every single device that needs to know about the global xpub. Why is this restricted to only multisigs? Just because that is the described use case in the original issue does not mean that it is the only use case. PSBTs and Descriptors are generic objects, we should avoid doing things that are specific to one type of descriptor or psbt.
achow101 (Migrated from github.com) reviewed 2026-09-07 22:51:25 +00:00
achow101 (Migrated from github.com) commented 2026-09-07 22:40:40 +00:00

In 92bf732c4e "wallet: fill PSBT_GLOBAL_XPUB for descriptors with more than one key"

This should return the map rather than taking it as an output parameter.

Do not provide SigningProvider, either the last hardened key is already cached, or it does not exist. There is no need to take a SigningProvider here, otherwise the wallet wouldn't function.

In 92bf732c4ee0e7096aa3f203ebcafcdf9366ff1a "wallet: fill PSBT_GLOBAL_XPUB for descriptors with more than one key" This should return the map rather than taking it as an output parameter. Do not provide `SigningProvider`, either the last hardened key is already cached, or it does not exist. There is no need to take a `SigningProvider` here, otherwise the wallet wouldn't function.
achow101 (Migrated from github.com) commented 2026-09-07 22:43:32 +00:00

In 92bf732c4e "wallet: fill PSBT_GLOBAL_XPUB for descriptors with more than one key"

We should not make assumptions about what the caller is going to use the xpubs for. This should return the root and it's fingerprint for any key where we cannot do the normalized key thing.

In 92bf732c4ee0e7096aa3f203ebcafcdf9366ff1a "wallet: fill PSBT_GLOBAL_XPUB for descriptors with more than one key" We should not make assumptions about what the caller is going to use the xpubs for. This should return the root and it's fingerprint for any key where we cannot do the normalized key thing.
achow101 (Migrated from github.com) commented 2026-09-07 22:46:43 +00:00

In 92bf732c4e "wallet: fill PSBT_GLOBAL_XPUB for descriptors with more than one key"

It is not necessary to determine what the last hardened index is, just ask the cache for it, and if the cache doesn't have that key, return the root.

In 92bf732c4ee0e7096aa3f203ebcafcdf9366ff1a "wallet: fill PSBT_GLOBAL_XPUB for descriptors with more than one key" It is not necessary to determine what the last hardened index is, just ask the cache for it, and if the cache doesn't have that key, return the root.
achow101 (Migrated from github.com) commented 2026-09-07 22:48:07 +00:00

In 92bf732c4e "wallet: fill PSBT_GLOBAL_XPUB for descriptors with more than one key"

This is incorrect. It should traverse the participants and get their xpubs.

In 92bf732c4ee0e7096aa3f203ebcafcdf9366ff1a "wallet: fill PSBT_GLOBAL_XPUB for descriptors with more than one key" This is incorrect. It should traverse the participants and get their xpubs.
DrahtBot commented 2026-09-09 11:30:30 +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).
fametrano commented 2026-10-02 11:03:18 +00:00 (Migrated from github.com)

@jeanpablojp, in case it saves you time: https://github.com/fametrano/bitcoin/tree/psbt-global-xpub-achow has achow101's points and the NetBSD thread-safety fix, rebased on master.

Changes: the multisig-only restriction is gone. Descriptor::GetExtPubKeysWithOrigins returns the map, takes no SigningProvider, and falls back to the root key when the cache lacks the last hardened one. musig() gives the participants' keys.

There are two commits. The wallet one is yours, with me as co-author. Take any of it or none. To use it as it is: git fetch https://github.com/fametrano/bitcoin psbt-global-xpub-achow && git reset --hard FETCH_HEAD, then force-push. A shorter description you could reword is below.

Written with LLM, a computer and the Internet; the mistakes, as usual, are all mine.

Suggested description

Closes #27583.

BIP 174 lets a PSBT carry, in PSBT_GLOBAL_XPUB, the extended public keys its inputs and outputs derive from. The wallet never writes the field. Some signers need them to rebuild the scripts.

FillPSBT now adds the extended keys of every descriptor that an input or output uses, unless bip32derivs is false. For each key expression this is the key at its last hardened step when the descriptor cache holds it, and the root key otherwise. For musig() these are the participants' keys. descriptorprocesspsbt does not go through the wallet and is left for a follow-up.

So, by default, a PSBT from the wallet carries the account xpubs of the descriptors it uses, and whoever gets it can derive the wallet's addresses. With hardened ranged derivation (/*h) the cache holds no such key, and the root key is published if its origin is known. Keys whose origin is unknown are left out.

@jeanpablojp, in case it saves you time: https://github.com/fametrano/bitcoin/tree/psbt-global-xpub-achow has achow101's points and the NetBSD thread-safety fix, rebased on master. Changes: the multisig-only restriction is gone. `Descriptor::GetExtPubKeysWithOrigins` returns the map, takes no `SigningProvider`, and falls back to the root key when the cache lacks the last hardened one. `musig()` gives the participants' keys. There are two commits. The wallet one is yours, with me as co-author. Take any of it or none. To use it as it is: `git fetch https://github.com/fametrano/bitcoin psbt-global-xpub-achow && git reset --hard FETCH_HEAD`, then force-push. A shorter description you could reword is below. *Written with LLM, a computer and the Internet; the mistakes, as usual, are all mine.* <details><summary>Suggested description</summary> Closes #27583. BIP 174 lets a PSBT carry, in `PSBT_GLOBAL_XPUB`, the extended public keys its inputs and outputs derive from. The wallet never writes the field. Some signers need them to rebuild the scripts. `FillPSBT` now adds the extended keys of every descriptor that an input or output uses, unless `bip32derivs` is false. For each key expression this is the key at its last hardened step when the descriptor cache holds it, and the root key otherwise. For `musig()` these are the participants' keys. `descriptorprocesspsbt` does not go through the wallet and is left for a follow-up. So, by default, a PSBT from the wallet carries the account xpubs of the descriptors it uses, and whoever gets it can derive the wallet's addresses. With hardened ranged derivation (`/*h`) the cache holds no such key, and the root key is published if its origin is known. Keys whose origin is unknown are left out. </details>
First-time contributor

Earlier concerns remain unresolved; see the Run archive linked from the Review report.

🔴 Major · Single-key PSBTs disclose the whole account by default

Default bip32derivs=true now exposes standard single-key receive and change chains to PSBT holders, although the established interoperability need is multisig and no single-key signer requiring the field was identified.

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

🟠 Minor · send, sendall, fee-bump and GUI PSBT exports lack an xpub opt-out

Unlike walletcreatefundedpsbt and walletprocesspsbt, these export paths provide no control to suppress eligible account xpubs, extending their pre-existing mandatory derivation metadata to account-wide address disclosure.

Location: doc/release-notes-36154.md:9 (head).

🔵 Suggestion · External-signer walletprocesspsbt skips the new xpub population

Because the pre-existing external-signer dispatch skips metadata filling, default walletprocesspsbt does not add the new xpubs before signing; callers must first process with sign=false.

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

🔵 Suggestion · Unhardened master imports expose sibling branches

An imported descriptor using an unhardened master publishes the master xpub, exposing branches outside that descriptor; wallet-generated descriptors avoid this form, and no current caller producing it was identified.

Location: src/script/descriptor.cpp:689 (head).

🔵 Suggestion · The bip32derivs tests do not protect the xpub-publication gate

Both new opt-out assertions would still pass without the explicit publication gate because neither attempts to add missing xpubs to a PSBT that already contains eligible derivation paths.

Location: test/functional/wallet_multisig_descriptor_psbt.py:335 (head).

🔵 Suggestion · send and fee-bump PSBT outputs lack xpub assertions

The new tests check walletcreatefundedpsbt and walletprocesspsbt, but do not verify global xpubs on the separately populated send, sendall or psbtbumpfee results.

Location: test/functional/wallet_multisig_descriptor_psbt.py:331 (head).

Review coverage was incomplete.


Reviewed: 8ae5b94cadcc · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:3705f06c6a27c475c77f2533c4d016ac03c829c839b7b538bba5e4768ccf54f1:1ed10c4979af6fc548d6b8d4534d505e02e84ac4b0aa4f8633555b2ba75119e8 --> <!-- ralph-base:3ee664ea98993c95a2a49b300d6ce67dcce71302 --> <!-- ralph-head:8ae5b94cadccc6d78eccc9d17928876f2340f72e --> <!-- ralph-case:6c2ab171186e0d563519777c77ac3e98f5ea2a6556ec9d36258c6f418c454f37 --> Earlier concerns remain unresolved; see the Run archive linked from the Review report. **🔴 Major · Single-key PSBTs disclose the whole account by default** Default `bip32derivs=true` now exposes standard single-key receive and change chains to PSBT holders, although the established interoperability need is multisig and no single-key signer requiring the field was identified. Location: [`src/wallet/scriptpubkeyman.cpp:1502`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/8ae5b94cadccc6d78eccc9d17928876f2340f72e/src/wallet/scriptpubkeyman.cpp#L1502>) (head). **🟠 Minor · `send`, `sendall`, fee-bump and GUI PSBT exports lack an xpub opt-out** Unlike `walletcreatefundedpsbt` and `walletprocesspsbt`, these export paths provide no control to suppress eligible account xpubs, extending their pre-existing mandatory derivation metadata to account-wide address disclosure. Location: [`doc/release-notes-36154.md:9`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/8ae5b94cadccc6d78eccc9d17928876f2340f72e/doc/release-notes-36154.md#L9>) (head). **🔵 Suggestion · External-signer `walletprocesspsbt` skips the new xpub population** Because the pre-existing external-signer dispatch skips metadata filling, default `walletprocesspsbt` does not add the new xpubs before signing; callers must first process with `sign=false`. Location: [`src/wallet/scriptpubkeyman.cpp:1503`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/8ae5b94cadccc6d78eccc9d17928876f2340f72e/src/wallet/scriptpubkeyman.cpp#L1503>) (head). **🔵 Suggestion · Unhardened master imports expose sibling branches** An imported descriptor using an unhardened master publishes the master xpub, exposing branches outside that descriptor; wallet-generated descriptors avoid this form, and no current caller producing it was identified. Location: [`src/script/descriptor.cpp:689`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/8ae5b94cadccc6d78eccc9d17928876f2340f72e/src/script/descriptor.cpp#L689>) (head). **🔵 Suggestion · The `bip32derivs` tests do not protect the xpub-publication gate** Both new opt-out assertions would still pass without the explicit publication gate because neither attempts to add missing xpubs to a PSBT that already contains eligible derivation paths. Location: [`test/functional/wallet_multisig_descriptor_psbt.py:335`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/8ae5b94cadccc6d78eccc9d17928876f2340f72e/test/functional/wallet_multisig_descriptor_psbt.py#L335>) (head). **🔵 Suggestion · `send` and fee-bump PSBT outputs lack xpub assertions** The new tests check `walletcreatefundedpsbt` and `walletprocesspsbt`, but do not verify global xpubs on the separately populated `send`, `sendall` or `psbtbumpfee` results. Location: [`test/functional/wallet_multisig_descriptor_psbt.py:331`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/8ae5b94cadccc6d78eccc9d17928876f2340f72e/test/functional/wallet_multisig_descriptor_psbt.py#L331>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`8ae5b94cadcc`](<https://git.fish.foo/bitcoin/bitcoin/commit/8ae5b94cadccc6d78eccc9d17928876f2340f72e>) · [Review report](<https://review.fish.foo/report/36154-8ae5b94cadccc6d78eccc9d17928876f2340f72e-2898-7.html>) · [Previous reports](<https://review.fish.foo/traces/36154/>) [permalink](<https://review.fish.foo/report/36154-8ae5b94cadccc6d78eccc9d17928876f2340f72e-2898-7.html>)
jeanpablojp (Migrated from github.com) reviewed 2026-10-30 22:15:16 +00:00
jeanpablojp (Migrated from github.com) commented 2026-10-30 22:15:16 +00:00

Done, it returns the map and takes only the cache.

Done, it returns the map and takes only the cache.
jeanpablojp (Migrated from github.com) reviewed 2026-10-30 22:15:18 +00:00
jeanpablojp (Migrated from github.com) commented 2026-10-30 22:15:18 +00:00

Done, it now returns the root and its fingerprint, /*h included.

Done, it now returns the root and its fingerprint, `/*h` included.
jeanpablojp (Migrated from github.com) reviewed 2026-10-30 22:15:20 +00:00
jeanpablojp (Migrated from github.com) commented 2026-10-30 22:15:20 +00:00

Done, it asks the cache and falls back to the root.

Done, it asks the cache and falls back to the root.
jeanpablojp (Migrated from github.com) reviewed 2026-10-30 22:15:22 +00:00
jeanpablojp (Migrated from github.com) commented 2026-10-30 22:15:22 +00:00

Right, done. It now merges whatever its participants return, and wallet_musig.py checks that every participant's xpub ends up in global_xpubs with the origin that leads to it.

Right, done. It now merges whatever its participants return, and `wallet_musig.py` checks that every participant's xpub ends up in `global_xpubs` with the origin that leads to it.
jeanpablojp commented 2026-10-30 22:23:48 +00:00 (Migrated from github.com)

@achow101 thanks, shortened the description and dropped the multisig restriction.

@fametrano thanks for the branch. The single-key test over the four address types follows yours. Unlike your branch, keys that derive none of the PSBT's keys stay out, like the root of a /*h expression, which in a migrated legacy wallet is the master key.

@achow101 thanks, shortened the description and dropped the multisig restriction. @fametrano thanks for the branch. The single-key test over the four address types follows yours. Unlike your branch, keys that derive none of the PSBT's keys stay out, like the root of a `/*h` expression, which in a migrated legacy wallet is the master key.
fametrano (Migrated from github.com) reviewed 2026-11-01 18:20:12 +00:00
fametrano (Migrated from github.com) left a comment

Concept ACK

One issue should be fixed before merge: a watch-only wallet holding one xpub under two origins now gets a PSBT that decodepsbt refuses. With wpkh([A/84h/1h/0h]xpub/0/*) and wpkh([00000000/84h/1h/0h]xpub/1/*), walletcreatefundedpsbt and send, which has no bip32derivs to turn it off, both report success and return it. No funds are at risk, but the error only shows when the next tool reads the file. This is the first of Ralph's two Minors; both reproduce at 437936e5 without an edited file.

The suggestion in AddGlobalXpubs keeps the origin already present, as MergeGlobalXPubs does since #35665. With all the suggestions, both reproductions exit 0, and the affected unit tests and eight functional tests pass; each regression test fails without its fix. Scripts and output: https://gist.github.com/fametrano/1cb22c31d89e06cd722dadaec3dc7230/b7f27effa3b47cd36468d9ae24407e71cf9970ee

Not blocking: the root exclusion falls to two RPCs. A sender calls descriptorprocesspsbt with wpkh([root origin]key) on a stranger's key, then a /*h wallet that the PSBT pays adds its root in walletprocesspsbt. That root derives no key of the wallet's descriptor, so no address is exposed, but the description says /*h adds nothing. The other two suggestions derive the key instead of comparing its path, and test it.

Concept ACK One issue should be fixed before merge: a watch-only wallet holding one xpub under two origins now gets a PSBT that `decodepsbt` refuses. With `wpkh([A/84h/1h/0h]xpub/0/*)` and `wpkh([00000000/84h/1h/0h]xpub/1/*)`, `walletcreatefundedpsbt` and `send`, which has no `bip32derivs` to turn it off, both report success and return it. No funds are at risk, but the error only shows when the next tool reads the file. This is the first of Ralph's two Minors; both reproduce at 437936e5 without an edited file. The suggestion in `AddGlobalXpubs` keeps the origin already present, as `MergeGlobalXPubs` does since #35665. With all the suggestions, both reproductions exit 0, and the affected unit tests and eight functional tests pass; each regression test fails without its fix. Scripts and output: https://gist.github.com/fametrano/1cb22c31d89e06cd722dadaec3dc7230/b7f27effa3b47cd36468d9ae24407e71cf9970ee Not blocking: the root exclusion falls to two RPCs. A sender calls `descriptorprocesspsbt` with `wpkh([root origin]key)` on a stranger's key, then a `/*h` wallet that the PSBT pays adds its root in `walletprocesspsbt`. That root derives no key of the wallet's descriptor, so no address is exposed, but the description says `/*h` adds nothing. The other two suggestions derive the key instead of comparing its path, and test it.
fametrano (Migrated from github.com) commented 2026-11-01 18:20:12 +00:00

walletcreatefundedpsbt and send both returned a PSBT decodepsbt refuses, in a wallet holding one xpub under two origins. MergeGlobalXPubs already keeps the first origin it sees (#35665), so this uses it. With this they decode, with one record, and the PR's tests still pass. In that wallet the origin that stays follows the pointer order of GetAllScriptPubKeyMans, so it can change across a restart.

    PartiallySignedTransaction candidates{CMutableTransaction{}};
    candidates.m_xpubs = std::move(xpubs);
    psbtx.MergeGlobalXPubs(candidates);
`walletcreatefundedpsbt` and `send` both returned a PSBT `decodepsbt` refuses, in a wallet holding one xpub under two origins. `MergeGlobalXPubs` already keeps the first origin it sees (#35665), so this uses it. With this they decode, with one record, and the PR's tests still pass. In that wallet the origin that stays follows the pointer order of `GetAllScriptPubKeyMans`, so it can change across a restart. ```suggestion PartiallySignedTransaction candidates{CMutableTransaction{}}; candidates.m_xpubs = std::move(xpubs); psbtx.MergeGlobalXPubs(candidates); ```
fametrano (Migrated from github.com) commented 2026-11-01 18:20:12 +00:00

Not blocking: a path in the PSBT is only a claim, so this derives the key and compares it. It keeps the hardened check, since CPubKey::Derive asserts on a hardened step, and the regression test is the suggestion in the functional test. Only entries at this origin cost a derivation, and a PSBT's real key stops the search; a hostile 2 MB file of 510,000 steps took 6 to 7 s in walletprocesspsbt here, against 0.06 s on the head.

//! Whether one of these keys, at this origin, derives a key the PSBT gives a derivation
//! path for, through unhardened steps alone. The key is derived rather than its path
//! compared, since a path in the PSBT says whatever its sender wrote.
static bool DerivesKeyInPSBT(const PartiallySignedTransaction& psbtx, const KeyOriginInfo& origin, const std::set<CExtPubKey>& keys)
{
    const auto derives{[&](const XOnlyPubKey& pubkey, const KeyOriginInfo& info) {
        if (info.fingerprint != origin.fingerprint || info.path.size() < origin.path.size()) return false;
        const auto rest{info.path.begin() + origin.path.size()};
        if (!std::equal(info.path.begin(), rest, origin.path.begin()) ||
            std::any_of(rest, info.path.end(), [](uint32_t step) { return (step & BIP32_HARDENED_FLAG) != 0; })) return false;
        return std::ranges::any_of(keys, [&](CExtPubKey key) {
            for (auto step{rest}; step != info.path.end(); ++step) {
                CExtPubKey child;
                if (!key.Derive(child, *step)) return false;
                key = child;
            }
            return XOnlyPubKey{key.pubkey} == pubkey;
        });
    }};
    const auto lists_derived_key{[&](const auto& in_or_out) {
        return std::ranges::any_of(in_or_out.hd_keypaths, [&](const auto& entry) { return derives(XOnlyPubKey{entry.first}, entry.second); }) ||
               std::ranges::any_of(in_or_out.m_tap_bip32_paths, [&](const auto& entry) { return derives(entry.first, entry.second.second); });
    }};
    return std::ranges::any_of(psbtx.inputs, lists_derived_key) || std::ranges::any_of(psbtx.outputs, lists_derived_key);
}

void DescriptorScriptPubKeyMan::AddGlobalXpubs(PartiallySignedTransaction& psbtx) const
{
    LOCK(cs_desc_man);
    std::map<KeyOriginInfo, std::set<CExtPubKey>> xpubs{
        m_wallet_descriptor.descriptor->GetExtPubKeysWithOrigins(&m_wallet_descriptor.cache)};

    // BIP 174 wants the keys that the transaction's keys derive from, each with as many
    // steps in its path as its depth. Where the cache lacks the key at the last hardened
    // step, the descriptor hands out its root instead, and a root with hardened steps still
    // below it derives none of them; a key written without its origin has a path too short
    // for its depth. Neither can go in.
    std::erase_if(xpubs, [&](const auto& entry) {
        const auto& [origin, keys]{entry};
        return !DerivesKeyInPSBT(psbtx, origin, keys) ||
Not blocking: a path in the PSBT is only a claim, so this derives the key and compares it. It keeps the hardened check, since `CPubKey::Derive` asserts on a hardened step, and the regression test is the suggestion in the functional test. Only entries at this origin cost a derivation, and a PSBT's real key stops the search; a hostile 2 MB file of 510,000 steps took 6 to 7 s in `walletprocesspsbt` here, against 0.06 s on the head. ```suggestion //! Whether one of these keys, at this origin, derives a key the PSBT gives a derivation //! path for, through unhardened steps alone. The key is derived rather than its path //! compared, since a path in the PSBT says whatever its sender wrote. static bool DerivesKeyInPSBT(const PartiallySignedTransaction& psbtx, const KeyOriginInfo& origin, const std::set<CExtPubKey>& keys) { const auto derives{[&](const XOnlyPubKey& pubkey, const KeyOriginInfo& info) { if (info.fingerprint != origin.fingerprint || info.path.size() < origin.path.size()) return false; const auto rest{info.path.begin() + origin.path.size()}; if (!std::equal(info.path.begin(), rest, origin.path.begin()) || std::any_of(rest, info.path.end(), [](uint32_t step) { return (step & BIP32_HARDENED_FLAG) != 0; })) return false; return std::ranges::any_of(keys, [&](CExtPubKey key) { for (auto step{rest}; step != info.path.end(); ++step) { CExtPubKey child; if (!key.Derive(child, *step)) return false; key = child; } return XOnlyPubKey{key.pubkey} == pubkey; }); }}; const auto lists_derived_key{[&](const auto& in_or_out) { return std::ranges::any_of(in_or_out.hd_keypaths, [&](const auto& entry) { return derives(XOnlyPubKey{entry.first}, entry.second); }) || std::ranges::any_of(in_or_out.m_tap_bip32_paths, [&](const auto& entry) { return derives(entry.first, entry.second.second); }); }}; return std::ranges::any_of(psbtx.inputs, lists_derived_key) || std::ranges::any_of(psbtx.outputs, lists_derived_key); } void DescriptorScriptPubKeyMan::AddGlobalXpubs(PartiallySignedTransaction& psbtx) const { LOCK(cs_desc_man); std::map<KeyOriginInfo, std::set<CExtPubKey>> xpubs{ m_wallet_descriptor.descriptor->GetExtPubKeysWithOrigins(&m_wallet_descriptor.cache)}; // BIP 174 wants the keys that the transaction's keys derive from, each with as many // steps in its path as its depth. Where the cache lacks the key at the last hardened // step, the descriptor hands out its root instead, and a root with hardened steps still // below it derives none of them; a key written without its origin has a path too short // for its depth. Neither can go in. std::erase_if(xpubs, [&](const auto& entry) { const auto& [origin, keys]{entry}; return !DerivesKeyInPSBT(psbtx, origin, keys) || ```
fametrano (Migrated from github.com) commented 2026-11-01 18:20:13 +00:00

Not blocking: no edited bytes are needed, since two RPCs give the stranger's key the root's origin. This fails on the head because the root gets in, and passes with the derivation suggestion.

        self._check_publishes_nothing(wallet, coordinator)

        # A path in a PSBT is only a claim: this one gives a stranger's key the root's origin.
        stranger = coordinator.getaddressinfo(coordinator.getnewaddress(address_type="bech32"))["pubkey"]
        forged_desc = descsum_create(f"wpkh({keys[0]['origin']}{stranger})")
        psbt = coordinator.walletcreatefundedpsbt(
            inputs=[], outputs={wallet.getnewaddress(): 0.1, self.node.deriveaddresses(forged_desc)[0]: 0.1},
            feeRate=0.00010, bip32derivs=False)["psbt"]
        forged = self.node.descriptorprocesspsbt(psbt, [forged_desc], bip32derivs=True, finalize=False)["psbt"]
        processed = wallet.walletprocesspsbt(forged, sign=False)["psbt"]
        assert_equal(wallet.decodepsbt(processed)["global_xpubs"], [])
Not blocking: no edited bytes are needed, since two RPCs give the stranger's key the root's origin. This fails on the head because the root gets in, and passes with the derivation suggestion. ```suggestion self._check_publishes_nothing(wallet, coordinator) # A path in a PSBT is only a claim: this one gives a stranger's key the root's origin. stranger = coordinator.getaddressinfo(coordinator.getnewaddress(address_type="bech32"))["pubkey"] forged_desc = descsum_create(f"wpkh({keys[0]['origin']}{stranger})") psbt = coordinator.walletcreatefundedpsbt( inputs=[], outputs={wallet.getnewaddress(): 0.1, self.node.deriveaddresses(forged_desc)[0]: 0.1}, feeRate=0.00010, bip32derivs=False)["psbt"] forged = self.node.descriptorprocesspsbt(psbt, [forged_desc], bip32derivs=True, finalize=False)["psbt"] processed = wallet.walletprocesspsbt(forged, sign=False)["psbt"] assert_equal(wallet.decodepsbt(processed)["global_xpubs"], []) ```
fametrano (Migrated from github.com) commented 2026-11-01 18:20:13 +00:00

This fails on the head with Duplicate Key and passes with the suggestion in AddGlobalXpubs.

            self._check_global_xpubs(funded["psbt"], [parent_desc[parent_desc.index("["):]], wallet)

        # One xpub under two origins is one record: a repeated record makes the PSBT undecodable.
        account = wallet.derivehdkey("m/84h/1h/0h")
        two_origins = self.node.get_wallet_rpc(self.node.createwallet(
            wallet_name="two_origins", blank=True, disable_private_keys=True)["name"])
        result = two_origins.importdescriptors([
            {"desc": descsum_create(f"wpkh({account['origin']}{account['xpub']}/0/*)"),
             "active": True, "timestamp": "now"},
            {"desc": descsum_create(f"wpkh([00000000/84h/1h/0h]{account['xpub']}/1/*)"),
             "active": True, "internal": True, "timestamp": "now"},
        ])
        assert all(r["success"] for r in result)
        coordinator.sendtoaddress(two_origins.getnewaddress(), 1)
        self.generate(self.node, 1)
        funded = two_origins.walletcreatefundedpsbt(inputs=[], outputs={coordinator.getnewaddress(): 0.5}, feeRate=0.00010)
        assert_equal(len(two_origins.decodepsbt(funded["psbt"])["global_xpubs"]), 1)
This fails on the head with `Duplicate Key` and passes with the suggestion in `AddGlobalXpubs`. ```suggestion self._check_global_xpubs(funded["psbt"], [parent_desc[parent_desc.index("["):]], wallet) # One xpub under two origins is one record: a repeated record makes the PSBT undecodable. account = wallet.derivehdkey("m/84h/1h/0h") two_origins = self.node.get_wallet_rpc(self.node.createwallet( wallet_name="two_origins", blank=True, disable_private_keys=True)["name"]) result = two_origins.importdescriptors([ {"desc": descsum_create(f"wpkh({account['origin']}{account['xpub']}/0/*)"), "active": True, "timestamp": "now"}, {"desc": descsum_create(f"wpkh([00000000/84h/1h/0h]{account['xpub']}/1/*)"), "active": True, "internal": True, "timestamp": "now"}, ]) assert all(r["success"] for r in result) coordinator.sendtoaddress(two_origins.getnewaddress(), 1) self.generate(self.node, 1) funded = two_origins.walletcreatefundedpsbt(inputs=[], outputs={coordinator.getnewaddress(): 0.5}, feeRate=0.00010) assert_equal(len(two_origins.decodepsbt(funded["psbt"])["global_xpubs"]), 1) ```
jeanpablojp (Migrated from github.com) reviewed 2026-11-02 19:00:34 +00:00
jeanpablojp (Migrated from github.com) commented 2026-11-02 19:00:34 +00:00

Taken, thanks. MergeGlobalXPubs now takes the map, so the wallet calls it without the throwaway PSBT.

Taken, thanks. `MergeGlobalXPubs` now takes the map, so the wallet calls it without the throwaway PSBT.
jeanpablojp (Migrated from github.com) reviewed 2026-11-02 19:00:36 +00:00
jeanpablojp (Migrated from github.com) commented 2026-11-02 19:00:36 +00:00

Added, with two more cases, the same xpub twice in one descriptor and a PSBT whose sender already lists the wallet's xpub under another origin. The second also made walletprocesspsbt return a PSBT that does not decode.

Added, with two more cases, the same xpub twice in one descriptor and a PSBT whose sender already lists the wallet's xpub under another origin. The second also made `walletprocesspsbt` return a PSBT that does not decode.
jeanpablojp (Migrated from github.com) reviewed 2026-11-02 19:00:39 +00:00
jeanpablojp (Migrated from github.com) commented 2026-11-02 19:00:39 +00:00

Taken, thanks, with non-taproot entries compared as full keys rather than x-only.

Taken, thanks, with non-taproot entries compared as full keys rather than x-only.
jeanpablojp (Migrated from github.com) reviewed 2026-11-02 19:00:41 +00:00
jeanpablojp (Migrated from github.com) commented 2026-11-02 19:00:41 +00:00

Added, with a second forged output through tr(), since the taproot comparison had no test otherwise, and a check that both claims reach the PSBT.

Added, with a second forged output through `tr()`, since the taproot comparison had no test otherwise, and a check that both claims reach the PSBT.
fametrano (Migrated from github.com) reviewed 2026-11-04 08:00:06 +00:00
fametrano (Migrated from github.com) left a comment

tACK 1cc67cf916

The four suggestions are in, and the new tests pin them. With each fix reverted on this head, wallet_multisig_descriptor_psbt.py fails: in test_one_record_per_xpub when the xpubs bypass MergeGlobalXPubs, and at the forged claims when DerivesKeyInPSBT stops comparing the derived key, even in the taproot map alone. Unmodified, the descriptor, PSBT, wallet and key_io unit suites and eight wallet and PSBT functional tests pass.

Not blocking: Ralph's first Minor here, the cost of deriving along unrelated paths, comes from my derivation suggestion. Beyond the 2 MB file I timed then, a 17 MB PSBT whose output lists 16,000 stranger keys at the root's origin, each 255 unhardened steps deep, kept walletprocesspsbt busy 73 to 96 s on a loaded 10-core machine. Ralph's fix would bound it, and I would take it here.

Commands and logs: https://gist.github.com/fametrano/1cb22c31d89e06cd722dadaec3dc7230/29b33df1cda87b91430efbb654e68b901f5f73ef

tACK 1cc67cf916 The four suggestions are in, and the new tests pin them. With each fix reverted on this head, `wallet_multisig_descriptor_psbt.py` fails: in `test_one_record_per_xpub` when the xpubs bypass `MergeGlobalXPubs`, and at the forged claims when `DerivesKeyInPSBT` stops comparing the derived key, even in the taproot map alone. Unmodified, the descriptor, PSBT, wallet and key_io unit suites and eight wallet and PSBT functional tests pass. Not blocking: Ralph's first Minor here, the cost of deriving along unrelated paths, comes from my derivation suggestion. Beyond the 2 MB file I timed then, a 17 MB PSBT whose output lists 16,000 stranger keys at the root's origin, each 255 unhardened steps deep, kept `walletprocesspsbt` busy 73 to 96 s on a loaded 10-core machine. Ralph's fix would bound it, and I would take it here. Commands and logs: https://gist.github.com/fametrano/1cb22c31d89e06cd722dadaec3dc7230/29b33df1cda87b91430efbb654e68b901f5f73ef
DrahtBot commented 2026-11-04 13:06:09 +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).
vicjuma (Migrated from github.com) reviewed 2026-11-07 10:21:39 +00:00
vicjuma (Migrated from github.com) left a comment

Concept ACK, global xpubs are optional, so including them is harmless, and wallets or signers that require them can use them

Concept ACK, global xpubs are optional, so including them is harmless, and wallets or signers that require them can use them
vicjuma (Migrated from github.com) commented 2026-11-07 08:51:19 +00:00

Good call 👍

Good call 👍
vicjuma (Migrated from github.com) commented 2026-11-07 09:17:52 +00:00

Weak nit :-) the naming sounds like an accessor for a member variable, the Get part i.e

**Weak nit** :-) the naming sounds like an accessor for a member variable, the `Get` part i.e
vicjuma (Migrated from github.com) commented 2026-11-07 09:29:15 +00:00

Weak nit:
Read-only operation on named variables warrants explicit const auto& as can be seen throughout the codebase

- for (auto& [suborigin, xpubs] : m_provider->GetExtPubKeysWithOrigins(cache)) {
+ for (const auto& [suborigin, xpubs] : m_provider->GetExtPubKeysWithOrigins(cache)) {
**Weak nit:** Read-only operation on named variables warrants explicit `const auto&` as can be seen throughout the codebase ```diff - for (auto& [suborigin, xpubs] : m_provider->GetExtPubKeysWithOrigins(cache)) { + for (const auto& [suborigin, xpubs] : m_provider->GetExtPubKeysWithOrigins(cache)) { ```
vicjuma (Migrated from github.com) commented 2026-11-07 10:02:49 +00:00

Weak nit:
with the explicit const auto& comes

- ret[origin].merge(xpubs);
+ ret[origin].insert(xpubs.begin(), xpubs.end());

the only place I have seen .merge used in the codebase is src/script/miniscript.h:1544: key_set.merge(*sub); where the sets are mutated. The sets used here are not large enough to warrant optimization, and .insert() has no side effects unlike .merge()

**Weak nit:** with the explicit `const auto&` comes ```diff - ret[origin].merge(xpubs); + ret[origin].insert(xpubs.begin(), xpubs.end()); ``` the only place I have seen .merge used in the codebase is `src/script/miniscript.h:1544: key_set.merge(*sub);` where the sets are mutated. The sets used here are not large enough to warrant optimization, and .insert() has no side effects unlike .merge()
vicjuma (Migrated from github.com) commented 2026-11-07 10:11:11 +00:00

Same here, explicit const on auto& and .insert() vs mutable auto& and .merge()

Same here, `explicit const on auto& and .insert()` vs `mutable auto& and .merge()`
vicjuma (Migrated from github.com) commented 2026-11-07 10:12:19 +00:00

Same

Same
vicjuma (Migrated from github.com) commented 2026-11-07 10:12:32 +00:00

Same

Same
vicjuma (Migrated from github.com) commented 2026-11-07 07:10:09 +00:00

Global xpubs populated successfully after this change

master branch

Image

psbt-global-xpubs branch

Image
Global xpubs populated successfully after this change **master branch** <img width="2644" height="1486" alt="Image" src="https://git.fish.foo/attachments/2bc68bc5-de68-4b38-9dbe-163d59939356" /> **psbt-global-xpubs branch** <img width="2640" height="948" alt="Image" src="https://git.fish.foo/attachments/356d3f57-9171-4467-ad00-f865570aaeac" />
jeanpablojp (Migrated from github.com) reviewed 2026-11-20 21:28:09 +00:00
jeanpablojp (Migrated from github.com) commented 2026-11-20 21:28:09 +00:00

I'd keep the name, since it follows GetPubKey and Descriptor::GetPubKeys, which also build their result rather than read a member.

I'd keep the name, since it follows `GetPubKey` and `Descriptor::GetPubKeys`, which also build their result rather than read a member.
jeanpablojp (Migrated from github.com) reviewed 2026-11-20 21:28:12 +00:00
jeanpablojp (Migrated from github.com) commented 2026-11-20 21:28:12 +00:00

I'd leave the four loops as they are. The sets come from a temporary map, so merge moves their nodes instead of copying them, as FlatSigningProvider::Merge does.

I'd leave the four loops as they are. The sets come from a temporary map, so `merge` moves their nodes instead of copying them, as `FlatSigningProvider::Merge` does.
jeanpablojp commented 2026-11-20 21:47:13 +00:00 (Migrated from github.com)

Rebased, and took Ralph's two minor findings on 1cc67cf916.
Also fixed the release note.

Rebased, and took Ralph's two minor findings on `1cc67cf916`. Also fixed the release note.
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!36154
No description provided.