@@ -103,6 +103,7 @@ func (s *Submitter) Start(ctx context.Context) error {
103103
104104 // Start DA submission loop if signer is available (aggregator nodes only)
105105 if s .signer != nil {
106+ s .logger .Info ().Msg ("starting DA submission loop" )
106107 s .wg .Add (1 )
107108 go func () {
108109 defer s .wg .Done ()
@@ -113,7 +114,14 @@ func (s *Submitter) Start(ctx context.Context) error {
113114 // Start DA inclusion processing loop (both sync and aggregator nodes)
114115 s .wg .Add (1 )
115116 go func () {
116- defer s .wg .Done ()
117+ defer func () {
118+ // fetch all from DA to ensure final height is set
119+ // todo: revisit this for a graceful shutdown scenario
120+ tCtx , cancelFunc := context .WithTimeout (context .Background (), 2 * time .Second )
121+ defer cancelFunc ()
122+ s .processAllFromDA (tCtx )
123+ s .wg .Done ()
124+ }()
117125 s .processDAInclusionLoop ()
118126 }()
119127
@@ -193,48 +201,63 @@ func (s *Submitter) processDAInclusionLoop() {
193201 case <- s .ctx .Done ():
194202 return
195203 case <- ticker .C :
196- currentDAIncluded := s .GetDAIncludedHeight ()
204+ s .processAllFromDA (s .ctx )
205+ }
206+ }
207+ }
197208
198- for {
199- nextHeight := currentDAIncluded + 1
209+ func ( s * Submitter ) processAllFromDA ( ctx context. Context ) {
210+ currentDAIncluded := s . GetDAIncludedHeight ()
200211
201- // Get block data first
202- header , data , err := s .store .GetBlockData (s .ctx , nextHeight )
203- if err != nil {
204- break
205- }
212+ for {
213+ select {
214+ case <- ctx .Done ():
215+ return
216+ default :
217+ }
206218
207- // Check if this height is DA included
208- if included , err := s .IsHeightDAIncluded (nextHeight , header , data ); err != nil || ! included {
209- break
210- }
219+ nextHeight := currentDAIncluded + 1
220+
221+ // Get block data first
222+ header , data , err := s .store .GetBlockData (s .ctx , nextHeight )
223+ if err != nil {
224+ return
225+ }
211226
212- s .logger .Debug ().Uint64 ("height" , nextHeight ).Msg ("advancing DA included height" )
227+ // Check if this height is DA included
228+ if included , err := s .IsHeightDAIncluded (nextHeight , header , data ); err != nil || ! included {
229+ return
230+ }
213231
214- // Set sequencer height to DA height mapping using already retrieved data
215- if err := s .setSequencerHeightToDAHeight (s .ctx , nextHeight , header , data , currentDAIncluded == 0 ); err != nil {
216- s .logger .Error ().Err (err ).Uint64 ("height" , nextHeight ).Msg ("failed to set sequencer height to DA height mapping" )
217- break
218- }
232+ s .logger .Debug ().Uint64 ("height" , nextHeight ).Msg ("advancing DA included height" )
219233
220- // Set final height in executor
221- if err := s .setFinalWithRetry (nextHeight ); err != nil {
222- s .sendCriticalError (fmt .Errorf ("failed to set final height: %w" , err ))
223- s .logger .Error ().Err (err ).Uint64 ("height" , nextHeight ).Msg ("failed to set final height" )
224- break
225- }
234+ // Set sequencer height to DA height mapping using already retrieved data
235+ if err := s .setSequencerHeightToDAHeight (s .ctx , nextHeight , header , data , currentDAIncluded == 0 ); err != nil {
236+ s .logger .Error ().Err (err ).Uint64 ("height" , nextHeight ).Msg ("failed to set sequencer height to DA height mapping" )
237+ return
238+ }
226239
227- // Update DA included height
228- s .SetDAIncludedHeight (nextHeight )
229- currentDAIncluded = nextHeight
240+ // Set final height in executor
241+ if err := s .setFinalWithRetry (nextHeight ); err != nil {
242+ s .sendCriticalError (fmt .Errorf ("failed to set final height: %w" , err ))
243+ s .logger .Error ().Err (err ).Uint64 ("height" , nextHeight ).Msg ("failed to set final height" )
244+ return
245+ }
230246
231- // Persist DA included height
232- bz := make ([]byte , 8 )
233- binary .LittleEndian .PutUint64 (bz , nextHeight )
234- if err := s .store .SetMetadata (s .ctx , store .DAIncludedHeightKey , bz ); err != nil {
235- s .logger .Error ().Err (err ).Uint64 ("height" , nextHeight ).Msg ("failed to persist DA included height" )
236- }
237- }
247+ // Update DA included height
248+ s .SetDAIncludedHeight (nextHeight )
249+ currentDAIncluded = nextHeight
250+
251+ // Persist DA included height
252+ bz := make ([]byte , 8 )
253+ binary .LittleEndian .PutUint64 (bz , nextHeight )
254+ if err := s .store .SetMetadata (s .ctx , store .DAIncludedHeightKey , bz ); err != nil {
255+ s .logger .Error ().Err (err ).Uint64 ("height" , nextHeight ).Msg ("failed to persist DA included height" )
256+ }
257+ if s .signer == nil {
258+ // bump height to keep cache in sync when submission loop is not active
259+ s .cache .SetLastSubmittedDataHeight (s .ctx , currentDAIncluded )
260+ s .cache .SetLastSubmittedHeaderHeight (s .ctx , currentDAIncluded )
238261 }
239262 }
240263}
@@ -280,6 +303,7 @@ func (s *Submitter) SetDAIncludedHeight(height uint64) {
280303// initializeDAIncludedHeight loads the DA included height from store
281304func (s * Submitter ) initializeDAIncludedHeight (ctx context.Context ) error {
282305 if height , err := s .store .GetMetadata (ctx , store .DAIncludedHeightKey ); err == nil && len (height ) == 8 {
306+ s .logger .Debug ().Uint64 ("height" , binary .LittleEndian .Uint64 (height )).Msg ("Initial DA included height loaded from store" )
283307 s .SetDAIncludedHeight (binary .LittleEndian .Uint64 (height ))
284308 }
285309 return nil
@@ -367,7 +391,7 @@ func (s *Submitter) IsHeightDAIncluded(height uint64, header *types.SignedHeader
367391 _ , headerIncluded := s .cache .GetHeaderDAIncluded (headerHash )
368392 _ , dataIncluded := s .cache .GetDataDAIncluded (dataHash )
369393
370- dataIncluded = bytes .Equal (data .DACommitment (), common .DataHashForEmptyTxs ) || dataIncluded
394+ dataIncluded = dataIncluded || bytes .Equal (data .DACommitment (), common .DataHashForEmptyTxs )
371395
372396 return headerIncluded && dataIncluded , nil
373397}
0 commit comments