Skip to content

Commit

Permalink
fix(store/commitment/iavl): honor tree.Remove error firstly
Browse files Browse the repository at this point in the history
Previously the check was if !res and then it would return
the error below but that has a consequence of ignoring/swallowing
up the error returned by (*iavl.MutableTree).Remove. Even more is
the fact that when !res, an error occurred and it could be anything
else, thus checking against the error firstly ensures that we only
return a synthesized error when we are certain the key wasn't in the tree.

Fixes #18650
  • Loading branch information
odeke-em committed Dec 8, 2023
1 parent f6df368 commit 2ee2063
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion store/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* [#16588](https://github.com/cosmos/cosmos-sdk/pull/16588) Propogate the Snapshotter's failure to the caller, (it will create a empty snapshot silently before).
* [#18651](https://github.com/cosmos/cosmos-sdk/pull/18651) Propagate iavl.MutableTree.Remove errors firstly to the caller instead of returning a synthesized error firstly.
* [#16588](https://github.com/cosmos/cosmos-sdk/pull/16588) Propagate the Snapshotter's failure to the caller, (it will create a empty snapshot silently before).

## [v0.1.0-alpha.1](https://github.com/cosmos/cosmos-sdk/releases/tag/store%2Fv0.1.0-alpha.1) - 2023-03-17

Expand Down
5 changes: 4 additions & 1 deletion store/commitment/iavl/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ func NewIavlTree(db dbm.DB, logger log.Logger, cfg *Config) *IavlTree {
// Remove removes the given key from the tree.
func (t *IavlTree) Remove(key []byte) error {
_, res, err := t.tree.Remove(key)
if err != nil {
return err
}
if !res {
return fmt.Errorf("key %x not found", key)
}
return err
return nil
}

// Set sets the given key-value pair in the tree.
Expand Down

0 comments on commit 2ee2063

Please sign in to comment.