Skip to content

Conversation

@ZocoLini
Copy link
Collaborator

Removed the headers field from ChainState. Also modified a StorageManager trait method return type removing a the possibility of error (bcs it cannot fail once the StorageManager is built) and added a little bit of noise to this PR, more than expected.

All tests pass and I was able to execute example simple_sync reaching height 2_391_372 in 15 min (more or less).

2025-12-19T18:11:48.080359Z  INFO 📊 [SYNC STATUS] Headers: 2391372 | Filter Headers: 0 | Filters: 0 | Latest ChainLock: #2391372 | Filters Matched: 0 | Blocks w/ Relevant Txs: 0 | Blocks Processed: 1 | Balance: 0 BTC

There is only one thing, one piece of logic that I didn't replace.

In dash-spv/src/types.rs line 303, inside method ChainState::new_for_network we can find this:

    /// Create a new chain state for the given network.
    pub fn new_for_network(network: Network) -> Self {
        let mut state = Self::default();

        // Initialize with genesis block
        let genesis_header = match network {
            Network::Dash => {
                // Use known genesis for mainnet
                dashcore::blockdata::constants::genesis_block(network).header
            }
            Network::Testnet => {
                // Use known genesis for testnet
                dashcore::blockdata::constants::genesis_block(network).header
            }
            _ => {
                // For other networks, use the existing genesis block function
                dashcore::blockdata::constants::genesis_block(network).header
            }
        };

        // Add genesis header to the chain state
        state.headers.push(genesis_header); // This is the line I was talking about

        tracing::debug!(
            "Initialized ChainState with genesis block - network: {:?}, hash: {}",
            network,
            genesis_header.block_hash()
        );

        // Initialize masternode engine for the network
        let mut engine = MasternodeListEngine::default_for_network(network);
        if let Some(genesis_hash) = network.known_genesis_block_hash() {
            engine.feed_block_height(0, genesis_hash);
        }
        state.masternode_engine = Some(engine);

        // Initialize checkpoint fields
        state.sync_base_height = 0;

        state
    }

I just dropped the push of the genesis_block without adding it to the storage expecting a future issue during sync or while executing the tests but that never happened. I guess we are sync the genesis block from the network instead of having it hardcoded there but I am not sure and make me wonder. Since it works and theorically this is somethign we can ask the network for I am not wasting time here unless someone knows something that I don't. I want to continue updating ChainState

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 19, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch remove-headers-from-chain-state

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ZocoLini ZocoLini force-pushed the remove-headers-from-chain-state branch 2 times, most recently from fb75d92 to 12c9304 Compare December 19, 2025 19:10
@ZocoLini ZocoLini force-pushed the remove-headers-from-chain-state branch from 12c9304 to bc544a5 Compare December 19, 2025 19:41
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