I found sqlite tracing was useful for debugging a test in #27790, and thought it might be helpful in other contexts too, so this PR adds an option to enable it. Tracing is still disabled by default and only shown with -debug=walletdb -loglevel=walletdb:trace options.
wallet: Add tracing for sqlite statements #27801
pull ryanofsky wants to merge 1 commits into bitcoin:master from ryanofsky:pr/sqtrace changing 1 files +22 −0-
ryanofsky commented at 4:26 PM on June 1, 2023: contributor
-
DrahtBot commented at 4:26 PM on June 1, 2023: contributor
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--021abf342d371248e50ceaed478a90ca-->
Reviews
See the guideline for information on the review process.
Type Reviewers ACK achow101, kevkevinpal, theStack If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
- DrahtBot added the label Wallet on Jun 1, 2023
-
kevkevinpal commented at 9:02 PM on June 1, 2023: contributor
Concept ACK
-
kevkevinpal commented at 9:26 PM on June 1, 2023: contributor
ACK f45e066 I tested by switching to this commit and doing the following
make -j"$(($(nproc)+1))" ./src/bitcoind -regtest -debug=walletdb -loglevel=walletdb:traceIn different window
./src/bitcoin-cli -regtest createwallet "node2"Then you can observe the bitcoind logs example of one
2023-06-01T21:14:59Z [/Users/<my path>/wallet.dat] SQLite Statement: INSERT or REPLACE into main values(x'05666c616773', x'0000000004000000') - theStack approved
-
theStack commented at 11:49 PM on June 1, 2023: contributor
tACK f45e0669dd1f1bdb243e645691e44993905a3919
Tested on OpenBSD 7.3, sqlite 3.41.0. Started bitcoind with
debug=walletdb -loglevel=walletdb:trace, ran RPCscreatewallet,getnewaddressandsetlabeland observed the debug output emiting sqlite statements (SQLite Statement: INSERT or REPLACE into main values(.....). -
achow101 commented at 6:47 PM on June 2, 2023: member
Turning this on will log private keys as they are being written to the db, which seems a little scary.
-
ff9d961bf3
wallet: Add tracing for sqlite statements
I found sqlite tracing was useful for debugging a test in #27790, and thought it might be helpful in other contexts too, so this PR adds an option to enable it. Tracing is still disabled by default and only shown with `-debug=walletdb -loglevel=walletdb:trace` options.
- ryanofsky force-pushed on Jun 2, 2023
-
ryanofsky commented at 9:07 PM on June 2, 2023: contributor
Turning this on will log private keys as they are being written to the db, which seems a little scary.
Yes when the tracing was turned on, having access to the debug log file would be like having access to the database file. The keys would at least be encrypted if the wallet had a password set, but it could still be scary/unexpected behavior.
I looked into ways of trying to mask values in the sql statement, but the
sqlite3_stmtobject is pretty opaque and I couldn't find any function https://www.sqlite.org/c3ref/stmt.html that would allow retrieving bound parameters or temporarily rebinding the statement with masked values before expanding it.So for now I just updated the PR to avoid expanding any update statement that could contain sensitive values. We might be able to do something better in the future like add a more sensitive tracing level, or expand sql statements more intelligently, but the update should be a safe enough compromise that avoids leaking information while still making it easy to see full values by modifying the code.
Updated f45e0669dd1f1bdb243e645691e44993905a3919 -> ff9d961bf38b24f8f931dcf66799cbc468e473df (
pr/sqtrace.1->pr/sqtrace.2, compare) to avoid expanding sensitive sql statements -
achow101 commented at 10:02 PM on June 2, 2023: member
ACK ff9d961bf38b24f8f931dcf66799cbc468e473df
-
kevkevinpal commented at 6:24 PM on June 4, 2023: contributor
- DrahtBot requested review from theStack on Jun 4, 2023
- theStack approved
-
theStack commented at 11:28 PM on June 4, 2023: contributor
ACK ff9d961bf38b24f8f931dcf66799cbc468e473df
- fanquake merged this on Jun 5, 2023
- fanquake closed this on Jun 5, 2023
- sidhujag referenced this in commit a072229683 on Jun 7, 2023
- PastaPastaPasta referenced this in commit 5738ed1063 on Oct 30, 2024
- PastaPastaPasta referenced this in commit 525d9a5492 on Oct 30, 2024
- bitcoin locked this on Dec 5, 2024