Repository navigation
Conversation
replace the false return after encryption on !Unlock
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste |
|
Is this consistent with PR 28333? |
Thanks for the comment. Both |
This PR you are mentioning added the conditional statement, this PR tends to maintein it, only this time logging instead of returning. It is the simplest way if the function is to return a bool. Changing the function to return an enum class variant is also possible, like enum class EncryptWalletResul {SUCCESS, FAILED, SUCCESS_UNLOCK_FAILED, SUCCESS_REWRITE_FAILED};This is however complicated solution for the simple problem |
|
I know I'm missing most of the thing here, but. If encryption of right-just-created wallets is currently broken, as I think your bitcoin-cli flow implies, isnt this change a lazy workaround fix instead of what would be a thorough elaborate fix? I can't see how this would be equivalent. |
It is not a break in encryption, its just the wrong error reporting. The process is error code: -16
error message:
Error: Failed to encrypt the wallet.which should not be the case because the encryption process has already happened. You can maybe try to reproduce it in regtest so that you see what is currently happening. The PR description shows the steps to reproduce it |
|
I'm not familiar with the wallet code, but I don't really feel like returning enum class is much of an overkill for wallet manipulation if you wanna edit this or as an idea for subsequent PRs if achow or whoever oversees wallet these days doesnt veto. |
|
I don't think this is correct. If a wallet is successfully encrypted, and then we are unable to unlock it, that is a catastrophic failure. It means that the wallet is corrupted, and the funds are probably lost. This should really be an |
Logging may not be right, this I did just to show that there might be an intermediate return value (instead of just a true or false), returning an internal RPC error may be appropriate here instead of telling the user that the encryption failed while it actually passed, just that maybe there an issue in the unlock process. |
> ratedg@0xratedg:~/Desktop/bitcoin/build/bin$ ./bitcoin-cli encryptwallet "testpass"
> error code: -16
> error message:
> Error: Failed to encrypt the wallet.
> ratedg@0xratedg:~/Desktop/bitcoin/build/bin$ ./bitcoin-cli encryptwallet "testpass"
> error code: -15
> error message:
> Error: running with an encrypted wallet, but encryptwallet was called.
> ratedg@0xratedg:~/Desktop/bitcoin/build/bin$
> As can be seen in this demonstration |
|
NACK As I stated previously, I don't think this is the right approach.
If the point of this PR is to serve as a proof of concept, it should be closed, and an issue opened instead. |
|
Closing now |

Summary
The above code
src/wallet/wallet.cpp:890:runs after the wallet encryption process is already complete. Making the failed unlock operation to return false leads to a misleading RPC error message, just in case the encryption happens but the unlock operation fails. Probably it was added there because the function should always return a boolean.Before change
This is the result of a failed unlock, i.e making the function to always return false to mimic the unlock failure
Mutated function
Output
Solution
The failed unlock is inconsequential to the encryption process. It can even just be written as
Instead of returning false, which leads to a misleading error message to the user, probably just logging a message might be necessary
After the change
The nature of the log is the one to be probably determined or the essence of the conditional statement