diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1217,11 +1217,11 @@ /** * Set the current HD master key (will reset the chain child index counters) - * If possibleOldChain is provided, the parameters from the old chain - * (version) will be preserved. + * Sets the master key's version based on the current wallet version (so the + * caller must ensure the current wallet version is correct before calling + * this function). */ - bool SetHDMasterKey(const CPubKey &key, - CHDChain *possibleOldChain = nullptr); + bool SetHDMasterKey(const CPubKey &key); /** * Blocks until the wallet state is up-to-date to /at least/ the current diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -751,12 +751,7 @@ // If we are using HD, replace the HD master key (seed) with a new one. if (IsHDEnabled()) { - CKey key; - CPubKey masterPubKey = GenerateNewHDMasterKey(); - // preserve the old chains version to not break backward - // compatibility - CHDChain oldChain = GetHDChain(); - if (!SetHDMasterKey(masterPubKey, &oldChain)) { + if (!SetHDMasterKey(GenerateNewHDMasterKey())) { return false; } } @@ -1545,17 +1540,15 @@ return pubkey; } -bool CWallet::SetHDMasterKey(const CPubKey &pubkey, - CHDChain *possibleOldChain) { +bool CWallet::SetHDMasterKey(const CPubKey &pubkey) { LOCK(cs_wallet); // Store the keyid (hash160) together with the child index counter in the // database as a hdchain object. CHDChain newHdChain; - if (possibleOldChain) { - // preserve the old chains version - newHdChain.nVersion = possibleOldChain->nVersion; - } + newHdChain.nVersion = CanSupportFeature(FEATURE_HD_SPLIT) + ? CHDChain::VERSION_HD_CHAIN_SPLIT + : CHDChain::VERSION_HD_BASE; newHdChain.masterKeyID = pubkey.GetID(); SetHDChain(newHdChain, false);