Skip to content

Commit 2d4cd71

Browse files
committed
No fetch when in cache
1 parent d245558 commit 2d4cd71

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

block/internal/da/async_block_retriever.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,17 @@ func (f *asyncBlockRetriever) HandleEvent(ctx context.Context, ev datypes.Subscr
183183

184184
// HandleCatchup fetches a single height via Retrieve and caches it.
185185
// Also applies the prefetch window for speculative forward fetching.
186-
func (f *asyncBlockRetriever) HandleCatchup(ctx context.Context, height uint64) error {
187-
f.fetchAndCacheBlock(ctx, height)
188-
186+
func (f *asyncBlockRetriever) HandleCatchup(ctx context.Context, daHeight uint64) error {
187+
if _, err := f.cache.Get(ctx, newBlockDataKey(daHeight)); err != nil {
188+
f.fetchAndCacheBlock(ctx, daHeight)
189+
}
189190
// Speculatively prefetch ahead.
190-
target := height + f.prefetchWindow
191-
for h := height + 1; h <= target; h++ {
191+
target := daHeight + f.prefetchWindow
192+
for h := daHeight + 1; h <= target; h++ {
192193
if err := ctx.Err(); err != nil {
193194
return err
194195
}
195-
key := newBlockDataKey(h)
196-
if _, err := f.cache.Get(ctx, key); err == nil {
196+
if _, err := f.cache.Get(ctx, newBlockDataKey(h)); err == nil {
197197
continue // Already cached.
198198
}
199199
f.fetchAndCacheBlock(ctx, h)
@@ -202,10 +202,6 @@ func (f *asyncBlockRetriever) HandleCatchup(ctx context.Context, height uint64)
202202
return nil
203203
}
204204

205-
// ---------------------------------------------------------------------------
206-
// Cache helpers
207-
// ---------------------------------------------------------------------------
208-
209205
// fetchAndCacheBlock fetches a block via Retrieve and caches it.
210206
func (f *asyncBlockRetriever) fetchAndCacheBlock(ctx context.Context, height uint64) {
211207
f.logger.Debug().Uint64("height", height).Msg("prefetching block")

block/internal/da/subscriber.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (s *Subscriber) runSubscription(ctx context.Context) error {
199199
local := s.localDAHeight.Load()
200200
isInline := ev.Height == local && s.localDAHeight.CompareAndSwap(local, local+1)
201201

202-
err = s.handler.HandleEvent(ctx, ev, isInline)
202+
err = s.handler.HandleEvent(subCtx, ev, isInline)
203203
if isInline {
204204
if err == nil {
205205
s.headReached.Store(true)

0 commit comments

Comments
 (0)