diff --git a/sequencer/batch.go b/sequencer/batch.go index 10a5bd3ceb..47b79cdf81 100644 --- a/sequencer/batch.go +++ b/sequencer/batch.go @@ -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, @@ -196,7 +197,7 @@ 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) } @@ -204,15 +205,13 @@ func (f *finalizer) closeAndOpenNewWIPBatch(ctx context.Context, closeReason sta 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 diff --git a/sequencer/errors.go b/sequencer/errors.go index 44fbc8bdd0..10c87aaa2f 100644 --- a/sequencer/errors.go +++ b/sequencer/errors.go @@ -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") ) diff --git a/sequencer/finalizer.go b/sequencer/finalizer.go index 9e9f5f5b19..c7021bdcd1 100644 --- a/sequencer/finalizer.go +++ b/sequencer/finalizer.go @@ -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)) @@ -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 @@ -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 diff --git a/sequencer/l2block.go b/sequencer/l2block.go index 28ccd40b2c..8ae00be9db 100644 --- a/sequencer/l2block.go +++ b/sequencer/l2block.go @@ -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 @@ -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 diff --git a/sequencer/worker.go b/sequencer/worker.go index 4e277b7b84..b0f07a2311 100644 --- a/sequencer/worker.go +++ b/sequencer/worker.go @@ -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 }