You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge bitcoin#20403: wallet: upgradewallet fixes, improvements, test coverage
3eb6f8b wallet (not for backport): improve upgradewallet error messages (Jon Atack)
ca8cd89 wallet: fix and improve upgradewallet error responses (Jon Atack)
99d56e3 wallet: fix and improve upgradewallet result responses (Jon Atack)
2498b04 Don't upgrade to HD split if it is already supported (Andrew Chow)
c46c18b wallet: refactor GetClosestWalletFeature() (Jon Atack)
Pull request description:
This follows up on bitcoin#18836 and bitcoin#20282 to fix and improve the as-yet unreleased `upgradewallet` feature and also implement review follow-up in bitcoin#18836 (comment).
This PR fixes 4 upgradewallet issues:
- this bug: bitcoin#20403 (comment)
- it returns nothing in the absence of an RPC error, which isn't reassuring for users
- it returns the same thing both in the case of a successful upgrade and when no upgrade took place
- the error message object is currently dead code
This PR fixes the above and provides:
...user feedback to not silently return without upgrading
```
{
"wallet_name": "disable private keys",
"previous_version": 169900,
"current_version": 169900,
"result": "Already at latest version. Wallet version unchanged."
}
```
...better feedback after successfully upgrading
```
{
"wallet_name": "watch-only",
"previous_version": 159900,
"current_version": 169900,
"result": "Wallet upgraded successfully from version 159900 to version 169900."
}
```
...helpful error responses
```
{
"wallet_name": "blank",
"previous_version": 169900,
"current_version": 169900,
"error": "Cannot downgrade wallet from version 169900 to version 159900. Wallet version unchanged."
}
{
"wallet_name": "blank",
"previous_version": 130000,
"current_version": 130000,
"error": "Cannot upgrade a non HD split wallet from version 130000 to version 169899 without upgrading to support pre-split keypool. Please use version 169900 or no version specified."
}
```
updated help:
```
upgradewallet ( version )
Upgrade the wallet. Upgrades to the latest version if no version number is specified.
New keys may be generated and a new wallet backup will need to be made.
Arguments:
1. version (numeric, optional, default=169900) The version number to upgrade to. Default is the latest wallet version.
Result:
{ (json object)
"wallet_name" : "str", (string) Name of wallet this operation was performed on
"previous_version" : n, (numeric) Version of wallet before this operation
"current_version" : n, (numeric) Version of wallet after this operation
"result" : "str", (string, optional) Description of result, if no error
"error" : "str" (string, optional) Error message (if there is one)
}
```
ACKs for top commit:
achow101:
ACK 3eb6f8b
MarcoFalke:
review ACK 3eb6f8b 🛡
Tree-SHA512: b767314069e26b5933b123acfea6aa40708507f504bdb22884da020a4ca1332af38a7072b061e36281533af9f4e236d94d3c129daf6fe5b55241127537038eed
"\nUpgrade the wallet. Upgrades to the latest version if no version number is specified\n"
4468
+
"\nUpgrade the wallet. Upgrades to the latest version if no version number is specified.\n"
4469
4469
"New keys may be generated and a new wallet backup will need to be made.",
4470
4470
{
4471
-
{"version", RPCArg::Type::NUM, /* default */strprintf("%d", FEATURE_LATEST), "The version number to upgrade to. Default is the latest wallet version"}
4471
+
{"version", RPCArg::Type::NUM, /* default */strprintf("%d", FEATURE_LATEST), "The version number to upgrade to. Default is the latest wallet version."}
4472
4472
},
4473
4473
RPCResult{
4474
4474
RPCResult::Type::OBJ, "", "",
4475
4475
{
4476
+
{RPCResult::Type::STR, "wallet_name", "Name of wallet this operation was performed on"},
4477
+
{RPCResult::Type::NUM, "previous_version", "Version of wallet before this operation"},
4478
+
{RPCResult::Type::NUM, "current_version", "Version of wallet after this operation"},
4479
+
{RPCResult::Type::STR, "result", /* optional */true, "Description of result, if no error"},
4476
4480
{RPCResult::Type::STR, "error", /* optional */true, "Error message (if there is one)"}
WalletLogPrintf("Allowing wallet upgrade up to %i\n", version);
4113
4113
}
4114
-
if (version < prev_version)
4115
-
{
4116
-
error = _("Cannot downgrade wallet");
4114
+
if (version < prev_version) {
4115
+
error = strprintf(_("Cannot downgrade wallet from version %i to version %i. Wallet version unchanged."), prev_version, version);
4117
4116
returnfalse;
4118
4117
}
4119
4118
4120
4119
LOCK(cs_wallet);
4121
4120
4122
4121
// Do not upgrade versions to any version between HD_SPLIT and FEATURE_PRE_SPLIT_KEYPOOL unless already supporting HD_SPLIT
4123
4122
if (!CanSupportFeature(FEATURE_HD_SPLIT) && version >= FEATURE_HD_SPLIT && version < FEATURE_PRE_SPLIT_KEYPOOL) {
4124
-
error = _("Cannot upgrade a non HD split wallet without upgrading to support presplit keypool. Please use version 169900 or no version specified.");
4123
+
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);
"result": "Already at latest version. Wallet version unchanged."ifunchangedelse"Wallet upgraded successfully from version {} to version {}.".format(previous_version, new_version),
0 commit comments