@@ -660,26 +660,15 @@ func (s *ClientSynchronizer) processSequenceBatches(sequencedBatches []etherman.
660
660
ForcedBatchNum : batch .ForcedBatchNum ,
661
661
}
662
662
663
- // Reprocess batch to compare the stateRoot with tBatch.StateRoot and get accInputHash
664
- p , err := s .state .ExecuteBatch (s .ctx , batch , false , dbTx )
665
- if err != nil {
666
- log .Errorf ("error executing L1 batch: %+v, error: %v" , batch , err )
667
- rollbackErr := dbTx .Rollback (s .ctx )
668
- if rollbackErr != nil {
669
- log .Fatalf ("error rolling back state. BatchNumber: %d, BlockNumber: %d, rollbackErr: %s, error : %v" , batch .BatchNumber , blockNumber , rollbackErr .Error (), err )
670
- }
671
- log .Fatalf ("error executing L1 batch: %+v, error: %v" , batch , err )
672
- }
673
- newRoot := common .BytesToHash (p .NewStateRoot )
674
- accumulatedInputHash := common .BytesToHash (p .NewAccInputHash )
663
+ var newRoot common.Hash
675
664
676
665
// First get trusted batch from db
677
666
tBatch , err := s .state .GetBatchByNumber (s .ctx , batch .BatchNumber , dbTx )
678
667
if err != nil {
679
668
if errors .Is (err , state .ErrNotFound ) || errors .Is (err , state .ErrStateNotSynchronized ) {
680
669
log .Debugf ("BatchNumber: %d, not found in trusted state. Storing it..." , batch .BatchNumber )
681
670
// If it is not found, store batch
682
- err = s .state .ProcessAndStoreClosedBatch (s .ctx , processCtx , batch .BatchL2Data , dbTx , state .SynchronizerCallerLabel )
671
+ p , err : = s .state .ProcessAndStoreClosedBatch (s .ctx , processCtx , batch .BatchL2Data , dbTx , state .SynchronizerCallerLabel )
683
672
if err != nil {
684
673
log .Errorf ("error storing trustedBatch. BatchNumber: %d, BlockNumber: %d, error: %v" , batch .BatchNumber , blockNumber , err )
685
674
rollbackErr := dbTx .Rollback (s .ctx )
@@ -690,6 +679,7 @@ func (s *ClientSynchronizer) processSequenceBatches(sequencedBatches []etherman.
690
679
log .Errorf ("error storing batch. BatchNumber: %d, BlockNumber: %d, error: %v" , batch .BatchNumber , blockNumber , err )
691
680
return err
692
681
}
682
+ newRoot = common .BytesToHash (p .NewStateRoot )
693
683
tBatch = & batch
694
684
tBatch .StateRoot = newRoot
695
685
} else {
@@ -702,6 +692,20 @@ func (s *ClientSynchronizer) processSequenceBatches(sequencedBatches []etherman.
702
692
return err
703
693
}
704
694
} else {
695
+ // Reprocess batch to compare the stateRoot with tBatch.StateRoot and get accInputHash
696
+ p , err := s .state .ExecuteBatch (s .ctx , batch , false , dbTx )
697
+ if err != nil {
698
+ log .Errorf ("error executing L1 batch: %+v, error: %v" , batch , err )
699
+ rollbackErr := dbTx .Rollback (s .ctx )
700
+ if rollbackErr != nil {
701
+ log .Errorf ("error rolling back state. BatchNumber: %d, BlockNumber: %d, rollbackErr: %s, error : %v" , batch .BatchNumber , blockNumber , rollbackErr .Error (), err )
702
+ return rollbackErr
703
+ }
704
+ return err
705
+ }
706
+ newRoot = common .BytesToHash (p .NewStateRoot )
707
+ accumulatedInputHash := common .BytesToHash (p .NewAccInputHash )
708
+
705
709
//AddAccumulatedInputHash
706
710
err = s .state .AddAccumulatedInputHash (s .ctx , batch .BatchNumber , accumulatedInputHash , dbTx )
707
711
if err != nil {
@@ -744,7 +748,7 @@ func (s *ClientSynchronizer) processSequenceBatches(sequencedBatches []etherman.
744
748
log .Errorf ("error resetting trusted state. BatchNumber: %d, BlockNumber: %d, error: %v" , batch .BatchNumber , blockNumber , err )
745
749
return err
746
750
}
747
- err = s .state .ProcessAndStoreClosedBatch (s .ctx , processCtx , batch .BatchL2Data , dbTx , state .SynchronizerCallerLabel )
751
+ _ , err = s .state .ProcessAndStoreClosedBatch (s .ctx , processCtx , batch .BatchL2Data , dbTx , state .SynchronizerCallerLabel )
748
752
if err != nil {
749
753
log .Errorf ("error storing trustedBatch. BatchNumber: %d, BlockNumber: %d, error: %v" , batch .BatchNumber , blockNumber , err )
750
754
rollbackErr := dbTx .Rollback (s .ctx )
@@ -868,7 +872,7 @@ func (s *ClientSynchronizer) processSequenceForceBatch(sequenceForceBatch []ethe
868
872
ForcedBatchNum : & forcedBatches [i ].ForcedBatchNumber ,
869
873
}
870
874
// Process batch
871
- err := s .state .ProcessAndStoreClosedBatch (s .ctx , batch , forcedBatches [i ].RawTxsData , dbTx , state .SynchronizerCallerLabel )
875
+ _ , err := s .state .ProcessAndStoreClosedBatch (s .ctx , batch , forcedBatches [i ].RawTxsData , dbTx , state .SynchronizerCallerLabel )
872
876
if err != nil {
873
877
log .Errorf ("error processing batch in processSequenceForceBatch. BatchNumber: %d, BlockNumber: %d, error: %v" , batch .BatchNumber , block .BlockNumber , err )
874
878
rollbackErr := dbTx .Rollback (s .ctx )
0 commit comments