stacks-network / stacks-core

The Stacks blockchain implementation
https://docs.stacks.co
GNU General Public License v3.0
3.01k stars 672 forks source link

feat: add index for stacks block id in nakamoto_block_headers #5414

Closed kantai closed 3 weeks ago

kantai commented 3 weeks ago

Description

Optimization: add index for index_block_hash in nakamoto_block_headers

kantai commented 3 weeks ago

Do we need a new schema version?

I didn't think so -- doesn't the index creation code just always run and check if indexes need to be created?

jcnelson commented 3 weeks ago

Ah, yes, you're right -- specifically for the chainstate (we really should do something about that too -- I bet those transactions are really unecessary)

oops, I missed the Self::need_schema_migrations() call

kantai commented 3 weeks ago

Ah, yes, you're right -- specifically for the chainstate (we really should do something about that too -- I bet those transactions are really unecessary)

Nope, I was wrong!

        if create_flag {
            // instantiate!
            StacksChainState::instantiate_db(mainnet, chain_id, index_path, true)
        } else {
            let mut marf = StacksChainState::open_index(index_path)?;
            if !Self::need_schema_migrations(marf.sqlite_conn(), mainnet, chain_id)? {
                return Ok(marf);
            }

            // need a migration
            let tx = marf.storage_tx()?;
            StacksChainState::apply_schema_migrations(&tx, mainnet, chain_id)?;
            StacksChainState::add_indexes(&tx)?;
            tx.commit()?;

Will add a schema version.

blockstack-devops commented 2 weeks ago

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.