Skip to content

Commit

Permalink
chore: add tracer in app.go
Browse files Browse the repository at this point in the history
  • Loading branch information
arrivets committed Oct 23, 2024
1 parent bd3ef46 commit 7789c56
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
50 changes: 50 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ import (
"github.com/evmos/ethermint/x/evm"
evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
v0evmtypes "github.com/evmos/ethermint/x/evm/migrations/v0/types"
evmtracing "github.com/evmos/ethermint/x/evm/tracing"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/evmos/ethermint/x/feemarket"
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
Expand All @@ -148,6 +149,7 @@ import (
// Force-load the tracer engines to trigger registration due to Go-Ethereum v1.10.15 changes
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
ethparams "github.com/ethereum/go-ethereum/params"
)

func init() {
Expand Down Expand Up @@ -248,6 +250,8 @@ type EthermintApp struct {

// the configurator
configurator module.Configurator

evmTracer *evmtracing.Hooks
}

// NewEthermintApp returns a reference to a new initialized Ethermint application.
Expand Down Expand Up @@ -794,6 +798,27 @@ func NewEthermintApp(
app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper

tracer := cast.ToString(appOpts.Get(srvflags.EVMTracer))

// Currently only the firehose live tracer is supported
if tracer == "firehose" {
liveTracer, err := evmtypes.NewFirehoseCosmosLiveTracer()
if err != nil {
panic(err)
}
app.EvmKeeper.SetTracer(liveTracer)
app.evmTracer = liveTracer
} else if tracer == "access_list" {
panic("access_list tracer is not supported")
} else if tracer != "" {
liveTracer := evmtypes.NewTracer(tracer, nil, ethparams.Rules{})
t := &evmtracing.Hooks{
Hooks: liveTracer.Hooks,
}
app.EvmKeeper.SetTracer(t)
app.evmTracer = t
}

return app
}

Expand Down Expand Up @@ -851,11 +876,26 @@ func (app *EthermintApp) PreBlocker(ctx sdk.Context, _ *abci.RequestFinalizeBloc

// BeginBlocker updates every begin block
func (app *EthermintApp) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error) {
if app.evmTracer != nil {
ctx = evmtracing.SetTracingHooks(ctx, app.evmTracer)
}

// Cosmos chains will only call InitChainer when the chain either starts
// from genesis or is being upgraded and a full state initialization is needed
if app.EvmKeeper != nil && app.EvmKeeper.ChainID() == nil {
app.EvmKeeper.WithChainID(ctx)
app.EvmKeeper.InitChainer(ctx)
}

return app.ModuleManager.BeginBlock(ctx)
}

// EndBlocker updates every end block
func (app *EthermintApp) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) {
if app.evmTracer != nil {
ctx = evmtracing.SetTracingHooks(ctx, app.evmTracer)
}

return app.ModuleManager.EndBlock(ctx)
}

Expand All @@ -872,6 +912,16 @@ func (app *EthermintApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain
if err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()); err != nil {
return nil, err
}

if app.evmTracer != nil {
ctx = evmtracing.SetTracingHooks(ctx, app.evmTracer)
}

if app.EvmKeeper != nil {
app.EvmKeeper.WithChainID(ctx)
app.EvmKeeper.InitChainer(ctx)
}

return app.ModuleManager.InitGenesis(ctx, app.appCodec, genesisState)
}

Expand Down
4 changes: 2 additions & 2 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ which accepts a path for the resulting pprof file.
cmd.Flags().Bool(srvflags.JSONRPCAllowIndexerGap, true, "Allow block gap for the custom tx indexer for json-rpc")
cmd.Flags().Bool(srvflags.JSONRPCEnableMetrics, false, "Define if EVM rpc metrics server should be enabled")

cmd.Flags().String(srvflags.EVMTracer, config.DefaultEVMTracer, "the EVM tracer type to collect execution traces from the EVM transaction execution (json|struct|access_list|markdown)") //nolint:lll
cmd.Flags().Uint64(srvflags.EVMMaxTxGasWanted, config.DefaultMaxTxGasWanted, "the gas wanted for each eth tx returned in ante handler in check tx mode") //nolint:lll
cmd.Flags().String(srvflags.EVMTracer, config.DefaultEVMTracer, "the EVM tracer type to collect execution traces from the EVM transaction execution (json|struct|access_list|markdown|firestore)") //nolint:lll
cmd.Flags().Uint64(srvflags.EVMMaxTxGasWanted, config.DefaultMaxTxGasWanted, "the gas wanted for each eth tx returned in ante handler in check tx mode") //nolint:lll

cmd.Flags().String(srvflags.TLSCertPath, "", "the cert.pem file path for the server TLS configuration")
cmd.Flags().String(srvflags.TLSKeyPath, "", "the key.pem file path for the server TLS configuration")
Expand Down

0 comments on commit 7789c56

Please sign in to comment.