-
Notifications
You must be signed in to change notification settings - Fork 35.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wallet: upgradewallet fixes, improvements, test coverage #20403
Conversation
Code review ACK b95925c |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
b95925c
to
377fa31
Compare
Removed the cast in UpgradeWallet() per @@ -4128,7 +4128,7 @@ bool CWallet::UpgradeWallet(int& version, bilingual_str& error, std::vector<bili
// Permanently upgrade to the version
const WalletFeature new_version{GetClosestWalletFeature(version)};
SetMinVersion(new_version);
- version = static_cast<int>(new_version); // return actual updated version
+ version = new_version; // return actual updated version |
ACK 377fa31 |
377fa31
to
877aba8
Compare
Rebased after the merge of #20139 and addressed #20403 (comment) with 877aba8. |
877aba8
to
dfec0a8
Compare
dfec0a8
to
25909e6
Compare
Found an edge case bug in the first commit, "wallet: enable CWallet::UpgradeWallet to return updated version", and the fix led to a simpler implementation. Fixed two tests in the third commit, "wallet: fix and improve upgradewallet result responses"; thanks @MarcoFalke for catching one of them. The other one led to seeing the edge case bug. Re-verified build and the Diff: |
# Upgrade the wallet. Should still have the same default key | ||
wallet.upgradewallet(159900) | ||
self.log.info("Upgrade the wallet. Should still have the same default key.") | ||
self.test_upgradewallet(wallet, previous_version=139900, requested_version=159900, expected_version=169900) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@achow101 sanity check, if current version is 139900 FEATURE_HD
, and upgradewallet 159900 FEATURE_NO_DEFAULT_KEY
is called, is the wallet actually upgrading to 169900 FEATURE_PRE_SPLIT_KEYPOOL/FEATURE_LATEST
the expected behavior ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Versions less than FEATURE_HD_SPLIT
cannot upgrade to FEATURE_HD_SPLIT
or FEATURE_NO_DEFAULT_KEY
. They must upgrade to FEATURE_PRE_SPLIT_KEYPOOL
at which time both the previous features will also be applied.
If a user specifies FEATURE_NO_DEFAULT_KEY
on FEATURE_HD
wallet, we should probably give an error and tell the user they can't do that.
Edit: This test is FEATURE_HD_SPLIT
, not FEATURE_HD
. I'm not sure why it jumps to FEATURE_LATEST
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found it. Here's a fix.
diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp
index d2e1be6402..7dbbf17302 100644
--- a/src/wallet/scriptpubkeyman.cpp
+++ b/src/wallet/scriptpubkeyman.cpp
@@ -453,7 +453,7 @@ bool LegacyScriptPubKeyMan::Upgrade(int prev_version, int new_version, bilingual
hd_upgrade = true;
}
// Upgrade to HD chain split if necessary
- if (IsFeatureSupported(new_version, FEATURE_HD_SPLIT)) {
+ if (!IsFeatureSupported(prev_version, FEATURE_HD_SPLIT) && IsFeatureSupported(new_version, FEATURE_HD_SPLIT)) {
WalletLogPrintf("Upgrading wallet to use HD chain split\n");
m_storage.SetMinVersion(FEATURE_PRE_SPLIT_KEYPOOL);
split_upgrade = FEATURE_HD_SPLIT > prev_version;
diff --git a/test/functional/wallet_upgradewallet.py b/test/functional/wallet_upgradewallet.py
index 7cae913fa1..fdd52ba574 100755
--- a/test/functional/wallet_upgradewallet.py
+++ b/test/functional/wallet_upgradewallet.py
@@ -342,7 +342,7 @@ class UpgradeWalletTest(BitcoinTestFramework):
old_kvs = dump_bdb_kv(node_master_wallet)
defaultkey = old_kvs[b'\x0adefaultkey']
self.log.info("Upgrade the wallet. Should still have the same default key.")
- self.test_upgradewallet(wallet, previous_version=139900, requested_version=159900, expected_version=169900)
+ self.test_upgradewallet(wallet, previous_version=139900, requested_version=159900, expected_version=159900)
new_kvs = dump_bdb_kv(node_master_wallet)
up_defaultkey = new_kvs[b'\x0adefaultkey']
assert_equal(defaultkey, up_defaultkey)
This particular change probably needs backport to 0.21, so I'll make a separate PR for it.
25909e6
to
e8e053f
Compare
Dropped the first commit to call |
It is unnecessary to upgrade to FEATURE_HD_SPLIT if this feature is already supported by the wallet. Because upgrading to FEATURE_HD_SPLIT actually requires upgrading to FEATURE_PRE_SPLIT_KEYPOOL, users would accidentally be upgraded to FEATURE_PRE_SPLIT_KEYPOOL instead of nothing being done. Fixes the issue described at bitcoin#20403 (comment)
It is unnecessary to upgrade to FEATURE_HD_SPLIT if this feature is already supported by the wallet. Because upgrading to FEATURE_HD_SPLIT actually requires upgrading to FEATURE_PRE_SPLIT_KEYPOOL, users would accidentally be upgraded to FEATURE_PRE_SPLIT_KEYPOOL instead of nothing being done. Fixes the issue described at bitcoin#20403 (comment)
It is unnecessary to upgrade to FEATURE_HD_SPLIT if this feature is already supported by the wallet. Because upgrading to FEATURE_HD_SPLIT actually requires upgrading to FEATURE_PRE_SPLIT_KEYPOOL, users would accidentally be upgraded to FEATURE_PRE_SPLIT_KEYPOOL instead of nothing being done. Fixes the issue described at bitcoin#20403 (comment)
e8e053f
to
8507c28
Compare
Pulled in #20420. |
8507c28
to
3eb6f8b
Compare
ACK 3eb6f8b |
@@ -4214,7 +4214,7 @@ static RPCHelpMan sethdseed() | |||
|
|||
// Do not do anything to non-HD wallets | |||
if (!pwallet->CanSupportFeature(FEATURE_HD)) { | |||
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot set a HD seed on a non-HD wallet. Use the upgradewallet RPC in order to upgrade a non-HD wallet to HD"); | |||
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot set an HD seed on a non-HD wallet. Use the upgradewallet RPC in order to upgrade a non-HD wallet to HD"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"a" is correct...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review ACK 3eb6f8b 🛡
Show signature and timestamp
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
review ACK 3eb6f8b2e61c24a22ea9396d86672307845f35eb 🛡
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUin9Av/YujicGdR4qxlxmUVaSijOicvW7fTqB6MnQH6+MJnzn5mApTxTVF4ZLZj
nrHGzoEVTcnok6tsDS62eGJvmuP/FxXDZExtb/DrjMdcXqjdP4kpH67tMGAnyrnw
V/M5psoZxs/u0qm4zFa08ni6OBaeSA3U8bZ5Qj6Uk1P9of3VblGEjlw8wa3P/JU0
71s8J3wcyfXY+GS5iQ1DIbz4SgP7Ch7wLPQtgvetEPRblTvhoAgueZeURmgwHai9
ZIf1T9DpMkkBuJiZM+BhygbYF5J3r7vD0hcT/rrp3XNHpLuuMK0/ijaoJk2VXC44
/pnjQNbNXW01NH2PiamTY84rdXJW6qt7NJQtuIeOm2jivvo+Av+DOboOR5KRURUW
m4Ux1i6VaJ1Hov34Sqcnm4zy+WEq2/Lkpl5viwSOqctm7Yak/R38X5wYAx8PmsLP
S8/HSAS4aZob64D/Kkakod5VG1xl9fFw7aUQVioBGQ17hQ3PBYyXnBaIfaOiMXyR
RaovSwTo
=l1/v
-----END PGP SIGNATURE-----
Timestamp of file with hash 1140e347b1496cc50a43fa6fca8080f5ac91dbec5a7d8191668b108f5c1bf70d -
Backported in #20490 |
…est coverage 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: Github-Pull: #20403 Rebased-From: c46c18b Github-Pull: #20403 Rebased-From: 2498b04 Github-Pull: #20403 Rebased-From: 99d56e3 Github-Pull: #20403 Rebased-From: ca8cd89 Top commit has no ACKs. Tree-SHA512: b18a1d015c963298740c585385eaa056988464112c88a519fe619be22dc78a8f6a102365cf799c50b781a77a09bec82b58ce411ab007b48f8b5de876e9c75060
It is unnecessary to upgrade to FEATURE_HD_SPLIT if this feature is already supported by the wallet. Because upgrading to FEATURE_HD_SPLIT actually requires upgrading to FEATURE_PRE_SPLIT_KEYPOOL, users would accidentally be upgraded to FEATURE_PRE_SPLIT_KEYPOOL instead of nothing being done. Fixes the issue described at bitcoin/bitcoin#20403 (comment)
It is unnecessary to upgrade to FEATURE_HD_SPLIT if this feature is already supported by the wallet. Because upgrading to FEATURE_HD_SPLIT actually requires upgrading to FEATURE_PRE_SPLIT_KEYPOOL, users would accidentally be upgraded to FEATURE_PRE_SPLIT_KEYPOOL instead of nothing being done. Fixes the issue described at bitcoin/bitcoin#20403 (comment) (cherry picked from commit 2498b04)
It is unnecessary to upgrade to FEATURE_HD_SPLIT if this feature is already supported by the wallet. Because upgrading to FEATURE_HD_SPLIT actually requires upgrading to FEATURE_PRE_SPLIT_KEYPOOL, users would accidentally be upgraded to FEATURE_PRE_SPLIT_KEYPOOL instead of nothing being done. Fixes the issue described at bitcoin/bitcoin#20403 (comment) (cherry picked from commit 2498b04)
It is unnecessary to upgrade to FEATURE_HD_SPLIT if this feature is already supported by the wallet. Because upgrading to FEATURE_HD_SPLIT actually requires upgrading to FEATURE_PRE_SPLIT_KEYPOOL, users would accidentally be upgraded to FEATURE_PRE_SPLIT_KEYPOOL instead of nothing being done. Fixes the issue described at bitcoin/bitcoin#20403 (comment) (cherry picked from commit 2498b04)
This follows up on #18836 and #20282 to fix and improve the as-yet unreleased
upgradewallet
feature and also implement review follow-up in #18836 (comment).This PR fixes 4 upgradewallet issues:
This PR fixes the above and provides:
...user feedback to not silently return without upgrading
...better feedback after successfully upgrading
...helpful error responses
updated help: