diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -85,7 +85,10 @@ // Wallet without a default key written FEATURE_NO_DEFAULT_KEY = 190700, - FEATURE_LATEST = FEATURE_NO_DEFAULT_KEY + // Upgraded to HD SPLIT and can have a pre-split keypool + FEATURE_PRE_SPLIT_KEYPOOL = 200300, + + FEATURE_LATEST = FEATURE_PRE_SPLIT_KEYPOOL, }; enum class OutputType { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4419,6 +4419,20 @@ // Upgrade to HD if explicit upgrade if (gArgs.GetBoolArg("-upgradewallet", false)) { LOCK(walletInstance->cs_wallet); + + // Do not upgrade versions to any version between HD_SPLIT and + // FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT + int max_version = walletInstance->nWalletVersion; + if (!walletInstance->CanSupportFeature(FEATURE_HD_SPLIT) && + max_version >= FEATURE_HD_SPLIT && + max_version < FEATURE_PRE_SPLIT_KEYPOOL) { + InitError( + _("Cannot upgrade a non HD split wallet without upgrading to " + "support pre split keypool. Please use -upgradewallet=200300 " + "or -upgradewallet with no version specified.")); + return nullptr; + } + bool hd_upgrade = false; bool split_upgrade = false; if (walletInstance->CanSupportFeature(FEATURE_HD) && @@ -4434,7 +4448,7 @@ // Upgrade to HD chain split if necessary if (walletInstance->CanSupportFeature(FEATURE_HD_SPLIT)) { LogPrintf("Upgrading wallet to use HD chain split\n"); - walletInstance->SetMinVersion(FEATURE_HD_SPLIT); + walletInstance->SetMinVersion(FEATURE_PRE_SPLIT_KEYPOOL); split_upgrade = FEATURE_HD_SPLIT > prev_version; } // Mark all keys currently in the keypool as pre-split