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

fix wipL2block imStateRoot #3148

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions sequencer/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (f *finalizer) setWIPBatch(ctx context.Context, wipStateBatch *state.Batch)
initialStateRoot: prevStateBatch.StateRoot,
finalStateRoot: wipStateBatch.StateRoot,
timestamp: wipStateBatch.Timestamp,
countOfL2Blocks: len(wipStateBatchBlocks.Blocks),
countOfTxs: wipStateBatchCountOfTxs,
imRemainingResources: remainingResources,
finalRemainingResources: remainingResources,
Expand Down Expand Up @@ -196,23 +197,21 @@ func (f *finalizer) closeAndOpenNewWIPBatch(ctx context.Context, closeReason sta
f.initWIPL2Block(ctx)
}

batch, err := f.openNewWIPBatch(ctx, lastBatchNumber+1, stateRoot)
f.wipBatch, err = f.openNewWIPBatch(ctx, lastBatchNumber+1, stateRoot)
if err != nil {
return fmt.Errorf("failed to open new wip batch, error: %v", err)
}

if f.wipL2Block != nil {
f.wipBatch.imStateRoot = f.wipL2Block.imStateRoot
// Subtract the WIP L2 block used resources to batch
overflow, overflowResource := batch.imRemainingResources.Sub(f.wipL2Block.usedResources)
overflow, overflowResource := f.wipBatch.imRemainingResources.Sub(f.wipL2Block.usedResources)
if overflow {
return fmt.Errorf("failed to subtract L2 block [%d] used resources to new wip batch %d, overflow resource: %s",
f.wipL2Block.trackingNum, batch.batchNumber, overflowResource)
f.wipL2Block.trackingNum, f.wipBatch.batchNumber, overflowResource)
}
}

f.wipBatch = batch

log.Infof("new WIP batch %d", f.wipBatch.batchNumber)

return nil
Expand Down
2 changes: 2 additions & 0 deletions sequencer/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var (
ErrExecutorError = errors.New("executor error")
// ErrNoFittingTransaction happens when there is not a tx (from the txSortedList) that fits in the remaining batch resources
ErrNoFittingTransaction = errors.New("no fit transaction")
// ErrBatchResourceUnderFlow happens when there is batch resoure underflow after sustract the resources from a tx
ErrBatchResourceUnderFlow = errors.New("batch resource underflow")
// ErrTransactionsListEmpty happens when txSortedList is empty
ErrTransactionsListEmpty = errors.New("transactions list empty")
)
6 changes: 5 additions & 1 deletion sequencer/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ func (f *finalizer) finalizeBatches(ctx context.Context) {
// If we have txs pending to process but none of them fits into the wip batch, we close the wip batch and open a new one
if err == ErrNoFittingTransaction {
f.finalizeWIPBatch(ctx, state.NoTxFitsClosingReason)
continue
}

metrics.WorkerProcessingTime(time.Since(start))
Expand All @@ -293,6 +294,9 @@ func (f *finalizer) finalizeBatches(ctx context.Context) {
firstTxProcess = false
log.Infof("reprocessing tx %s because of effective gas price calculation", tx.HashStr)
continue
} else if err == ErrBatchResourceUnderFlow {
log.Infof("skipping tx %s due to a batch resource underflow", tx.HashStr)
break
} else {
log.Errorf("failed to process tx %s, error: %v", err)
break
Expand Down Expand Up @@ -528,7 +532,7 @@ func (f *finalizer) handleProcessTransactionResponse(ctx context.Context, tx *Tx
start := time.Now()
f.workerIntf.UpdateTxZKCounters(result.BlockResponses[0].TransactionResponses[0].TxHash, tx.From, result.UsedZkCounters)
metrics.WorkerProcessingTime(time.Since(start))
return nil, err
return nil, ErrBatchResourceUnderFlow
}

// Save Enabled, GasPriceOC, BalanceOC and final effective gas price for later logging
Expand Down
5 changes: 3 additions & 2 deletions sequencer/l2block.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ func (f *finalizer) openNewWIPL2Block(ctx context.Context, prevTimestamp uint64,
}

// Update imStateRoot
oldIMStateRoot := f.wipBatch.imStateRoot
f.wipL2Block.imStateRoot = batchResponse.NewStateRoot
f.wipBatch.imStateRoot = f.wipL2Block.imStateRoot

Expand All @@ -509,9 +510,9 @@ func (f *finalizer) openNewWIPL2Block(ctx context.Context, prevTimestamp uint64,
}
}

log.Infof("created new WIP L2 block [%d], batch: %d, deltaTimestamp: %d, timestamp: %d, l1InfoTreeIndex: %d, l1InfoTreeIndexChanged: %v, oldStateRoot: %s, stateRoot: %s, used counters: %s",
log.Infof("created new WIP L2 block [%d], batch: %d, deltaTimestamp: %d, timestamp: %d, l1InfoTreeIndex: %d, l1InfoTreeIndexChanged: %v, oldStateRoot: %s, imStateRoot: %s, used counters: %s",
f.wipL2Block.trackingNum, f.wipBatch.batchNumber, f.wipL2Block.deltaTimestamp, f.wipL2Block.timestamp, f.wipL2Block.l1InfoTreeExitRoot.L1InfoTreeIndex,
f.wipL2Block.l1InfoTreeExitRootChanged, f.wipBatch.imStateRoot, batchResponse.NewStateRoot, f.logZKCounters(f.wipL2Block.usedResources.ZKCounters))
f.wipL2Block.l1InfoTreeExitRootChanged, oldIMStateRoot, f.wipL2Block.imStateRoot, f.logZKCounters(f.wipL2Block.usedResources.ZKCounters))
}

// executeNewWIPL2Block executes an empty L2 Block in the executor and returns the batch response from the executor
Expand Down
2 changes: 1 addition & 1 deletion sequencer/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func (w *Worker) ExpireTransactions(maxTime time.Duration) []*TxTracker {
delete(w.pool, addrQueue.fromStr)
}
}
log.Debug("expire transactions ended, addrQueue length: %d, delete count: %d ", len(w.pool), len(txs))
log.Debugf("expire transactions ended, addrQueue length: %d, delete count: %d ", len(w.pool), len(txs))

return txs
}
Loading