Skip to content

feat(chain): add ChainState::open() for load-or-create#925

Open
Sandipmandal25 wants to merge 1 commit intogetfloresta:masterfrom
Sandipmandal25:fix/chain-state-open
Open

feat(chain): add ChainState::open() for load-or-create#925
Sandipmandal25 wants to merge 1 commit intogetfloresta:masterfrom
Sandipmandal25:fix/chain-state-open

Conversation

@Sandipmandal25
Copy link
Copy Markdown

@Sandipmandal25 Sandipmandal25 commented Apr 2, 2026

Description and Notes

Closes #911.

ChainState::new() does not check whether the underlying store is already populated. As a result, calling it on an existing store resets the chain to genesis (height 0).

This change introduces ChainState::open(), which:

  • Attempts load_chain_state first
  • Falls back to new() only if the store is empty (ChainNotInitialized)
  • Propagates all other errors unchanged

To keep the API generic over different ChainStore implementations, the method accepts a factory closure instead of a FlatChainStoreConfig. The existing BlockchainError: From<E> bound already covers all DatabaseError implementors via the blanket implementation.

On the caller side:

  • florestad::load_chain_state and the load_chain_store helper are replaced with a single ChainState::open() call
  • The unused CouldNotCreateFlatChainStore error variant is removed

How to verify

cargo test -p floresta-chain --features flat-chainstore open_resumes_existing_chain_state

image stopped at height 16001, restarted, loaded at height 18000.

@jaoleal jaoleal self-requested a review April 2, 2026 16:29
@moisesPompilio moisesPompilio added reliability Related to runtime reliability, stability and production readiness and removed reliability Related to runtime reliability, stability and production readiness labels Apr 2, 2026
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.

[chain] ChainStore::new won't check if the FlatChainStore is already populated

2 participants