node: move index ownership to NodeContext #35474

pull w0xlt wants to merge 6 commits into bitcoin:master from w0xlt:global-state-index-nodecontext changing 27 files +257 −175
  1. w0xlt commented at 6:01 PM on June 6, 2026: contributor

    This removes the remaining process-global index ownership and stores node-owned indexes in NodeContext instead.

    Indexes moved:

    • g_txindex
    • g_txospenderindex
    • g_coin_stats_index
    • g_filter_indexes

    NodeContext now owns these index instances, while node.indexes remains a non-owning list used for common index startup, shutdown, and getindexinfo handling.

    Behavior should be unchanged, apart from the key order in getindexinfo output. Indexes are still created from the same startup options, started in the same init step, stopped before destruction, and destroyed while validation_signals is still alive so they can unregister safely.

    The block filter index registry is moved to node/indexes.{h,cpp} so index/ code does not depend on NodeContext. PeerManager receives a small lookup callback instead of reaching into global state.

    Review notes:

    • The first four commits are small and mostly mechanical: move txindex, txospenderindex, and coinstatsindex ownership to NodeContext, then make getindexinfo use node.indexes. The first commit also adds custom deleters in node/indexes.cpp, so node/context.cpp does not include index headers, which would create circular dependencies.
    • The fifth commit adds a block filter index lookup callback to PeerManager::Options, still backed by the global registry.
    • The last commit is the main one to review carefully. It moves block filter index ownership to NodeContext, moves the block filter registry to node/indexes.{h,cpp}, and points the PeerManager lookup at NodeContext instead of global state.
  2. DrahtBot commented at 6:01 PM on June 6, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    Concept ACK sedited, fjahr

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36447 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36447.svg"></sub> (test: Misc fixes for pending validation events races by maflcko)
    • #36244 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36244.svg"></sub> (validation, net: Process blocks asynchronously and reduce cs_main contention by w0xlt)
    • #36167 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36167.svg"></sub> ([RFC] Enable -Wunused by fanquake)
    • #35642 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35642.svg"></sub> (headersync: do parameter search at runtime by sipa)
    • #34132 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34132.svg"></sub> (coins, dbwrapper: remove error catcher, make point-read failures fatal by l0rinc)
    • #31260 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/31260.svg"></sub> (scripted-diff: Type-safe settings retrieval by ryanofsky)
    • #30437 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/30437.svg"></sub> (ipc: add bitcoin-mine test program by ryanofsky)
    • #24230 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/24230.svg"></sub> (indexes: Stop using node internal types and locking cs_main, improve sync logic by ryanofsky)
    • #19461 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/19461.svg"></sub> (multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky)
    • #19460 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/19460.svg"></sub> (multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky)
    • #10102 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/10102.svg"></sub> (Multiprocess bitcoin by ryanofsky)

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    LLM Linter (✨ experimental)

    Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

    • node::InitBlockFilterIndex(m_node, [&]{ return interfaces::MakeChain(m_node); }, BlockFilterType::BASIC, 1_MiB, true, false) in src/test/blockfilter_index_tests.cpp

    <sup>2026-09-30 19:27:32</sup>

  3. sedited commented at 7:48 PM on June 6, 2026: contributor

    Concept ACK

  4. sedited requested review from fjahr on Jun 9, 2026
  5. Sjors commented at 8:22 AM on June 17, 2026: member

    How does this interact with #24230?

  6. w0xlt commented at 5:01 PM on June 17, 2026: contributor

    #24230 still keeps process-global index ownership.

    So this PR is mostly orthogonal to it: #24230 changes how indexes sync with the chain and removes index dependencies on node internals, while this PR moves index ownership into NodeContext.

    There is no conceptual conflict. In terms of code there will be rebase conflicts after one or the other lands, since both touch the index/init/RPC/REST paths.

    Removing process-global index ownership seems aligned with the multiprocess direction anyway.

  7. fjahr commented at 2:41 PM on June 21, 2026: contributor

    Concept ACK

  8. willcl-ark added the label Refactoring on Jul 9, 2026
  9. willcl-ark added the label UTXO Db and Indexes on Jul 9, 2026
  10. DrahtBot added the label Needs rebase on Jul 14, 2026
  11. sedited commented at 9:38 AM on August 17, 2026: contributor

    Ping for rebase @w0xlt

  12. w0xlt force-pushed on Aug 18, 2026
  13. w0xlt commented at 10:00 PM on August 18, 2026: contributor

    Rebased. Thanks @sedited

  14. DrahtBot removed the label Needs rebase on Aug 18, 2026
  15. DrahtBot added the label Needs rebase on Aug 21, 2026
  16. w0xlt force-pushed on Sep 15, 2026
  17. w0xlt commented at 11:03 PM on September 15, 2026: contributor

    Reabsed

  18. DrahtBot removed the label Needs rebase on Sep 16, 2026
  19. node: move txindex ownership to NodeContext
    Replace the g_txindex global with NodeContext::txindex and pass the
    index to GetTransaction() explicitly instead of reading the global.
    
    Index types are destroyed through deleters defined in node/indexes.cpp
    because including index headers in node/context.cpp would create
    circular dependencies (index/base.cpp includes node/context.h). These
    can become plain unique_ptrs once index code no longer depends on
    NodeContext.
    bdaf67c2c8
  20. node: move txospenderindex ownership to NodeContext 3df63408a0
  21. node: move coinstatsindex ownership to NodeContext 6833bda571
  22. rpc: get index info from NodeContext indexes
    getindexinfo now iterates NodeContext::indexes instead of querying each
    index type separately. The set of reported indexes is unchanged, but
    when several indexes are enabled the keys in the result follow the
    order in which the indexes are registered at startup.
    3a1d8b3087
  23. net_processing: get block filter index via PeerManager::Options
    Add a get_block_filter_index callback to PeerManager::Options and use it
    instead of calling the global GetBlockFilterIndex() directly. Callers
    still pass the global lookup, so behavior is unchanged.
    
    This lets the next commit move block filter index ownership without
    net_processing depending on NodeContext.
    39069ac64e
  24. node: move block filter index ownership to NodeContext fc948ca8e4
  25. in src/node/context.h:53 in 3c05b4eb83
      49 | @@ -49,6 +50,20 @@ namespace node {
      50 |  class KernelNotifications;
      51 |  class Warnings;
      52 |  
      53 | +// Keep NodeContext from depending on index modules while still owning indexes.
    


    fjahr commented at 11:09 PM on September 26, 2026:

    Are the custom deleters really needed? NodeContext already handles this for its other unique_ptr members via the destructor here: https://github.com/bitcoin/bitcoin/blob/ed7dd7cf4e1561a97edf72eba29a67b14e28c717/src/node/context.h#L95 Since node/context.cpp and index/*.cpp are both in bitcoin_node, I think you could just add the index includes there and use plain std::unique_ptr<TxIndex> etc.


    w0xlt commented at 8:28 PM on September 30, 2026:

    Thanks! Plain unique_ptrs would compile, but index/base.cpp includes node/context.h, so including the index headers in node/context.cpp introduces new circular dependencies:

    index/base -> node/context -> index/blockfilterindex -> index/base
    index/base -> node/context -> index/coinstatsindex -> index/base
    index/base -> node/context -> index/txindex -> index/base
    index/base -> node/context -> index/txospenderindex -> index/base
    

    The deleters are defined in node/indexes.cpp to avoid that.

    They can be dropped in a follow-up once index/base.cpp no longer needs node/context.h. #24230 already removes most of that dependency, leaving only the AbortNode() call in FatalErrorf(). Replacing that with a Chain method would allow plain unique_ptrs here and also remove the existing index/base -> node/context -> net_processing -> ... lint exception.

    If you'd rather add these to EXPECTED_CIRCULAR_DEPENDENCIES for now, I'm happy to switch to plain unique_ptrs.

    I've updated the code comment and commit message to make the reason clearer.

  26. w0xlt force-pushed on Sep 30, 2026
  27. w0xlt commented at 8:33 PM on September 30, 2026: contributor

    PR description updated.

  28. DrahtBot added the label Needs rebase on Oct 7, 2026
  29. DrahtBot commented at 2:20 PM on October 7, 2026: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->

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


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-10-15 15:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me