mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 11:50:39 +00:00
wallet, rpc: log instead of returning false #35966
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35966
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-misleading-wallet-encryption-error"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Is this consistent with PR 28333?
Can
GetDatabase().Rewrite();get called in a dangeruz way?Thanks for the comment. Both
GetDatabase().Rewrite();and!Unlock(strWalletPassphrase)are called after the encryption is already successful. This PR does not look at the database rewrite in any way because its result does not also change anything. Whether the rewrite is a success or not, the encryption has already happened. Same as whether the unlock is successful or not. That's why returning false raises the wrong error message as I have demonstrated above.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
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
Encryption -> Unlock Wallet -> Rewrite Database. Now returning false in the place of unlock is what results inwhich 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
Assertor some failure mode which results in the wallet no longer being loaded and in use. Logging a warning is not the right thing to do. Returningfalseis reasonable, but not actually far enough in preventing usage of the wallet as we really should be if this were to occur.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.
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
Base:
65896ac58ea63e29ad19d41b492e37f8722ac715Head:
d682e5fddfea4a88e12d47a38769db99d44b65fb🟡 Minor
Failed unlock throws during wallet setup (src/wallet/wallet.cpp:891, head)
If
Unlockreturns false,EncryptWalletremains locked: it calledLock()immediately beforehand, andUnlocksets the master key only on success. For a nonblank, private-key-enabled wallet,SetupWalletGeneration()then reachesSetupDescriptorScriptPubKeyMan(), which throws when the wallet is locked. This branch therefore does not complete encryption setup or reach the successful return; it replaces the formerfalsereturn with an exception. Handle the failure explicitly and report that encryption committed but follow-up setup did not complete, rather than logging and falling through. No current caller or ordinary input producing this false result in the fresh-encryption flow was identified, so production impact is unconfirmed.Review coverage was incomplete. The archaeology review had incomplete evidence. The adversarial review had incomplete evidence. The adversarial_glm review did not complete. Verification was partial.
Full review report