Browse Source

Switch to 100% for the HD internal keypool size

0.15
Jonas Schnelli 8 years ago
parent
commit
79df9df348
No known key found for this signature in database
GPG Key ID: 1EB776BB03C7922D
  1. 4
      src/wallet/rpcwallet.cpp
  2. 6
      src/wallet/wallet.cpp
  3. 1
      test/functional/fundrawtransaction.py
  4. 10
      test/functional/keypool.py
  5. 6
      test/functional/wallet-dump.py

4
src/wallet/rpcwallet.cpp

@ -2424,8 +2424,8 @@ UniValue getwalletinfo(const JSONRPCRequest& request) @@ -2424,8 +2424,8 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
" \"immature_balance\": xxxxxx, (numeric) the total immature balance of the wallet in " + CURRENCY_UNIT + "\n"
" \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n"
" \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since Unix epoch) of the oldest pre-generated key in the key pool\n"
" \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated (excluding internal-/chnage-output keys)\n"
" \"keypoolsize_hd_internal\": xxxx, (numeric) how many new keys are pre-generated for internal use (change outputs, 20% of the -keypoolsize target, only appears if HD is enabled)\n"
" \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated (only counts external keys)\n"
" \"keypoolsize_hd_internal\": xxxx, (numeric) how many new keys are pre-generated for internal use (used for change outputs, only appears if HD is enabled otherwise there is no need for internal keys)\n"
" \"unlocked_until\": ttt, (numeric) the timestamp in seconds since epoch (midnight Jan 1 1970 GMT) that the wallet is unlocked for transfers, or 0 if the wallet is locked\n"
" \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT + "/kB\n"
" \"hdmasterkeyid\": \"<hash160>\" (string) the Hash160 of the HD master pubkey\n"

6
src/wallet/wallet.cpp

@ -2946,13 +2946,11 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize) @@ -2946,13 +2946,11 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
nTargetSize = std::max(GetArg("-keypool", DEFAULT_KEYPOOL_SIZE), (int64_t) 0);
// count amount of available keys (internal, external)
// make sure the keypool of external keys fits the user selected target (-keypool)
// generate +20% internal keys (minimum 2 keys)
// make sure the keypool of external and internal keys fits the user selected target (-keypool)
int64_t amountExternal = KeypoolCountExternalKeys();
int64_t amountInternal = setKeyPool.size() - amountExternal;
int64_t targetInternal = std::max((int64_t)ceil(nTargetSize * 0.2), (int64_t) 2);
int64_t missingExternal = std::max(std::max((int64_t) nTargetSize, (int64_t) 1) - amountExternal, (int64_t) 0);
int64_t missingInternal = std::max(targetInternal - amountInternal, (int64_t) 0);
int64_t missingInternal = std::max(std::max((int64_t) nTargetSize, (int64_t) 1) - amountInternal, (int64_t) 0);
if (!IsHDEnabled() || !CanSupportFeature(FEATURE_HD_SPLIT))
{

1
test/functional/fundrawtransaction.py

@ -468,7 +468,6 @@ class RawTransactionsTest(BitcoinTestFramework): @@ -468,7 +468,6 @@ class RawTransactionsTest(BitcoinTestFramework):
# drain the keypool
self.nodes[1].getnewaddress()
self.nodes[1].getrawchangeaddress()
self.nodes[1].getrawchangeaddress()
inputs = []
outputs = {self.nodes[0].getnewaddress():1.1}
rawTx = self.nodes[1].createrawtransaction(inputs, outputs)

10
test/functional/keypool.py

@ -29,17 +29,21 @@ class KeyPoolTest(BitcoinTestFramework): @@ -29,17 +29,21 @@ class KeyPoolTest(BitcoinTestFramework):
assert(addr_data['hdmasterkeyid'] == wallet_info['hdmasterkeyid'])
assert_raises_jsonrpc(-12, "Error: Keypool ran out, please call keypoolrefill first", nodes[0].getnewaddress)
# put six (plus 2) new keys in the keypool (100% external-, +20% internal-keys, 2 in min)
# put six (plus 2) new keys in the keypool (100% external-, +100% internal-keys, 1 in min)
nodes[0].walletpassphrase('test', 12000)
nodes[0].keypoolrefill(6)
nodes[0].walletlock()
wi = nodes[0].getwalletinfo()
assert_equal(wi['keypoolsize_hd_internal'], 2)
assert_equal(wi['keypoolsize_hd_internal'], 6)
assert_equal(wi['keypoolsize'], 6)
# drain the internal keys
nodes[0].getrawchangeaddress()
nodes[0].getrawchangeaddress()
nodes[0].getrawchangeaddress()
nodes[0].getrawchangeaddress()
nodes[0].getrawchangeaddress()
nodes[0].getrawchangeaddress()
addr = set()
# the next one should fail
assert_raises_jsonrpc(-12, "Keypool ran out", nodes[0].getrawchangeaddress)
@ -72,7 +76,7 @@ class KeyPoolTest(BitcoinTestFramework): @@ -72,7 +76,7 @@ class KeyPoolTest(BitcoinTestFramework):
nodes[0].walletpassphrase('test', 100)
nodes[0].keypoolrefill(100)
wi = nodes[0].getwalletinfo()
assert_equal(wi['keypoolsize_hd_internal'], 20)
assert_equal(wi['keypoolsize_hd_internal'], 100)
assert_equal(wi['keypoolsize'], 100)
def __init__(self):

6
test/functional/wallet-dump.py

@ -88,7 +88,7 @@ class WalletDumpTest(BitcoinTestFramework): @@ -88,7 +88,7 @@ class WalletDumpTest(BitcoinTestFramework):
read_dump(tmpdir + "/node0/wallet.unencrypted.dump", addrs, None)
assert_equal(found_addr, test_addr_count) # all keys must be in the dump
assert_equal(found_addr_chg, 50) # 50 blocks where mined
assert_equal(found_addr_rsv, 90*1.2) # 90 keys plus 20% internal keys
assert_equal(found_addr_rsv, 90*2) # 90 keys plus 100% internal keys
#encrypt wallet, restart, unlock and dump
self.nodes[0].encryptwallet('test')
@ -102,8 +102,8 @@ class WalletDumpTest(BitcoinTestFramework): @@ -102,8 +102,8 @@ class WalletDumpTest(BitcoinTestFramework):
found_addr, found_addr_chg, found_addr_rsv, hd_master_addr_enc = \
read_dump(tmpdir + "/node0/wallet.encrypted.dump", addrs, hd_master_addr_unenc)
assert_equal(found_addr, test_addr_count)
assert_equal(found_addr_chg, 90*1.2 + 50) # old reserve keys are marked as change now
assert_equal(found_addr_rsv, 90*1.2)
assert_equal(found_addr_chg, 90*2 + 50) # old reserve keys are marked as change now
assert_equal(found_addr_rsv, 90*2)
if __name__ == '__main__':
WalletDumpTest().main ()

Loading…
Cancel
Save