wallet: fix gethdkeys RPC for descriptors with partial xprvs #34379

pull rkrux wants to merge 2 commits into bitcoin:master from rkrux:gethdkeys changing 2 files +36 βˆ’20
  1. rkrux commented at 12:08 pm on January 22, 2026: contributor

    Fixes #34378

    A non-watch-only wallet allows to import descriptors with partial private keys, eg: a multisig descriptor with one private key and one public key. In case an xpub is imported in any such descriptors whose private key the wallet doesn’t have, then the gethdkeys RPC throws an unhandled error like below when the private keys are requested.

    This fix ensures that such calls are properly handled by conditionally finding the corresponding xprv and the related functional test is accordingly updated.

    0➜ bitcoincli -named gethdkeys private=true
    1error code: -1
    2error message:
    3map::at:  key not found
    
  2. DrahtBot added the label Wallet on Jan 22, 2026
  3. DrahtBot commented at 12:08 pm on January 22, 2026: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34379.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK w0xlt

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

  4. rkrux force-pushed on Jan 22, 2026
  5. DrahtBot added the label CI failed on Jan 22, 2026
  6. DrahtBot removed the label CI failed on Jan 22, 2026
  7. in test/functional/wallet_gethdkeys.py:141 in 3b2add6f8a
    139         wallet = self.nodes[0].get_wallet_rpc("ranged_multisig")
    140 
    141-        xpub1 = wallet.gethdkeys()[0]["xpub"]
    142-        xprv1 = wallet.gethdkeys(private=True)[0]["xprv"]
    143-        xpub2 = def_wallet.gethdkeys()[0]["xpub"]
    144+        xpubs_info = wallet.gethdkeys(private=True)
    


    w0xlt commented at 3:58 pm on January 22, 2026:

    nit: xpubs_info isn’t an accurate name, since it also includes private keys.

    0        hdkeys_info = wallet.gethdkeys(private=True)
    

    rkrux commented at 9:57 am on January 23, 2026:
    Makes sense, done.
  8. w0xlt commented at 3:59 pm on January 22, 2026: contributor
    Approach ACK
  9. rkrux force-pushed on Jan 23, 2026
  10. rkrux commented at 10:06 am on January 23, 2026: contributor

    In the latest push, I split the diff into two commits: first is the fix, second is the test.

    Running the tests with only the test commit & without the fix commit should lead to a failure, though it’s something that I have not tried myself.

  11. fanquake commented at 10:53 am on January 23, 2026: member
    0/home/admin/actions-runner/_work/_temp/src/wallet/rpc/wallet.cpp:710:72: error: argument name 'private' in comment does not match parameter name 'priv' [bugprone-argument-comment,-warnings-as-errors]
    1  710 |                     bool ok = desc_spkm->GetDescriptorString(desc_str, /*private=*/false);
    2      |                                                                        ^~~~~~~~~~~~
    3      |                                                                        /*priv=*/
    4/home/admin/actions-runner/_work/_temp/src/wallet/scriptpubkeyman.h:405:67: note: 'priv' declared here
    5  405 |     [[nodiscard]] bool GetDescriptorString(std::string& out, bool priv) const;
    
  12. DrahtBot added the label CI failed on Jan 23, 2026
  13. DrahtBot commented at 11:04 am on January 23, 2026: contributor

    🚧 At least one of the CI tasks failed. Task tidy: https://github.com/bitcoin/bitcoin/actions/runs/21282075830/job/61254230415 LLM reason (✨ experimental): clang-tidy failure: argument-comment mismatch (private vs priv) in wallet.cpp causes the CI to fail.

    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.

  14. wallet: fix `gethdkeys` RPC for descriptors with partial xprvs
    A non-watch-only wallet allows to import descriptors with partial
    private keys, eg: a multisig descriptor with one private key and
    one public key. In case an xpub is imported in any such descriptors
    whose private key the wallet doesn't have, then the `gethdkeys` RPC
    throws an unhandled error like below when the private keys are
    requested.
    
    This fix ensures that such calls are properly handled by conditionally
    finding the corresponding xprv. Some related documentation of this RPC
    is also updated.
    
    ```
    ➜ bitcoincli -named gethdkeys private=true
    error code: -1
    error message:
    map::at:  key not found
    ```
    6e3a0afc2f
  15. wallet, test: update `gethdkeys` functional test
    Update the `test_ranged_multisig` test case to verify the partial
    xprv fix in the `gethdkeys` RPC. Also, update some existing variable
    names.
    43c528aba9
  16. rkrux force-pushed on Jan 23, 2026
  17. DrahtBot removed the label CI failed on Jan 23, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-01-27 06:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me