@@ -315,26 +315,43 @@ func GenerateDataStreamFile(ctx context.Context, streamServer *datastreamer.Stre
315
315
}
316
316
317
317
currentL2BlockNumber := transaction .L2BlockNumber
318
- currentBatchNumber = transaction .L2BlockNumber
319
318
lastAddedL2BlockNumber = currentL2BlockNumber
320
319
321
- // Get Previous l2block timestamp
322
- bookMark := & datastream.BookMark {
320
+ // Get current batch number
321
+ bookMarkCurrentL2Block := & datastream.BookMark {
323
322
Type : datastream .BookmarkType_BOOKMARK_TYPE_L2_BLOCK ,
324
- Value : currentL2BlockNumber - 1 ,
323
+ Value : currentL2BlockNumber ,
325
324
}
326
325
327
- marshalledBookMark , err := proto .Marshal (bookMark )
326
+ marshalledBookMarkCurrentL2Block , err := proto .Marshal (bookMarkCurrentL2Block )
328
327
if err != nil {
329
328
return err
330
329
}
331
330
332
- prevL2BlockEntryNumber , err := streamServer .GetBookmark ( marshalledBookMark )
331
+ currentL2BlockEntry , err := streamServer .GetFirstEventAfterBookmark ( marshalledBookMarkCurrentL2Block )
333
332
if err != nil {
334
333
return err
335
334
}
336
335
337
- prevL2BlockEntry , err := streamServer .GetEntry (prevL2BlockEntryNumber )
336
+ currentL2Block := & datastream.L2Block {}
337
+ if err := proto .Unmarshal (currentL2BlockEntry .Data , currentL2Block ); err != nil {
338
+ return err
339
+ }
340
+
341
+ currentBatchNumber = currentL2Block .BatchNumber
342
+
343
+ // Get Previous l2block timestamp
344
+ bookMarkPrevL2Block := & datastream.BookMark {
345
+ Type : datastream .BookmarkType_BOOKMARK_TYPE_L2_BLOCK ,
346
+ Value : currentL2BlockNumber - 1 ,
347
+ }
348
+
349
+ marshalledBookMarkPrevL2Block , err := proto .Marshal (bookMarkPrevL2Block )
350
+ if err != nil {
351
+ return err
352
+ }
353
+
354
+ prevL2BlockEntry , err := streamServer .GetFirstEventAfterBookmark (marshalledBookMarkPrevL2Block )
338
355
if err != nil {
339
356
return err
340
357
}
@@ -683,20 +700,22 @@ func GenerateDataStreamFile(ctx context.Context, streamServer *datastreamer.Stre
683
700
}
684
701
}
685
702
686
- batchEnd := & datastream.BatchEnd {
687
- Number : batch .BatchNumber ,
688
- LocalExitRoot : batch .LocalExitRoot .Bytes (),
689
- StateRoot : batch .StateRoot .Bytes (),
690
- }
703
+ if ! batch .WIP {
704
+ batchEnd := & datastream.BatchEnd {
705
+ Number : batch .BatchNumber ,
706
+ LocalExitRoot : batch .LocalExitRoot .Bytes (),
707
+ StateRoot : batch .StateRoot .Bytes (),
708
+ }
691
709
692
- marshalledBatch , err := proto .Marshal (batchEnd )
693
- if err != nil {
694
- return err
695
- }
710
+ marshalledBatch , err := proto .Marshal (batchEnd )
711
+ if err != nil {
712
+ return err
713
+ }
696
714
697
- _ , err = streamServer .AddStreamEntry (datastreamer .EntryType (datastream .EntryType_ENTRY_TYPE_BATCH_END ), marshalledBatch )
698
- if err != nil {
699
- return err
715
+ _ , err = streamServer .AddStreamEntry (datastreamer .EntryType (datastream .EntryType_ENTRY_TYPE_BATCH_END ), marshalledBatch )
716
+ if err != nil {
717
+ return err
718
+ }
700
719
}
701
720
702
721
// Commit at the end of each batch group
0 commit comments