Skip to content

Commit

Permalink
chore: move NewTracer to keeper (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Sep 27, 2024
1 parent 2fad916 commit f34e2a4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 29 deletions.
2 changes: 1 addition & 1 deletion x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func (k *Keeper) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *et

// Tracer return a default vm.Tracer based on current keeper state
func (k Keeper) Tracer(ctx sdk.Context, msg core.Message, ethCfg *params.ChainConfig) vm.EVMLogger {
return types.NewTracer(k.tracer, msg, ethCfg, ctx.BlockHeight())
return NewTracer(k.tracer, msg, ethCfg, ctx.BlockHeight())
}

// GetAccountWithoutBalance load nonce and codehash without balance,
Expand Down
50 changes: 50 additions & 0 deletions x/evm/keeper/tracer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2021 Evmos Foundation
// This file is part of Evmos' Ethermint library.
//
// The Ethermint library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The Ethermint library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Ethermint library. If not, see https://github.com/zeta-chain/ethermint/blob/main/LICENSE
package keeper

import (
"math/big"
"os"

"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/params"
"github.com/zeta-chain/ethermint/x/evm/types"
)

// NewTracer creates a new Logger tracer to collect execution traces from an
// EVM transaction.
func NewTracer(tracer string, msg core.Message, cfg *params.ChainConfig, height int64) vm.EVMLogger {
// TODO: enable additional log configuration
logCfg := &logger.Config{
Debug: true,
}

switch tracer {
case types.TracerAccessList:
preCompiles := vm.DefaultActivePrecompiles(cfg.Rules(big.NewInt(height), cfg.MergeNetsplitBlock != nil))
return logger.NewAccessListTracer(msg.AccessList(), msg.From(), *msg.To(), preCompiles)
case types.TracerJSON:
return logger.NewJSONLogger(logCfg, os.Stderr)
case types.TracerMarkdown:
return logger.NewMarkdownLogger(logCfg, os.Stdout) // TODO: Stderr ?
case types.TracerStruct:
return logger.NewStructLogger(logCfg)
default:
return types.NewNoOpTracer()
}
}
28 changes: 0 additions & 28 deletions x/evm/types/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ package types

import (
"math/big"
"os"
"time"

"github.com/ethereum/go-ethereum/eth/tracers/logger"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"
)

const (
Expand All @@ -35,29 +30,6 @@ const (
TracerMarkdown = "markdown"
)

// NewTracer creates a new Logger tracer to collect execution traces from an
// EVM transaction.
func NewTracer(tracer string, msg core.Message, cfg *params.ChainConfig, height int64) vm.EVMLogger {
// TODO: enable additional log configuration
logCfg := &logger.Config{
Debug: true,
}

switch tracer {
case TracerAccessList:
preCompiles := vm.DefaultActivePrecompiles(cfg.Rules(big.NewInt(height), cfg.MergeNetsplitBlock != nil))
return logger.NewAccessListTracer(msg.AccessList(), msg.From(), *msg.To(), preCompiles)
case TracerJSON:
return logger.NewJSONLogger(logCfg, os.Stderr)
case TracerMarkdown:
return logger.NewMarkdownLogger(logCfg, os.Stdout) // TODO: Stderr ?
case TracerStruct:
return logger.NewStructLogger(logCfg)
default:
return NewNoOpTracer()
}
}

// TxTraceResult is the result of a single transaction trace during a block trace.
type TxTraceResult struct {
Result interface{} `json:"result,omitempty"` // Trace results produced by the tracer
Expand Down

0 comments on commit f34e2a4

Please sign in to comment.