core: track and expose the dynamic gas calculation time

This commit is contained in:
Ömer Faruk IRMAK 2025-07-08 15:48:58 +03:00
parent 90c6197d2f
commit 58ebc106a6
5 changed files with 15 additions and 1 deletions

View file

@ -97,6 +97,7 @@ var (
blockValidationTimer = metrics.NewRegisteredResettingTimer("chain/validation", nil)
blockCrossValidationTimer = metrics.NewRegisteredResettingTimer("chain/crossvalidation", nil)
blockExecutionTimer = metrics.NewRegisteredResettingTimer("chain/execution", nil)
dynamicGasTimer = metrics.NewRegisteredResettingTimer("chain/execution/dynamicgas", nil)
blockWriteTimer = metrics.NewRegisteredResettingTimer("chain/write", nil)
blockReorgMeter = metrics.NewRegisteredMeter("chain/reorg/executes", nil)
@ -2101,7 +2102,7 @@ func (bc *BlockChain) processBlock(parentRoot common.Hash, block *types.Block, s
blockExecutionTimer.Update(ptime - (statedb.AccountReads + statedb.StorageReads)) // The time spent on EVM processing
blockValidationTimer.Update(vtime - (triehash + trieUpdate)) // The time spent on block validation
blockCrossValidationTimer.Update(xvtime) // The time spent on stateless cross validation
dynamicGasTimer.Update(res.dynamicGasCalculation)
// Write the block to the chain and get the status.
var (
wstart = time.Now()

View file

@ -130,6 +130,8 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
Requests: requests,
Logs: allLogs,
GasUsed: *usedGas,
dynamicGasCalculation: evm.DynamicGasCalculation,
}, nil
}

View file

@ -18,6 +18,7 @@ package core
import (
"sync/atomic"
"time"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
@ -57,4 +58,7 @@ type ProcessResult struct {
Requests [][]byte
Logs []*types.Log
GasUsed uint64
// Time measurements
dynamicGasCalculation time.Duration
}

View file

@ -20,6 +20,7 @@ import (
"errors"
"math/big"
"sync/atomic"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
@ -125,6 +126,9 @@ type EVM struct {
// jumpDests is the aggregated result of JUMPDEST analysis made through
// the life cycle of EVM.
jumpDests map[common.Hash]bitvec
// Time measurements
DynamicGasCalculation time.Duration
}
// NewEVM constructs an EVM instance with the supplied block context, state

View file

@ -18,6 +18,7 @@ package vm
import (
"fmt"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
@ -269,6 +270,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
// All ops with a dynamic memory usage also has a dynamic gas cost.
var memorySize uint64
if operation.dynamicGas != nil {
dynamicGasCalculationStart := time.Now()
// calculate the new memory size and expand the memory to fit
// the operation
// Memory check needs to be done prior to evaluating the dynamic gas portion,
@ -289,6 +291,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
var dynamicCost uint64
dynamicCost, err = operation.dynamicGas(in.evm, contract, stack, mem, memorySize)
cost += dynamicCost // for tracing
in.evm.DynamicGasCalculation += time.Since(dynamicGasCalculationStart)
if err != nil {
return nil, fmt.Errorf("%w: %v", ErrOutOfGas, err)
}