#35474 node: move index ownership to NodeContext
https://github.com/bitcoin/bitcoin/pull/35474 · · +255/-175 in 27 files, 5 commits · labels: Refactoring, UTXO Db and Indexes
Goal
- Make index lifecycles explicit during node startup and shutdown
- Help future work on running multiple node instances or separating processes
This PR moves ownership of the optional indexes (`g_txindex`, `g_txospenderindex`, `g_coin_stats_index`, and `g_filter_indexes`) from process-global static pointers into `NodeContext`. It introduces custom deleters to keep `NodeContext` decoupled from full index headers, relocates the block filter index registry into `node/indexes.{h,cpp}`, and routes index access in peer management, REST, and RPC callers through context references rather than global state.
Problem: Optional indexes currently rely on process-global singletons (`g_txindex`, etc.), making testing harder, impeding multi-node or multiprocess execution, and scattering index lifetime management across global state.
Category: Indexes (#5 of 7)
P3 · cleanup
- P3 because removing global index state clarifies component lifetimes
- Destruction order is bound directly to node context teardown
P3 because this is an internal architectural cleanup that eliminates process-global index pointers. It removes globals like `g_txindex` and `g_filter_indexes`, which aligns with the project's multiprocess goals and aids test isolation, but does not alter index performance, validity, or storage format.
Membership: Refactors ownership, registration, and lookup mechanisms for txindex, coinstatsindex, txospenderindex, and blockfilterindex.
Factors: security/stability 0, bug 0, performance 0, user value 0, leverage 1
Reviewability: Ready
- Ready to review with clean CI and no author blockers
The branch is clean, CI passes, and the author recently rebased it.
Author status: Active; promptly rebased when requested by reviewers.
Resolved concerns:
Agreement: Positive
- Generally positive sentiment with no objections
- Concept approval without stated reasons (sedited, fjahr)
- Clarified relationship with concurrent index changes without dispute (Sjors)
Positive; two Concept ACKs with no objections raised.
Maintainers and reviewers have offered Concept ACKs, and questions regarding overlapping index PRs were addressed satisfactorily.
- sedited: Concept ACK (2026-06-06)
- fjahr: Concept ACK (2026-06-21)
Objections: none enumerated.
Support:
- sedited: Concept ACK [not substantive]
- fjahr: Concept ACK [not substantive]
Participants: sedited (support), Sjors (question), fjahr (support)
State derived from the lists: support without stated reasons, no open objection (sedited, fjahr)
Review verdicts (DrahtBot): 0
Files
41 lines under test/bench/ci.
- src/node/indexes.cpp +65/-0
- src/node/indexes.h +51/-0
- src/index/blockfilterindex.cpp +0/-35
- src/init.cpp +20/-13
- src/rpc/blockchain.cpp +19/-14
- src/index/blockfilterindex.h +0/-27
- src/node/context.h +24/-1
- src/test/blockfilter_index_tests.cpp +12/-11
- src/rpc/node.cpp +3/-18
- src/rest.cpp +12/-7
- src/rpc/mempool.cpp +6/-8
- src/rpc/rawtransaction.cpp +7/-7
- src/wallet/test/wallet_tests.cpp +7/-6
- src/rpc/txoutproof.cpp +7/-4
- src/node/transaction.cpp +3/-3
- src/node/transaction.h +4/-2
- src/net_processing.h +5/-0
- src/node/interfaces.cpp +3/-2
- src/test/util/setup_common.cpp +5/-0
- src/index/txospenderindex.h +0/-4
- src/index/coinstatsindex.h +0/-3
- src/index/txindex.h +0/-3
- src/index/coinstatsindex.cpp +0/-2
- src/index/txindex.cpp +0/-2
- src/index/txospenderindex.cpp +0/-2
- src/net_processing.cpp +1/-1
- src/CMakeLists.txt +1/-0
Card
This PR moves ownership of all optional index instances (txindex, coinstatsindex, txospenderindex, and block filter indexes) from process-global variables into NodeContext. It eliminates global singletons across the indexing subsystem and routes lookups in RPC, REST, and peer management through context pointers or callbacks. The change is internal architectural cleanup that improves testability and aligns with the multiprocess project, but does not alter user-facing behavior or indexing logic. Review state is positive with two Concept ACKs and no objections.