diff options
author | Matt Corallo <git@bluematt.me> | 2017-03-29 12:33:13 -0400 |
---|---|---|
committer | Matt Corallo <git@bluematt.me> | 2017-04-13 11:55:43 -0400 |
commit | 185c7f08be68eec878f4b32b3a52145dd57e13bd (patch) | |
tree | a5c8399d8b98895e71eec550e617d1f56103e111 | |
parent | f34cdcbd806d3e7c9d5dbac2a201755a4cc9828b (diff) | |
download | bitcoin-185c7f08be68eec878f4b32b3a52145dd57e13bd.tar.xz |
Avoid reading the old hd master key during wallet encryption
This makes SetHDMasterKey responsible for maintinaing the CHDChain
version instead of always creating it with the latest version and
making EncryptWallet responsible for keeping the version from
changing.
-rw-r--r-- | src/wallet/wallet.cpp | 14 | ||||
-rw-r--r-- | src/wallet/wallet.h | 7 |
2 files changed, 8 insertions, 13 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e631c86bb2..42cecfb541 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -637,12 +637,9 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase) // 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; + } } NewKeyPool(); @@ -1308,17 +1305,14 @@ CPubKey CWallet::GenerateNewHDMasterKey() 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); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index ccede60097..4e7e1b5797 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1056,9 +1056,10 @@ public: CPubKey GenerateNewHDMasterKey(); /* 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. */ - bool SetHDMasterKey(const CPubKey& key, CHDChain *possibleOldChain = nullptr); + 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); }; /** A key allocated from the key pool. */ |