Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(store): stop doing header verification in GetRangeByHeight #180

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
cristaloleg marked this conversation as resolved.
Show resolved Hide resolved
}

// 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
Loading