@@ -37,6 +37,8 @@ type BasedSequencer struct {
3737
3838 // Cached transactions from the current DA block being processed
3939 currentBatchTxs [][]byte
40+ // DA epoch end time for timestamp calculation
41+ currentDAEndTime time.Time
4042}
4143
4244// NewBasedSequencer creates a new based sequencer instance
@@ -97,7 +99,6 @@ func (s *BasedSequencer) GetNextBatch(ctx context.Context, req coresequencer.Get
9799 // If we have no cached transactions or we've consumed all from the current DA block,
98100 // fetch the next DA epoch
99101 daHeight := s .GetDAHeight ()
100- t := time.Time {}
101102
102103 if len (s .currentBatchTxs ) == 0 || s .checkpoint .TxIndex >= uint64 (len (s .currentBatchTxs )) {
103104 daEndTime , daEndHeight , err := s .fetchNextDAEpoch (ctx , req .MaxBytes )
@@ -106,7 +107,7 @@ func (s *BasedSequencer) GetNextBatch(ctx context.Context, req coresequencer.Get
106107 }
107108
108109 daHeight = daEndHeight
109- t = daEndTime
110+ s . currentDAEndTime = daEndTime
110111 }
111112
112113 // Create batch from current position up to MaxBytes
@@ -132,11 +133,15 @@ func (s *BasedSequencer) GetNextBatch(ctx context.Context, req coresequencer.Get
132133 }
133134 }
134135
136+ // Calculate timestamp based on remaining transactions after this batch
137+ // timestamp correspond to the last block time of a DA epoch, based on the remaining transactions to be executed
138+ // this is done in order to handle the case where a DA epoch must fit in multiple blocks
139+ remainingTxs := uint64 (len (s .currentBatchTxs )) - s .checkpoint .TxIndex
140+ timestamp := s .currentDAEndTime .Add (- time .Duration (remainingTxs ) * time .Millisecond )
141+
135142 return & coresequencer.GetNextBatchResponse {
136- Batch : batch ,
137- // timestamp correspond to the last block time of a DA epoch, based on the remaining transactions to be executed
138- // this is done in order to handle the case where a DA epoch must fit in multiple blocks
139- Timestamp : t .Add (- time .Duration (len (batch .Transactions )) * time .Millisecond ),
143+ Batch : batch ,
144+ Timestamp : timestamp ,
140145 BatchData : req .LastBatchData ,
141146 }, nil
142147}
0 commit comments