Skip to content

Commit

Permalink
fix(gas-pool): create a gas pool per block in normalcy mode on sequen…
Browse files Browse the repository at this point in the history
…cer (#1712)

fix(gas-pool): changed name normalcy gas pool
  • Loading branch information
elliothllm authored Feb 5, 2025
1 parent 91b020b commit 823248e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion zk/stages/stage_sequence_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func sequencingBatchStep(
batchState := newBatchState(forkId, batchNumberForStateInitialization, executionAt+1, cfg.zk.UseExecutors(), cfg.zk.IsL1Recovery(), cfg.txPool, resequenceBatchJob)
blockDataSizeChecker := NewBlockDataChecker(cfg.zk.ShouldCountersBeUnlimited(batchState.isL1Recovery()))
streamWriter := newSequencerBatchStreamWriter(batchContext, batchState)
normalcyGasPool := new(core.GasPool).AddGas(transactionGasLimit) // used in normalcy mode per block

// injected batch
if executionAt == 0 {
Expand Down Expand Up @@ -471,7 +472,7 @@ func sequencingBatchStep(

// The copying of this structure is intentional
backupDataSizeChecker := *blockDataSizeChecker
receipt, execResult, txCounters, anyOverflow, err := attemptAddTransaction(cfg, sdb, ibs, batchCounters, &blockContext, header, transaction, effectiveGas, batchState.isL1Recovery(), batchState.forkId, l1TreeUpdateIndex, &backupDataSizeChecker)
receipt, execResult, txCounters, anyOverflow, err := attemptAddTransaction(cfg, sdb, ibs, batchCounters, &blockContext, header, transaction, effectiveGas, batchState.isL1Recovery(), batchState.forkId, l1TreeUpdateIndex, &backupDataSizeChecker, normalcyGasPool)
if err != nil {
if batchState.isLimboRecovery() {
panic("limbo transaction has already been executed once so they must not fail while re-executing")
Expand Down
4 changes: 3 additions & 1 deletion zk/stages/stage_sequence_execute_injected_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ func handleInjectedBatch(

batchCounters := vm.NewBatchCounterCollector(batchContext.sdb.smt.GetDepth(), uint16(forkId), batchContext.cfg.zk.VirtualCountersSmtReduction, batchContext.cfg.zk.ShouldCountersBeUnlimited(false), nil)

normalcyGasPool := new(core.GasPool).AddGas(transactionGasLimit)

// process the tx and we can ignore the counters as an overflow at this stage means no network anyway
effectiveGas := DeriveEffectiveGasPrice(*batchContext.cfg, decodedBlocks[0].Transactions[0])
receipt, execResult, _, _, err := attemptAddTransaction(*batchContext.cfg, batchContext.sdb, ibs, batchCounters, blockContext, header, decodedBlocks[0].Transactions[0], effectiveGas, false, forkId, 0 /* use 0 for l1InfoIndex in injected batch */, nil)
receipt, execResult, _, _, err := attemptAddTransaction(*batchContext.cfg, batchContext.sdb, ibs, batchCounters, blockContext, header, decodedBlocks[0].Transactions[0], effectiveGas, false, forkId, 0 /* use 0 for l1InfoIndex in injected batch */, nil, normalcyGasPool)
if err != nil {
return nil, nil, nil, 0, err
}
Expand Down
14 changes: 13 additions & 1 deletion zk/stages/stage_sequence_execute_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package stages

import (
"context"
"errors"

"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/kv"
Expand Down Expand Up @@ -131,6 +132,7 @@ func attemptAddTransaction(
l1Recovery bool,
forkId, l1InfoIndex uint64,
blockDataSizeChecker *BlockDataChecker,
normalcyGasPool *core.GasPool,
) (*types.Receipt, *core.ExecutionResult, *vm.TransactionCounter, overflowType, error) {
var batchDataOverflow, overflow bool
var err error
Expand Down Expand Up @@ -158,7 +160,13 @@ func attemptAddTransaction(
return nil, nil, txCounters, overflowCounters, nil
}

gasPool := new(core.GasPool).AddGas(transactionGasLimit)
// if not normalcy we want to create a gas pool per transaction (zkevm block gas limit is infinite), if normalcy create a pool per block.
var gasPool *core.GasPool
if !cfg.chainConfig.IsNormalcy(blockContext.BlockNumber) {
gasPool = new(core.GasPool).AddGas(transactionGasLimit)
} else {
gasPool = normalcyGasPool
}

// set the counter collector on the config so that we can gather info during the execution
cfg.zkVmConfig.CounterCollector = txCounters.ExecutionCounters()
Expand Down Expand Up @@ -187,6 +195,10 @@ func attemptAddTransaction(
)

if err != nil {
if errors.Is(err, core.ErrGasLimitReached) {
log.Debug("Transaction gas limit reached", "txHash", transaction.Hash())
return nil, nil, txCounters, overflowGas, nil
}
return nil, nil, txCounters, overflowNone, err
}

Expand Down

0 comments on commit 823248e

Please sign in to comment.