Skip to content

Commit fa9a03f

Browse files
authored
refactor(syncing): go through all cache first (#2709)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview Follow-up of #2702. Optimistically fetch from cache first before checking da. <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> -->
1 parent 8365d41 commit fa9a03f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

block/internal/syncing/syncer.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ func (s *Syncer) isHeightFromFutureError(err error) bool {
550550
}
551551

552552
// processPendingEvents fetches and processes pending events from cache
553+
// optimistically fetches the next events from cache until no matching heights are found
553554
func (s *Syncer) processPendingEvents() {
554555
currentHeight, err := s.store.Height(s.ctx)
555556
if err != nil {
@@ -559,7 +560,12 @@ func (s *Syncer) processPendingEvents() {
559560

560561
// Try to get the next processable event (currentHeight + 1)
561562
nextHeight := currentHeight + 1
562-
if event := s.cache.GetNextPendingEvent(nextHeight); event != nil {
563+
for {
564+
event := s.cache.GetNextPendingEvent(nextHeight)
565+
if event == nil {
566+
return
567+
}
568+
563569
heightEvent := common.DAHeightEvent{
564570
Header: event.Header,
565571
Data: event.Data,
@@ -573,8 +579,12 @@ func (s *Syncer) processPendingEvents() {
573579
s.logger.Debug().Uint64("height", nextHeight).Msg("sent pending event to processing")
574580
case <-s.ctx.Done():
575581
s.cache.SetPendingEvent(nextHeight, event)
582+
return
576583
default:
577584
s.cache.SetPendingEvent(nextHeight, event)
585+
return
578586
}
587+
588+
nextHeight++
579589
}
580590
}

0 commit comments

Comments
 (0)