Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move NewTracer to keeper #126

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
lumtis marked this conversation as resolved.
Show resolved Hide resolved
logCfg := &logger.Config{
Debug: true,
}
gartnera marked this conversation as resolved.
Show resolved Hide resolved

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)
gartnera marked this conversation as resolved.
Show resolved Hide resolved
case types.TracerJSON:
return logger.NewJSONLogger(logCfg, os.Stderr)
case types.TracerMarkdown:
return logger.NewMarkdownLogger(logCfg, os.Stdout) // TODO: Stderr ?
lumtis marked this conversation as resolved.
Show resolved Hide resolved
case types.TracerStruct:
return logger.NewStructLogger(logCfg)
default:
return types.NewNoOpTracer()
}
gartnera marked this conversation as resolved.
Show resolved Hide resolved
}
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
Loading