Skip to content

Commit f34cdcb

Browse files
committed
Merge #9294: Use internal HD chain for change outputs (hd split)
4115af7 Fix rebase issue where pwalletMain was used instead of pwallet Ser./Deser. nInternalChainCounter as last element (Jonas Schnelli) 9382f04 Do not break backward compatibility during wallet encryption (Jonas Schnelli) 1df08d1 Add assertion for CanSupportFeature(FEATURE_HD_SPLIT) (Jonas Schnelli) cd468d0 Define CWallet::DeriveNewChildKey() as private (Jonas Schnelli) ed79e4f Optimize GetOldestKeyPoolTime(), return as soon as we have both oldest keys (Jonas Schnelli) 771a304 Make sure we set the wallets min version to FEATURE_HD_SPLIT at the very first point (Jonas Schnelli) 1b3b5c6 Slightly modify fundrawtransaction.py test (change getnewaddress() into getrawchangeaddress()) (Jonas Schnelli) 003e197 Remove FEATURE_HD_SPLIT bump TODO (Jonas Schnelli) d9638e5 Overhaul the internal/external key derive switch (Jonas Schnelli) 1090502 Fix superfluous cast and code style nits in RPC wallet-hd.py test (Jonas Schnelli) 58e1483 CKeyPool avoid "catch (...)" in SerializationOp (Jonas Schnelli) e138876 Only show keypoolsize_hd_internal if HD split is enabled (Jonas Schnelli) add38d9 GetOldestKeyPoolTime: if HD & HD Chain Split is enabled, response max(oldest-internal-key, oldest-external-key) (Jonas Schnelli) dd526c2 Don't switch to HD-chain-split during wallet encryption of non HD-chain-split wallets (Jonas Schnelli) 79df9df Switch to 100% for the HD internal keypool size (Jonas Schnelli) bcafca1 Make sure we always generate one keypool key at minimum (Jonas Schnelli) d0a627a Fix issue where CDataStream->nVersion was taken a CKeyPool record version (Jonas Schnelli) 9af8f00 Make sure we hand out keypool keys if HD_SPLIT is not enabled (Jonas Schnelli) 469a47b Make sure ReserveKeyFromKeyPool only hands out internal keys if HD_SPLIT is supported (Jonas Schnelli) 05a9b49 Fix wrong keypool internal size in RPC getwalletinfo help (Jonas Schnelli) 01de822 Removed redundant IsLocked() check in NewKeyPool() (Jonas Schnelli) d59531d Immediately return setKeyPool's size if HD or HD_SPLIT is disabled or not supported (Jonas Schnelli) 02592f4 [Wallet] split the keypool in an internal and external part (Jonas Schnelli) Tree-SHA512: 80d355d5e844b48c3163b56c788ab8b5b5285db0ceeb19858a3ef517d5a702afeca21dbae526d7b8fb4101c2a745af1d92bf557c40cf516780f17992bf678c1a
2 parents f2734c2 + 4115af7 commit f34cdcb

File tree

8 files changed

+241
-89
lines changed

8 files changed

+241
-89
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ UniValue getrawchangeaddress(const JSONRPCRequest& request)
221221

222222
CReserveKey reservekey(pwallet);
223223
CPubKey vchPubKey;
224-
if (!reservekey.GetReservedKey(vchPubKey))
224+
if (!reservekey.GetReservedKey(vchPubKey, true))
225225
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
226226

227227
reservekey.KeepKey();
@@ -1852,7 +1852,7 @@ UniValue gettransaction(const JSONRPCRequest& request)
18521852
" \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n"
18531853
" 'send' category of transactions.\n"
18541854
" \"abandoned\": xxx (bool) 'true' if the transaction has been abandoned (inputs are respendable). Only available for the \n"
1855-
" 'send' category of transactions.\n"
1855+
" 'send' category of transactions.\n"
18561856
" }\n"
18571857
" ,...\n"
18581858
" ],\n"
@@ -2418,16 +2418,17 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
24182418
"Returns an object containing various wallet state info.\n"
24192419
"\nResult:\n"
24202420
"{\n"
2421-
" \"walletversion\": xxxxx, (numeric) the wallet version\n"
2422-
" \"balance\": xxxxxxx, (numeric) the total confirmed balance of the wallet in " + CURRENCY_UNIT + "\n"
2423-
" \"unconfirmed_balance\": xxx, (numeric) the total unconfirmed balance of the wallet in " + CURRENCY_UNIT + "\n"
2424-
" \"immature_balance\": xxxxxx, (numeric) the total immature balance of the wallet in " + CURRENCY_UNIT + "\n"
2425-
" \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n"
2426-
" \"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\n"
2428-
" \"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"
2429-
" \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT + "/kB\n"
2430-
" \"hdmasterkeyid\": \"<hash160>\" (string) the Hash160 of the HD master pubkey\n"
2421+
" \"walletversion\": xxxxx, (numeric) the wallet version\n"
2422+
" \"balance\": xxxxxxx, (numeric) the total confirmed balance of the wallet in " + CURRENCY_UNIT + "\n"
2423+
" \"unconfirmed_balance\": xxx, (numeric) the total unconfirmed balance of the wallet in " + CURRENCY_UNIT + "\n"
2424+
" \"immature_balance\": xxxxxx, (numeric) the total immature balance of the wallet in " + CURRENCY_UNIT + "\n"
2425+
" \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n"
2426+
" \"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 (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 the wallet is using this feature, otherwise external keys are used)\n"
2429+
" \"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"
2430+
" \"paytxfee\": x.xxxx, (numeric) the transaction fee configuration, set in " + CURRENCY_UNIT + "/kB\n"
2431+
" \"hdmasterkeyid\": \"<hash160>\" (string) the Hash160 of the HD master pubkey\n"
24312432
"}\n"
24322433
"\nExamples:\n"
24332434
+ HelpExampleCli("getwalletinfo", "")
@@ -2437,18 +2438,23 @@ UniValue getwalletinfo(const JSONRPCRequest& request)
24372438
LOCK2(cs_main, pwallet->cs_wallet);
24382439

24392440
UniValue obj(UniValue::VOBJ);
2441+
2442+
size_t kpExternalSize = pwallet->KeypoolCountExternalKeys();
24402443
obj.push_back(Pair("walletversion", pwallet->GetVersion()));
24412444
obj.push_back(Pair("balance", ValueFromAmount(pwallet->GetBalance())));
24422445
obj.push_back(Pair("unconfirmed_balance", ValueFromAmount(pwallet->GetUnconfirmedBalance())));
24432446
obj.push_back(Pair("immature_balance", ValueFromAmount(pwallet->GetImmatureBalance())));
24442447
obj.push_back(Pair("txcount", (int)pwallet->mapWallet.size()));
24452448
obj.push_back(Pair("keypoololdest", pwallet->GetOldestKeyPoolTime()));
2446-
obj.push_back(Pair("keypoolsize", (int)pwallet->GetKeyPoolSize()));
2449+
obj.push_back(Pair("keypoolsize", (int64_t)kpExternalSize));
2450+
CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID;
2451+
if (!masterKeyID.IsNull() && pwallet->CanSupportFeature(FEATURE_HD_SPLIT)) {
2452+
obj.push_back(Pair("keypoolsize_hd_internal", (int64_t)(pwallet->GetKeyPoolSize() - kpExternalSize)));
2453+
}
24472454
if (pwallet->IsCrypted()) {
24482455
obj.push_back(Pair("unlocked_until", pwallet->nRelockTime));
24492456
}
24502457
obj.push_back(Pair("paytxfee", ValueFromAmount(payTxFee.GetFeePerK())));
2451-
CKeyID masterKeyID = pwallet->GetHDChain().masterKeyID;
24522458
if (!masterKeyID.IsNull())
24532459
obj.push_back(Pair("hdmasterkeyid", masterKeyID.GetHex()));
24542460
return obj;

0 commit comments

Comments
 (0)