diff --git a/db/db.go b/db/db.go index e6412c0..9b3bf98 100644 --- a/db/db.go +++ b/db/db.go @@ -140,7 +140,11 @@ func (db *OperationDB) Flush(ctx context.Context, cursor *sink.Cursor) (count in func (db *OperationDB) PurgeUndoOperations(ctx context.Context, finalBlockHeight uint64) error { keys := make([][]byte, 0) - scanOutput := db.store.Scan(ctx, undoKey(finalBlockHeight), undoKey(finalBlockHeight-1000), 0) + if finalBlockHeight < 200 { + return nil + } + + scanOutput := db.store.Scan(ctx, undoKey(finalBlockHeight), undoKey(finalBlockHeight-200), 0) if scanOutput.Err() != nil { return fmt.Errorf("scanning undo operations for block %d: %w", finalBlockHeight, scanOutput.Err()) diff --git a/db/db_test.go b/db/db_test.go index c0a82e6..c9cc6e4 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -57,7 +57,7 @@ func TestDB_HandleOperations(t *testing.T) { name: "undo deletion", blocks: []blockOperations{ { - blockNumber: 1, + blockNumber: 200, operations: &pbkv.KVOperations{ Operations: []*pbkv.KVOperation{ { @@ -67,10 +67,10 @@ func TestDB_HandleOperations(t *testing.T) { }, }, }, - finalBlockHeight: 1, + finalBlockHeight: 200, }, { - blockNumber: 2, + blockNumber: 201, operations: &pbkv.KVOperations{ Operations: []*pbkv.KVOperation{ { @@ -80,10 +80,10 @@ func TestDB_HandleOperations(t *testing.T) { }, }, }, - finalBlockHeight: 1, + finalBlockHeight: 200, }, { - blockNumber: 3, + blockNumber: 202, operations: &pbkv.KVOperations{ Operations: []*pbkv.KVOperation{ { @@ -93,10 +93,10 @@ func TestDB_HandleOperations(t *testing.T) { }, }, }, - finalBlockHeight: 1, + finalBlockHeight: 200, }, }, - expectedRemainingKey: [][]byte{userKey("key.1"), userKey("key.2"), userKey("key.3"), []byte("xc"), undoKey(3), undoKey(2)}, + expectedRemainingKey: [][]byte{userKey("key.1"), userKey("key.2"), userKey("key.3"), []byte("xc"), undoKey(202), undoKey(201)}, }, }