4 minor findings · 3 suggestions
Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.
Findings
[minor] · Enabling walletdb tracing with the new RPC argument does not trace wallets that are already open
The RPC reports walletdb as traced, but wallets that were already loaded produce no SQL trace output until they are reloaded.
Location: src/rpc/node.cpp:282 (head).
Details and suggested fix
SQLiteDatabase::Open installs TraceSqlCallback with sqlite3_trace_v2 only when it opens the connection, and only if ShouldTraceLog(WALLETDB) is already true. The new trace argument of the logging RPC only updates the category masks. So a node started without -trace=walletdb that later calls logging with trace=["walletdb"] lists walletdb under trace, but SQL statements on wallets that are already loaded produce no trace output until the wallet is unloaded and reloaded.
The open-time-only registration predates this PR: at base, -loglevel=walletdb:trace followed by logging ["walletdb"] behaved the same way. But the release note now pairs runtime trace switching through this argument with wallet SQL as the only trace output, which makes this the advertised path.
One fix: always install the callback, and have TraceSqlCallback return early when ShouldTraceLog(BCLog::WALLETDB) is false, before it calls sqlite3_expanded_sql.
[minor] · MakeNoLogFileContext leaves debug and trace logging on for all categories
Fuzz targets and benchmarks built on it now format and discard every debug/trace message and run debug-only bookkeeping that base skipped.
Location: src/test/util/setup_common.cpp:167 (head).
Details and suggested fix
BasicTestingSetup now passes -trace instead of -loglevel=trace -debug. MakeNoLogFileContext still adds only -nodebuglogfile and -nodebug. Under the new semantics, -nodebug clears only -debug values. GetArgs("-trace") still returns [""], which GetLogCategory maps to ALL, so SetLoggingCategories puts every category except leveldb at trace (and therefore also debug). At base, -nodebug left the category mask empty, so nothing was debug-logged in these contexts.
Callers such as the partially_downloaded_block fuzz target and the wallet benchmarks now:
- run the
debug_logbookkeeping inPartiallyDownloadedBlock::InitData - install the SQLite trace callback for every database
- format messages that
util::log::Logthen drops because no output is enabled
This changes what benchmarks measure and lowers fuzz throughput. bench/logging.cpp already adds -trace=0 next to -debug=0 for the same reason.
Fix: add -notrace next to -nodebug in MakeNoLogFileContext, ahead of the caller's extra_args, so callers can still opt back in.
[minor] · Kernel log masks can be left stale when SetMinLevel races with connection create/destroy
A libbitcoinkernel client calling these from different threads can lose Debug/Trace entries for an active subscriber until the next configuration change.
Location: src/kernel/bitcoinkernel.cpp:548 (head).
Details and suggested fix
The inline ShouldDebugLog/ShouldTraceLog checks now read cached masks. KernelLogger::UpdateLoggerMasks derives them from m_callback_count and m_min_level. RegisterCallback and UnregisterCallback recompute the masks while holding m_mutex, but SetMinLevel stores the level and recomputes without the lock.
Example:
- Thread A calls
btck_logging_set_min_level(Debug), reads a callback count of 0 and computesNONE. - Thread B registers the first callback and publishes
debug=ALL. - Thread A then stores
NONE.
The end state is one callback with minimum level Debug but an empty debug mask. LogDebug/LogTrace call sites then skip their entries before MaybeLog ever checks the level. Two concurrent SetMinLevel calls can leave a similar mismatch. The reverse interleaving can leave the masks at ALL with no subscribers, which only wastes formatting. At base these checks called ShouldLog() on the live atomics, so the state could not go stale.
No in-tree caller making these calls concurrently was identified, and bitcoinkernel.h does not say whether they must be serialized, so production impact is unconfirmed.
Fix: take m_mutex in SetMinLevel around both the store and the UpdateLoggerMasks() call, and annotate UpdateLoggerMasks with EXCLUSIVE_LOCKS_REQUIRED(m_mutex).
[minor] · Concurrent logging RPC updates can leave a category traced but not debug-logged
Overlapping updates to the same category can leave it reported as trace while its debug messages are dropped, until it is reconfigured.
Location: src/logging.cpp:565 (head).
Details and suggested fix
SetCategoryLogLevel updates m_debug_categories and m_trace_categories with two separate atomic operations, and the logging RPC calls it without any writer lock. RPC handlers run on the HTTP worker pool, which has 16 threads by default.
This interleaving leaves the category with only the trace bit set, a state no serial order produces:
- A Trace update runs
m_debug_categories |= flag. - An Info (
exclude) update for the same category clears both bits. - The Trace update runs
m_trace_categories |= flag.
LogCategoriesInfo checks the trace bit first, so the RPC reports the category as trace, but ShouldDebugLog returns false. Debug messages are dropped, and so are trace messages nested inside ShouldDebugLog guards, such as the GETBLOCKTXN trace in net_processing.cpp. At base, enabling or disabling a category was a single atomic mask operation, and per-category levels were changed under m_cs.
No in-tree workflow that issues overlapping, conflicting logging calls was identified, so production impact is unconfirmed.
Fix: serialize the writers in SetCategoryLogLevel (and ResetLogLevels) with a small static mutex. The inline readers can stay lock-free.
Optional improvements
[suggestion] · logging include/debug now removes trace logging from categories that were at trace
Callers that list an already-traced category to enable debug logging silently lose its trace output, and neither the help text nor the release note says so.
Location: src/rpc/node.cpp:279 (head).
Details and suggested fix
The handler maps params[0] to SetCategoryLogLevel(cat, Debug), which sets the debug bit and clears the trace bit. At base, include only ran EnableCategory (m_categories |= flag), so a category configured for trace through -loglevel stayed at trace.
Now, on a node started with -trace=net, logging ["net"] or logging ["all"] drops trace output for those categories. This also hits callers using -deprecatedrpc=logging, whose output still shows the category as enabled. rpc_misc.py asserts this downgrade, so it looks intentional. But the argument help still says "The categories to add to debug logging", and the release note only mentions the output format change.
Two options:
- Keep
debug|includeadditive (set only the debug bit), and downgrade withexcludefollowed bydebug. - Keep the current behavior, and state in the help text and release note that listing a traced category here lowers it to debug.
[suggestion] · Release note says wallet SQL is the only supported trace logging
cmpctblock and ipc also emit trace logs, so the note understates what -trace turns on.
Location: doc/release-notes-34038.md:4 (head).
Details and suggested fix
The note says the only trace logs currently supported are wallet SQL statement logs. The tree also has LogTrace calls for compact-block reconstruction and GETBLOCKTXN requests (blockencodings.cpp, net_processing.cpp). ipc/capnp/protocol.cpp also selects libmultiprocess trace logging when ShouldTraceLog(BCLog::IPC) is true. Users who enable -trace or -trace=1 will see these as well. Describe -trace=walletdb as an example, or list the walletdb, cmpctblock and ipc categories.
[suggestion] · -trace help does not explain how it interacts with -debug and -nodebug
Users can't tell from the help that -trace also enables debug output or that -nodebug leaves it on, which is the same assumption MakeNoLogFileContext got wrong.
Location: src/init/common.cpp:33 (head).
Details and suggested fix
The new help says -trace will "Output trace logging" and that with 0 or none "any other categories are ignored". What SetLoggingCategories actually does:
- A Trace level sets both the debug and trace masks.
0/nonediscards only the-tracevalues that come before it.-debugand-traceare processed independently, so-nodebugor-debug=0do not cancel categories enabled by-trace, and-trace=alltakes precedence over any-debug=<cat>.
The commit message explains this, but users only see the help text. The MakeNoLogFileContext issue is an in-tree example of the same misunderstanding.
Suggested fix: state in the help that -trace enables both debug and trace output, that 0/none and -notrace cancel only earlier -trace values, and that -nodebug does not affect categories enabled by -trace.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [suggestion]: Remove the unused log-level formatting helpers