add config for tracers

This commit is contained in:
Sina Mahmoodi 2024-02-14 16:52:10 +01:00
parent 4cd7cb3637
commit 674a38ed60
5 changed files with 23 additions and 6 deletions

View File

@ -100,6 +100,7 @@ if one is set. Otherwise it prints the genesis from the datadir.`,
utils.MetricsInfluxDBOrganizationFlag,
utils.TxLookupLimitFlag,
utils.VMTraceFlag,
utils.VMTraceConfigFlag,
utils.TransactionHistoryFlag,
utils.StateHistoryFlag,
}, utils.DatabaseFlags),

View File

@ -18,6 +18,7 @@ package main
import (
"bufio"
"encoding/json"
"errors"
"fmt"
"os"
@ -181,7 +182,11 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
if ctx.IsSet(utils.VMTraceFlag.Name) {
if name := ctx.String(utils.VMTraceFlag.Name); name != "" {
t, err := live.Directory.New(name)
var config string
if ctx.IsSet(utils.VMTraceConfigFlag.Name) {
config = ctx.String(utils.VMTraceConfigFlag.Name)
}
t, err := live.Directory.New(name, json.RawMessage(config))
if err != nil {
utils.Fatalf("Failed to create tracer %q: %v", name, err)
}

View File

@ -138,6 +138,7 @@ var (
utils.DeveloperPeriodFlag,
utils.VMEnableDebugFlag,
utils.VMTraceFlag,
utils.VMTraceConfigFlag,
utils.NetworkIdFlag,
utils.EthStatsURLFlag,
utils.NoCompactionFlag,

View File

@ -21,6 +21,7 @@ import (
"context"
"crypto/ecdsa"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math"
@ -502,7 +503,11 @@ var (
Usage: "Name of tracer which should record internal VM operations (costly)",
Category: flags.VMCategory,
}
VMTraceConfigFlag = &cli.StringFlag{
Name: "vmtrace.config",
Usage: "Tracer configuration (JSON)",
Category: flags.VMCategory,
}
// API options.
RPCGlobalGasCapFlag = &cli.Uint64Flag{
Name: "rpc.gascap",
@ -2128,7 +2133,11 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
vmcfg := vm.Config{EnablePreimageRecording: ctx.Bool(VMEnableDebugFlag.Name)}
if ctx.IsSet(VMTraceFlag.Name) {
if name := ctx.String(VMTraceFlag.Name); name != "" {
t, err := live.Directory.New(name)
var config string
if ctx.IsSet(VMTraceConfigFlag.Name) {
config = ctx.String(VMTraceConfigFlag.Name)
}
t, err := live.Directory.New(name, json.RawMessage(config))
if err != nil {
Fatalf("Failed to create tracer %q: %v", name, err)
}

View File

@ -1,12 +1,13 @@
package live
import (
"encoding/json"
"errors"
"github.com/ethereum/go-ethereum/core"
)
type ctorFunc func() (core.BlockchainLogger, error)
type ctorFunc func(config json.RawMessage) (core.BlockchainLogger, error)
// Directory is the collection of tracers which can be used
// during normal block import operations.
@ -22,9 +23,9 @@ func (d *directory) Register(name string, f ctorFunc) {
}
// New instantiates a tracer by name.
func (d *directory) New(name string) (core.BlockchainLogger, error) {
func (d *directory) New(name string, config json.RawMessage) (core.BlockchainLogger, error) {
if f, ok := d.elems[name]; ok {
return f()
return f(config)
}
return nil, errors.New("not found")
}