Skip to content

Commit c50cb0f

Browse files
committed
use backoff system for all errors
1 parent 14f597b commit c50cb0f

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

block/internal/syncing/syncer.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,13 @@ func (s *Syncer) syncLoop() {
246246
lastHeaderHeight := initialHeight
247247
lastDataHeight := initialHeight
248248

249-
// Backoff control when DA replies with height-from-future
249+
// Backoff control when DA replies with errors
250250
var hffDelay time.Duration
251251
var nextDARequestAt time.Time
252252

253253
blockTicker := time.NewTicker(s.config.Node.BlockTime.Duration)
254254
defer blockTicker.Stop()
255255

256-
// TODO: we should request to see what the head of the chain is at
257-
// then we know if we are falling behind or in sync mode
258256
for {
259257
select {
260258
case <-s.ctx.Done():
@@ -268,23 +266,26 @@ func (s *Syncer) syncLoop() {
268266
// Respect backoff window if set
269267
if nextDARequestAt.IsZero() || now.After(nextDARequestAt) || now.Equal(nextDARequestAt) {
270268
// Retrieve from DA as fast as possible (unless throttled by HFF)
269+
// DaHeight is only increased on successful retrieval, it will retry on failure at the next iteration
271270
events, err := s.daRetriever.RetrieveFromDA(s.ctx, s.GetDAHeight())
272271
if err != nil {
273-
if s.isHeightFromFutureError(err) {
272+
if errors.Is(err, coreda.ErrBlobNotFound) {
273+
// no data at this height, increase DA height
274+
// we do still want to check p2p
275+
s.SetDAHeight(s.GetDAHeight() + 1)
276+
} else {
274277
// Back off exactly by DA block time to avoid overloading
275278
hffDelay = s.config.DA.BlockTime.Duration
276279
if hffDelay <= 0 {
277280
hffDelay = 2 * time.Second
278281
}
279-
s.logger.Debug().Dur("delay", hffDelay).Uint64("da_height", s.GetDAHeight()).Msg("height from future; backing off DA requests")
280282
nextDARequestAt = now.Add(hffDelay)
281-
} else if errors.Is(err, coreda.ErrBlobNotFound) {
282-
// no data at this height, increase DA height
283-
s.SetDAHeight(s.GetDAHeight() + 1)
284-
} else {
285-
// Non-HFF errors: do not backoff artificially
286-
nextDARequestAt = time.Time{}
287-
s.logger.Error().Err(err).Msg("failed to retrieve from DA")
283+
284+
if s.isHeightFromFutureError(err) {
285+
s.logger.Debug().Dur("delay", hffDelay).Uint64("da_height", s.GetDAHeight()).Msg("height from future; backing off DA requests")
286+
} else {
287+
s.logger.Error().Err(err).Dur("delay", hffDelay).Uint64("da_height", s.GetDAHeight()).Msg("failed to retrieve from DA; backing off DA requests")
288+
}
288289
}
289290
} else {
290291
// Reset backoff on success
@@ -301,7 +302,7 @@ func (s *Syncer) syncLoop() {
301302

302303
// increment DA height on successful retrieval and continue immediately
303304
s.SetDAHeight(s.GetDAHeight() + 1)
304-
continue
305+
continue // event sent, no need to check p2p
305306
}
306307
}
307308

0 commit comments

Comments
 (0)