diff --git a/libs/iavl/nodedb.go b/libs/iavl/nodedb.go index 16b18f3b56..a9c4d8a350 100644 --- a/libs/iavl/nodedb.go +++ b/libs/iavl/nodedb.go @@ -648,17 +648,12 @@ func (ndb *nodeDB) deleteOrphansFromDB(version int64) { // TODO optimize. ndb.traverseOrphansVersion(version, func(key, hash []byte) { var fromVersion, toVersion int64 + var err error // See comment on `orphanKeyFmt`. Note that here, `version` and // `toVersion` are always equal. orphanKeyFormat.Scan(key, &toVersion, &fromVersion) - // Delete orphan key and reverse-lookup key. - err := ndb.db.Delete(key) - if err != nil { - panic(err) - } - // If there is no predecessor, or the predecessor is earlier than the // beginning of the lifetime (ie: negative lifetime), or the lifetime // spans a single version and that version is the one being deleted, we @@ -679,6 +674,12 @@ func (ndb *nodeDB) deleteOrphansFromDB(version int64) { panic(err) } } + + // Delete orphan key and reverse-lookup key. + err = ndb.db.Delete(key) + if err != nil { + panic(err) + } }) }