@@ -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
509526func (s * Syncer ) validateBlock (
510527 lastState types.State ,
0 commit comments