From d91f5a96f55063e7c3a636e4763be9ea1d7580db Mon Sep 17 00:00:00 2001 From: huangyi Date: Mon, 23 Sep 2024 16:06:07 +0800 Subject: [PATCH] Problem: trace block not accurate for dynamic fee transaction --- x/evm/keeper/state_transition.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index 02e534f822..9c1b3e98d7 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -337,7 +337,14 @@ func (k *Keeper) ApplyMessageWithConfig( if vmCfg.Tracer != nil { if cfg.DebugTrace { // msg.GasPrice should have been set to effective gas price - stateDB.SubBalance(sender.Address(), new(big.Int).Mul(msg.GasPrice, new(big.Int).SetUint64(msg.GasLimit))) + var gasPrice *big.Int + if cfg.BaseFee == nil { + gasPrice = msg.GasPrice + } else { + // for legacy tx, the GasFeeCap/GasTipCap defaults to GasPrice, so it's compatible. + gasPrice = types.EffectiveGasPrice(cfg.BaseFee, msg.GasFeeCap, msg.GasTipCap) + } + stateDB.SubBalance(sender.Address(), new(big.Int).Mul(gasPrice, new(big.Int).SetUint64(msg.GasLimit))) stateDB.SetNonce(sender.Address(), stateDB.GetNonce(sender.Address())+1) } vmCfg.Tracer.CaptureTxStart(leftoverGas)