Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reprocess empty batch to update state root before sanity check (full batch) #1921

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

@ToniRamirezM ToniRamirezM Mar 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only need to do this if the batch has no transactions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but if initialStateRoot is equal to the stateRoot this means that the batch is empty (no txs executed), isn't it?

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