Skip to content

Commit e356d7d

Browse files
authored
fix: reth compatible trace config (#160)
* Make the trace config object case sensitive We noticed that the TraceConfig struct from github.com/ethereum/go-ethereum/eth/tracers didn't specify json tags, which made it encode like: { "Tracer": "callTracer" }. Geth decodes this correctly to use "callTracer", but Reth interprets this as passing a null tracer, since it's only looking for the "tracer" field. This struct is only used internally to mesh-geth-sdk for encoding as a parameter to go-ethereum client's CallContext method so replacing it with a custom struct should be safe. * remove println from test
1 parent 9e2c6d7 commit e356d7d

3 files changed

Lines changed: 31 additions & 12 deletions

File tree

client/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import (
3939
"github.com/ethereum/go-ethereum/consensus/ethash"
4040
"github.com/ethereum/go-ethereum/core"
4141
EthTypes "github.com/ethereum/go-ethereum/core/types"
42-
"github.com/ethereum/go-ethereum/eth/tracers"
4342
"github.com/ethereum/go-ethereum/p2p"
4443
"github.com/ethereum/go-ethereum/params"
4544
"github.com/ethereum/go-ethereum/rpc"
@@ -48,7 +47,7 @@ import (
4847

4948
type SDKClient struct {
5049
P *params.ChainConfig
51-
tc *tracers.TraceConfig
50+
tc *RethCompatibleTraceConfig
5251
customizedTc interface{}
5352

5453
rosettaConfig configuration.RosettaConfig
@@ -1005,7 +1004,8 @@ func (ec *SDKClient) GetBlockReceipts(
10051004
}
10061005

10071006
func (ec *SDKClient) GetNativeTransferGasLimit(ctx context.Context, toAddress string,
1008-
fromAddress string, value *big.Int) (uint64, error) {
1007+
fromAddress string, value *big.Int,
1008+
) (uint64, error) {
10091009
return 0, errors.New("GetNativeTransferGasLimit not implemented")
10101010
}
10111011

client/tracer.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"github.com/ethereum/go-ethereum/common"
2424
"github.com/ethereum/go-ethereum/common/hexutil"
25-
"github.com/ethereum/go-ethereum/eth/tracers"
25+
"github.com/ethereum/go-ethereum/eth/tracers/logger"
2626
)
2727

2828
// convert raw eth data from SDKClient to rosetta
@@ -36,24 +36,43 @@ var (
3636
nativeTracer = "callTracer"
3737
)
3838

39-
func GetTraceConfig(useNative bool) (*tracers.TraceConfig, error) {
39+
// RethCompatibleTraceConfig copies the fields from github.com/ethereum/go-ethereum/eth/tracers.TraceConfig
40+
// but defines json-encoding tags that use the correct casing. We've seen that geth is case-insensitive,
41+
// but reth implementations are case-sensitive (because they use the rust standard library `serde`).
42+
//
43+
// Using the builtin geth trace config struct when calling reth nodes causes the default tracer
44+
// to be used instead of callTracer, which causes the node to return huge (1.5Gb) payloads that consume
45+
// lots of resources on the node and client.
46+
type RethCompatibleTraceConfig struct {
47+
*logger.Config
48+
49+
Tracer *string `json:"tracer"`
50+
Timeout *string `json:"timeout"`
51+
Reexec *uint64 `json:"reexec"`
52+
53+
// Config specific to given tracer. Note struct logger
54+
// config are historically embedded in main object.
55+
TracerConfig json.RawMessage `json:"tracerConfig"`
56+
}
57+
58+
func GetTraceConfig(useNative bool) (*RethCompatibleTraceConfig, error) {
4059
if useNative {
41-
return &tracers.TraceConfig{
60+
return &RethCompatibleTraceConfig{
4261
Timeout: &tracerTimeout,
4362
Tracer: &nativeTracer,
4463
}, nil
4564
}
4665
return loadTraceConfig()
4766
}
4867

49-
func loadTraceConfig() (*tracers.TraceConfig, error) {
68+
func loadTraceConfig() (*RethCompatibleTraceConfig, error) {
5069
loadedFile, err := os.ReadFile(tracerPath)
5170
if err != nil {
5271
return nil, fmt.Errorf("could not load tracer file: %w", err)
5372
}
5473

5574
loadedTracer := string(loadedFile)
56-
return &tracers.TraceConfig{
75+
return &RethCompatibleTraceConfig{
5776
Timeout: &tracerTimeout,
5877
Tracer: &loadedTracer,
5978
}, nil

services/construction/contract_call_data_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package construction
1616

1717
import (
1818
"errors"
19-
"fmt"
2019
"testing"
2120

2221
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -114,7 +113,6 @@ func TestConstruction_ContractCallData(t *testing.T) {
114113
t.Run(name, func(t *testing.T) {
115114
bytes, err := ConstructContractCallDataGeneric(test.methodSig, test.methodArgs)
116115
if err != nil {
117-
fmt.Println(err)
118116
assert.EqualError(t, err, test.expectedError.Error())
119117
} else {
120118
assert.Equal(t, test.expectedResponse, hexutil.Encode(bytes))
@@ -137,12 +135,14 @@ func TestConstruction_preprocessArgs(t *testing.T) {
137135
"0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22",
138136
"32941055343948244352",
139137
"0",
140-
"0x"},
138+
"0x",
139+
},
141140
expectedResponse: []interface{}{
142141
"0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22",
143142
"32941055343948244352",
144143
"0",
145-
"0x"},
144+
"0x",
145+
},
146146
},
147147
"happy path: method sig is empty and args is nil": {
148148
methodSig: "",

0 commit comments

Comments
 (0)