Skip to content

Commit f860043

Browse files
committed
align
1 parent e77ca1d commit f860043

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

block/internal/submitting/submitter.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ func (s *Submitter) processDAInclusionLoop() {
219219

220220
// Set final height in executor
221221
if err := s.setFinalWithRetry(nextHeight, header.Height()); err != nil {
222+
s.sendCriticalError(fmt.Errorf("failed to set final height: %w", err))
222223
s.logger.Error().Err(err).Uint64("height", nextHeight).Msg("failed to set final height")
223224
break
224225
}
@@ -243,9 +244,7 @@ func (s *Submitter) setFinalWithRetry(nextHeight uint64, headerHeight uint64) er
243244
for attempt := 1; attempt <= common.MaxRetriesBeforeHalt; attempt++ {
244245
if err := s.exec.SetFinal(s.ctx, nextHeight); err != nil {
245246
if attempt == common.MaxRetriesBeforeHalt {
246-
err = fmt.Errorf("failed to set final height after %d attempts: %w", attempt, err)
247-
s.sendCriticalError(err)
248-
return err
247+
return fmt.Errorf("failed to set final height after %d attempts: %w", attempt, err)
249248
}
250249

251250
s.logger.Error().Err(err).

block/internal/syncing/syncer.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -482,19 +482,11 @@ func (s *Syncer) applyBlock(header types.Header, data *types.Data, currentState
482482

483483
// Execute transactions
484484
ctx := context.WithValue(s.ctx, types.HeaderContextKey, header)
485-
newAppHash, _, err := s.exec.ExecuteTxs(ctx, rawTxs, header.Height(),
486-
header.Time(), currentState.AppHash)
485+
newAppHash, err := s.executeTxsWithRetry(ctx, rawTxs, header, currentState)
487486
if err != nil {
488-
s.retriesBeforeHalt[header.Height()]++
489-
if s.retriesBeforeHalt[header.Height()] > common.MaxRetriesBeforeHalt {
490-
s.sendCriticalError(fmt.Errorf("failed to execute transactions: %w", err))
491-
return types.State{}, fmt.Errorf("failed to execute transactions: %w", err)
492-
}
493-
494-
time.Sleep(common.MaxRetriesTimeout) // sleep before retrying
495-
return types.State{}, fmt.Errorf("failed to execute transactions (retry %d / %d): %w", s.retriesBeforeHalt[header.Height()], common.MaxRetriesBeforeHalt, err)
487+
s.sendCriticalError(fmt.Errorf("failed to execute transactions: %w", err))
488+
return types.State{}, fmt.Errorf("failed to execute transactions: %w", err)
496489
}
497-
delete(s.retriesBeforeHalt, header.Height())
498490

499491
// Create new state
500492
newState, err := currentState.NextState(header, newAppHash)
@@ -505,6 +497,31 @@ func (s *Syncer) applyBlock(header types.Header, data *types.Data, currentState
505497
return newState, nil
506498
}
507499

500+
// executeTxsWithRetry executes transactions with retry logic
501+
func (s *Syncer) executeTxsWithRetry(ctx context.Context, rawTxs [][]byte, header types.Header, currentState types.State) ([]byte, error) {
502+
for attempt := 1; attempt <= common.MaxRetriesBeforeHalt; attempt++ {
503+
newAppHash, _, err := s.exec.ExecuteTxs(ctx, rawTxs, header.Height(), header.Time(), currentState.AppHash)
504+
if err != nil {
505+
if attempt == common.MaxRetriesBeforeHalt {
506+
return nil, fmt.Errorf("failed to execute transactions: %w", err)
507+
}
508+
509+
s.logger.Error().Err(err).
510+
Int("attempt", attempt).
511+
Int("max_attempts", common.MaxRetriesBeforeHalt).
512+
Uint64("height", header.Height()).
513+
Msg("failed to execute transactions, retrying")
514+
515+
time.Sleep(common.MaxRetriesTimeout)
516+
continue
517+
}
518+
519+
return newAppHash, nil
520+
}
521+
522+
return nil, nil
523+
}
524+
508525
// validateBlock validates a synced block
509526
func (s *Syncer) validateBlock(
510527
lastState types.State,

0 commit comments

Comments
 (0)