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. jnewbery cross-referenced this on Aug 10, 2017 from issue [Do not merge] Stop advancing best block and shutdown node if keypool drops below critical threshold by jnewbery
  8. [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
  9. [wallet] [tests] Add keypool topup functional test d34957e17e
  10. 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

  11. 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

    wallet/wallet.cpp: In member function ‘bool CWallet::HasUnusedKeys(int) const’:
    wallet/wallet.cpp:3663:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         return setExternalKeyPool.size() >= min_keys && (setInternalKeyPool.size() >= min_keys || !CanSupportFeature(FEATURE_HD_SPLIT));
                                          ^
    wallet/wallet.cpp:3663:80: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         return setExternalKeyPool.size() >= min_keys && (setInternalKeyPool.size() >= min_keys || !CanSupportFeature(FEATURE_HD_SPLIT));
    
  12. laanwj added the label Wallet on Aug 10, 2017
  13. jnewbery force-pushed on Aug 10, 2017
  14. 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.

  15. ryanofsky commented at 6:57 PM on August 10, 2017: contributor

    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.

  16. gmaxwell approved
  17. gmaxwell commented at 7:05 PM on August 10, 2017: contributor

    utACK

  18. MarcoFalke added this to the milestone 0.15.0 on Aug 10, 2017
  19. sipa commented at 8:18 PM on August 10, 2017: member

    utACK d34957e17e8c9740104533aaf4a896e93548c87e

  20. instagibbs approved
  21. instagibbs commented at 8:20 PM on August 10, 2017: member

    utACK

  22. 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

  23. achow101 commented at 10:49 PM on August 10, 2017: member

    utACK d34957e17e8c9740104533aaf4a896e93548c87e

  24. laanwj merged this on Aug 14, 2017
  25. laanwj closed this on Aug 14, 2017

  26. laanwj referenced this in commit 653a46dd91 on Aug 14, 2017
  27. jnewbery commented at 2:53 PM on August 14, 2017: member

    :tada:

  28. jnewbery deleted the branch on Aug 14, 2017
  29. paveljanik commented at 5:21 PM on August 14, 2017: contributor

    This brings two new warnings:

    wallet/wallet.cpp:3668:38: warning: comparison of integers of different signs: 'size_type' (aka 'unsigned long') and 'int' [-Wsign-compare]
        return setExternalKeyPool.size() >= min_keys && (setInternalKeyPool.size() >= min_keys || !CanSupportFeature(FEATURE_HD_SPLIT));
               ~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~
    wallet/wallet.cpp:3668:80: warning: comparison of integers of different signs: 'size_type' (aka 'unsigned long') and 'int' [-Wsign-compare]
        return setExternalKeyPool.size() >= min_keys && (setInternalKeyPool.size() >= min_keys || !CanSupportFeature(FEATURE_HD_SPLIT));
                                                         ~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~
    2 warnings generated.
    
  30. jnewbery cross-referenced this on Aug 14, 2017 from issue [wallet] Keypool topup cleanups by jnewbery
  31. 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.

  32. laanwj referenced this in commit 0e5b7486cb on Aug 18, 2017
  33. mempko referenced this in commit d83d1522a6 on Sep 28, 2017
  34. meshcollider cross-referenced this on Jan 17, 2018 from issue TODO for release notes 0.16.0 by laanwj
  35. sipa cross-referenced this on Mar 30, 2018 from issue Implement gap detection for deterministic wallets by sipa
  36. jnewbery cross-referenced this on Apr 2, 2018 from issue Assertion failure during rescan by GSPP
  37. jasonbcox referenced this in commit 08e2c02735 on Sep 13, 2019
  38. PastaPastaPasta referenced this in commit 546865aca1 on Sep 18, 2019
  39. PastaPastaPasta referenced this in commit 6946848e02 on Sep 19, 2019
  40. PastaPastaPasta referenced this in commit f1312e1539 on Sep 20, 2019
  41. PastaPastaPasta referenced this in commit 1d1e735610 on Sep 20, 2019
  42. PastaPastaPasta referenced this in commit c438c9322f on Sep 20, 2019
  43. PastaPastaPasta referenced this in commit 02328ae966 on Sep 20, 2019
  44. charlesrocket referenced this in commit a8de928400 on Dec 9, 2019
  45. barrystyle referenced this in commit 2cf9a16f02 on Jan 22, 2020
  46. barrystyle referenced this in commit 4e643e4d4a on Jan 22, 2020
  47. random-zebra cross-referenced this on Apr 28, 2021 from issue [Wallet] Laggard wallet-related backports from btc 0.15 by random-zebra
  48. random-zebra referenced this in commit 2d50b6e3b9 on Jun 9, 2021
  49. bitcoin 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: 2026-05-19 06:54 UTC