Review report

core: PR #30342

Provider refusals

write_verifier: Provider declined the request because of a cybersecurity restriction. Experiments remain incomplete; static verification can continue.

2 major findings · 2 minor findings · 6 suggestions

Findings

Link

[major] · bitcoin node and bitcoin gui can abort while probing configuration

Without explicit -m or -M, valid configuration or argument inputs that log make the wrapper assert before launching the selected executable because it never constructs an application logger.

Location: src/logging.cpp:53 (head).

Details and suggested fix

UseMultiprocess() parses subcommand arguments and reads configuration files before executing the node or GUI. A successfully read includeconf file emits LogInfo, and a supported double negative such as -nolisten=0 emits LogWarning. These context-free calls reach LogInstance(), but bitcoin.cpp never creates a BCLog::Logger, so the new Assert(BCLog::g_logger) aborts. The base lazily created a logger and buffered these messages. Construct a BCLog::Logger at the start of the wrapper's main; leaving it buffering is sufficient. Add a wrapper test using a valid included configuration file.


Link

[major] · Manager teardown can read a freed discard logger

Releasing the context and manager-options handles before a manager with no logging connection can free its discard logger while block-tree LevelDB background work still uses it.

Location: src/kernel/bitcoinkernel.cpp:466 (head).

Details and suggested fix

A context without a logging connection passes its embedded m_discard_logger into the manager and its databases. If the caller releases the context and chainstate-manager-options handles first, ChainMan holds the last context reference. Its implicit destructor destroys m_context before m_chainman, freeing the logger too early. btck_chainstate_manager_destroy resets coins views, but leaves BlockTreeDB for subsequent member destruction. An already-running LevelDB WriteLevel0Table can log after its unlocked table build while database destruction waits for background work. CBitcoinLevelDBLogger::Logv then reaches LogConnection::ShouldLog and reads m_fn from the freed context, even though this logger discards output. The base used a process-lifetime kernel logger. No current in-tree caller was found that releases both handles before the manager, so production occurrence is unconfirmed. Declare m_context before m_chainman, adjusting the constructor accordingly, so the context survives complete manager destruction. Add teardown coverage that releases these handles first.


Link

[minor] · Fixture loggers remain unconfigured when a harness logger already exists

Fuzz, benchmark and Qt-test harnesses configure the outer LogInstance but pass the fixture's separate, buffering m_logger to kernel objects, losing configured diagnostics and adding buffer maintenance.

Location: src/test/util/setup_common.h:60 (head).

Details and suggested fix

BCLog::Logger registers itself only when no application logger exists. The fuzz runner, benchmark main and Qt-test main create one before their fixtures, so BasicTestingSetup::m_logger is not the backend configured by InitLogging, AppInitParameterInteraction and LogInstance().StartLogging(). Converted kernel objects receive the unconfigured member instead. Its default buffering state retains Info-and-higher messages without delivering them, while requested Debug categories remain disabled. For example, script_sigcache adds a signature-cache message on every input despite using MakeNoLogFileContext. Retention is bounded; relative to base, the added hot-loop work is buffering and eviction, not Info-message formatting. Pass LogInstance() to the converted kernel constructors so they use the backend the fixture configures, and cover fixture construction while an outer logger exists.


Link

[minor] · -loglevelalways no longer labels Info messages

With -loglevelalways, the new severity guard removes Info prefixes and the category from Warning/Error prefixes, contrary to the option's documented behavior.

Location: src/logging.cpp:372 (head).

Details and suggested fix

Previously, m_always_print_category_level forced a prefix even for category ALL, producing [all:info] and [all:warning]. The new level <= Level::Debug condition makes has_category false at higher levels regardless of that setting. Info then returns an empty prefix, while Warning and Error retain only their severity. Default output is unchanged. If hiding high-level categories is intentional, retain the explicitly requested level tag, such as [info], and make the help describe the category restriction. Add option-enabled formatting coverage for Debug, Info, Warning and Error.


Optional improvements

Link

[suggestion] · Timer and validation-event diagnostics bypass kernel log routing

Category-only timers and ValidationSignals log without a logger, so kernel connections lose their timing and event diagnostics even when their minimum level enables Debug.

Location: src/validation.cpp:2793 (head).

Details and suggested fix

FlushStateToDisk and CCoinsViewDB::BatchWrite still construct category-only LOG_TIME_* timers. Timer::Log emits context-free messages from its header, outside the callers' later LOG_REQUIRE_CONTEXT definitions, and the kernel hook rejects their null logger. ValidationSignals::LOG_MSG and LOG_EVENT likewise omit a context; kernel contexts with validation callbacks instantiate this class, so its event diagnostics disappear too. Give timers and validation signals an optional log context and pass the owning logger at kernel call sites, using BENCH for the timers. Preserve the existing null-context defaults for executable callers. If conversion is deferred, document these additional dropped sources.


Link

[suggestion] · Disabled Debug/Trace checks now acquire the logger mutex

Checking Enabled first removes the lock-free rejection path for disabled categories from ordinary logging checks.

Location: src/logging.cpp:638 (head).

Details and suggested fix

hooks::ShouldLog calls Enabled() before WillLogCategoryLevel(), so every check takes m_cs even when its Debug/Trace category is disabled. Previously these checks reached the atomic category-mask rejection directly. Return logger.WillLogCategoryLevel(static_cast<BCLog::LogFlags>(category), level) && logger.Enabled() instead. Disabled categories then short-circuit without locking, while accepted categories and Info-or-higher entries still check output enablement. The throughput impact has not been measured.


Link

[suggestion] · Kernel logging tests miss nested routing and independent thresholds

The isolation test exercises only a direct C API Error message, so broken logger propagation into kernel objects or shared minimum-level state would escape its assertions.

Location: src/test/kernel/test_kernel.cpp:747 (head).

Details and suggested fix

LogContextError rejects empty directories before any manager or database exists, and every connection keeps its default Info threshold. Keep those assertions, but also create managers for two separately logged contexts in distinct temporary directories. Check a path-identifiable nested message, such as Opening LevelDB in <path>, reaches only its owning connection, with no delivery from a no-logger context or to an unused connection. Then trigger the missing-hash Debug message on both managers at Info and after lowering only one connection to Debug. Assert suppression and delivery independently to cover the new per-connection setter.


Link

[suggestion] · The new max_file_size minimum is overwritten before use

GetOptions appears to enforce a minimum file size, but its only caller replaces that value before LevelDB sees it.

Location: src/dbwrapper.cpp:157 (head).

Details and suggested fix

GetOptions() now assigns std::max(options.max_file_size, DBWRAPPER_MAX_FILE_SIZE). After it returns, CDBWrapper unconditionally assigns params.max_file_size before DB::Open; the intervening helper only configures max_open_files. Remove the new assignment. It has no runtime effect and misleadingly suggests that this logging refactor changes LevelDB file-size selection.


Link

[suggestion] · Context options bypass the logging-connection lifetime guard

Violating the documented options lifetime requirement can pass the new connection-destruction assertion and leave a dangling logger pointer.

Location: src/kernel/bitcoinkernel.cpp:1028 (head).

Details and suggested fix

btck_context_options_set_logger stores a raw connection pointer without incrementing m_uses. If only the options still reference the connection, destroying it passes assert(m_uses == 0), and the next btck_context_create(options) accesses freed memory in AddUse(1). This is documented caller misuse, but the PR already detects the equivalent mistake with live contexts. Count option references too: increment when setting a logger, decrement any replaced logger, and release the reference in ~ContextOptions. That makes both lifetime violations abort at connection destruction.


Link

[suggestion] · Valgrind suppression still targets the removed LogInstance allocation

The retained suppression cannot match the logger allocation after this PR moves it out of LogInstance.

Location: src/logging.cpp:55 (head).

Details and suggested fix

The rule in valgrind.supp matches _Znwm called directly from _Z11LogInstancev. LogInstance() now only asserts and returns the application logger, so that allocation stack no longer exists. Delete this rule, as with the removed GetKernelLogger suppression. Check whether the intentional allocations in main and GuiMain need suppressions for their new call stacks.


Coverage details