wallet: fix the behavior of IsHDEnabled, return false in case of a blank hd wallet. #22781

pull Saibato wants to merge 1 commits into bitcoin:master from Saibato:fix_ishdenabled changing 1 files +3 −2
  1. Saibato commented at 5:13 pm on August 23, 2021: contributor

    the result of CWallet::IsHDEnabled() was initialized with true.

    But in case of no keys or a blank hd wallet the iterator would be skipped and not set to false but true, since the loop would be not entered.

    That had resulted in a wrong return and subsequent false HD and watch-only icon display in GUi when reloading a wallet after closing.

  2. DrahtBot added the label Wallet on Aug 23, 2021
  3. Saibato commented at 5:19 pm on August 23, 2021: contributor

    While testing the GUI I noticed that after reloading a blank HD wallet or a key less wallet the icons are displayed not blanked 50%, and also not the correct strike thru HD icon.

    When we create the wallet that is handled correct since we init IsHDEnabled there with 0. (false)

  4. hebasto commented at 8:24 pm on August 23, 2021: member
    Concept ACK. @jarolrod and me were discussing the same issue with CWallet::IsHDEnabled while working on https://github.com/bitcoin-core/gui/pull/403.
  5. in src/wallet/wallet.cpp:1373 in 0310f704f9 outdated
    1370-        result &= spk_man->IsHDEnabled();
    1371+        if (spk_man->IsHDEnabled()) {
    1372+            result = true;
    1373+        } else {
    1374+            return false;
    1375+        }
    


    hebasto commented at 8:28 pm on August 23, 2021:
    0        if (!spk_man->IsHDEnabled()) return false;
    1        result = true;
    

    hebasto commented at 8:32 pm on August 23, 2021:

    Or, even better:

     0--- a/src/wallet/wallet.cpp
     1+++ b/src/wallet/wallet.cpp
     2@@ -1364,11 +1364,11 @@ CAmount CWallet::GetDebit(const CTransaction& tx, const isminefilter& filter) co
     3 bool CWallet::IsHDEnabled() const
     4 {
     5     // All Active ScriptPubKeyMans must be HD for this to be true
     6-    bool result = true;
     7+    if (GetActiveScriptPubKeyMans().empty()) return false;
     8     for (const auto& spk_man : GetActiveScriptPubKeyMans()) {
     9-        result &= spk_man->IsHDEnabled();
    10+        if (!spk_man->IsHDEnabled()) return false;
    11     }
    12-    return result;
    13+    return true;
    14 }
    15 
    16 bool CWallet::CanGetAddresses(bool internal) const
    

    ?


    Saibato commented at 7:21 am on August 24, 2021:

    I thought too about using a check if keys are empty, but then was not sure if empty will work correctly. So the second suggestion might work, the first not, since we will never enter the loop when wallet is empty, and subsequently return true, when indeed false would be correct.

    I saw btw the discussion https://github.com/bitcoin-core/gui/pull/403 and found that a review statement there **…the pr works and the behavior after refraktor has not changed_**__ quite revealing, i tested too that PR and saw that it would not change this vital aspect, that is wrong since a lot of releases, but i guess it is not only a GUI issue and to some extent this PR is also a hint to the implications of constructions in the form of bare for (const auto& x : X()) .... when we can no be sure about the size of x and make vital decisions only in the loop.


    hebasto commented at 7:27 am on August 24, 2021:

    … the first not, since we will never enter the loop when wallet is empty, and subsequently return true, when indeed false would be correct.

    I don’t think this is correct description of the suggested change. Both lines are within a loop body, and there is no return true; statement at all.


    Saibato commented at 7:37 am on August 24, 2021:
    yup :+1: , my fault , the init value is still false from the initial change in this pr, your suggestion is shorter and better…
  6. fanquake requested review from achow101 on Aug 24, 2021
  7. theStack commented at 7:40 am on August 24, 2021: member
    Concept ACK
  8. hebasto commented at 7:58 am on August 24, 2021: member

    Tested e6cae38dad49b196e91e24fef34591b1555f1390, works flawlessly.

    Loading of a blank wallet:

    master (dbcb5742c48fd26f77e500291d7083e12eec741b) this PR
    Screenshot from 2021-08-24 10-54-33 Screenshot from 2021-08-24 10-53-39

    @Saibato

    Could you squash your commits?

  9. the result of CWallet::IsHDEnabled() was initialized with true.
    But in case of no keys or a blank hd wallet the iterator would be skipped
    and not set to false but true, since the loop would be not entered.
    
    That had resulted in a wrong return and subsequent false HD and watch-only
    icon display in gui when reloading a wallet after closing.
    
    Update src/wallet/wallet.cpp
    
    Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
    8733a8e84c
  10. Saibato force-pushed on Aug 24, 2021
  11. hebasto approved
  12. hebasto commented at 9:16 am on August 24, 2021: member
    ACK 8733a8e84c4b2e484f6ed6159fcf5f29a360d42e
  13. Saibato commented at 9:18 am on August 24, 2021: contributor
    thx for fast confirm that it works, as intended. :+1: squashed and rebased.
  14. achow101 commented at 7:31 pm on August 24, 2021: member
    ACK 8733a8e84c4b2e484f6ed6159fcf5f29a360d42e
  15. theStack approved
  16. theStack commented at 8:23 pm on August 24, 2021: member
    utACK 8733a8e84c4b2e484f6ed6159fcf5f29a360d42e
  17. meshcollider commented at 3:22 am on August 25, 2021: contributor
    utACK 8733a8e84c4b2e484f6ed6159fcf5f29a360d42e
  18. meshcollider merged this on Aug 25, 2021
  19. meshcollider closed this on Aug 25, 2021

  20. luke-jr referenced this in commit 6aa1466278 on Oct 10, 2021
  21. fanquake referenced this in commit ecc16fc9e0 on Oct 20, 2021
  22. fanquake referenced this in commit dbd9cf9a6e on Oct 21, 2021
  23. fanquake referenced this in commit aadb6827f4 on Feb 14, 2022
  24. fanquake referenced this in commit c671c6f470 on Feb 15, 2022
  25. fanquake referenced this in commit 9b5f674abb on Mar 1, 2022
  26. DrahtBot locked this on Aug 25, 2022

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: 2024-12-22 12:12 UTC

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