Merge bitcoin/bitcoin#32023: wallet: removed duplicate call to GetDescriptorScriptPubKeyMan

55b931934a removed duplicate calling of GetDescriptorScriptPubKeyMan (Saikiran)

Pull request description:

  Removed duplicate call to GetDescriptorScriptPubKeyMan and
  Instead of checking linearly I have used find method so time complexity reduced significantly for GetDescriptorScriptPubKeyMan
  after this fix improved performance of importdescriptor part refs https://github.com/bitcoin/bitcoin/issues/32013.

  **Steps to reproduce in testnet environment**

  **Input size:** 2 million address in the wallet

  **Step1:** call importaddresdescriptor rpc method
  observe the time it has taken.

  **With the provided fix:**
  Do the same steps again
  observe the time it has taken.

  There is a huge improvement in the performance. (previously it may take 5 to 6 seconds now it will take 1 seconds or less)

  main changes i've made during this pr:

  1. remove duplicate call to GetDescriptorScriptPubKeyMan method
  2. And inside GetDescriptorScriptPubKeyMan method previously we checking **each address linearly** so each time it is calling HasWallet method which has aquired lock.
  3. Now i've modified this logic call **find method on the map (O(logn)**) time it is taking, so only once we calling HasWallet method.

  **Note:** Smaller inputs in the wallet you may not see the issue but huge wallet size it will definitely impact the performance.

ACKs for top commit:
  achow101:
    ACK 55b931934a
  w0xlt:
    ACK 55b931934a

Tree-SHA512: 4a7fdbcbb4e55bd034e9cf28ab4e7ee3fb1745fc8847adb388c98a19c952a1fb66d7b54f0f28b4c2a75a42473923742b4a99fb26771577183a98e0bcbf87a8ca
This commit is contained in:
Ava Chow
2025-04-23 13:51:48 -07:00
12 changed files with 45 additions and 29 deletions

View File

@@ -59,7 +59,7 @@ struct FuzzedWallet {
WalletDescriptor w_desc{std::move(parsed_desc), /*creation_time=*/0, /*range_start=*/0, /*range_end=*/1, /*next_index=*/0};
assert(!wallet->GetDescriptorScriptPubKeyMan(w_desc));
LOCK(wallet->cs_wallet);
auto spk_manager{wallet->AddWalletDescriptor(w_desc, keys, /*label=*/"", internal)};
auto spk_manager = *Assert(wallet->AddWalletDescriptor(w_desc, keys, /*label=*/"", internal));
assert(spk_manager);
wallet->AddActiveScriptPubKeyMan(spk_manager->GetID(), *Assert(w_desc.descriptor->GetOutputType()), internal);
}