Skip to content

Commit

Permalink
fix(store): stop doing header verification in GetRangeByHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed May 22, 2024
1 parent 88c5b8c commit 93ecf62
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
8 changes: 0 additions & 8 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,6 @@ func (s *Store[H]) GetRangeByHeight(
if err != nil {
return nil, err
}

for _, h := range headers {
err := from.Verify(h)
if err != nil {
return nil, err
}
from = h
}
return headers, nil
}

Expand Down
26 changes: 24 additions & 2 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,29 @@ func TestStore_GetRangeByHeight_ExpectedRange(t *testing.T) {
assert.Equal(t, lastHeaderInRangeHeight, out[len(out)-1].Height())
}

func TestStore_Append_BadHeader(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
t.Cleanup(cancel)

suite := headertest.NewTestSuite(t)

ds := sync.MutexWrap(datastore.NewMapDatastore())
store, err := NewStoreWithHead(ctx, ds, suite.Head())
require.NoError(t, err)

err = store.Start(ctx)
require.NoError(t, err)

head, err := store.Head(ctx)
require.NoError(t, err)
assert.EqualValues(t, suite.Head().Hash(), head.Hash())

in := suite.GenDummyHeaders(10)
in[0].VerifyFailure = true
err = store.Append(ctx, in...)
require.Error(t, err)
}

// TestStore_GetRange tests possible combinations of requests and ensures that
// the store can handle them adequately (even malformed requests)
func TestStore_GetRange(t *testing.T) {
Expand All @@ -159,7 +182,7 @@ func TestStore_GetRange(t *testing.T) {
err = store.Append(ctx, in...)
require.NoError(t, err)

var tests = []struct {
tests := []struct {
name string
from uint64
to uint64
Expand Down Expand Up @@ -212,7 +235,6 @@ func TestStore_GetRange(t *testing.T) {
assert.Equal(t, lastHeaderInRangeHeight, out[len(out)-1].Height())
})
}

}

func TestStorePendingCacheMiss(t *testing.T) {
Expand Down

0 comments on commit 93ecf62

Please sign in to comment.