#30342 kernel, logging: Deliver each context's log output to its own logging connection

ReviewabilityReviewsAgreementSize
#30342 ryanofsky kernel, logging: Deliver each context's log output to its own logging connectionReview #29256 first0 -1Mild832 + 437 tests
  • Prevent interleaved log streams when running multiple chainstate contexts or kernel library instances
  • Allow kernel consumers and multi-context tests to cleanly separate log output by context
  • Concept approval without stated reasons (sedited)
  • Thinks review cost and merge conflicts outweigh current user demand, favoring simpler logging (stickies-v)
  • Earlier objection about cumbersome logger plumbing was resolved with per-file enforcement (stickies-v)
  • 832 lines added or modified outside tests
  • 437 lines added or modified in tests
  • 744 lines removed in total
  • 79 files, 18 commits
Kernel (libbitcoinkernel)#7 of 18
P2 · cleanup
  • P2 because it eliminates process-wide global logging state from the kernel library
  • Enables clean concurrent execution of multiple independent chainstate contexts in one process
  • Provides architectural leverage for making the kernel usable as an isolated library
Utilities (logging, arguments, libraries)#36 of 59
P3 · cleanup
  • P3 because it decouples general logging primitives from mandatory global singletons
  • Provides modular logging sinks without altering behavior for standalone executables
Reviewability: ReadyStalePaused
Agreement: StrongPositivePositive w/ caveatsNeutralMildDisputedBlockedCrickets
Reviews: current code-review ACKs, then (+stale ACKs) and -NACKs; greener = more ACKs.
Size: lines added or modified outside tests, then in tests; greener = smaller.

Goal

Pass `Logger` instances into kernel and storage classes (including `ChainstateManager`, `BlockManager`, `CDBWrapper`, `CCoinsViewDB`, and `FlatFileSeq`) and update kernel logging to use local contexts instead of the global logger. In `libbitcoinkernel`, route log entries exclusively to the logging connection associated with each context and eliminate the global `KernelLogger` instance entirely. Standalone executables like `bitcoind` retain their existing logging behavior by passing their application-managed logger.

Problem: Applications using `libbitcoinkernel` or tests that initialize multiple chainstate contexts (such as mainnet and signet concurrently) receive an interleaved log stream with no way to determine which context produced each message. Even with per-context connections, kernel internals previously logged through a global logger singleton that broadcasted all messages to every active connection.

Evidence of importance:

  • PR description: 'An application that opens two chainstates (say mainnet and signet, or a test creating several contexts) gets log lines from both in one interleaved stream, with no way to tell which context each came from.'
  • Commit bcf65a7627: 'The process-wide KernelLogger and its callback list are gone, so the kernel library no longer has global logging state.'

Scope: A wide-ranging mechanical refactoring spanning 79 files (+1269/-744) that updates constructors for core validation, block storage, and database wrapper classes, along with corresponding unit and fuzz test harness setup code.

Risk of a mistake: medium (validation, tooling). A lifetime mismatch or dangling pointer between a kernel object and its assigned Logger could cause a crash or use-after-free during logging.

Changed since the previous assessment: Rebased following the merge of base PR #34374, dropping it from dependencies. The commit stack now explicitly removes the global `Logger` instance from the kernel library and cleans up redundant decode failure log messages in the kernel C API.

Reviewability

Ready · Review #29256 first

Stacked on #29256; the base PR's changes are included in this diff.

Waiting on (from the thread read):

  • decision: whether to pursue contextualized logging or simpler global logging (#34775) 2026-03-08

Agreement

Mild

NACK from stickies-v not withdrawn (plumbing logger instances through kernel objects makes the logging interface cumbersome and easy to misuse if forgetting to log to context cannot be enforced)

Thread notes: Processed author's rebase updates through push 54 recorded in edited comment c:2218833239; claims and support are unchanged.

Objections, suggestions, and questions:

ReviewerTypeHarm, request, or questionStatusMust beAuthor repliedQuote
stickies-v (member)objection, interfaceplumbing logger instances through kernel objects makes the logging interface cumbersome and easy to misuse if forgetting to log to context cannot be enforcedaccepted · fix pushed · stickies-v accepted the author's suggested per-file compile-time enforcement approachchangedyes2026-03-06: 'logging interface becomes more cumbersome, i.e. caller has to figure out if a logger is in scope and if it should be used. It is easy to misuse (e.g. forget to log to context when it exists, which see'
Status from: 2026-03-08: stickies-v: 'Nice, I hadn't thought of a per-file approach, that seems elegant.'
stickies-v (member)suggestion, usefulnessdefer contextualized logging until there is clear demand and use cases from users, rather than incurring large review cost and merge conflictscontested · author asked what was difficult to review; stickies-v pushed back, reiterating that users do not need contextualized logging and favoring simpler global logging (#34775)answeredyes2026-03-06: 'non-trivial code change / review cost, lots of merge conflicts... I think this change might become more desirable if/when we have more demand for this feature'
Status from: 2026-03-08: stickies-v: 'I just don't think it's currently important as it seems users (incl myself) don't actually need this. Just making kernel'

Support:

  • sedited (member) (Concept ACK, 2024-06-26): Concept ACK. [not substantive]

Participants:

  • sedited (member, support, 1 statements 2024-06-26 to 2024-06-26): Concept ACK with no rationale
  • stickies-v (member, objection, 2 statements 2026-03-06 to 2026-03-08): leans Approach NACK over review cost, churn, and lack of demand, favoring simpler global logging (#34775)

Dependencies

Depends on: #34778, #29256, #33847

Enables:

Based on (shares commits with): #29256, #33847, #34778

Files

575 lines under test/bench/ci.

  • src/validation.cpp +176/-152
  • src/kernel/bitcoinkernel.cpp +116/-169
  • src/util/log.h +193/-62
  • src/test/logging_tests.cpp +207/-21
  • src/node/blockstorage.cpp +54/-49
  • src/dbwrapper.cpp +40/-34
  • src/logging.cpp +38/-31
  • src/test/kernel/test_kernel.cpp +51/-17
  • src/kernel/bitcoinkernel.h +39/-13
  • src/test/coinsviewoverlay_tests.cpp +21/-20
  • src/test/dbwrapper_tests.cpp +17/-17
  • src/txdb.cpp +16/-13
  • src/flatfile.cpp +14/-13
  • src/test/fuzz/fuzz.cpp +24/-1
  • src/node/chainstate.cpp +14/-10
  • src/test/fuzz/dbwrapper.cpp +18/-5
  • src/test/fuzz/coins_view.cpp +15/-7
  • src/kernel/bitcoinkernel_wrapper.h +16/-5
  • src/txmempool.cpp +11/-9
  • src/node/utxo_snapshot.cpp +8/-7
  • src/validation.h +10/-4
  • src/coins.cpp +6/-6
  • src/test/fuzz/coinscache_sim.cpp +9/-2
  • src/coins.h +6/-4
  • src/test/flatfile_tests.cpp +5/-5
  • src/logging.h +6/-3
  • src/test/fuzz/script_sigcache.cpp +7/-2
  • src/node/blockstorage.h +6/-2
  • src/test/fuzz/threadpool.cpp +7/-1
  • src/test/threadpool_tests.cpp +7/-1
  • src/dbwrapper.h +6/-1
  • src/script/sigcache.cpp +5/-2
  • test/sanitizer_suppressions/valgrind.supp +0/-7
  • src/script/sigcache.h +4/-2
  • src/test/coins_tests.cpp +3/-3
  • src/test/fuzz/block_index.cpp +3/-3
  • src/test/fuzz/mini_miner.cpp +4/-2
  • src/test/streams_tests.cpp +3/-3
  • src/bitcoind.cpp +4/-1
  • src/index/base.h +5/-0
  • src/node/utxo_snapshot.h +4/-1
  • src/test/script_assets_tests.cpp +3/-2
  • src/flatfile.h +3/-1
  • src/index/base.cpp +2/-2
  • src/qt/bitcoin.cpp +4/-0
  • src/test/blockmanager_tests.cpp +2/-2
  • src/test/txindex_tests.cpp +2/-2
  • src/test/util/setup_common.cpp +3/-1
  • src/test/validation_chainstatemanager_tests.cpp +2/-2
  • src/test/validation_tests.cpp +2/-2
  • src/txdb.h +3/-1
  • doc/developer-notes.md +1/-2
  • src/blockencodings.cpp +2/-1
  • src/blockencodings.h +2/-1
  • src/index/blockfilterindex.cpp +2/-1
  • src/test/blockfilter_tests.cpp +2/-1
  • src/test/fuzz/fuzz.h +2/-1
  • src/test/reverselock_tests.cpp +2/-1
  • src/test/scheduler_tests.cpp +2/-1
  • src/test/sync_tests.cpp +2/-1
  • src/wallet/test/fuzz/fees.cpp +2/-1
  • src/bench/bench_bitcoin.cpp +2/-0
  • src/bitcoin-cli.cpp +2/-0
  • src/bitcoin-tx.cpp +2/-0
  • src/bitcoin-util.cpp +2/-0
  • src/bitcoin-wallet.cpp +2/-0
  • src/checkqueue.h +0/-2
  • src/init.cpp +1/-1
  • src/kernel/mempool_options.h +2/-0
  • src/net_processing.cpp +1/-1
  • src/qt/test/test_main.cpp +2/-0
  • src/rpc/blockchain.cpp +2/-0
  • src/test/fuzz/partially_downloaded_block.cpp +1/-1
  • src/test/miner_tests.cpp +1/-1
  • src/test/script_p2sh_tests.cpp +1/-1
  • src/test/transaction_tests.cpp +1/-1
  • src/test/util/setup_common.h +2/-0
  • src/bitcoin-chainstate.cpp +1/-0
  • src/txmempool.h +1/-0

Card

The short text the ranking pass compares across PRs.

This pull request passes Logger instances into core kernel objects such as ChainstateManager, BlockManager, and CDBWrapper, routing kernel logging to these local instances instead of a global singleton. In libbitcoinkernel, this isolates logging so that each context delivers entries strictly to its own logging connection, solving the issue where multiple chainstate contexts produce an interleaved log stream. It removes global logging state from the kernel library while preserving default logging for bitcoind and other executables. The PR depends on #34778, #29256, and #33847, and unblocks contextual wallet logging in #30343.

Data

dossier JSON · extract JSON · model ledger, generated 2026-11-01T01:16, confidence high, input hash f71681cca35bdac1
thread read through 2026-03-08 (6 statements), head bcf65a7627
labels: none · draft

Categories

Kernel (libbitcoinkernel)

P2 · cleanup

Removes global logging state from libbitcoinkernel, allowing separate chainstate contexts to operate without interleaved log streams. Eliminating process-wide singletons is core architectural work for making the kernel usable as an independent library.

Membership: Eliminates the process-wide KernelLogger singleton in libbitcoinkernel and routes logging per context.

Factors: security/stability 0, bug 0, performance 0, user value 1, leverage 2

Utilities (logging, arguments, libraries)

P3 · cleanup

Refactors node-wide logging primitives to support context-specific logging destinations alongside the global logger. It cleanly decouples log emission from singleton instances, reducing cross-cutting logging assumptions across the codebase.

Membership: Changes logging infrastructure in src/util/log.h and src/logging.cpp to support local contextual logging.

Factors: security/stability 0, bug 0, performance 0, user value 1, leverage 2