Skip to content

Commit 79df9df

Browse files
committed
Switch to 100% for the HD internal keypool size
1 parent bcafca1 commit 79df9df

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,8 +2424,8 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
24242424
" \"immature_balance\": xxxxxx, (numeric) the total immature balance of the wallet in " + CURRENCY_UNIT + "\n"
24252425
" \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n"
24262426
" \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since Unix epoch) of the oldest pre-generated key in the key pool\n"
2427-
" \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated (excluding internal-/chnage-output keys)\n"
2428-
" \"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"
2427+
" \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated (only counts external keys)\n"
2428+
" \"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"
24292429
" \"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"
24302430
" \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT + "/kB\n"
24312431
" \"hdmasterkeyid\": \"<hash160>\" (string) the Hash160 of the HD master pubkey\n"

src/wallet/wallet.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,13 +2946,11 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize)
29462946
nTargetSize = std::max(GetArg("-keypool", DEFAULT_KEYPOOL_SIZE), (int64_t) 0);
29472947

29482948
// count amount of available keys (internal, external)
2949-
// make sure the keypool of external keys fits the user selected target (-keypool)
2950-
// generate +20% internal keys (minimum 2 keys)
2949+
// make sure the keypool of external and internal keys fits the user selected target (-keypool)
29512950
int64_t amountExternal = KeypoolCountExternalKeys();
29522951
int64_t amountInternal = setKeyPool.size() - amountExternal;
2953-
int64_t targetInternal = std::max((int64_t)ceil(nTargetSize * 0.2), (int64_t) 2);
29542952
int64_t missingExternal = std::max(std::max((int64_t) nTargetSize, (int64_t) 1) - amountExternal, (int64_t) 0);
2955-
int64_t missingInternal = std::max(targetInternal - amountInternal, (int64_t) 0);
2953+
int64_t missingInternal = std::max(std::max((int64_t) nTargetSize, (int64_t) 1) - amountInternal, (int64_t) 0);
29562954

29572955
if (!IsHDEnabled() || !CanSupportFeature(FEATURE_HD_SPLIT))
29582956
{

test/functional/fundrawtransaction.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ def run_test(self):
468468
# drain the keypool
469469
self.nodes[1].getnewaddress()
470470
self.nodes[1].getrawchangeaddress()
471-
self.nodes[1].getrawchangeaddress()
472471
inputs = []
473472
outputs = {self.nodes[0].getnewaddress():1.1}
474473
rawTx = self.nodes[1].createrawtransaction(inputs, outputs)

test/functional/keypool.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,21 @@ def run_test(self):
2929
assert(addr_data['hdmasterkeyid'] == wallet_info['hdmasterkeyid'])
3030
assert_raises_jsonrpc(-12, "Error: Keypool ran out, please call keypoolrefill first", nodes[0].getnewaddress)
3131

32-
# put six (plus 2) new keys in the keypool (100% external-, +20% internal-keys, 2 in min)
32+
# put six (plus 2) new keys in the keypool (100% external-, +100% internal-keys, 1 in min)
3333
nodes[0].walletpassphrase('test', 12000)
3434
nodes[0].keypoolrefill(6)
3535
nodes[0].walletlock()
3636
wi = nodes[0].getwalletinfo()
37-
assert_equal(wi['keypoolsize_hd_internal'], 2)
37+
assert_equal(wi['keypoolsize_hd_internal'], 6)
3838
assert_equal(wi['keypoolsize'], 6)
3939

4040
# drain the internal keys
4141
nodes[0].getrawchangeaddress()
4242
nodes[0].getrawchangeaddress()
43+
nodes[0].getrawchangeaddress()
44+
nodes[0].getrawchangeaddress()
45+
nodes[0].getrawchangeaddress()
46+
nodes[0].getrawchangeaddress()
4347
addr = set()
4448
# the next one should fail
4549
assert_raises_jsonrpc(-12, "Keypool ran out", nodes[0].getrawchangeaddress)
@@ -72,7 +76,7 @@ def run_test(self):
7276
nodes[0].walletpassphrase('test', 100)
7377
nodes[0].keypoolrefill(100)
7478
wi = nodes[0].getwalletinfo()
75-
assert_equal(wi['keypoolsize_hd_internal'], 20)
79+
assert_equal(wi['keypoolsize_hd_internal'], 100)
7680
assert_equal(wi['keypoolsize'], 100)
7781

7882
def __init__(self):

test/functional/wallet-dump.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def run_test (self):
8888
read_dump(tmpdir + "/node0/wallet.unencrypted.dump", addrs, None)
8989
assert_equal(found_addr, test_addr_count) # all keys must be in the dump
9090
assert_equal(found_addr_chg, 50) # 50 blocks where mined
91-
assert_equal(found_addr_rsv, 90*1.2) # 90 keys plus 20% internal keys
91+
assert_equal(found_addr_rsv, 90*2) # 90 keys plus 100% internal keys
9292

9393
#encrypt wallet, restart, unlock and dump
9494
self.nodes[0].encryptwallet('test')
@@ -102,8 +102,8 @@ def run_test (self):
102102
found_addr, found_addr_chg, found_addr_rsv, hd_master_addr_enc = \
103103
read_dump(tmpdir + "/node0/wallet.encrypted.dump", addrs, hd_master_addr_unenc)
104104
assert_equal(found_addr, test_addr_count)
105-
assert_equal(found_addr_chg, 90*1.2 + 50) # old reserve keys are marked as change now
106-
assert_equal(found_addr_rsv, 90*1.2)
105+
assert_equal(found_addr_chg, 90*2 + 50) # old reserve keys are marked as change now
106+
assert_equal(found_addr_rsv, 90*2)
107107

108108
if __name__ == '__main__':
109109
WalletDumpTest().main ()

0 commit comments

Comments
 (0)