-
Notifications
You must be signed in to change notification settings - Fork 37.7k
wallet: Allow read-only database access for info and dump commands #32685
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
base: master
Are you sure you want to change the base?
wallet: Allow read-only database access for info and dump commands #32685
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32685. 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. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
cd8109d
to
f6f1f41
Compare
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
Review request: @achow101 @furszy @ryanofsky @Sjors |
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.
Could we also guard higher-level wallet operations (e.g., in LoadWallet, TopUpKeyPool, UpgradeWallet, etc.) against unintended writes in read-only mode?.
This helps future-proof against accidental changes, even if developers mistakenly invoke write operations upstream.
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
Good idea. I would check it and work on it. But I just think they are well guarded because this PR is working for Database level read-only mode... |
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.
We require that all commits compile and pass the tests by themselves, but it looks like the commits in this PR do not. Please revise your commits so that they pass all of the tests individually.
Okay, but it seems without permission, I cannot run some CIs and tests on GitHub. I have passed 11 CIs on GitHub, and all tests on my machine. How should I confirm whether they are all passed on Git Action or not? |
Approved, they should be run automatically now. |
719afbe
to
e4e94df
Compare
Seems that I still could not run all ci tests without approval. Can you fix it? |
e4e94df
to
4dc9a17
Compare
@achow101 I modified the code as your review comments, and I hope you can recheck them. It seems i could still not run all ci tests without your approval, is it because of mechanism? or other reason which we did not realize... |
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
7d5e234
to
8e83621
Compare
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.
Run all tests.
Please squash your commits; reviewer feedback does not need to be addressed in a separate commit. The current commit layout is difficult to review as code is introduced in one commit, only to be removed/rewritten in the next commit. When I said that all commits need to pass the tests, I did not mean that everything should be squashed into one commit. While that can be okay to do, it's better to have individual commits that introduce specific things, as long as those commits still pass the tests. My suggestion was more that the commits could be reordered, and some of them squashed, in order to allow all of the tests to pass. I highly advise that you compile and run the tests yourself instead of relying on CI. CI on PRs submitted by new contributors requires manual approval to run. Please stop asking for it to be run, it will be run when a maintainer notices that it was not run. You can compile and run everything locally which will cover most things that CI fails on. |
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
d6f3f85
to
0fc315f
Compare
You'll have to rebase. Did you see the immediately previous comment? Also, ref #32818 |
Re: Merge branch 'master' into wallet-readonly-access I don't think merging master in the PR branch is preferred, instead rebasing is done. |
fa0699e
to
dac8bfb
Compare
dac8bfb
to
6efd78c
Compare
Fixes bitcoin#29559 1. Add read-only database access for bitcoin-wallet info and dump commands 2. Implement read-only mode in database layer with SQLite handling 3. Prevent write operations when wallet files are write-protected 4. Enable safe inspection of wallet files without risk of modification
- Add ReadName() and ReadPurpose() methods to WalletBatch class - Replace MockableDatabase direct tests with WalletBatch-based tests - Deduplicate tool_wallet.py test methods using lambda functions
6efd78c
to
ec679bc
Compare
I have rebased but it seems one ci failed because of timeout issue. To confirm this issue did't fail accidentally, I request to rerun it. |
I have rebased and read comment. I consider my implementation is better... |
Problem
Fixes #29559
The
bitcoin-wallet info
andbitcoin-wallet dump
commands currently fail when wallet files are write-protected, throwing "Database opened in readonly mode but read-write permissions are needed" errors. This prevents users from safely inspecting write-protected wallet files, which is important for:Solution
This PR adds comprehensive read-only database support to enable
bitcoin-wallet info
anddump
commands to work with write-protected wallet files.Key Changes
Database Layer (
src/wallet/db.h
,src/wallet/sqlite.h
,src/wallet/sqlite.cpp
)read_only
boolean option toDatabaseOptions
structureIsReadOnly()
virtual method toWalletDatabase
interfaceSQLiteDatabase
to properly handle read-only mode:SQLITE_OPEN_READONLY
flag whenread_only=true
Wallet Tool (
src/wallet/wallettool.cpp
)bitcoin-wallet info
command to useoptions.read_only = true
bitcoin-wallet dump
command to useoptions.read_only = true
Wallet Loading (
src/wallet/walletdb.cpp
)LoadWallet()
to detect read-only mode viadatabase.IsReadOnly()
Legacy Support (
src/wallet/migrate.h
)IsReadOnly()
method toBerkeleyRODatabase
for consistencyTesting
The implementation has been thoroughly tested:
Manual Testing
chmod 444
)bitcoin-wallet info
works with read-only filesbitcoin-wallet dump
works with read-only filesUnit Tests
All existing wallet tests continue to pass, confirming no regression in normal wallet operations.
Safety Verification
Security Considerations
This change improves security by:
The implementation is conservative and safe:
info
anddump
commands)Backwards Compatibility
Full backwards compatibility is maintained:
Related Work
This builds upon existing read-only database patterns in Bitcoin Core, particularly the
BerkeleyRODatabase
class used for wallet migration scenarios.#28116