Skip to content

Commit f06b381

Browse files
fix: take care of the case where the requested height is above the head of latest da block height (#90)
* Return an err `no blob at a given height` in case there is no blob * Fix lint * Silly way of checking error for proxy test * Add logic to check for the requested height * Fix test * Fix test
1 parent 67c3cff commit f06b381

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

test/dummy.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
// DefaultMaxBlobSize is the default max blob size
1717
const DefaultMaxBlobSize = 64 * 64 * 482
1818

19-
// ErrNoBlobAtHeight is returned when there is no blob at given height.
20-
var ErrNoBlobAtHeight = errors.New("no blob at given height")
19+
// ErrTooHigh is returned when requested height is to high
20+
var ErrTooHigh = errors.New("given height is from the future")
2121

2222
// DummyDA is a simple implementation of in-memory DA. Not production ready! Intended only for testing!
2323
//
@@ -85,10 +85,16 @@ func (d *DummyDA) Get(ctx context.Context, ids []da.ID, _ da.Namespace) ([]da.Bl
8585
func (d *DummyDA) GetIDs(ctx context.Context, height uint64, _ da.Namespace) ([]da.ID, error) {
8686
d.mu.Lock()
8787
defer d.mu.Unlock()
88+
89+
if height > d.height {
90+
return nil, ErrTooHigh
91+
}
92+
8893
kvps, ok := d.data[height]
8994
if !ok {
90-
return nil, ErrNoBlobAtHeight
95+
return nil, nil
9196
}
97+
9298
ids := make([]da.ID, len(kvps))
9399
for i, kv := range kvps {
94100
ids[i] = kv.key

test/test_suite.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package test
33
import (
44
"bytes"
55
"context"
6-
"strings"
76
"sync"
87
"testing"
98
"time"
@@ -29,8 +28,8 @@ func RunDATestSuite(t *testing.T, d da.DA) {
2928
t.Run("Concurrent read/write test", func(t *testing.T) {
3029
ConcurrentReadWriteTest(t, d)
3130
})
32-
t.Run("No blobs at a given height", func(t *testing.T) {
33-
NoBlobsAtHeightTest(t, d)
31+
t.Run("Given height is from the future", func(t *testing.T) {
32+
HeightFromFutureTest(t, d)
3433
})
3534
}
3635

@@ -138,28 +137,27 @@ func ConcurrentReadWriteTest(t *testing.T, d da.DA) {
138137
defer wg.Done()
139138
for i := uint64(1); i <= 100; i++ {
140139
_, err := d.GetIDs(ctx, i, []byte{})
141-
if err != nil && !strings.Contains(err.Error(), ErrNoBlobAtHeight.Error()) {
142-
assert.NoError(t, err)
140+
if err != nil {
141+
assert.Equal(t, err.Error(), ErrTooHigh.Error())
143142
}
144143
}
145144
}()
146145

147146
go func() {
148147
defer wg.Done()
149148
for i := uint64(1); i <= 100; i++ {
150-
_, err := d.Submit(ctx, [][]byte{[]byte("test")}, 0, testNamespace)
149+
_, err := d.Submit(ctx, [][]byte{[]byte("test")}, 0, []byte{})
151150
assert.NoError(t, err)
152151
}
153152
}()
154153

155154
wg.Wait()
156155
}
157156

158-
// NoBlobsAtHeightTest tests the case when there are no blobs at a given height in DA
159-
func NoBlobsAtHeightTest(t *testing.T, d da.DA) {
157+
// HeightFromFutureTest tests the case when the given height is from the future
158+
func HeightFromFutureTest(t *testing.T, d da.DA) {
160159
ctx := context.TODO()
161-
// GetIDs should return ErrNoBlobAtHeight when there are no blobs at a given height
162-
_, err := d.GetIDs(ctx, 999999999, []byte{})
160+
ids, err := d.GetIDs(ctx, 999999999, []byte{})
163161
assert.Error(t, err)
164-
assert.ErrorContains(t, err, ErrNoBlobAtHeight.Error())
162+
assert.Nil(t, ids)
165163
}

0 commit comments

Comments
 (0)