@@ -241,10 +241,15 @@ func (s *RollupSyncService) parseAndUpdateRollupEventLogs(logs []types.Log, endB
241
241
log .Warn ("got nil when reading last finalized batch index. This should happen only once." )
242
242
}
243
243
244
+ parentBatchMeta := & rawdb.FinalizedBatchMeta {}
245
+ if startBatchIndex > 0 {
246
+ parentBatchMeta = rawdb .ReadFinalizedBatchMeta (s .db , startBatchIndex - 1 )
247
+ }
248
+
244
249
var highestFinalizedBlockNumber uint64
245
250
batchWriter := s .db .NewBatch ()
246
251
for index := startBatchIndex ; index <= batchIndex ; index ++ {
247
- parentBatchMeta , chunks , err := s .getLocalInfoForBatch (index )
252
+ chunks , err := s .getLocalChunksForBatch (index )
248
253
if err != nil {
249
254
return fmt .Errorf ("failed to get local node info, batch index: %v, err: %w" , index , err )
250
255
}
@@ -256,6 +261,7 @@ func (s *RollupSyncService) parseAndUpdateRollupEventLogs(logs []types.Log, endB
256
261
257
262
rawdb .WriteFinalizedBatchMeta (batchWriter , index , finalizedBatchMeta )
258
263
highestFinalizedBlockNumber = endBlock
264
+ parentBatchMeta = finalizedBatchMeta
259
265
260
266
if index % 100 == 0 {
261
267
log .Info ("finalized batch progress" , "batch index" , index , "finalized l2 block height" , endBlock )
@@ -283,17 +289,17 @@ func (s *RollupSyncService) parseAndUpdateRollupEventLogs(logs []types.Log, endB
283
289
return nil
284
290
}
285
291
286
- func (s * RollupSyncService ) getLocalInfoForBatch (batchIndex uint64 ) (* rawdb. FinalizedBatchMeta , []* encoding.Chunk , error ) {
292
+ func (s * RollupSyncService ) getLocalChunksForBatch (batchIndex uint64 ) ([]* encoding.Chunk , error ) {
287
293
chunkBlockRanges := rawdb .ReadBatchChunkRanges (s .db , batchIndex )
288
294
if len (chunkBlockRanges ) == 0 {
289
- return nil , nil , fmt .Errorf ("failed to get batch chunk ranges, empty chunk block ranges" )
295
+ return nil , fmt .Errorf ("failed to get batch chunk ranges, empty chunk block ranges" )
290
296
}
291
297
292
298
endBlockNumber := chunkBlockRanges [len (chunkBlockRanges )- 1 ].EndBlockNumber
293
299
for i := 0 ; i < defaultMaxRetries ; i ++ {
294
300
if s .ctx .Err () != nil {
295
301
log .Info ("Context canceled" , "reason" , s .ctx .Err ())
296
- return nil , nil , s .ctx .Err ()
302
+ return nil , s .ctx .Err ()
297
303
}
298
304
299
305
localSyncedBlockHeight := s .bc .CurrentBlock ().Number ().Uint64 ()
@@ -308,7 +314,7 @@ func (s *RollupSyncService) getLocalInfoForBatch(batchIndex uint64) (*rawdb.Fina
308
314
309
315
localSyncedBlockHeight := s .bc .CurrentBlock ().Number ().Uint64 ()
310
316
if localSyncedBlockHeight < endBlockNumber {
311
- return nil , nil , fmt .Errorf ("local node is not synced up to the required block height: %v, local synced block height: %v" , endBlockNumber , localSyncedBlockHeight )
317
+ return nil , fmt .Errorf ("local node is not synced up to the required block height: %v, local synced block height: %v" , endBlockNumber , localSyncedBlockHeight )
312
318
}
313
319
314
320
chunks := make ([]* encoding.Chunk , len (chunkBlockRanges ))
@@ -317,12 +323,12 @@ func (s *RollupSyncService) getLocalInfoForBatch(batchIndex uint64) (*rawdb.Fina
317
323
for j := cr .StartBlockNumber ; j <= cr .EndBlockNumber ; j ++ {
318
324
block := s .bc .GetBlockByNumber (j )
319
325
if block == nil {
320
- return nil , nil , fmt .Errorf ("failed to get block by number: %v" , i )
326
+ return nil , fmt .Errorf ("failed to get block by number: %v" , i )
321
327
}
322
328
txData := encoding .TxsToTxsData (block .Transactions ())
323
329
state , err := s .bc .StateAt (block .Root ())
324
330
if err != nil {
325
- return nil , nil , fmt .Errorf ("failed to get block state, block: %v, err: %w" , block .Hash ().Hex (), err )
331
+ return nil , fmt .Errorf ("failed to get block state, block: %v, err: %w" , block .Hash ().Hex (), err )
326
332
}
327
333
withdrawRoot := withdrawtrie .ReadWTRSlot (rcfg .L2MessageQueueAddress , state )
328
334
chunks [i ].Blocks [j - cr .StartBlockNumber ] = & encoding.Block {
@@ -333,13 +339,7 @@ func (s *RollupSyncService) getLocalInfoForBatch(batchIndex uint64) (*rawdb.Fina
333
339
}
334
340
}
335
341
336
- // get metadata of parent batch: default to genesis batch metadata.
337
- parentBatchMeta := & rawdb.FinalizedBatchMeta {}
338
- if batchIndex > 0 {
339
- parentBatchMeta = rawdb .ReadFinalizedBatchMeta (s .db , batchIndex - 1 )
340
- }
341
-
342
- return parentBatchMeta , chunks , nil
342
+ return chunks , nil
343
343
}
344
344
345
345
func (s * RollupSyncService ) getChunkRanges (batchIndex uint64 , vLog * types.Log ) ([]* rawdb.ChunkBlockRange , error ) {
0 commit comments