From 1cd62a274c1471a67d8b6635fb9b2012fd9a9d2c Mon Sep 17 00:00:00 2001 From: Oleg Kovalov Date: Thu, 23 May 2024 16:23:28 +0200 Subject: [PATCH] fix(store): make heightIndexer.IndexTo as a func --- store/height_indexer.go | 12 ------------ store/store.go | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/store/height_indexer.go b/store/height_indexer.go index bd534dc4..f769d87e 100644 --- a/store/height_indexer.go +++ b/store/height_indexer.go @@ -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 -} diff --git a/store/store.go b/store/store.go index 1e958672..27b10496 100644 --- a/store/store.go +++ b/store/store.go @@ -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 } @@ -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 +}