mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
node: move index ownership to NodeContext #35474
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35474
Loading…
Reference in a new issue
No description provided.
Delete branch "global-state-index-nodecontext"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This removes the remaining process-global index ownership and stores node-owned indexes in
NodeContextinstead.Indexes moved:
g_txindexg_txospenderindexg_coin_stats_indexg_filter_indexesNodeContextnow owns these index instances, whilenode.indexesremains a non-owning list used for common index startup, shutdown, andgetindexinfohandling.Behavior should be unchanged, apart from the key order in
getindexinfooutput. Indexes are still created from the same startup options, started in the same init step, stopped before destruction, and destroyed whilevalidation_signalsis still alive so they can unregister safely.The block filter index registry is moved to
node/indexes.{h,cpp}soindex/code does not depend onNodeContext.PeerManagerreceives a small lookup callback instead of reaching into global state.Review notes:
txindex,txospenderindex, andcoinstatsindexownership toNodeContext, then makegetindexinfousenode.indexes. The first commit also adds custom deleters innode/indexes.cpp, sonode/context.cppdoes not include index headers, which would create circular dependencies.PeerManager::Options, still backed by the global registry.NodeContext, moves the block filter registry tonode/indexes.{h,cpp}, and points thePeerManagerlookup atNodeContextinstead of global state.The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
src/test/fuzzand treat them as errors by hebasto)-Wunusedby fanquake)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.
Concept ACK
How does this interact with #24230?
https://github.com/bitcoin/bitcoin/pull/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.
Concept ACK
🐙 This pull request conflicts with the target branch and needs rebase.
Ping for rebase @w0xlt
Rebased. Thanks @sedited
🐙 This pull request conflicts with the target branch and needs rebase.
Reabsed
Are the custom deleters really needed?
NodeContextalready handles this for its otherunique_ptrmembers via the destructor here:github.com/bitcoin/bitcoin@ed7dd7cf4e/src/node/context.h (L95)Sincenode/context.cppandindex/*.cppare both in bitcoin_node, I think you could just add the index includes there and use plainstd::unique_ptr<TxIndex>etc.🔵 Suggestion ·
blockfilter_index_lookupleaves cross-context isolation untestedThe current lookup is correct, but
blockfilter_index_lookupexercises onlym_node, leaving the per-context isolation introduced by this PR without regression coverage.Location:
src/test/blockfilter_index_tests.cpp:232(head).Review coverage was incomplete.
Reviewed:
bb357fcd2fc5· Review report · Previous reportspermalink
Thanks! Plain
unique_ptrswould compile, butindex/base.cppincludesnode/context.h, so including the index headers innode/context.cppintroduces new circular dependencies:The deleters are defined in
node/indexes.cppto avoid that.They can be dropped in a follow-up once
index/base.cppno longer needsnode/context.h.#24230 already removes most of that dependency, leaving only the
AbortNode()call inFatalErrorf(). Replacing that with aChainmethod would allow plain unique_ptrs here and also remove the existingindex/base->node/context->net_processing-> ... lint exception.If you'd rather add these to
EXPECTED_CIRCULAR_DEPENDENCIESfor now, I'm happy to switch to plain unique_ptrs.I've updated the code comment and commit message to make the reason clearer.
PR description updated.
🐙 This pull request conflicts with the target branch and needs rebase.
Ping for rebase @w0xlt. I'm still interested in the change.
Rebased on master. Thanks @sedited for the ping.
Ok, it seems fine for me to keep the deleters then.
Looks in pretty good shape but I think there may be more lines of code that can be saved from the last commit :)
nit: ordering (same in the
node/interfaces.cppfile)I think it's actually not needed to move all this code over here, given that the vector of blockfilter indexes is a public member now anyway. We could just do things directly using that and remove almost 100 LOC compared to the current version here:
github.com/fjahr/bitcoin@7e6b7f8427and I see no real downside to this.Not sure what this
constversion of the function is useful for, it seems it can be dropped?Now that the index is passed in as a nullable pointer,
index_requestedis redundant.GetUTXOStatsonly reads it ascoin_stats_index && index_requested, sogettxoutsetinfocan passnullptrwhenuse_indexis false and the bool parameter can go.Suggested diff
This was to only caller of
ForEachBlockFilterIndexaside from a test. So the function can be removed here as well.Done. Thanks. Added you as co-author.
Done. Thanks
Done. Thanks
Done. Thanks
Done. Thanks
Code review ACK
560faa4310Thank you for taking my suggestions! I found a few more nits that you may address when you have to retouch but this already looks good to me as is.
nit: The usage of
newisn't really our preferred style afaik but there seems to be no hard rule about it and the way the deleters are used this seems to be unavoidable. I guess there may be ways to avoid it but not sure if that is worth it. Just noting that this is a bit of an unusual sight here.nit: The four deleter structs could be one struct with four overloads to save a few extra lines.
unique_ptrpicks the matching overload by pointer type, and that works with the forward declarations here.Suggested diff
nit: I don't think there is any other place?
nit: I think it should also be below
warningsbecause there is a call inBaseIndex::FatalErrorf. It seems to be a non-issue because the shutdown handles the indexes explicitly but it might be nicer to not rely on that.nit
nit: The
clear()calls (here and one more below) seem to be redundant since the unit test framework does it for us:github.com/bitcoin/bitcoin@d55f55eda7/src/test/util/setup_common.cpp (L349)I suspect the idea behind doing it explicitly here was to check the return value but I think I would rather suggest removing those lines.Done. Thanks.
Done. Thanks.
Done. Thanks.
Done. Thanks.
Done. Thanks.
Done. Thanks.
ACK
bb357fcd2freview ACK
bb357fcd2f💬Show signature
Signature:
nit in the first commit: Remove
2026-presentto stay in symmetry with the header?unrelated nit in the first commit: After commit
d7f61e7d59, the comment here can be removed:txindex->BlockUntilSyncedToCurrentChain();should be self-explanatory what it does, andcs_mainreference is confusing, because it is only taken for the block index lookup, and it is unclear why txindex syncing has anything to do with a block index lookup.Recall the same call is in
getrawtransaction, but there is also no comment.Concept ACK
I had been thinking about how to do this without knowing this PR already existed. I think moving index ownership out of globals and into NodeContext is a good idea
ACK
bb357fcd2fnit: We could inline
SummaryToJSONnow.SummaryToJSON
huh