Skip to content

Commit

Permalink
fix(store): make heightIndexer.IndexTo as a func
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed May 23, 2024
1 parent 9979590 commit 1cd62a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
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
}

0 comments on commit 1cd62a2

Please sign in to comment.