Skip to content

Commit

Permalink
Reprocess empty batch to update state root before sanity check (full …
Browse files Browse the repository at this point in the history
…batch) (#1921)
  • Loading branch information
agnusmor authored Mar 24, 2023
1 parent 1c8cd3d commit 4b67fbc
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions sequencer/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ func (f *finalizer) newWIPBatch(ctx context.Context) (*WipBatch, error) {
return nil, errors.New("state root and local exit root must have value to close batch")
}

// We need to process the batch to update the state root before closing the batch
if f.batch.initialStateRoot == f.batch.stateRoot {
log.Info("reprocessing batch because the state root has not changed...")
err := f.processTransaction(ctx, nil)
if err != nil {
return nil, err
}
}

// Reprocess full batch as sanity check
processBatchResponse, err := f.reprocessFullBatch(ctx, f.batch.batchNumber, f.batch.stateRoot)
if err != nil || !processBatchResponse.IsBatchProcessed {
Expand Down Expand Up @@ -660,15 +669,6 @@ func (f *finalizer) openWIPBatch(ctx context.Context, batchNum uint64, ger, stat

// closeBatch closes the current batch in the state
func (f *finalizer) closeBatch(ctx context.Context) error {
// We need to process the batch to update the state root before closing the batch
if f.batch.initialStateRoot == f.batch.stateRoot {
log.Info("reprocessing batch because the state root has not changed...")
err := f.processTransaction(ctx, nil)
if err != nil {
return err
}
}

transactions, err := f.dbManager.GetTransactionsByBatchNumber(ctx, f.batch.batchNumber)
if err != nil {
return fmt.Errorf("failed to get transactions from transactions, err: %w", err)
Expand Down

0 comments on commit 4b67fbc

Please sign in to comment.