Basic keypool topup #11022

pull jnewbery wants to merge 7 commits into bitcoin:master from jnewbery:basic_keypool_topup changing 7 files +289 −161
  1. jnewbery commented at 2:25 pm on August 10, 2017: member

    This PR contains the first part of #10882 :

    • if a key from the keypool is used, mark all keys up to that key as used, and then try to top up the keypool
    • top up the keypool on startup

    Notably, it does not stop the node or prevent the best block from advancing if the keypool drops below a threshold (which means that transactions may be missed and funds lost if restoring from an old HD wallet backup).

  2. [wallet] [moveonly] Move CAffectedKeysVisitor cab8557e35
  3. [wallet] [moveonly] Move LoadKeyPool to cpp 2376bfcf24
  4. [wallet] Don't hold cs_LastBlockFile while calling setBestChain
    cs_LastBlockFile shouldn't be held while calling wallet functions.
    83f1ec33ce
  5. [wallet] Cache keyid -> keypool id mappings f2123e3a7b
  6. [wallet] Add HasUnusedKeys() helper c25d90f125
  7. [wallet] keypool mark-used and topup
    This commit adds basic keypool mark-used and topup:
    
    - try to topup the keypool on initial load
    - if a key in the keypool is used, mark all keys before that as used and
    try to top up
    095142d1f9
  8. [wallet] [tests] Add keypool topup functional test d34957e17e
  9. in test/functional/test_framework/test_framework.py:212 in 96df362174 outdated
    208@@ -209,7 +209,7 @@ def start_node(self, i, dirname, extra_args=None, rpchost=None, timewait=None, b
    209         datadir = os.path.join(dirname, "node" + str(i))
    210         if binary is None:
    211             binary = os.getenv("BITCOIND", "bitcoind")
    212-        args = [binary, "-datadir=" + datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-logtimemicros", "-debug", "-debugexclude=libevent", "-debugexclude=leveldb", "-mocktime=" + str(self.mocktime), "-uacomment=testnode%d" % i]
    213+        args = [binary, "-datadir=" + datadir, "-server", "-keypool=1", "-keypoolcritical=0", "-discover=0", "-rest", "-logtimemicros", "-debug", "-debugexclude=libevent", "-debugexclude=leveldb", "-mocktime=" + str(self.mocktime), "-uacomment=testnode%d" % i]
    


    ryanofsky commented at 4:34 pm on August 10, 2017:

    In commit “[wallet] keypool mark-used and topup”

    It looks like these test changes got added to the wrong commit.


    jnewbery commented at 6:01 pm on August 10, 2017:
    Thanks Russ. You’re right, this was in the wrong commit and shouldn’t be in this PR. Fixed
  10. in src/wallet/wallet.cpp:3614 in c25d90f125 outdated
    3610@@ -3611,6 +3611,11 @@ void CReserveKey::ReturnKey()
    3611     vchPubKey = CPubKey();
    3612 }
    3613 
    3614+bool CWallet::HasUnusedKeys(int min_keys) const
    


    ryanofsky commented at 4:57 pm on August 10, 2017:

    In commit “[wallet] Add HasUnusedKeys() helper”

    Should use size_t instead of int to silence some warnings

    0wallet/wallet.cpp: In member function bool CWallet::HasUnusedKeys(int) const:
    1wallet/wallet.cpp:3663:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    2     return setExternalKeyPool.size() >= min_keys && (setInternalKeyPool.size() >= min_keys || !CanSupportFeature(FEATURE_HD_SPLIT));
    3                                      ^
    4wallet/wallet.cpp:3663:80: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    5     return setExternalKeyPool.size() >= min_keys && (setInternalKeyPool.size() >= min_keys || !CanSupportFeature(FEATURE_HD_SPLIT));
    
  11. laanwj added the label Wallet on Aug 10, 2017
  12. jnewbery force-pushed on Aug 10, 2017
  13. in src/wallet/wallet.cpp:3656 in 095142d1f9 outdated
    3651+
    3652+        CKeyPool keypool;
    3653+        if (walletdb.ReadPool(index, keypool)) { //TODO: This should be unnecessary
    3654+            m_pool_key_to_index.erase(keypool.vchPubKey.GetID());
    3655+        }
    3656+        walletdb.ErasePool(index);
    


    ryanofsky commented at 6:48 pm on August 10, 2017:

    In commit “[wallet] keypool mark-used and topup”

    An older version of this PR was calling KeepKey instead of doing this manually. It’d be nice to either call KeepKey here, or add the “keypool keep” log print here from that method. Logging about the key being kept would help debugging and make this code clearer.

  14. ryanofsky commented at 6:57 pm on August 10, 2017: member
    Slightly tested ACK d34957e17e8c9740104533aaf4a896e93548c87e. Confirmed disabling topup breaks the new test. Would be nice to get this merged, because this makes updating unlocked wallets a lot safer, and because merging it would considerably simplify #10882.
  15. gmaxwell approved
  16. gmaxwell commented at 7:05 pm on August 10, 2017: contributor
    utACK
  17. MarcoFalke added this to the milestone 0.15.0 on Aug 10, 2017
  18. sipa commented at 8:18 pm on August 10, 2017: member
    utACK d34957e17e8c9740104533aaf4a896e93548c87e
  19. instagibbs approved
  20. instagibbs commented at 8:20 pm on August 10, 2017: member
    utACK
  21. jnewbery commented at 8:26 pm on August 10, 2017: member

    Thanks for the code review @ryanofsky . This branch now has some ACKs so I’m going to hold off making any additional changes (unless others think them necessary)

    I’ll happily review and ACK a cleanup PR after v0.15

  22. achow101 commented at 10:49 pm on August 10, 2017: member
    utACK d34957e17e8c9740104533aaf4a896e93548c87e
  23. laanwj merged this on Aug 14, 2017
  24. laanwj closed this on Aug 14, 2017

  25. laanwj referenced this in commit 653a46dd91 on Aug 14, 2017
  26. jnewbery commented at 2:53 pm on August 14, 2017: member
    :tada:
  27. jnewbery deleted the branch on Aug 14, 2017
  28. paveljanik commented at 5:21 pm on August 14, 2017: contributor

    This brings two new warnings:

    0wallet/wallet.cpp:3668:38: warning: comparison of integers of different signs: 'size_type' (aka 'unsigned long') and 'int' [-Wsign-compare]
    1    return setExternalKeyPool.size() >= min_keys && (setInternalKeyPool.size() >= min_keys || !CanSupportFeature(FEATURE_HD_SPLIT));
    2           ~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~
    3wallet/wallet.cpp:3668:80: warning: comparison of integers of different signs: 'size_type' (aka 'unsigned long') and 'int' [-Wsign-compare]
    4    return setExternalKeyPool.size() >= min_keys && (setInternalKeyPool.size() >= min_keys || !CanSupportFeature(FEATURE_HD_SPLIT));
    5                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~
    62 warnings generated.
    
  29. jnewbery commented at 5:41 pm on August 14, 2017: member

    Thanks @paveljanik . This was pointed out by @ryanofsky before but I didn’t fix it because this PR had already collected a few ACKs

    Cleanup commits here: #11044 . Not required for v0.15.

  30. laanwj referenced this in commit 0e5b7486cb on Aug 18, 2017
  31. mempko referenced this in commit d83d1522a6 on Sep 28, 2017
  32. jasonbcox referenced this in commit 08e2c02735 on Sep 13, 2019
  33. PastaPastaPasta referenced this in commit 546865aca1 on Sep 18, 2019
  34. PastaPastaPasta referenced this in commit 6946848e02 on Sep 19, 2019
  35. PastaPastaPasta referenced this in commit f1312e1539 on Sep 20, 2019
  36. PastaPastaPasta referenced this in commit 1d1e735610 on Sep 20, 2019
  37. PastaPastaPasta referenced this in commit c438c9322f on Sep 20, 2019
  38. PastaPastaPasta referenced this in commit 02328ae966 on Sep 20, 2019
  39. charlesrocket referenced this in commit a8de928400 on Dec 9, 2019
  40. barrystyle referenced this in commit 2cf9a16f02 on Jan 22, 2020
  41. barrystyle referenced this in commit 4e643e4d4a on Jan 22, 2020
  42. random-zebra referenced this in commit 2d50b6e3b9 on Jun 9, 2021
  43. DrahtBot locked this on Sep 8, 2021

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-18 12:12 UTC

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