Skip to content

backport: bitcoin/bitcoin#24304: [kernel 0/n] Introduce bitcoin-chainstate#7234

Draft
knst wants to merge 42 commits intodashpay:developfrom
knst:bp-kernel-0
Draft

backport: bitcoin/bitcoin#24304: [kernel 0/n] Introduce bitcoin-chainstate#7234
knst wants to merge 42 commits intodashpay:developfrom
knst:bp-kernel-0

Conversation

@knst
Copy link
Collaborator

@knst knst commented Mar 17, 2026

Issue being fixed or feature implemented

This PR sum up all changes that are required to backport bitcoin#24304 and proof-of-concept that it is possible after just couple extra tiny steps.

The first blocker is already have PR: #7178

What was done?

Beside changes that already has been merged or having PRs such as #7178 [in review], #7070, #7008, #6992, #6959, #7106 (by Udjin), #7065 (by kwvg) and many other PRs:

  • drop dependency of InstantSend on CActiveMasternodeSync
  • drop dependency of InstantSend on CChainState
  • new stub implementation NullNodeSyncNotifier of CActiveMaternodeSync for governance
  • further refactorings of CGovernanceManager to reduce dependencies on other components
  • add guards for CTxMempool is nullptr [which could be for chainstate case]
  • removed multiple includes of msg_result.h over codebase
  • moved multiple functions between modules to reduce extra dependencies
  • done the backport kernel zero [kernel 0/n] Introduce bitcoin-chainstate bitcoin/bitcoin#24304 which unblocks the whole multiple series of all kernel backports

There are several dirty hacks that meant to be fixed and they will be done by extra PRs; local branches for these fixes are semi-ready:

  • CDKGSessionManager should be split to network & non-network pieces. For right now a workaround for linkage is used by moving some code to net_processing.cpp
  • CSporkManager - the same workaround as CDKGSessionManager
  • llmq::utils::EnsureQuorumConnections and llmq::utils::AddQuorumProbeConnections - the same workaround
  • CQuorumManager::RequestQuorumData should be moved away to avoid network dependencies

There are several dependencies of dash-chainstate that looks excessive, but they are not a blocker and may be removed in any time in the future:
- base58.cpp
- core_write.cpp
- evo/core_write.cpp
- key_io.cpp
- node/interface_ui.cpp
- protocol.cpp
- scheduler.cpp
- node/bloom.cpp
- index/txindex.cpp
- batchedlogger.cpp
- Reduce governance significantly so far as there's no actual governance enabled in chainstate mode (governance is out of blockchain anyway)
- Reduce llmq dependencies, probably to drop: dkgsession, dkgsessionmgr, dkgsessionohandler, debug
- Remove CSigningManager from LLMQContext. LLMQContext should be quorum-only-context; CSigningManager should be inside active/

How Has This Been Tested?

Build succeed with bitcoin#24304, functional & unit tests runs

Run dash-chainstate:

$ src/dash-chainstate /home/knst/.dashcore/
Hello! I'm going to print out some information about your datadir.
        Path: "/home/knst/.dashcore"
        Reindexing: false
        Snapshot Active: false
        Active Height: 2294070
        Active IBD: true
        CBlockIndex(pprev=0x5654a3bdb218, nHeight=2294070, merkle=5c87e557b9e697e9308a4a6bd684e362910fe418ca60e59ae1376e91c487df77, hashBlock=0000000000000010938b2d1c2f1ff08163dae17f4196a41d73b9e6e3c4114cc2)

Breaking Changes

N/A

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

knst and others added 30 commits March 12, 2026 20:34
- Rename IsKnownTx to HasTxForLock for clarity (returns true when
  the lock's transaction is known, not pending without a TX)
- Fix unconditional LookupBlockIndex in CheckCanLock: only take
  cs_main on cache miss instead of every call
- Fix log prefix typos: NetSigning -> NetInstantSend in
  ProcessInstantSendLock
- Remove redundant LookupBlockIndex fallback in ProcessInstantSendLock
  that duplicated the static GetBlockHeight helper
- Simplify AttachISLockToTx: use for-loop with early-continue,
  remove unnecessary variable
- Remove double blank line

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There's new helper IsValidAndSynced in CGovernanceManager that incapsulate usages of CMasternodeSync in CMNPayment
…otifier is introduced to use it for CChainState
2c03cec ci: Build bitcoin-chainstate (Carl Dong)
095aa6c build: Add example bitcoin-chainstate executable (Carl Dong)

Pull request description:

  Part of: bitcoin#24303

  This PR introduces an example/demo `bitcoin-chainstate` executable using said library which can print out information about a datadir and take in new blocks on stdin.

  Please read the commit messages for more details.

  -----

  #### You may ask: WTF?! Why is `index/*.cpp`, etc. being linked in?

  This PR is meant only to capture the state of dependencies in our consensus engine as of right now. There are many things to decouple from consensus, which will be done in subsequent PRs. Listing the files out right now in `bitcoin_chainstate_SOURCES` is purely to give us a clear picture of the task at hand, it is **not** to say that these dependencies _belongs_ there in any way.

  ### TODO

  1. Clean up `bitcoin-chainstate.cpp`
     It is quite ugly, with a lot of comments I've left for myself, I should clean it up to the best of my abilities (the ugliness of our init/shutdown might be the upper bound on cleanliness here...)

ACKs for top commit:
  ajtowns:
    ACK 2c03cec
  ryanofsky:
    Code review ACK 2c03cec. Just rebase, comments, formatting change since last review
  MarcoFalke:
    re-ACK 2c03cec 🏔

Tree-SHA512: 86e7fb5718caa577df8abc8288c754f4a590650d974df9d2f6476c87ed25c70f923c4db651c6963f33498fc7a3a31f6692b9a75cbc996bf4888c5dac2f34a13b
…avoid extra heavy dependencies

Implemented:
  - ValueFromAmount (core_write.cpp)
  - GetPrettyExceptionStr (stacktrackes.cpp)
knst added 12 commits March 17, 2026 20:01
…ssage for detailed notes about further todo-to-remove

TODO to remove:
  base58.cpp \
  core_write.cpp \
  evo/core_write.cpp \
  key_io.cpp \
  node/interface_ui.cpp \
  protocol.cpp \
  scheduler.cpp \
  node/bloom.cpp \
  index/txindex.cpp \
  batchedlogger.cpp \

  Reduce governance significantly so far as there's no actual governance enabled

  Reduce llmq: dkgsession, dkgsessionmgr, dkgsessionohandler, debug

  Remove CSigningManager from LLMQContext. LLMQContext should be quorum-only-context
@github-actions
Copy link

This pull request has conflicts, please rebase.

@github-actions
Copy link

⚠️ Potential Merge Conflicts Detected

This PR has potential conflicts with the following open PRs:

Please coordinate with the authors of these PRs to avoid merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants