@@ -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.
210206func (f * asyncBlockRetriever ) fetchAndCacheBlock (ctx context.Context , height uint64 ) {
211207 f .logger .Debug ().Uint64 ("height" , height ).Msg ("prefetching block" )
0 commit comments