Skip to content

Commit

Permalink
Fix on tx end hook call
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduard-Voiculescu committed Oct 16, 2024
1 parent 7867d50 commit b7a2952
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package keeper
import (
"bytes"
"fmt"
cosmostracing "github.com/evmos/ethermint/x/evm/tracing"
"math/big"
"sort"

Expand Down Expand Up @@ -74,11 +73,6 @@ func (k *Keeper) NewEVM(
}
txCtx := core.NewEVMTxContext(msg)

// Set Config Tracer if it was not already initialized
if tracer := cosmostracing.GetCtxBlockchainTracer(ctx); tracer != nil {
cfg.Tracer = tracer
}

vmConfig := k.VMConfig(ctx, cfg)
contracts := make(map[common.Address]vm.PrecompiledContract)
active := make([]common.Address, 0)
Expand Down Expand Up @@ -239,6 +233,24 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, msgEth *types.MsgEthereumTx)
}
}

defer func() {
// These errors are not vm related, so they should not be passed to the vm tracer
if errorsmod.IsOf(applyMessageErr, types.ErrCreateDisabled, types.ErrCallDisabled) {
return
}

if applyMessageErr != nil && applyMessageErr.Error() != configOverridesErrDesc {
return
}

if cfg.Tracer != nil && cfg.Tracer.OnTxEnd != nil {
cfg.Tracer.OnTxEnd(
receipt,
applyMessageErr,
)
}
}()

// refund gas in order to match the Ethereum gas consumption instead of the default SDK one.
if err = k.RefundGas(ctx, msg, msg.GasLimit-res.GasUsed, cfg.Params.EvmDenom); err != nil {
return nil, errorsmod.Wrapf(err, "failed to refund leftover gas to sender %s", msg.From)
Expand All @@ -252,18 +264,6 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, msgEth *types.MsgEthereumTx)
// reset the gas meter for current cosmos transaction
k.ResetGasMeterAndConsumeGas(ctx, totalGasUsed)

defer func() {
// These errors are not vm related, so they should not be passed to the vm tracer
if !errorsmod.IsOf(applyMessageErr, types.ErrCreateDisabled, types.ErrCallDisabled) && (applyMessageErr != nil && applyMessageErr.Error() != configOverridesErrDesc) {
if cfg.Tracer != nil && cfg.Tracer.OnTxEnd != nil {
cfg.Tracer.OnTxEnd(
receipt,
applyMessageErr,
)
}
}
}()

return res, nil
}

Expand Down

0 comments on commit b7a2952

Please sign in to comment.