Skip to content

Commit

Permalink
Bump wallet version for pre split keypool
Browse files Browse the repository at this point in the history
Bump the wallet version to indicate support for the pre split keypool.
Also prevents any wallets from upgrading to versions between HD_SPLIT
and PRE_SPLIT_KEYPOOL.
  • Loading branch information
achow101 committed May 12, 2018
1 parent dfcd9f3 commit a8da482
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4060,6 +4060,14 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&
// 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=169900 or -upgradewallet with no version specified."));
return nullptr;
}

bool hd_upgrade = false;
bool split_upgrade = false;
if (walletInstance->CanSupportFeature(FEATURE_HD) && !walletInstance->IsHDEnabled()) {
Expand All @@ -4076,7 +4084,7 @@ CWallet* CWallet::CreateWalletFromFile(const std::string& name, const fs::path&
// 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
Expand Down
4 changes: 3 additions & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ enum WalletFeature

FEATURE_NO_DEFAULT_KEY = 159900, // Wallet without a default key written

FEATURE_LATEST = FEATURE_NO_DEFAULT_KEY
FEATURE_PRE_SPLIT_KEYPOOL = 169900, // Upgraded to HD SPLIT and can have a pre-split keypool

FEATURE_LATEST = FEATURE_PRE_SPLIT_KEYPOOL
};

enum class OutputType {
Expand Down

0 comments on commit a8da482

Please sign in to comment.