Skip to content

Conversation

ryanofsky
Copy link
Contributor

@ryanofsky ryanofsky commented Jun 26, 2024

Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() compatible with wallet code and drop custom WalletLogPrintf() function. The new logging macros introduced in #28318 weren't previously useful in wallet code because wallet code prefixes most log messages with the wallet names to be be able to distinguish log output from multiple wallets. Fix this by introducing a new WalletLogSource class inheriting from BCLog::Source which can include the wallet name in log messages.


This is based on #29256. The non-base commits are:

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 26, 2024

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/30343.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #32149 (wallet, migration: Fix empty wallet crash by pablomartin4btc)
  • #32023 (wallet: removed duplicate call to GetDescriptorScriptPubKeyMan by saikiran57)
  • #31423 (wallet: migration, don't create spendable wallet from a watch-only legacy wallet by furszy)
  • #31398 (wallet: refactor: various master key encryption cleanups by theStack)
  • #31296 (wallet: Translate [default wallet] string in progress messages by ryanofsky)
  • #30221 (wallet: Ensure best block matches wallet scan state by achow101)
  • #29641 (scripted-diff: Use LogInfo over LogPrintf [WIP, NOMERGE, DRAFT] by maflcko)
  • #29415 (Broadcast own transactions only via short-lived Tor or I2P connections by vasild)
  • #29136 (wallet: addhdkey RPC to add just keys to wallets via new void(KEY) descriptor by achow101)
  • #28333 (wallet: Construct ScriptPubKeyMans with all data rather than loaded progressively by achow101)

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.

Copy link
Contributor

@hodlinator hodlinator left a comment

Choose a reason for hiding this comment

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

Went through this and the parent PR together. It was helpful to see how that other PR's changes were used in this one.

@@ -3866,13 +3868,13 @@ ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const Flat
AssertLockHeld(cs_wallet);

if (!IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
WalletLogPrintf("Cannot add WalletDescriptor to a non-descriptor wallet\n");
LogInfo(m_log, "Cannot add WalletDescriptor to a non-descriptor wallet\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should maybe have been a warning all along?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #30343 (comment)

Should maybe have been a warning all along?

Good catch. It actually looks to me like all of the log prints in this function should be errors. I changed them to use LogError in a new commit. It's a separate commit because the level change is a minor change in behavior, and is less obvious than other level changes.

Copy link
Member

Choose a reason for hiding this comment

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

Are you sure that LogError is the right level? It should only be used for fatal errors where the node needs to shut down, according to the docs. This seems like a warning here, as suggested above.

Some wallet code can probably use Result and pass errors up, possibly here as well. And the caller can decide whether to log as a warning or return over RPC (or something else).

Copy link
Contributor Author

@ryanofsky ryanofsky Jun 27, 2024

Choose a reason for hiding this comment

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

Are you sure that LogError is the right level? It should only be used for fatal errors where the node needs to shut down, according to the docs. This seems like a warning here, as suggested above.

Oh, that is interesting. The descriptions of those log levels in https://github.com/bitcoin/bitcoin/blob/b27afb7fb774809c9c075d56e44657e0b607a00c/doc/developer-notes.md#logging are much more severe than I would have expected. Based on those descriptions I would expect LogError to be called LogFatal and LogWarning to be called LogCritical. I would have expected LogError to be used for normal errors, and LogWarning to be used for normal warnings.

Maybe the naming would be worth following up on, but I don't think it would be good to do in this PR. It actually seems like LogInfo is the right log level to use here, not LogWarning. Or do you disagree? Should I just drop the last two commits in this PR?

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jun 27, 2024
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors.

Suggested by hodlinator in
bitcoin#30343 (comment)
bitcoin#30343 (comment)
bitcoin#30343 (comment)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jun 27, 2024
Seems like all of these cases are treated as errors, so it makes sense to use
the corresponding log level.

Change suggested by hodlinator in bitcoin#30343 (comment)
Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Thanks for the review! The suggestions are a big improvement and make the logging code more succinct and clean.

Rebased 5b30f17 -> 5a629a6 (pr/gwlog.1 -> pr/gwlog.2, compare) on top of the updated parent PR implementing review suggestions.

@@ -3866,13 +3868,13 @@ ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const Flat
AssertLockHeld(cs_wallet);

if (!IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
WalletLogPrintf("Cannot add WalletDescriptor to a non-descriptor wallet\n");
LogInfo(m_log, "Cannot add WalletDescriptor to a non-descriptor wallet\n");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #30343 (comment)

Should maybe have been a warning all along?

Good catch. It actually looks to me like all of the log prints in this function should be errors. I changed them to use LogError in a new commit. It's a separate commit because the level change is a minor change in behavior, and is less obvious than other level changes.

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jun 27, 2024
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors.

Suggested by hodlinator in
bitcoin#30343 (comment)
bitcoin#30343 (comment)
bitcoin#30343 (comment)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jun 27, 2024
Seems like all of these cases are treated as errors, so it makes sense to use
the corresponding log level.

Change suggested by hodlinator in bitcoin#30343 (comment)
@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.

Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.

Leave a comment here, if you need help tracking down a confusing failure.

Debug: https://github.com/bitcoin/bitcoin/runs/26740126920

@ryanofsky
Copy link
Contributor Author

Updated 5a629a6 -> db8c6fc (pr/gwlog.2 -> pr/gwlog.3, compare) fixing initialization order bug in last push

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jun 28, 2024
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors.

Suggested by hodlinator in
bitcoin#30343 (comment)
bitcoin#30343 (comment)
bitcoin#30343 (comment)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jun 28, 2024
Seems like all of these cases are treated as errors, so it makes sense to use
the corresponding log level.

Change suggested by hodlinator in bitcoin#30343 (comment)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jun 28, 2024
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors.

Suggested by hodlinator in
bitcoin#30343 (comment)
bitcoin#30343 (comment)
bitcoin#30343 (comment)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jun 28, 2024
Seems like all of these cases are treated as errors, so it makes sense to use
the corresponding log level.

Change suggested by hodlinator in bitcoin#30343 (comment)
@ryanofsky
Copy link
Contributor Author

ryanofsky commented Jun 28, 2024

Updated and rebased db8c6fc -> 29eaec2 (pr/gwlog.3 -> pr/gwlog.4, compare) with suggestion to use constexpr
Rebased 29eaec2 -> 0260cd5 (pr/gwlog.4 -> pr/gwlog.5, compare) due to conflict with #30406
Rebased 0260cd5 -> 0d49ada (pr/gwlog.5 -> pr/gwlog.6, compare) on top of updated base pr/bclog.20
Rebased 0d49ada -> f6b93a9 (pr/gwlog.6 -> pr/gwlog.7, compare) due to conflict with #30485
Rebased f6b93a9 -> 4c8fe04 (pr/gwlog.7 -> pr/gwlog.8, compare) due to conflicts with #26619, #30659, and other PRs
Rebased 4c8fe04 -> e8c6095 (pr/gwlog.8 -> pr/gwlog.9, compare) due to conflicts with #31061

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Mar 12, 2025
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors.

Suggested by hodlinator in
bitcoin#30343 (comment)
bitcoin#30343 (comment)
bitcoin#30343 (comment)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Mar 12, 2025
Seems like all of these cases are treated as errors, so it makes sense to use
the corresponding log level.

Change suggested by hodlinator in bitcoin#30343 (comment)
ryanofsky and others added 8 commits April 3, 2025 05:54
Test will be extended in next commit to cover support for context objects.
Allow LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() macros to
accept context arguments to provide more information in log messages and more
control over logging to callers.

This functionality is used in followup PRs:

- bitcoin#30342 - To let libbitcoinkernel send
  output to specfic `BCLog::Logger` instances instead of a global instance, so
  output can be disambiguated and applications can have more control over
  logging.

- bitcoin#30343 - To replace custom
  `WalletLogPrintf` calls with standard logging calls that automatically include
  wallet names and don't log everything at info level.

This commit does not change behavior of current log prints or require them to
be updated. It includes tests and documentation covering the new functionality.

Co-Authored-By: Hodlinator <172445034+hodlinator@users.noreply.github.com>
Disallow passing BCLog category constants to LogInfo(), LogWarning(), and
LogError() macros, and disallow omitting BCLog categories when calling
LogDebug() and LogTrace() macros.

These restrictions have existed since the logging macros were added in bitcoin#28318
and not technically neccessary, but are believed to be useful to prevent log
spam and prevent users from filtering out important messages based on category.

Co-Authored-By: Hodlinator <172445034+hodlinator@users.noreply.github.com>
Make new logging macros LogDebug(), LogTrace(), LogInfo(), LogWarning(), and
LogError() compatible with wallet code and drop custom WalletLogPrintf()
function. The new logging macros introduced in bitcoin#28318 weren't previously useful
in wallet code because wallet code prefixes most log messages with the wallet
names to be be able to distinguish log output from multiple wallets. Fix this
by introducing a new WalletLogContext class inheriting from BCLog::Context
which can include the wallet name in log messages
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors.

Suggested by hodlinator in
bitcoin#30343 (comment)
bitcoin#30343 (comment)
bitcoin#30343 (comment)
Seems like all of these cases are treated as errors, so it makes sense to use
the corresponding log level.

Change suggested by hodlinator in bitcoin#30343 (comment)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Apr 3, 2025
Allow LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() macros to
accept context arguments to provide more information in log messages and more
control over logging to callers.

This functionality is used in followup PRs:

- bitcoin#30342 - To let libbitcoinkernel send
  output to specfic `BCLog::Logger` instances instead of a global instance, so
  output can be disambiguated and applications can have more control over
  logging.

- bitcoin#30343 - To replace custom
  `WalletLogPrintf` calls with standard logging calls that automatically include
  wallet names and don't log everything at info level.

This commit does not change behavior of current log prints or require them to
be updated. It includes tests and documentation covering the new functionality.
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Apr 3, 2025
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors.

Suggested by hodlinator in
bitcoin#30343 (comment)
bitcoin#30343 (comment)
bitcoin#30343 (comment)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Apr 3, 2025
Seems like all of these cases are treated as errors, so it makes sense to use
the corresponding log level.

Change suggested by hodlinator in bitcoin#30343 (comment)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Apr 3, 2025
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors.

Suggested by hodlinator in
bitcoin#30343 (comment)
bitcoin#30343 (comment)
bitcoin#30343 (comment)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Apr 3, 2025
Seems like all of these cases are treated as errors, so it makes sense to use
the corresponding log level.

Change suggested by hodlinator in bitcoin#30343 (comment)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Apr 3, 2025
Allow LogDebug(), LogTrace(), LogInfo(), LogWarning(), and LogError() macros to
accept context arguments to provide more information in log messages and more
control over logging to callers.

This functionality is used in followup PRs:

- bitcoin#30342 - To let libbitcoinkernel send
  output to specfic `BCLog::Logger` instances instead of a global instance, so
  output can be disambiguated and applications can have more control over
  logging.

- bitcoin#30343 - To replace custom
  `WalletLogPrintf` calls with standard logging calls that automatically include
  wallet names and don't log everything at info level.

This commit does not change behavior of current log prints or require them to
be updated. It includes tests and documentation covering the new functionality.
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Apr 4, 2025
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors.

Suggested by hodlinator in
bitcoin#30343 (comment)
bitcoin#30343 (comment)
bitcoin#30343 (comment)
ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Apr 4, 2025
Seems like all of these cases are treated as errors, so it makes sense to use
the corresponding log level.

Change suggested by hodlinator in bitcoin#30343 (comment)
@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 4, 2025

🚧 At least one of the CI tasks failed.
Debug: https://github.com/bitcoin/bitcoin/runs/39937553048

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@DrahtBot DrahtBot removed the CI failed label Apr 4, 2025
@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 8, 2025

⌛ There hasn't been much activity lately and the patch still needs rebase. What is the status here?

  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

1 similar comment
@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 8, 2025

⌛ There hasn't been much activity lately and the patch still needs rebase. What is the status here?

  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants