@@ -568,16 +568,35 @@ func (r *Layer2Relayer) ProcessPendingBundles() {
568568 switch status {
569569 case types .ProvingTaskUnassigned , types .ProvingTaskAssigned :
570570 if r .cfg .EnableTestEnvBypassFeatures && utils .NowUTC ().Sub (bundle .CreatedAt ) > time .Duration (r .cfg .FinalizeBundleWithoutProofTimeoutSec )* time .Second {
571+ // check if last batch is finalized, because in fake finalize bundle mode, the contract does not verify if the previous bundle or batch is finalized.
572+ if bundle .StartBatchIndex == 0 {
573+ log .Error ("invalid args: start batch index of bundle is 0" , "bundle index" , bundle .Index , "start batch index" , bundle .StartBatchIndex , "end batch index" , bundle .EndBatchIndex )
574+ return
575+ }
576+
577+ lastBatch , err := r .batchOrm .GetBatchByIndex (r .ctx , bundle .StartBatchIndex - 1 )
578+ if err != nil {
579+ log .Error ("failed to get last batch" , "batch index" , bundle .StartBatchIndex - 1 , "err" , err )
580+ return
581+ }
582+
583+ if types .RollupStatus (lastBatch .RollupStatus ) != types .RollupFinalized {
584+ log .Error ("previous bundle or batch is not finalized" , "batch index" , lastBatch .Index , "batch hash" , lastBatch .Hash , "rollup status" , types .RollupStatus (lastBatch .RollupStatus ))
585+ return
586+ }
587+
571588 if err := r .finalizeBundle (bundle , false ); err != nil {
572- log .Error ("Failed to finalize timeout bundle without proof" , "index" , bundle .Index , "start batch index" , bundle .StartBatchIndex , "end batch index" , bundle .EndBatchIndex , "err" , err )
589+ log .Error ("failed to finalize timeout bundle without proof" , "bundle index" , bundle .Index , "start batch index" , bundle .StartBatchIndex , "end batch index" , bundle .EndBatchIndex , "err" , err )
590+ return
573591 }
574592 }
575593
576594 case types .ProvingTaskVerified :
577595 log .Info ("Start to roll up zk proof" , "bundle hash" , bundle .Hash )
578596 r .metrics .rollupL2RelayerProcessPendingBundlesFinalizedTotal .Inc ()
579597 if err := r .finalizeBundle (bundle , true ); err != nil {
580- log .Error ("Failed to finalize bundle with proof" , "index" , bundle .Index , "start batch index" , bundle .StartBatchIndex , "end batch index" , bundle .EndBatchIndex , "err" , err )
598+ log .Error ("failed to finalize bundle with proof" , "bundle index" , bundle .Index , "start batch index" , bundle .StartBatchIndex , "end batch index" , bundle .EndBatchIndex , "err" , err )
599+ return
581600 }
582601
583602 case types .ProvingTaskFailed :
@@ -589,7 +608,7 @@ func (r *Layer2Relayer) ProcessPendingBundles() {
589608 // stop the ledger, fix the limit, revert all the violating blocks,
590609 // chunks, batches, bundles and all subsequent ones, and resume,
591610 // i.e. this case requires manual resolution.
592- log .Error ("bundle proving failed" , "index" , bundle .Index , "hash" , bundle .Hash , "proved at" , bundle .ProvedAt , "proof time sec" , bundle .ProofTimeSec )
611+ log .Error ("bundle proving failed" , "bundle index" , bundle .Index , "bundle hash" , bundle .Hash , "proved at" , bundle .ProvedAt , "proof time sec" , bundle .ProofTimeSec )
593612
594613 default :
595614 log .Error ("encounter unreachable case in ProcessPendingBundles" , "proving status" , status )
0 commit comments