Skip to content
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
4 changes: 2 additions & 2 deletions rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ type EVMBackend interface {
Status() (map[string]hexutil.Uint, error)

// Tracing
TraceTransaction(hash common.Hash, config *evmtypes.TraceConfig) (interface{}, error)
TraceTransaction(hash common.Hash, config *rpctypes.TraceConfig) (interface{}, error)
TraceBlock(
height rpctypes.BlockNumber,
config *evmtypes.TraceConfig,
config *rpctypes.TraceConfig,
block *tmrpctypes.ResultBlock,
) ([]*evmtypes.TxTraceResult, error)
}
Expand Down
7 changes: 5 additions & 2 deletions rpc/backend/evm_query_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,18 @@ func RegisterTraceTransactionError(queryClient *mocks.EVMQueryClient, msgEthTx *
}

// TraceBlock
func RegisterTraceBlock(queryClient *mocks.EVMQueryClient, txs []*evmtypes.MsgEthereumTx) {
func RegisterTraceBlock(queryClient *mocks.EVMQueryClient, txs []*evmtypes.MsgEthereumTx, traceConfig *evmtypes.TraceConfig) {
data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d}
if traceConfig == nil {
traceConfig = &evmtypes.TraceConfig{}
}
queryClient.On(
"TraceBlock",
rpc.ContextWithHeight(1),
&evmtypes.QueryTraceBlockRequest{
Txs: txs,
BlockNumber: 1,
TraceConfig: &evmtypes.TraceConfig{},
TraceConfig: traceConfig,
ChainId: int64(ChainID.EVMChainID),
BlockMaxGas: -1,
},
Expand Down
46 changes: 42 additions & 4 deletions rpc/backend/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

// TraceTransaction returns the structured logs created during the execution of EVM
// and returns them as a JSON object.
func (b *Backend) TraceTransaction(hash common.Hash, config *evmtypes.TraceConfig) (interface{}, error) {
func (b *Backend) TraceTransaction(hash common.Hash, config *rpctypes.TraceConfig) (interface{}, error) {
// Get transaction by hash
transaction, _, err := b.GetTxByEthHash(hash)
if err != nil {
Expand Down Expand Up @@ -77,7 +77,10 @@ func (b *Backend) TraceTransaction(hash common.Hash, config *evmtypes.TraceConfi
}

if config != nil {
traceTxRequest.TraceConfig = config
traceTxRequest.TraceConfig, err = toEVMTraceConfig(config)
if err != nil {
return nil, err
}
}

// minus one to get the context of block beginning
Expand Down Expand Up @@ -106,7 +109,7 @@ func (b *Backend) TraceTransaction(hash common.Hash, config *evmtypes.TraceConfi
// executes all the transactions contained within. The return value will be one item
// per transaction, dependent on the requested tracer.
func (b *Backend) TraceBlock(height rpctypes.BlockNumber,
config *evmtypes.TraceConfig,
config *rpctypes.TraceConfig,
block *tmrpctypes.ResultBlock,
) ([]*evmtypes.TxTraceResult, error) {
txs := block.Block.Txs
Expand All @@ -132,6 +135,11 @@ func (b *Backend) TraceBlock(height rpctypes.BlockNumber,
}
ctxWithHeight := rpctypes.ContextWithHeight(int64(contextHeight))

traceConfig, err := toEVMTraceConfig(config)
if err != nil {
return nil, err
}

nc, ok := b.ClientCtx.Client.(tmrpcclient.NetworkClient)
if !ok {
return nil, errors.New("invalid rpc client")
Expand All @@ -144,7 +152,7 @@ func (b *Backend) TraceBlock(height rpctypes.BlockNumber,

traceBlockRequest := &evmtypes.QueryTraceBlockRequest{
Txs: msgs,
TraceConfig: config,
TraceConfig: traceConfig,
BlockNumber: block.Block.Height,
BlockTime: block.Block.Time,
BlockHash: common.Bytes2Hex(block.BlockID.Hash),
Expand All @@ -165,3 +173,33 @@ func (b *Backend) TraceBlock(height rpctypes.BlockNumber,

return decodedResults, nil
}

// toEVMTraceConfig converts rpctypes.TraceConfig to evmtypes.TraceConfig
func toEVMTraceConfig(config *rpctypes.TraceConfig) (*evmtypes.TraceConfig, error) {
if config == nil {
return nil, nil
}

cfg := config.TraceConfig

// if TracerConfig is an object, we need to encode it into JSON string
if config.TracerConfig != nil && config.TracerJsonConfig == "" {
switch v := config.TracerConfig.(type) {
case string:
// It's already a string, use it directly
cfg.TracerJsonConfig = v
case map[string]interface{}:
// this is the compliant style
// we need to encode it to a string before passing it to the ethermint side
jsonBytes, err := json.Marshal(v)
if err != nil {
return nil, fmt.Errorf("unable to encode traceConfig to JSON: %w", err)
}
cfg.TracerJsonConfig = string(jsonBytes)
default:
return nil, fmt.Errorf("unexpected traceConfig type: %T", v)
}
}

return &cfg, nil
}
17 changes: 13 additions & 4 deletions rpc/backend/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/cosmos/evm/indexer"
evmtypes "github.com/cosmos/evm/x/vm/types"
"github.com/zeta-chain/node/rpc/backend/mocks"
rpctypes "github.com/zeta-chain/node/rpc/types"

"cosmossdk.io/log"

Expand Down Expand Up @@ -280,29 +281,37 @@ func (s *TestSuite) TestTraceBlock() {
registerMock func()
expTraceResults []*evmtypes.TxTraceResult
resBlock *tmrpctypes.ResultBlock
config *evmtypes.TraceConfig
config *rpctypes.TraceConfig
expPass bool
}{
{
"pass - no transaction returning empty array",
func() {},
[]*evmtypes.TxTraceResult{},
&resBlockEmpty,
&evmtypes.TraceConfig{},
&rpctypes.TraceConfig{},
true,
},
{
"fail - cannot unmarshal data",
func() {
QueryClient := s.backend.QueryClient.QueryClient.(*mocks.EVMQueryClient)
client := s.backend.ClientCtx.Client.(*mocks.Client)
RegisterTraceBlock(QueryClient, []*evmtypes.MsgEthereumTx{msgEthTx})
// convert rpctypes.TraceConfig to evmtypes.TraceConfig by marshaling the map to JSON string
traceConfig := &evmtypes.TraceConfig{
TracerJsonConfig: `{"disableCode":true}`,
}
RegisterTraceBlock(QueryClient, []*evmtypes.MsgEthereumTx{msgEthTx}, traceConfig)
RegisterConsensusParams(client, 1)
RegisterBlockResults(client, 1)
},
[]*evmtypes.TxTraceResult{},
&resBlockFilled,
&evmtypes.TraceConfig{},
&rpctypes.TraceConfig{
TracerConfig: map[string]interface{}{
"disableCode": true,
},
},
false,
},
}
Expand Down
6 changes: 3 additions & 3 deletions rpc/namespaces/ethereum/debug/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewAPI(

// TraceTransaction returns the structured logs created during the execution of EVM
// and returns them as a JSON object.
func (a *API) TraceTransaction(hash common.Hash, config *evmtypes.TraceConfig) (interface{}, error) {
func (a *API) TraceTransaction(hash common.Hash, config *rpctypes.TraceConfig) (interface{}, error) {
a.logger.Debug("debug_traceTransaction", "hash", hash)
return a.backend.TraceTransaction(hash, config)
}
Expand All @@ -68,7 +68,7 @@ func (a *API) TraceTransaction(hash common.Hash, config *evmtypes.TraceConfig) (
// EVM and returns them as a JSON object.
func (a *API) TraceBlockByNumber(
height rpctypes.BlockNumber,
config *evmtypes.TraceConfig,
config *rpctypes.TraceConfig,
) ([]*evmtypes.TxTraceResult, error) {
a.logger.Debug("debug_traceBlockByNumber", "height", height)
if height == 0 {
Expand All @@ -86,7 +86,7 @@ func (a *API) TraceBlockByNumber(

// TraceBlockByHash returns the structured logs created during the execution of
// EVM and returns them as a JSON object.
func (a *API) TraceBlockByHash(hash common.Hash, config *evmtypes.TraceConfig) ([]*evmtypes.TxTraceResult, error) {
func (a *API) TraceBlockByHash(hash common.Hash, config *rpctypes.TraceConfig) ([]*evmtypes.TxTraceResult, error) {
a.logger.Debug("debug_traceBlockByHash", "hash", hash)
// Get Tendermint Block
resBlock, err := a.backend.TendermintBlockByHash(hash)
Expand Down
Loading