Skip to content

Conversation

ryanofsky
Copy link
Contributor

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 1, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

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 DrahtBot added the Wallet label Jun 1, 2023
@kevkevinpal
Copy link
Contributor

Concept ACK

@kevkevinpal
Copy link
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:trace

In 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')

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK f45e066

Tested on OpenBSD 7.3, sqlite 3.41.0. Started bitcoind with debug=walletdb -loglevel=walletdb:trace, ran RPCs createwallet, getnewaddress and setlabel and observed the debug output emiting sqlite statements (SQLite Statement: INSERT or REPLACE into main values(.....).

@achow101
Copy link
Member

achow101 commented Jun 2, 2023

Turning this on will log private keys as they are being written to the db, which seems a little scary.

I found sqlite tracing was useful for debugging a test in bitcoin#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
Copy link
Contributor Author

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_stmt object 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 f45e066 -> ff9d961 (pr/sqtrace.1 -> pr/sqtrace.2, compare) to avoid expanding sensitive sql statements

@achow101
Copy link
Member

achow101 commented Jun 2, 2023

ACK ff9d961

@kevkevinpal
Copy link
Contributor

ACK ff9d961

@DrahtBot DrahtBot requested a review from theStack June 4, 2023 18:24
Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK ff9d961

@fanquake fanquake merged commit f4a8269 into bitcoin:master Jun 5, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 7, 2023
ff9d961 wallet: Add tracing for sqlite statements (Ryan Ofsky)

Pull request description:

  I found sqlite tracing was useful for debugging a test in bitcoin#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.

ACKs for top commit:
  achow101:
    ACK ff9d961
  kevkevinpal:
    ACK bitcoin@ff9d961
  theStack:
    ACK ff9d961

Tree-SHA512: 592fabfab3218cec36c2d00a21cd535fa840daa126ee8440c384952fbb3913180aa3796066c630087e933d6517f19089b867f158e0b737f25283a14799eefb05
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Oct 30, 2024
ff9d961 wallet: Add tracing for sqlite statements (Ryan Ofsky)

Pull request description:

  I found sqlite tracing was useful for debugging a test in bitcoin#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.

ACKs for top commit:
  achow101:
    ACK ff9d961
  kevkevinpal:
    ACK bitcoin@ff9d961
  theStack:
    ACK ff9d961

Tree-SHA512: 592fabfab3218cec36c2d00a21cd535fa840daa126ee8440c384952fbb3913180aa3796066c630087e933d6517f19089b867f158e0b737f25283a14799eefb05
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Oct 30, 2024
@bitcoin bitcoin locked and limited conversation to collaborators Dec 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants