diff --git a/CHANGELOG.md b/CHANGELOG.md index 436e07b1c..652c37db2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Improvements + +- [#483](https://github.com/cosmos/iavl/pull/483) Allow delete latest version. + ## 0.18.0 (March 10, 2022) ### Breaking Changes diff --git a/mutable_tree.go b/mutable_tree.go index 496aa4293..74a28cf81 100644 --- a/mutable_tree.go +++ b/mutable_tree.go @@ -566,13 +566,10 @@ func (tree *MutableTree) deleteVersion(version int64) error { if version <= 0 { return errors.New("version must be greater than 0") } - if version == tree.version { - return errors.Errorf("cannot delete latest saved version (%d)", version) - } if !tree.VersionExists(version) { return errors.Wrap(ErrVersionDoesNotExist, "") } - if err := tree.ndb.DeleteVersion(version, true); err != nil { + if err := tree.ndb.DeleteVersion(version, false); err != nil { return err } diff --git a/nodedb.go b/nodedb.go index d1313ab5d..5c057b736 100644 --- a/nodedb.go +++ b/nodedb.go @@ -281,8 +281,8 @@ func (ndb *nodeDB) DeleteVersionsRange(fromVersion, toVersion int64) error { defer ndb.mtx.Unlock() latest := ndb.getLatestVersion() - if latest < toVersion { - return errors.Errorf("cannot delete latest saved version (%d)", latest) + if latest+1 < toVersion { + return errors.Errorf("cannot delete future versions [%d..%d)", latest+1, toVersion) } predecessor := ndb.getPreviousVersion(fromVersion)