Skip to content

Commit

Permalink
wallet (not for backport): improve upgradewallet error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatack committed Nov 19, 2020
1 parent ca8cd89 commit 3eb6f8b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4111,17 +4111,16 @@ bool CWallet::UpgradeWallet(int version, bilingual_str& error)
} else {
WalletLogPrintf("Allowing wallet upgrade up to %i\n", version);
}
if (version < prev_version)
{
error = _("Cannot downgrade wallet");
if (version < prev_version) {
error = strprintf(_("Cannot downgrade wallet from version %i to version %i. Wallet version unchanged."), prev_version, version);
return false;
}

LOCK(cs_wallet);

// Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT
if (!CanSupportFeature(FEATURE_HD_SPLIT) && version >= FEATURE_HD_SPLIT && version < FEATURE_PRE_SPLIT_KEYPOOL) {
error = _("Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use version 169900 or no version specified.");
error = strprintf(_("Cannot upgrade a non HD split wallet from version %i to version %i without upgrading to support pre-split keypool. Please use version %i or no version specified."), prev_version, version, FEATURE_PRE_SPLIT_KEYPOOL);
return false;
}

Expand Down
6 changes: 4 additions & 2 deletions test/functional/wallet_upgradewallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ def copy_split_hd():

self.log.info('Wallets cannot be downgraded')
copy_non_hd()
self.test_upgradewallet_error(wallet, previous_version=60000, requested_version=40000, msg="Cannot downgrade wallet")
self.test_upgradewallet_error(wallet, previous_version=60000, requested_version=40000,
msg="Cannot downgrade wallet from version 60000 to version 40000. Wallet version unchanged.")
wallet.unloadwallet()
assert_equal(before_checksum, sha256sum_file(node_master_wallet))
node_master.loadwallet('')
Expand Down Expand Up @@ -250,7 +251,8 @@ def copy_split_hd():
self.log.info('Cannot upgrade to HD Split, needs Pre Split Keypool')
for version in [139900, 159900, 169899]:
self.test_upgradewallet_error(wallet, previous_version=130000, requested_version=version,
msg="Cannot upgrade a non HD split wallet without upgrading to support pre split keypool. Please use version 169900 or no version specified.")
msg="Cannot upgrade a non HD split wallet from version {} to version {} without upgrading to "
"support pre-split keypool. Please use version 169900 or no version specified.".format(130000, version))

self.log.info('Upgrade HD to HD chain split')
self.test_upgradewallet(wallet, previous_version=130000, requested_version=169900)
Expand Down

0 comments on commit 3eb6f8b

Please sign in to comment.