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): make heightIndexer.IndexTo as a func #182

Merged
merged 1 commit 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
12 changes: 0 additions & 12 deletions store/height_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,3 @@ func (hi *heightIndexer[H]) HashByHeight(ctx context.Context, h uint64) (header.
hi.cache.Add(h, header.Hash(val))
return val, nil
}

// IndexTo saves mapping between header Height and Hash to the given batch.
func (hi *heightIndexer[H]) IndexTo(ctx context.Context, batch datastore.Batch, headers ...H) error {
for _, h := range headers {
err := batch.Put(ctx, heightKey(h.Height()), h.Hash())
if err != nil {
return err
}
}

return nil
}
14 changes: 12 additions & 2 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ func (s *Store[H]) flush(ctx context.Context, headers ...H) error {
}

// write height indexes for headers as well
err = s.heightIndex.IndexTo(ctx, batch, headers...)
if err != nil {
if err := indexTo(ctx, batch, headers...); err != nil {
return err
}

Expand Down Expand Up @@ -516,3 +515,14 @@ func (s *Store[H]) get(ctx context.Context, hash header.Hash) ([]byte, error) {
s.metrics.readSingle(ctx, time.Since(startTime), false)
return data, nil
}

// indexTo saves mapping between header Height and Hash to the given batch.
func indexTo[H header.Header[H]](ctx context.Context, batch datastore.Batch, headers ...H) error {
for _, h := range headers {
err := batch.Put(ctx, heightKey(h.Height()), h.Hash())
if err != nil {
return err
}
}
return nil
}
Loading