Skip to content

Commit 42060b2

Browse files
authored
fix(store): make heightIndexer.IndexTo as a func (#182)
1 parent 9979590 commit 42060b2

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

store/height_indexer.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,3 @@ func (hi *heightIndexer[H]) HashByHeight(ctx context.Context, h uint64) (header.
4444
hi.cache.Add(h, header.Hash(val))
4545
return val, nil
4646
}
47-
48-
// IndexTo saves mapping between header Height and Hash to the given batch.
49-
func (hi *heightIndexer[H]) IndexTo(ctx context.Context, batch datastore.Batch, headers ...H) error {
50-
for _, h := range headers {
51-
err := batch.Put(ctx, heightKey(h.Height()), h.Hash())
52-
if err != nil {
53-
return err
54-
}
55-
}
56-
57-
return nil
58-
}

store/store.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,7 @@ func (s *Store[H]) flush(ctx context.Context, headers ...H) error {
476476
}
477477

478478
// write height indexes for headers as well
479-
err = s.heightIndex.IndexTo(ctx, batch, headers...)
480-
if err != nil {
479+
if err := indexTo(ctx, batch, headers...); err != nil {
481480
return err
482481
}
483482

@@ -516,3 +515,14 @@ func (s *Store[H]) get(ctx context.Context, hash header.Hash) ([]byte, error) {
516515
s.metrics.readSingle(ctx, time.Since(startTime), false)
517516
return data, nil
518517
}
518+
519+
// indexTo saves mapping between header Height and Hash to the given batch.
520+
func indexTo[H header.Header[H]](ctx context.Context, batch datastore.Batch, headers ...H) error {
521+
for _, h := range headers {
522+
err := batch.Put(ctx, heightKey(h.Height()), h.Hash())
523+
if err != nil {
524+
return err
525+
}
526+
}
527+
return nil
528+
}

0 commit comments

Comments
 (0)