Check if the wallet already contains the descriptor GetDescriptorScriptPubKeyMan #32013

issue saikiran57 openend this issue on March 7, 2025
  1. saikiran57 commented at 7:46 am on March 7, 2025: none

    Is there an existing issue for this?

    • I have searched the existing issues

    Current behaviour

    In importdescriptors rpc call when we try import descriptor address we are internally calling ProcessDescriptorImport() method which checking

    // Check if the wallet already contains the descriptor auto existing_spk_manager = wallet.GetDescriptorScriptPubKeyMan(w_desc); if (existing_spk_manager) { if (!existing_spk_manager->CanUpdateToWalletDescriptor(w_desc, error)) { throw JSONRPCError(RPC_INVALID_PARAMETER, error); } }

    and below we have

    // Add descriptor to the wallet auto spk_manager = wallet.AddWalletDescriptor(w_desc, keys, label, desc_internal); if (spk_manager == nullptr) { throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Could not add descriptor '%s'", descriptor)); }

    but in AddWalletDescriptor method again we are checking auto spk_man = GetDescriptorScriptPubKeyMan(desc);

    By calling twice we are facing lot of delay when we import address.

    2025-01-24T03:26:28Z [wt_wallet] ProcessDescriptorImport: GetDescriptorScriptPubKeyMan time 619 milliseconds 2025-01-24T03:26:28Z [wt_wallet] ProcessDescriptorImport: AddWalletDescriptor time 33 milliseconds 2025-01-24T03:26:28Z [wt_wallet] operator(): ProcessDescriptorImport time 653 milliseconds

    I’ve made some improvement like using only GetDescriptorScriptPubKeyMan method it is bit faster. Kindly verify this issue so I can create Pull request.

    Expected behaviour

    GetDescriptorScriptPubKeyMan method should be called only once in the importdescriptor call.

    Steps to reproduce

    1. call importdescriptors()

    GetDescriptor_time_1.txt

    Improved_getdescriptor.txt

    1. Add debug logs auto startTime = std::chrono::steady_clock::now(); const UniValue result = ProcessDescriptorImport(*pwallet, request, timestamp); auto endTime = std::chrono::steady_clock::now(); auto duratioMilliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(endTime-startTime).count(); pwallet->WalletLogPrintf("%s: ProcessDescriptorImport time %d milliseconds \n", __func__, duratioMilliseconds);

    auto startTime = std::chrono::steady_clock::now(); // Check if the wallet already contains the descriptor auto existing_spk_manager = wallet.GetDescriptorScriptPubKeyMan(w_desc); if (existing_spk_manager) { if (!existing_spk_manager->CanUpdateToWalletDescriptor(w_desc, error)) { throw JSONRPCError(RPC_INVALID_PARAMETER, error); } } auto endTime = std::chrono::steady_clock::now(); auto duratioMilliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(endTime-startTime).count(); pwallet->WalletLogPrintf("%s: GetDescriptorScriptPubKeyMantime %d milliseconds \n", __func__, duratioMilliseconds); `

    ` auto startTime = std::chrono::steady_clock::now(); // Add descriptor to the wallet auto spk_manager = wallet.AddWalletDescriptor(w_desc, keys, label, desc_internal); if (spk_manager == nullptr) { throw JSONRPCError(RPC_WALLET_ERROR, strprintf(“Could not add descriptor ‘%s’”, descriptor)); }

            auto endTime = std::chrono::steady_clock::now();
            auto duratioMilliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(endTime-startTime).count();
            wallet.WalletLogPrintf("%s: AddWalletDescriptor time %d milliseconds \n", __func__, duratioMilliseconds);`
    

    Relevant log output

    No response

    How did you obtain Bitcoin Core

    Compiled from source

    What version of Bitcoin Core are you using?

    master

    Operating system and version

    wsl ubuntu 22.04 LTS

    Machine specifications

    No response

  2. achow101 commented at 4:23 pm on March 7, 2025: member
    If you believe you have a useful change, please just open a PR. There’s no need to ask permission to do so, and doing code review in an issue is painful.
  3. saikiran57 referenced this in commit d53f4d8b43 on Mar 10, 2025
  4. saikiran57 referenced this in commit 4ee0dd97dd on Mar 13, 2025
  5. saikiran57 referenced this in commit c986b43f0c on Mar 14, 2025
  6. saikiran57 referenced this in commit 78e398a91a on Mar 17, 2025
  7. saikiran57 referenced this in commit 5aa2c0ed73 on Mar 19, 2025
  8. saikiran57 referenced this in commit b4742ec35c on Mar 19, 2025
  9. willcl-ark added the label Wallet on Mar 19, 2025
  10. saikiran57 referenced this in commit 5899dbfc26 on Mar 21, 2025
  11. saikiran57 referenced this in commit 39a2006300 on Mar 21, 2025
  12. maflcko commented at 3:15 pm on March 21, 2025: member
    Let’s move the discussion to the pull request
  13. maflcko closed this on Mar 21, 2025


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: 2025-03-31 09:12 UTC

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