Skip to content

Commit 5b16aa2

Browse files
committed
fixes
1 parent 689f21a commit 5b16aa2

1 file changed

Lines changed: 5 additions & 21 deletions

File tree

pkg/store/store.go

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func (s *DefaultStore) Rollback(ctx context.Context, height uint64, aggregator b
277277
}
278278

279279
if currentHeight <= height {
280-
return nil
280+
return fmt.Errorf("current height %d is already less than or equal to rollback height %d", currentHeight, height)
281281
}
282282

283283
daIncludedHeightBz, err := s.GetMetadata(ctx, DAIncludedHeightKey)
@@ -322,6 +322,10 @@ func (s *DefaultStore) Rollback(ctx context.Context, height uint64, aggregator b
322322
return fmt.Errorf("failed to delete index key in batch: %w", err)
323323
}
324324

325+
if err := batch.Delete(ctx, ds.NewKey(getStateAtHeightKey(currentHeight))); err != nil {
326+
return fmt.Errorf("failed to delete header blob in batch: %w", err)
327+
}
328+
325329
currentHeight--
326330
}
327331

@@ -332,26 +336,6 @@ func (s *DefaultStore) Rollback(ctx context.Context, height uint64, aggregator b
332336
return fmt.Errorf("failed to set height: %w", err)
333337
}
334338

335-
targetState, err := s.GetStateAtHeight(ctx, height)
336-
if err != nil {
337-
return fmt.Errorf("failed to get state at height %d: %w", height, err)
338-
}
339-
340-
// update state manually to keep using the batch
341-
pbState, err := targetState.ToProto()
342-
if err != nil {
343-
return fmt.Errorf("failed to convert type state to protobuf type: %w", err)
344-
}
345-
346-
data, err := proto.Marshal(pbState)
347-
if err != nil {
348-
return fmt.Errorf("failed to marshal state to protobuf: %w", err)
349-
}
350-
351-
if err := batch.Put(ctx, ds.NewKey(getStateAtHeightKey(height)), data); err != nil {
352-
return fmt.Errorf("failed to set state at height %d: %w", height, err)
353-
}
354-
355339
if err := batch.Commit(ctx); err != nil {
356340
return fmt.Errorf("failed to commit batch: %w", err)
357341
}

0 commit comments

Comments
 (0)