-
Notifications
You must be signed in to change notification settings - Fork 35.6k
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: Set descriptors flag after migrating blank wallets #29367
wallet: Set descriptors flag after migrating blank wallets #29367
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
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.
tested ACK 3904123
confirmed that the test assertion fails without the change to wallet.cpp
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.
Concept ACK
success = local_wallet->IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET); | ||
if (!success) { | ||
success = DoMigration(*local_wallet, context, error, res); | ||
} else { | ||
// Make sure that descriptors flag is actually set | ||
local_wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); |
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.
Given that the PR describes the setting of the flag as a special case for blank wallets, I’d be more comfortable if the setting of the flag were conditional on a wallet being blank instead of success being true here.
- success = local_wallet->IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET);
+ if(local_wallet->IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET)) {
+ local_wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
+ success = true;
+ }
+
if (!success) {
success = DoMigration(*local_wallet, context, error, res);
- } else {
- // Make sure that descriptors flag is actually set
- local_wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
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.
I’d be more comfortable if the setting of the flag were conditional on a wallet being blank instead of success being true
Just to be clear, these two conditions should be exactly equivalent due to the success = local_wallet->IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET);
line so the suggestion is a style change, not a change in behavior. I agree the suggestion looks a little better, but the style of dealing with the success
variable seems here to follow a particular pattern, so would leave it up to achow to decide which way fits better.
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.
I think it should actually unconditionally set the flag, but I haven't fully thought through if that is safe yet. Intuitively, it should be safe since a failed migration would result in the wallet being deleted anyways, but I haven't considered all of the possibilities yet.
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.
@ryanofsky Yeah, I was not proposing a change in behavior. It just seems cleaner to tie the intended behavior directly to the relevant wallet property than to a generic boolean like success
that is instantiated half a code block away and much more likely to change its meaning in the course of the project.
@achow101: I would have expected that DoMigration
sets WALLET_FLAG_DESCRIPTOR
, but it doesn’t seem to be the case. If you wanted to set it generally, perhaps you could just set it after the if (!success) {…}
block here?
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.
DoMigration
does do that, that's why this is only a problem for blank wallets.
As currently implemented, this only sets it for blank wallets, but I do also think the correct behavior is to set it for all wallets, but as I said earlier, I have not analyzed that yet.
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.
re: #29367 (comment)
DoMigration
does do that, that's why this is only a problem for blank wallets.
Seems like in a followup it might be cleaner to do this inside DoMigration, so the flag is set in one place. In the meantime it could help to change the "Make sure that descriptors flag is actually set" comment to "Make sure that descriptors flag is set if DoMigration is not called (otherwise DoMigration will set it)"
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.
Code review ACK 3904123
success = local_wallet->IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET); | ||
if (!success) { | ||
success = DoMigration(*local_wallet, context, error, res); | ||
} else { | ||
// Make sure that descriptors flag is actually set | ||
local_wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); |
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.
I’d be more comfortable if the setting of the flag were conditional on a wallet being blank instead of success being true
Just to be clear, these two conditions should be exactly equivalent due to the success = local_wallet->IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET);
line so the suggestion is a style change, not a change in behavior. I agree the suggestion looks a little better, but the style of dealing with the success
variable seems here to follow a particular pattern, so would leave it up to achow to decide which way fits better.
Tested ACK 3904123. |
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.
code review ACK 3904123
Nit: The code behavior seems correct to me, but I would prefer if either the commit message were adapted to state that the WALLET_FLAG_DESCRIPTOR
is being set for all successfully migrated wallets, or if the code were adapted to more explicitly implement the behavior described in the commit as described in my comment above.
success = local_wallet->IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET); | ||
if (!success) { | ||
success = DoMigration(*local_wallet, context, error, res); | ||
} else { | ||
// Make sure that descriptors flag is actually set | ||
local_wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS); |
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.
@ryanofsky Yeah, I was not proposing a change in behavior. It just seems cleaner to tie the intended behavior directly to the relevant wallet property than to a generic boolean like success
that is instantiated half a code block away and much more likely to change its meaning in the course of the project.
@achow101: I would have expected that DoMigration
sets WALLET_FLAG_DESCRIPTOR
, but it doesn’t seem to be the case. If you wanted to set it generally, perhaps you could just set it after the if (!success) {…}
block here?
I went ahead and merged this in its current form since it is a minimal bugfix for a bug introduced yesterday in #28976. Without #28976, blank wallets would refuse to migrate. But with #28976 and without this fix, blank wallets would appear to successfully migrate but be in an unsupported legacy mode + sqlite backend state, so it seemed better to merge sooner rather than later. It should be possible to followup on comments here and in the previous PR:
in future wallet migration PRs (maybe #28868) |
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.
post-merge ACK 3904123
In the test, would be nice to decouple the migratewallet()
call into another function, to consistently check that all migrated wallet contain this flag.
Github-Pull: bitcoin#29367 Rebased-From: 072d506
Github-Pull: bitcoin#29367 Rebased-From: 3904123
While rebasing #28710 after #28976 was merged, I realized that although blank wallets were being moved to sqlite,
WALLET_FLAG_DESCRIPTORS
was not being set so those blank wallets would still continue to be treated as legacy wallets.To fix that, just set the descriptor flags for blank wallets. Also added a test to catch this.