Skip to content

Conversation

@m-kus
Copy link
Member

@m-kus m-kus commented Oct 6, 2025

Add Chain State Management

This PR adds a chain state management system to track and maintain the Bitcoin chain state, which is essential for SPV verification. The implementation includes:

  • New ChainState struct to store block height, total work, best block hash, current target, epoch start time, and previous timestamps
  • ChainStateManager to handle state updates when new blocks are processed
  • SQLite storage for chain states with serialization using bincode
  • New RPC endpoint /chain-state/:block_height to retrieve chain state at a specific height
  • Integration with the indexer to update chain state alongside MMR updates
  • Refactored block header storage to separate it from MMR functionality

These changes enable proper tracking of chain parameters needed for SPV verification and provide a way for clients to access this information through the API.

Copy link
Member Author

m-kus commented Oct 6, 2025

@m-kus m-kus marked this pull request as ready for review October 6, 2025 13:28
@m-kus m-kus requested a review from maciejka as a code owner October 6, 2025 13:28
@m-kus m-kus force-pushed the 09-30-thread_safe_mmr branch from 907f75f to 4a0b9a3 Compare October 6, 2025 20:37
@m-kus m-kus force-pushed the 10-06-add_chain_state_indexing_and_rpc_endpoint branch from ca681be to 4825451 Compare October 6, 2025 20:37
@m-kus m-kus force-pushed the 09-30-thread_safe_mmr branch from 4a0b9a3 to 5cb9acf Compare October 6, 2025 20:48
@m-kus m-kus force-pushed the 10-06-add_chain_state_indexing_and_rpc_endpoint branch 2 times, most recently from 5886c91 to a5a7116 Compare October 6, 2025 21:29
@m-kus m-kus force-pushed the 09-30-thread_safe_mmr branch from 5cb9acf to 80547bc Compare October 6, 2025 21:29
Base automatically changed from 09-30-thread_safe_mmr to main October 6, 2025 21:37
@m-kus m-kus force-pushed the 10-06-add_chain_state_indexing_and_rpc_endpoint branch from a5a7116 to 812c6d3 Compare October 6, 2025 21:37
@m-kus m-kus merged commit 7d8df65 into main Oct 7, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants