@@ -22,6 +22,7 @@ import (
2222 "github.com/ledgerwatch/erigon/core/types"
2323 "github.com/ledgerwatch/erigon/core/types/accounts"
2424 "github.com/ledgerwatch/erigon/core/vm"
25+ "github.com/ledgerwatch/erigon/eth/tracers"
2526 "github.com/ledgerwatch/erigon/polygon/tracer"
2627 "github.com/ledgerwatch/erigon/rpc"
2728 "github.com/ledgerwatch/erigon/turbo/rpchelper"
@@ -224,7 +225,24 @@ func (args *TraceCallParam) ToMessage(globalGasCap uint64, baseFee *uint256.Int)
224225 return msg , nil
225226}
226227
227- // OpenEthereum-style tracer
228+ func parseOeTracerConfig (traceConfig * tracers.TraceConfig ) (OeTracerConfig , error ) {
229+ if traceConfig == nil || traceConfig .TracerConfig == nil || * traceConfig .TracerConfig == nil {
230+ return OeTracerConfig {}, nil
231+ }
232+
233+ var config OeTracerConfig
234+ if err := json .Unmarshal (* traceConfig .TracerConfig , & config ); err != nil {
235+ return OeTracerConfig {}, err
236+ }
237+
238+ return config , nil
239+ }
240+
241+ type OeTracerConfig struct {
242+ IncludePrecompiles bool `json:"includePrecompiles"` // by default Parity/OpenEthereum format does not include precompiles
243+ }
244+
245+ // OeTracer is an OpenEthereum-style tracer
228246type OeTracer struct {
229247 r * TraceCallResult
230248 traceAddr []int
@@ -240,6 +258,7 @@ type OeTracer struct {
240258 lastOffStack * VmTraceOp
241259 vmOpStack []* VmTraceOp // Stack of vmTrace operations as call depth increases
242260 idx []string // Prefix for the "idx" inside operations, for easier navigation
261+ config OeTracerConfig
243262}
244263
245264func (ot * OeTracer ) CaptureTxStart (gasLimit uint64 ) {}
@@ -279,7 +298,9 @@ func (ot *OeTracer) captureStartOrEnter(deep bool, typ vm.OpCode, from libcommon
279298 }
280299 if precompile && deep && (value == nil || value .IsZero ()) {
281300 ot .precompile = true
282- return
301+ if ! ot .config .IncludePrecompiles {
302+ return
303+ }
283304 }
284305 if gas > 500000000 {
285306 gas = 500000001 - (0x8000000000000000 - gas )
@@ -378,7 +399,9 @@ func (ot *OeTracer) captureEndOrExit(deep bool, output []byte, usedGas uint64, e
378399 }
379400 if ot .precompile {
380401 ot .precompile = false
381- return
402+ if ! ot .config .IncludePrecompiles {
403+ return
404+ }
382405 }
383406 if ! deep {
384407 ot .r .Output = libcommon .CopyBytes (output )
@@ -711,7 +734,7 @@ func (sd *StateDiff) CompareStates(initialIbs, ibs *state.IntraBlockState) {
711734 }
712735}
713736
714- func (api * TraceAPIImpl ) ReplayTransaction (ctx context.Context , txHash libcommon.Hash , traceTypes []string , gasBailOut * bool ) (* TraceCallResult , error ) {
737+ func (api * TraceAPIImpl ) ReplayTransaction (ctx context.Context , txHash libcommon.Hash , traceTypes []string , gasBailOut * bool , traceConfig * tracers. TraceConfig ) (* TraceCallResult , error ) {
715738 if gasBailOut == nil {
716739 gasBailOut = new (bool ) // false by default
717740 }
@@ -770,7 +793,7 @@ func (api *TraceAPIImpl) ReplayTransaction(ctx context.Context, txHash libcommon
770793
771794 signer := types .MakeSigner (chainConfig , blockNum , block .Time ())
772795 // Returns an array of trace arrays, one trace array for each transaction
773- traces , _ , err := api .callManyTransactions (ctx , tx , block , traceTypes , txnIndex , * gasBailOut , signer , chainConfig )
796+ traces , _ , err := api .callManyTransactions (ctx , tx , block , traceTypes , txnIndex , * gasBailOut , signer , chainConfig , traceConfig )
774797 if err != nil {
775798 return nil , err
776799 }
@@ -811,7 +834,7 @@ func (api *TraceAPIImpl) ReplayTransaction(ctx context.Context, txHash libcommon
811834 return result , nil
812835}
813836
814- func (api * TraceAPIImpl ) ReplayBlockTransactions (ctx context.Context , blockNrOrHash rpc.BlockNumberOrHash , traceTypes []string , gasBailOut * bool ) ([]* TraceCallResult , error ) {
837+ func (api * TraceAPIImpl ) ReplayBlockTransactions (ctx context.Context , blockNrOrHash rpc.BlockNumberOrHash , traceTypes []string , gasBailOut * bool , traceConfig * tracers. TraceConfig ) ([]* TraceCallResult , error ) {
815838 if gasBailOut == nil {
816839 gasBailOut = new (bool ) // false by default
817840 }
@@ -854,7 +877,7 @@ func (api *TraceAPIImpl) ReplayBlockTransactions(ctx context.Context, blockNrOrH
854877
855878 signer := types .MakeSigner (chainConfig , blockNumber , block .Time ())
856879 // Returns an array of trace arrays, one trace array for each transaction
857- traces , _ , err := api .callManyTransactions (ctx , tx , block , traceTypes , - 1 /* all tx indices */ , * gasBailOut , signer , chainConfig )
880+ traces , _ , err := api .callManyTransactions (ctx , tx , block , traceTypes , - 1 /* all tx indices */ , * gasBailOut , signer , chainConfig , traceConfig )
858881 if err != nil {
859882 return nil , err
860883 }
@@ -882,7 +905,7 @@ func (api *TraceAPIImpl) ReplayBlockTransactions(ctx context.Context, blockNrOrH
882905}
883906
884907// Call implements trace_call.
885- func (api * TraceAPIImpl ) Call (ctx context.Context , args TraceCallParam , traceTypes []string , blockNrOrHash * rpc.BlockNumberOrHash ) (* TraceCallResult , error ) {
908+ func (api * TraceAPIImpl ) Call (ctx context.Context , args TraceCallParam , traceTypes []string , blockNrOrHash * rpc.BlockNumberOrHash , traceConfig * tracers. TraceConfig ) (* TraceCallResult , error ) {
886909 tx , err := api .kv .BeginRo (ctx )
887910 if err != nil {
888911 return nil , err
@@ -952,6 +975,10 @@ func (api *TraceAPIImpl) Call(ctx context.Context, args TraceCallParam, traceTyp
952975 traceResult .VmTrace = & VmTrace {Ops : []* VmTraceOp {}}
953976 }
954977 var ot OeTracer
978+ ot .config , err = parseOeTracerConfig (traceConfig )
979+ if err != nil {
980+ return nil , err
981+ }
955982 ot .compat = api .compatibility
956983 if traceTypeTrace || traceTypeVmTrace {
957984 ot .r = traceResult
@@ -1016,7 +1043,7 @@ func (api *TraceAPIImpl) Call(ctx context.Context, args TraceCallParam, traceTyp
10161043}
10171044
10181045// CallMany implements trace_callMany.
1019- func (api * TraceAPIImpl ) CallMany (ctx context.Context , calls json.RawMessage , parentNrOrHash * rpc.BlockNumberOrHash ) ([]* TraceCallResult , error ) {
1046+ func (api * TraceAPIImpl ) CallMany (ctx context.Context , calls json.RawMessage , parentNrOrHash * rpc.BlockNumberOrHash , traceConfig * tracers. TraceConfig ) ([]* TraceCallResult , error ) {
10201047 dbtx , err := api .kv .BeginRo (ctx )
10211048 if err != nil {
10221049 return nil , err
@@ -1096,12 +1123,13 @@ func (api *TraceAPIImpl) CallMany(ctx context.Context, calls json.RawMessage, pa
10961123 return nil , fmt .Errorf ("convert callParam to msg: %w" , err )
10971124 }
10981125 }
1099- results , _ , err := api .doCallMany (ctx , dbtx , msgs , callParams , parentNrOrHash , nil , true /* gasBailout */ , - 1 /* all tx indices */ )
1126+ results , _ , err := api .doCallMany (ctx , dbtx , msgs , callParams , parentNrOrHash , nil , true /* gasBailout */ , - 1 /* all tx indices */ , traceConfig )
11001127 return results , err
11011128}
11021129
11031130func (api * TraceAPIImpl ) doCallMany (ctx context.Context , dbtx kv.Tx , msgs []types.Message , callParams []TraceCallParam ,
11041131 parentNrOrHash * rpc.BlockNumberOrHash , header * types.Header , gasBailout bool , txIndexNeeded int ,
1132+ traceConfig * tracers.TraceConfig ,
11051133) ([]* TraceCallResult , * state.IntraBlockState , error ) {
11061134 chainConfig , err := api .chainConfig (ctx , dbtx )
11071135 if err != nil {
@@ -1184,6 +1212,10 @@ func (api *TraceAPIImpl) doCallMany(ctx context.Context, dbtx kv.Tx, msgs []type
11841212 vmConfig := vm.Config {}
11851213 if (traceTypeTrace && (txIndexNeeded == - 1 || txIndex == txIndexNeeded )) || traceTypeVmTrace {
11861214 var ot OeTracer
1215+ ot .config , err = parseOeTracerConfig (traceConfig )
1216+ if err != nil {
1217+ return nil , nil , err
1218+ }
11871219 ot .compat = api .compatibility
11881220 ot .r = traceResult
11891221 ot .idx = []string {fmt .Sprintf ("%d-" , txIndex )}
0 commit comments