#30342 kernel, logging: Pass Logger instances to kernel objects

full analysis

https://github.com/bitcoin/bitcoin/pull/30342 · ryanofsky · +1099/-591 in 69 files, 18 commits · labels: Needs rebase · draft

Goal

  • Allow kernel library consumers to route log output per instance rather than through a global logger
  • Help multi-instance applications segregate and control their own log streams

This pull request passes `Logger` instances into core kernel objects such as `BlockManager`, `CCoinsViewDB`, `CDBWrapper`, `ChainstateManager`, and `CTxMemPool`. It also introduces a `LOG_REQUIRE_CONTEXT` macro check in `src/util/log.h` to enforce at compile time that log calls supply an explicit context rather than falling back to the global logger.

Problem: Currently, `libbitcoinkernel` relies on a global `BCLog::Logger` singleton (`LogInstance()`), preventing library consumers from cleanly routing kernel logs to custom destinations or isolating log streams across multiple kernel instances.

Category: Kernel (libbitcoinkernel) (#7 of 18)

P3 · cleanup

  • P3 because eliminating global state aligns with library design goals without urgent user demand
  • Kernel working group inquiries showed minimal caller need for contextual logging

De-globalizing the logger in kernel objects is a clean architectural step for the library boundary. However, stickies-v pointed out that consumers currently have little concrete demand for separate logging streams, keeping urgency modest.

Membership: Directly modifies libbitcoinkernel interfaces and chainstate components to de-globalize logging.

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

Category: Utilities (logging, arguments, libraries) (#29 of 66)

P3 · cleanup

  • P3 because contextual log macros add conceptual complexity to logging utilities ahead of direct need
  • Refactoring log utilities remains optional until downstream subsystems require instanced routing

Extends the core logging macros to optionally enforce explicit context arguments at compile time and support scoped logger instances.

Membership: Changes logging infrastructure in src/util/log.h and src/logging.h, introducing LOG_REQUIRE_CONTEXT and instanced logger support.

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

Reviewability: Stale: Needs rebase

  • Wait for rebase due to substantial merge conflicts across dozens of files
  • Review #34778 first

The branch has merge conflicts with master and has the 'Needs rebase' label applied.

Author status: Active; repeatedly rebasing and keeping the branch updated despite merge conflicts.

Open concerns:

  • stickies-v raised an Approach NACK arguing that plumbing logger instances through many interfaces introduces review cost and interface complexity without proven demand, favoring a global callback approach instead (#34775).

Resolved concerns:

  • stickies-v noted that callers might easily forget to pass a log context; ryanofsky demonstrated a compile-time `LOG_REQUIRE_CONTEXT` static assertion mechanism to prevent accidental global logging.

Agreement: Disputed

  • Disputed whether instanced logging justifies the interface verbosity and maintenance cost
  • Concept approval without stated reasons (sedited)
  • Approach objection: review cost and verbosity outweigh benefits without consumer demand (stickies-v)
  • Prefers keeping logging callback explicitly global via alternative PR #34775 (stickies-v)

Disputed: stickies-v favors explicit global logging (#34775) over passing logger instances throughout the kernel.

While sedited gave a Concept ACK and ryanofsky mitigated the risk of accidental global log fallback with compile-time checks, stickies-v maintains an Approach NACK prioritizing a simpler global logging model (#34775).

  • sedited: Concept ACK (2024-06-26)
  • stickies-v: leaning Concept ACK, Approach NACK, opened competing #34775 (2026-03-06, 2026-03-08)

Objections:

ReviewerKindHarmStatusBlockingAuthor repliedQuote
stickies-vapproachMakes the logging interface more cumbersome across many call sites and incurs substantial churn and rebase cost without current demand from kernel consumers.openyesyes2026-03-06: 'I'm currently leaning Concept ACK, Approach NACK... logging interface becomes more cumbersome... non-trivial code change / review cost... Just making kernel logging explicitly global... seems like the more pragmatic change to me now.'

Support:

  • sedited: Concept ACK [not substantive]

Participants: sedited (support), stickies-v (objection)

State derived from the lists: blocking objection open, author engaging (stickies-v)

Review verdicts (DrahtBot): 0 -1

Dependencies

Depends on: #34778, #29256, #33847

Enables:

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

Files

476 lines under test/bench/ci.

  • src/validation.cpp +173/-150
  • src/util/log.h +193/-62
  • src/test/logging_tests.cpp +207/-21
  • src/node/blockstorage.cpp +53/-48
  • src/kernel/bitcoinkernel.cpp +48/-43
  • src/dbwrapper.cpp +40/-34
  • src/logging.cpp +38/-31
  • src/kernel/bitcoinkernel.h +28/-38
  • src/kernel/bitcoinkernel_wrapper.h +31/-26
  • src/txdb.cpp +16/-13
  • src/test/kernel/test_kernel.cpp +16/-11
  • src/test/dbwrapper_tests.cpp +13/-13
  • src/test/fuzz/fuzz.cpp +24/-1
  • src/node/chainstate.cpp +14/-10
  • src/test/coinsviewoverlay_tests.cpp +12/-11
  • src/test/fuzz/dbwrapper.cpp +18/-5
  • src/txmempool.cpp +11/-9
  • src/test/fuzz/coins_view.cpp +13/-5
  • src/validation.h +10/-4
  • src/logging.h +6/-3
  • src/test/fuzz/script_sigcache.cpp +7/-2
  • src/node/blockstorage.h +6/-2
  • src/test/fuzz/coinscache_sim.cpp +7/-1
  • 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
  • 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/bitcoind.cpp +4/-1
  • src/index/base.h +5/-0
  • src/test/script_assets_tests.cpp +3/-2
  • src/bitcoin-chainstate.cpp +2/-2
  • 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_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/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
  • .github/workflows/ci.yml +1/-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/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/test/validation_chainstatemanager_tests.cpp +1/-1
  • src/txmempool.h +1/-0

Card

This PR refactors libbitcoinkernel logging by passing explicit Logger instances to classes such as ChainstateManager, BlockManager, and CTxMemPool, eliminating reliance on the global logger singleton. It also adds a LOG_REQUIRE_CONTEXT mechanism in the logging framework to enforce context passing at compile time. Reviewers are split on the approach: stickies-v entered an Approach NACK favoring simpler global logging (#34775) over pervasive interface plumbing. The PR is currently marked draft and needs a rebase due to merge conflicts.

Data

dossier JSON · extract JSON · model openrouter/google/gemini-3.8-flash, generated 2026-09-17T21:20, confidence high, input hash 4bb669b7c910f864