Skip to content

Commit e77ca1d

Browse files
committed
improve
1 parent 40a5958 commit e77ca1d

1 file changed

Lines changed: 43 additions & 29 deletions

File tree

block/internal/submitting/submitter.go

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ type Submitter struct {
5959
logger zerolog.Logger
6060

6161
// Lifecycle
62-
ctx context.Context
63-
cancel context.CancelFunc
64-
wg sync.WaitGroup
65-
retriesBeforeHalt map[uint64]uint64
62+
ctx context.Context
63+
cancel context.CancelFunc
64+
wg sync.WaitGroup
6665
}
6766

6867
// NewSubmitter creates a new DA submitter component
@@ -79,18 +78,17 @@ func NewSubmitter(
7978
errorCh chan<- error,
8079
) *Submitter {
8180
return &Submitter{
82-
store: store,
83-
exec: exec,
84-
cache: cache,
85-
metrics: metrics,
86-
config: config,
87-
genesis: genesis,
88-
daSubmitter: daSubmitter,
89-
signer: signer,
90-
daStateMtx: &sync.RWMutex{},
91-
errorCh: errorCh,
92-
logger: logger.With().Str("component", "submitter").Logger(),
93-
retriesBeforeHalt: make(map[uint64]uint64),
81+
store: store,
82+
exec: exec,
83+
cache: cache,
84+
metrics: metrics,
85+
config: config,
86+
genesis: genesis,
87+
daSubmitter: daSubmitter,
88+
signer: signer,
89+
daStateMtx: &sync.RWMutex{},
90+
errorCh: errorCh,
91+
logger: logger.With().Str("component", "submitter").Logger(),
9492
}
9593
}
9694

@@ -219,21 +217,11 @@ func (s *Submitter) processDAInclusionLoop() {
219217
break
220218
}
221219

222-
retry:
223220
// Set final height in executor
224-
if err := s.exec.SetFinal(s.ctx, nextHeight); err != nil {
225-
s.retriesBeforeHalt[header.Height()]++
226-
if s.retriesBeforeHalt[header.Height()] > common.MaxRetriesBeforeHalt {
227-
s.sendCriticalError(fmt.Errorf("failed to set final height: %w", err))
228-
s.logger.Error().Err(err).Uint64("height", nextHeight).Msg("failed to set final height")
229-
return
230-
}
231-
232-
time.Sleep(common.MaxRetriesTimeout) // sleep before retrying
233-
s.logger.Error().Err(err).Msgf("failed to set final height (retry %d / %d): %w", s.retriesBeforeHalt[header.Height()], common.MaxRetriesBeforeHalt, err)
234-
goto retry
221+
if err := s.setFinalWithRetry(nextHeight, header.Height()); err != nil {
222+
s.logger.Error().Err(err).Uint64("height", nextHeight).Msg("failed to set final height")
223+
break
235224
}
236-
delete(s.retriesBeforeHalt, header.Height())
237225

238226
// Update DA included height
239227
s.SetDAIncludedHeight(nextHeight)
@@ -250,6 +238,32 @@ func (s *Submitter) processDAInclusionLoop() {
250238
}
251239
}
252240

241+
// setFinalWithRetry sets the final height in executor with retry logic
242+
func (s *Submitter) setFinalWithRetry(nextHeight uint64, headerHeight uint64) error {
243+
for attempt := 1; attempt <= common.MaxRetriesBeforeHalt; attempt++ {
244+
if err := s.exec.SetFinal(s.ctx, nextHeight); err != nil {
245+
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
249+
}
250+
251+
s.logger.Error().Err(err).
252+
Int("attempt", attempt).
253+
Int("max_attempts", common.MaxRetriesBeforeHalt).
254+
Uint64("height", nextHeight).
255+
Msg("failed to set final height, retrying")
256+
257+
time.Sleep(common.MaxRetriesTimeout)
258+
continue
259+
}
260+
261+
return nil
262+
}
263+
264+
return nil
265+
}
266+
253267
// GetDAIncludedHeight returns the DA included height
254268
func (s *Submitter) GetDAIncludedHeight() uint64 {
255269
s.daStateMtx.RLock()

0 commit comments

Comments
 (0)