@@ -251,13 +251,13 @@ func (bc *BatchCache) InitAndSyncFromDatabase() error {
251251 }
252252 lastPackedBlockHeight = store .BlockNumber .Uint64 ()
253253 }
254+ bc .lastPackedBlockHeight = lastPackedBlockHeight
254255 bc .sealedBatches = batches
255256 bc .sealedBatchHeaders = headers
256257 bc .parentBatchHeader = latestHeaderBytes
257258 bc .currentBlockNumber = bc .lastPackedBlockHeight
258259 bc .prevStateRoot = prevStateRoot
259260 bc .totalL1MessagePopped = totalL1MessagePopped
260- bc .lastPackedBlockHeight = lastPackedBlockHeight
261261
262262 bc .initDone = true
263263 log .Info ("Sync sealed batch from database success" , "count" , len (batches ))
@@ -426,18 +426,13 @@ func (bc *BatchCache) GetSealedBatchHeader(batchIndex uint64) (*BatchHeaderBytes
426426 defer bc .mu .RUnlock ()
427427 header , ok := bc .sealedBatchHeaders [batchIndex ]
428428 if ! ok {
429- // Try to load from storage
430- bc .mu .RUnlock ()
431- bc .mu .Lock ()
432- defer bc .mu .Unlock ()
433429 // Check again after acquiring write lock
434430 header , ok = bc .sealedBatchHeaders [batchIndex ]
435431 if ! ok {
436432 loadedHeader , err := bc .batchStorage .LoadSealedBatchHeader (batchIndex )
437433 if err != nil {
438434 return nil , false
439435 }
440- bc .sealedBatchHeaders [batchIndex ] = loadedHeader
441436 return loadedHeader , true
442437 }
443438 return header , true
@@ -1135,8 +1130,7 @@ func (bc *BatchCache) logSealedBatch(batchHeader BatchHeaderBytes, batchHash com
11351130
11361131func (bc * BatchCache ) AssembleCurrentBatchHeader () error {
11371132 if ! bc .initDone {
1138- log .Warn ("batch has not been initialized, should wait" )
1139- return nil
1133+ return errors .New ("batch has not been initialized, should wait" )
11401134 }
11411135 callOpts := & bind.CallOpts {
11421136 Context : bc .ctx ,
@@ -1148,9 +1142,26 @@ func (bc *BatchCache) AssembleCurrentBatchHeader() error {
11481142 if endBlockNum < bc .currentBlockNumber {
11491143 return fmt .Errorf ("has reorg, should check block status current %v, now %v" , bc .currentBlockNumber , endBlockNum )
11501144 }
1151- startBlockNum , err := bc .parentBatchHeader .LastBlockNumber ()
1152- if err != nil {
1153- return err
1145+ startBlockNum := uint64 (0 )
1146+ version , _ := bc .parentBatchHeader .Version ()
1147+ if version < 1 {
1148+ parentIndex , err := bc .parentBatchHeader .BatchIndex ()
1149+ if err != nil {
1150+ log .Error ("failed to get block index" , "err" , err )
1151+ return err
1152+ }
1153+ store , err := bc .rollupContract .BatchDataStore (nil , new (big.Int ).SetUint64 (parentIndex ))
1154+ if err != nil {
1155+ log .Error ("failed to get batch store" , "err" , err )
1156+ return err
1157+ }
1158+ startBlockNum = store .BlockNumber .Uint64 ()
1159+ } else {
1160+ startBlockNum , err = bc .parentBatchHeader .LastBlockNumber ()
1161+ if err != nil {
1162+ log .Error ("failed to get block number" , "err" , err )
1163+ return err
1164+ }
11541165 }
11551166 startBlockNum ++
11561167 // Get start block once to avoid repeated queries
0 commit comments