Skip to content

Commit

Permalink
fix: Handle empty tree lookup gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
Eengineer1 committed Mar 28, 2024
1 parent 70a3ce5 commit 6a08817
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ func UnsafeNewStore(tree *iavl.MutableTree) *Store {
// Any mutable operations executed will result in a panic.
func (st *Store) GetImmutable(version int64) (*Store, error) {
if !st.VersionExists(version) {
return nil, fmt.Errorf("version mismatch on immutable IAVL tree; version does not exist. Version has either been pruned, or is for a future block height")
// CONTRACT: If the version does not exist, return an empty immutable IAVL tree
// This is to prevent panics when querying or iterating over the store
/* return nil, fmt.Errorf("version mismatch on immutable IAVL tree; version does not exist. Version has either been pruned, or is for a future block height") */
return &Store{tree: &immutableTree{&iavl.ImmutableTree{}}}, nil
}

iTree, err := st.tree.GetImmutable(version)
Expand Down

0 comments on commit 6a08817

Please sign in to comment.